mirror of
https://github.com/rancher/steve.git
synced 2025-09-08 02:39:26 +00:00
Hard-wire external associations: 3 sections in, this one is 4/7 (#645)
* Continue rebasing. * Wrote unit tests for external associations. * Fix the generated SQL. Some syntactic sugar (capitalizing the keywords), but use the 'ON' syntax on JOINs. * whitespace fix post rebase * We want "management.cattle.io.projects:spec.displayName" not "...spec.clusterName" * Fix the database calls: drop the key * Fix breakage during automatic rebase merging gone wrong. * ws fix - NFC * Post rebase-merge fixes * Fix rebase-driven merge. * Fix rebase breakage. * go-uber v0.5.2 prefers real arg names to '<argN>'
This commit is contained in:
@@ -44,6 +44,7 @@ type Client interface {
|
||||
QueryForRows(ctx context.Context, stmt transaction.Stmt, params ...any) (*sql.Rows, error)
|
||||
ReadObjects(rows Rows, typ reflect.Type, shouldDecrypt bool) ([]any, error)
|
||||
ReadStrings(rows Rows) ([]string, error)
|
||||
ReadStrings2(rows Rows) ([][]string, error)
|
||||
ReadInt(rows Rows) (int, error)
|
||||
Upsert(tx transaction.Client, stmt *sql.Stmt, key string, obj any, shouldEncrypt bool) error
|
||||
CloseStmt(closable Closable) error
|
||||
@@ -265,6 +266,34 @@ func (c *client) ReadStrings(rows Rows) ([]string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ReadStrings2 scans the given rows into pairs of strings, and then returns the strings as a slice.
|
||||
func (c *client) ReadStrings2(rows Rows) ([][]string, error) {
|
||||
c.connLock.RLock()
|
||||
defer c.connLock.RUnlock()
|
||||
|
||||
var result [][]string
|
||||
for rows.Next() {
|
||||
var key1, key2 string
|
||||
err := rows.Scan(&key1, &key2)
|
||||
if err != nil {
|
||||
return nil, closeRowsOnError(rows, err)
|
||||
}
|
||||
|
||||
result = append(result, []string{key1, key2})
|
||||
}
|
||||
err := rows.Err()
|
||||
if err != nil {
|
||||
return nil, closeRowsOnError(rows, err)
|
||||
}
|
||||
|
||||
err = rows.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ReadInt scans the first of the given rows into a single int (eg. for COUNT() queries)
|
||||
func (c *client) ReadInt(rows Rows) (int, error) {
|
||||
c.connLock.RLock()
|
||||
|
Reference in New Issue
Block a user