Skip to content

Commit

Permalink
fixup! feat: sqlconnect library
Browse files Browse the repository at this point in the history
  • Loading branch information
atzoum committed Mar 4, 2024
1 parent 787c042 commit c1fff79
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
1 change: 0 additions & 1 deletion sqlconnect/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ type RowMapper[T any] func(cols []*sql.ColumnType, row RowScan) (T, error)
// JSONRowMapper returns a row mapper that scans rows and maps them to [map[string]any]
func JSONRowMapper(valueMapper func(databaseTypeName string, value any) any) RowMapper[map[string]any] {
return func(cols []*sql.ColumnType, row RowScan) (map[string]any, error) {
// scan all values in nullable strings
values := make([]any, len(cols))
for i := range values {
values[i] = new(NilAny)
Expand Down
6 changes: 3 additions & 3 deletions sqlconnect/internal/base/tableadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ func (db *DB) ListColumnsForSqlQuery(ctx context.Context, sql string) ([]sqlconn
}

// CountTableRows returns the number of rows in the given table
func (c *DB) CountTableRows(ctx context.Context, table sqlconnect.RelationRef) (int, error) {
func (c *DB) CountTableRows(ctx context.Context, relation sqlconnect.RelationRef) (int, error) {
var count int
if err := c.QueryRowContext(ctx, c.sqlCommands.CountTableRows(c.QuoteTable(table))).Scan(&count); err != nil {
return 0, fmt.Errorf("counting table rows for %s: %w", table.String(), err)
if err := c.QueryRowContext(ctx, c.sqlCommands.CountTableRows(c.QuoteTable(relation))).Scan(&count); err != nil {
return 0, fmt.Errorf("counting table rows for %s: %w", relation.String(), err)
}
return count, nil
}
Expand Down
6 changes: 6 additions & 0 deletions sqlconnect/internal/bigquery/legacy_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func legacyColumnTypeMapper(columnType base.ColumnType) string {
if mappedType, ok := columnTypeMappings[strings.ToUpper(databaseTypeName)]; ok {
return mappedType
}
if databaseTypeName == "ARRAY" {
return "array"
}
if databaseTypeName == "STRUCT" {
return "RECORD"
}
return databaseTypeName
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_order": "int",
"_array": "ARRAY",
"_array": "array",
"_bignumeric": "float",
"_bignumericnoscale": "float",
"_bigdecimal": "float",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_order": "int",
"_array": "ARRAY",
"_array": "array",
"_bignumeric": "float",
"_bignumericnoscale": "float",
"_bigdecimal": "float",
Expand All @@ -23,7 +23,7 @@
"_numeric": "float",
"_decimal": "float",
"_string": "string",
"_struct": "STRUCT",
"_struct": "RECORD",
"_time": "datetime",
"_timestamp": "datetime"
}

0 comments on commit c1fff79

Please sign in to comment.