(ctx context.Context, tableName string, pks []string)
| 10 | ) |
| 11 | |
| 12 | func (c *Client) getTableColumns(ctx context.Context, tableName string, pks []string) (schema.ColumnList, error) { |
| 13 | query, params := queries.GetTableSchema(c.spec.Schema, tableName) |
| 14 | |
| 15 | rows, err := c.db.QueryContext(ctx, query, params...) |
| 16 | if err != nil { |
| 17 | c.logErr(err) |
| 18 | return nil, err |
| 19 | } |
| 20 | |
| 21 | columns := make(schema.ColumnList, 0) |
| 22 | if err := processRows(rows, func(row *sql.Rows) error { |
| 23 | var name string |
| 24 | var sqlType string |
| 25 | var nullable string |
| 26 | var charMaxLength *string |
| 27 | |
| 28 | if err := row.Scan(&name, &sqlType, &nullable, &charMaxLength); err != nil { |
| 29 | return err |
| 30 | } |
| 31 | |
| 32 | if (sqlType == "nvarchar" || sqlType == "varbinary") && charMaxLength != nil { |
| 33 | if *charMaxLength == "-1" { |
| 34 | *charMaxLength = "max" |
| 35 | } |
| 36 | sqlType += "(" + *charMaxLength + ")" |
| 37 | } |
| 38 | |
| 39 | dataType := queries.SchemaType(sqlType) |
| 40 | |
| 41 | columns = append(columns, schema.Column{ |
| 42 | Name: name, |
| 43 | Type: dataType, |
| 44 | PrimaryKey: slices.Contains(pks, name), |
| 45 | NotNull: nullable == "NO", |
| 46 | }) |
| 47 | |
| 48 | return nil |
| 49 | }); err != nil { |
| 50 | c.logErr(err) |
| 51 | return nil, err |
| 52 | } |
| 53 | |
| 54 | return slices.Clip(columns), nil |
| 55 | } |
| 56 | |
| 57 | func (c *Client) getTablePK(ctx context.Context, tableName string) ([]string, error) { |
| 58 | query, params := queries.GetTablePK(c.spec.Schema, tableName) |
no test coverage detected