diff --git a/internal/cmd/shim.go b/internal/cmd/shim.go index 16534707b8..35c5dc00ea 100644 --- a/internal/cmd/shim.go +++ b/internal/cmd/shim.go @@ -166,10 +166,11 @@ func pluginCatalog(c *catalog.Catalog) *plugin.Catalog { Schema: c.Type.Schema, Name: c.Type.Name, }, - Comment: c.Comment, - NotNull: c.IsNotNull, - IsArray: c.IsArray, - Length: int32(l), + Comment: c.Comment, + NotNull: c.IsNotNull, + IsArray: c.IsArray, + ArrayBounds: int32(c.ArrayBounds), + Length: int32(l), Table: &plugin.Identifier{ Catalog: t.Rel.Catalog, Schema: t.Rel.Schema, @@ -246,6 +247,7 @@ func pluginQueryColumn(c *compiler.Column) *plugin.Column { Comment: c.Comment, NotNull: c.NotNull, IsArray: c.IsArray, + ArrayBounds: int32(c.ArrayBounds), Length: int32(l), IsNamedParam: c.IsNamedParam, IsFuncCall: c.IsFuncCall, diff --git a/internal/codegen/golang/go_type.go b/internal/codegen/golang/go_type.go index 01b1c1c807..7641f2643e 100644 --- a/internal/codegen/golang/go_type.go +++ b/internal/codegen/golang/go_type.go @@ -38,7 +38,11 @@ func goType(req *plugin.CodeGenRequest, col *plugin.Column) string { } typ := goInnerType(req, col) if col.IsArray || col.IsSqlcSlice { - return "[]" + typ + dims := "" + for i := int32(0); i < col.ArrayBounds; i++ { + dims += "[]" + } + return dims + typ } return typ } diff --git a/internal/compiler/output_columns.go b/internal/compiler/output_columns.go index 8a450470bc..21a4c5c1a7 100644 --- a/internal/compiler/output_columns.go +++ b/internal/compiler/output_columns.go @@ -26,12 +26,13 @@ func (c *Compiler) OutputColumns(stmt ast.Node) ([]*catalog.Column, error) { catCols := make([]*catalog.Column, 0, len(cols)) for _, col := range cols { catCols = append(catCols, &catalog.Column{ - Name: col.Name, - Type: ast.TypeName{Name: col.DataType}, - IsNotNull: col.NotNull, - IsArray: col.IsArray, - Comment: col.Comment, - Length: col.Length, + Name: col.Name, + Type: ast.TypeName{Name: col.DataType}, + IsNotNull: col.NotNull, + IsArray: col.IsArray, + ArrayBounds: col.ArrayBounds, + Comment: col.Comment, + Length: col.Length, }) } return catCols, nil @@ -248,15 +249,16 @@ func outputColumns(qc *QueryCatalog, node ast.Node) ([]*Column, error) { cname = *res.Name } cols = append(cols, &Column{ - Name: cname, - Type: c.Type, - Scope: scope, - Table: c.Table, - TableAlias: t.Rel.Name, - DataType: c.DataType, - NotNull: c.NotNull, - IsArray: c.IsArray, - Length: c.Length, + Name: cname, + Type: c.Type, + Scope: scope, + Table: c.Table, + TableAlias: t.Rel.Name, + DataType: c.DataType, + NotNull: c.NotNull, + IsArray: c.IsArray, + ArrayBounds: c.ArrayBounds, + Length: c.Length, }) } } @@ -545,15 +547,16 @@ func outputColumnRefs(res *ast.ResTarget, tables []*Table, node *ast.ColumnRef) cname = *res.Name } cols = append(cols, &Column{ - Name: cname, - Type: c.Type, - Table: c.Table, - TableAlias: alias, - DataType: c.DataType, - NotNull: c.NotNull, - IsArray: c.IsArray, - Length: c.Length, - EmbedTable: c.EmbedTable, + Name: cname, + Type: c.Type, + Table: c.Table, + TableAlias: alias, + DataType: c.DataType, + NotNull: c.NotNull, + IsArray: c.IsArray, + ArrayBounds: c.ArrayBounds, + Length: c.Length, + EmbedTable: c.EmbedTable, }) } } diff --git a/internal/compiler/query.go b/internal/compiler/query.go index 97066f1733..9dca173ddb 100644 --- a/internal/compiler/query.go +++ b/internal/compiler/query.go @@ -19,6 +19,7 @@ type Column struct { DataType string NotNull bool IsArray bool + ArrayBounds int Comment string Length *int IsNamedParam bool diff --git a/internal/compiler/query_catalog.go b/internal/compiler/query_catalog.go index 79ceeba75e..1e7a6cb6bc 100644 --- a/internal/compiler/query_catalog.go +++ b/internal/compiler/query_catalog.go @@ -52,13 +52,14 @@ func buildQueryCatalog(c *catalog.Catalog, node ast.Node, embeds rewrite.EmbedSe func ConvertColumn(rel *ast.TableName, c *catalog.Column) *Column { return &Column{ - Table: rel, - Name: c.Name, - DataType: dataType(&c.Type), - NotNull: c.IsNotNull, - IsArray: c.IsArray, - Type: &c.Type, - Length: c.Length, + Table: rel, + Name: c.Name, + DataType: dataType(&c.Type), + NotNull: c.IsNotNull, + IsArray: c.IsArray, + ArrayBounds: c.ArrayBounds, + Type: &c.Type, + Length: c.Length, } } diff --git a/internal/compiler/resolve.go b/internal/compiler/resolve.go index 1caef55d10..1c2b7798cb 100644 --- a/internal/compiler/resolve.go +++ b/internal/compiler/resolve.go @@ -215,6 +215,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar, DataType: dataType(&c.Type), NotNull: p.NotNull(), IsArray: c.IsArray, + ArrayBounds: c.ArrayBounds, Length: c.Length, Table: table, IsNamedParam: isNamed, @@ -274,6 +275,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar, DataType: dataType(&c.Type), NotNull: p.NotNull(), IsArray: c.IsArray, + ArrayBounds: c.ArrayBounds, Table: table, IsNamedParam: isNamed, }, @@ -445,6 +447,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar, DataType: dataType(&c.Type), NotNull: p.NotNull(), IsArray: c.IsArray, + ArrayBounds: c.ArrayBounds, Table: &ast.TableName{Schema: schema, Name: rel}, Length: c.Length, IsNamedParam: isNamed, @@ -552,6 +555,7 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar, DataType: dataType(&c.Type), NotNull: c.IsNotNull, IsArray: c.IsArray, + ArrayBounds: c.ArrayBounds, Table: table, IsNamedParam: isNamed, IsSqlcSlice: p.IsSqlcSlice(), diff --git a/internal/compiler/to_column.go b/internal/compiler/to_column.go index 14dee0ac2f..11498529b7 100644 --- a/internal/compiler/to_column.go +++ b/internal/compiler/to_column.go @@ -23,9 +23,10 @@ func toColumn(n *ast.TypeName) *Column { panic("toColumn: " + err.Error()) } return &Column{ - Type: typ, - DataType: strings.TrimPrefix(astutils.Join(n.Names, "."), "."), - NotNull: true, // XXX: How do we know if this should be null? - IsArray: isArray(n), + Type: typ, + DataType: strings.TrimPrefix(astutils.Join(n.Names, "."), "."), + NotNull: true, // XXX: How do we know if this should be null? + IsArray: isArray(n), + ArrayBounds: len(n.ArrayBounds.Items), } } diff --git a/internal/endtoend/testdata/multidimension_array/pgx/v4/go/db.go b/internal/endtoend/testdata/multidimension_array/pgx/v4/go/db.go new file mode 100644 index 0000000000..439db75e69 --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/pgx/v4/go/db.go @@ -0,0 +1,32 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.17.2 + +package querytest + +import ( + "context" + + "github.com/jackc/pgconn" + "github.com/jackc/pgx/v4" +) + +type DBTX interface { + Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error) + Query(context.Context, string, ...interface{}) (pgx.Rows, error) + QueryRow(context.Context, string, ...interface{}) pgx.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx pgx.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/internal/endtoend/testdata/multidimension_array/pgx/v4/go/models.go b/internal/endtoend/testdata/multidimension_array/pgx/v4/go/models.go new file mode 100644 index 0000000000..1348d2049e --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/pgx/v4/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.17.2 + +package querytest + +import () + +type Bar struct { + Tags [][]string +} diff --git a/internal/endtoend/testdata/multidimension_array/pgx/v4/go/query.sql.go b/internal/endtoend/testdata/multidimension_array/pgx/v4/go/query.sql.go new file mode 100644 index 0000000000..ba9508da83 --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/pgx/v4/go/query.sql.go @@ -0,0 +1,34 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.17.2 +// source: query.sql + +package querytest + +import ( + "context" +) + +const textArray = `-- name: TextArray :many +SELECT tags FROM bar +` + +func (q *Queries) TextArray(ctx context.Context) ([][][]string, error) { + rows, err := q.db.Query(ctx, textArray) + if err != nil { + return nil, err + } + defer rows.Close() + var items [][][]string + for rows.Next() { + var tags [][]string + if err := rows.Scan(&tags); err != nil { + return nil, err + } + items = append(items, tags) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/internal/endtoend/testdata/multidimension_array/pgx/v4/query.sql b/internal/endtoend/testdata/multidimension_array/pgx/v4/query.sql new file mode 100644 index 0000000000..29a4bdbc4a --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/pgx/v4/query.sql @@ -0,0 +1,4 @@ +CREATE TABLE bar (tags text[][] not null); + +-- name: TextArray :many +SELECT * FROM bar; diff --git a/internal/endtoend/testdata/multidimension_array/pgx/v4/sqlc.json b/internal/endtoend/testdata/multidimension_array/pgx/v4/sqlc.json new file mode 100644 index 0000000000..9403bd0279 --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/pgx/v4/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "postgresql", + "sql_package": "pgx/v4", + "name": "querytest", + "schema": "query.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/multidimension_array/pgx/v5/go/db.go b/internal/endtoend/testdata/multidimension_array/pgx/v5/go/db.go new file mode 100644 index 0000000000..a84825e0e1 --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/pgx/v5/go/db.go @@ -0,0 +1,32 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.17.2 + +package querytest + +import ( + "context" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgconn" +) + +type DBTX interface { + Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error) + Query(context.Context, string, ...interface{}) (pgx.Rows, error) + QueryRow(context.Context, string, ...interface{}) pgx.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx pgx.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/internal/endtoend/testdata/multidimension_array/pgx/v5/go/models.go b/internal/endtoend/testdata/multidimension_array/pgx/v5/go/models.go new file mode 100644 index 0000000000..1348d2049e --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/pgx/v5/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.17.2 + +package querytest + +import () + +type Bar struct { + Tags [][]string +} diff --git a/internal/endtoend/testdata/multidimension_array/pgx/v5/go/query.sql.go b/internal/endtoend/testdata/multidimension_array/pgx/v5/go/query.sql.go new file mode 100644 index 0000000000..ba9508da83 --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/pgx/v5/go/query.sql.go @@ -0,0 +1,34 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.17.2 +// source: query.sql + +package querytest + +import ( + "context" +) + +const textArray = `-- name: TextArray :many +SELECT tags FROM bar +` + +func (q *Queries) TextArray(ctx context.Context) ([][][]string, error) { + rows, err := q.db.Query(ctx, textArray) + if err != nil { + return nil, err + } + defer rows.Close() + var items [][][]string + for rows.Next() { + var tags [][]string + if err := rows.Scan(&tags); err != nil { + return nil, err + } + items = append(items, tags) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/internal/endtoend/testdata/multidimension_array/pgx/v5/query.sql b/internal/endtoend/testdata/multidimension_array/pgx/v5/query.sql new file mode 100644 index 0000000000..29a4bdbc4a --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/pgx/v5/query.sql @@ -0,0 +1,4 @@ +CREATE TABLE bar (tags text[][] not null); + +-- name: TextArray :many +SELECT * FROM bar; diff --git a/internal/endtoend/testdata/multidimension_array/pgx/v5/sqlc.json b/internal/endtoend/testdata/multidimension_array/pgx/v5/sqlc.json new file mode 100644 index 0000000000..65ee88ef90 --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/pgx/v5/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "postgresql", + "sql_package": "pgx/v5", + "name": "querytest", + "schema": "query.sql", + "queries": "query.sql" + } + ] +} \ No newline at end of file diff --git a/internal/endtoend/testdata/multidimension_array/stdlib/go/db.go b/internal/endtoend/testdata/multidimension_array/stdlib/go/db.go new file mode 100644 index 0000000000..02974bda59 --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.17.2 + +package querytest + +import ( + "context" + "database/sql" +) + +type DBTX interface { + ExecContext(context.Context, string, ...interface{}) (sql.Result, error) + PrepareContext(context.Context, string) (*sql.Stmt, error) + QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) + QueryRowContext(context.Context, string, ...interface{}) *sql.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx *sql.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/internal/endtoend/testdata/multidimension_array/stdlib/go/models.go b/internal/endtoend/testdata/multidimension_array/stdlib/go/models.go new file mode 100644 index 0000000000..1348d2049e --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/stdlib/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.17.2 + +package querytest + +import () + +type Bar struct { + Tags [][]string +} diff --git a/internal/endtoend/testdata/multidimension_array/stdlib/go/query.sql.go b/internal/endtoend/testdata/multidimension_array/stdlib/go/query.sql.go new file mode 100644 index 0000000000..661745028f --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/stdlib/go/query.sql.go @@ -0,0 +1,39 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.17.2 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/lib/pq" +) + +const textArray = `-- name: TextArray :many +SELECT tags FROM bar +` + +func (q *Queries) TextArray(ctx context.Context) ([][][]string, error) { + rows, err := q.db.QueryContext(ctx, textArray) + if err != nil { + return nil, err + } + defer rows.Close() + var items [][][]string + for rows.Next() { + var tags [][]string + if err := rows.Scan(pq.Array(&tags)); err != nil { + return nil, err + } + items = append(items, tags) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/internal/endtoend/testdata/multidimension_array/stdlib/query.sql b/internal/endtoend/testdata/multidimension_array/stdlib/query.sql new file mode 100644 index 0000000000..29a4bdbc4a --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/stdlib/query.sql @@ -0,0 +1,4 @@ +CREATE TABLE bar (tags text[][] not null); + +-- name: TextArray :many +SELECT * FROM bar; diff --git a/internal/endtoend/testdata/multidimension_array/stdlib/sqlc.json b/internal/endtoend/testdata/multidimension_array/stdlib/sqlc.json new file mode 100644 index 0000000000..ac7c2ed829 --- /dev/null +++ b/internal/endtoend/testdata/multidimension_array/stdlib/sqlc.json @@ -0,0 +1,11 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "querytest", + "schema": "query.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/engine/postgresql/parse.go b/internal/engine/postgresql/parse.go index 8b45f9a365..0bc997bf67 100644 --- a/internal/engine/postgresql/parse.go +++ b/internal/engine/postgresql/parse.go @@ -285,10 +285,11 @@ func translate(node *nodes.Node) (ast.Node, error) { } item.Subtype = ast.AT_AddColumn item.Def = &ast.ColumnDef{ - Colname: d.ColumnDef.Colname, - TypeName: rel.TypeName(), - IsNotNull: isNotNull(d.ColumnDef), - IsArray: isArray(d.ColumnDef.TypeName), + Colname: d.ColumnDef.Colname, + TypeName: rel.TypeName(), + IsNotNull: isNotNull(d.ColumnDef), + IsArray: isArray(d.ColumnDef.TypeName), + ArrayBounds: len(d.ColumnDef.TypeName.ArrayBounds), } case nodes.AlterTableType_AT_AlterColumnType: @@ -310,10 +311,11 @@ func translate(node *nodes.Node) (ast.Node, error) { } item.Subtype = ast.AT_AlterColumnType item.Def = &ast.ColumnDef{ - Colname: col, - TypeName: rel.TypeName(), - IsNotNull: isNotNull(d.ColumnDef), - IsArray: isArray(d.ColumnDef.TypeName), + Colname: col, + TypeName: rel.TypeName(), + IsNotNull: isNotNull(d.ColumnDef), + IsArray: isArray(d.ColumnDef.TypeName), + ArrayBounds: len(d.ColumnDef.TypeName.ArrayBounds), } case nodes.AlterTableType_AT_DropColumn: @@ -439,10 +441,11 @@ func translate(node *nodes.Node) (ast.Node, error) { return nil, err } create.Cols = append(create.Cols, &ast.ColumnDef{ - Colname: item.ColumnDef.Colname, - TypeName: rel.TypeName(), - IsNotNull: isNotNull(item.ColumnDef) || primaryKey[item.ColumnDef.Colname], - IsArray: isArray(item.ColumnDef.TypeName), + Colname: item.ColumnDef.Colname, + TypeName: rel.TypeName(), + IsNotNull: isNotNull(item.ColumnDef) || primaryKey[item.ColumnDef.Colname], + IsArray: isArray(item.ColumnDef.TypeName), + ArrayBounds: len(item.ColumnDef.TypeName.ArrayBounds), }) } } diff --git a/internal/plugin/codegen.pb.go b/internal/plugin/codegen.pb.go index d906eb0f3f..8bb1d65881 100644 --- a/internal/plugin/codegen.pb.go +++ b/internal/plugin/codegen.pb.go @@ -1143,6 +1143,7 @@ type Column struct { Type *Identifier `protobuf:"bytes,12,opt,name=type,proto3" json:"type,omitempty"` IsSqlcSlice bool `protobuf:"varint,13,opt,name=is_sqlc_slice,json=isSqlcSlice,proto3" json:"is_sqlc_slice,omitempty"` EmbedTable *Identifier `protobuf:"bytes,14,opt,name=embed_table,json=embedTable,proto3" json:"embed_table,omitempty"` + ArrayBounds int32 `protobuf:"varint,15,opt,name=array_bounds,json=arrayBounds,proto3" json:"array_bounds,omitempty"` } func (x *Column) Reset() { @@ -1268,6 +1269,13 @@ func (x *Column) GetEmbedTable() *Identifier { return nil } +func (x *Column) GetArrayBounds() int32 { + if x != nil { + return x.ArrayBounds + } + return 0 +} + type Query struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -1748,7 +1756,7 @@ var file_plugin_codegen_proto_rawDesc = []byte{ 0x6c, 0x6f, 0x67, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, - 0xae, 0x03, 0x0a, 0x06, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, + 0xd1, 0x03, 0x0a, 0x06, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x6e, 0x6f, 0x74, 0x5f, 0x6e, 0x75, 0x6c, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x6e, 0x6f, 0x74, 0x4e, 0x75, 0x6c, 0x6c, 0x12, 0x19, 0x0a, 0x08, 0x69, 0x73, 0x5f, @@ -1775,55 +1783,57 @@ var file_plugin_codegen_proto_rawDesc = []byte{ 0x6d, 0x62, 0x65, 0x64, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x52, 0x0a, 0x65, 0x6d, 0x62, 0x65, 0x64, 0x54, 0x61, 0x62, 0x6c, 0x65, - 0x22, 0x94, 0x02, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x65, - 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, 0x74, 0x12, 0x12, - 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, - 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x6d, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x03, 0x63, 0x6d, 0x64, 0x12, 0x28, 0x0a, 0x07, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x18, - 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x43, - 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x52, 0x07, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x12, 0x2d, - 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, - 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, - 0x72, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, 0x12, 0x1a, 0x0a, - 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x09, 0x52, - 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x66, 0x69, 0x6c, - 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x66, 0x69, 0x6c, - 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x40, 0x0a, 0x11, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x5f, - 0x69, 0x6e, 0x74, 0x6f, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x12, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, - 0x66, 0x69, 0x65, 0x72, 0x52, 0x11, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x5f, 0x69, 0x6e, 0x74, - 0x6f, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x4b, 0x0a, 0x09, 0x50, 0x61, 0x72, 0x61, 0x6d, - 0x65, 0x74, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, 0x26, 0x0a, 0x06, - 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x70, - 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x52, 0x06, 0x63, 0x6f, - 0x6c, 0x75, 0x6d, 0x6e, 0x22, 0xde, 0x01, 0x0a, 0x0e, 0x43, 0x6f, 0x64, 0x65, 0x47, 0x65, 0x6e, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2c, 0x0a, 0x08, 0x73, 0x65, 0x74, 0x74, 0x69, - 0x6e, 0x67, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, 0x6c, 0x75, 0x67, - 0x69, 0x6e, 0x2e, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x52, 0x08, 0x73, 0x65, 0x74, - 0x74, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x29, 0x0a, 0x07, 0x63, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, - 0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x52, 0x07, 0x63, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, - 0x12, 0x27, 0x0a, 0x07, 0x71, 0x75, 0x65, 0x72, 0x69, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, - 0x52, 0x07, 0x71, 0x75, 0x65, 0x72, 0x69, 0x65, 0x73, 0x12, 0x22, 0x0a, 0x0c, 0x73, 0x71, 0x6c, - 0x63, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0c, 0x73, 0x71, 0x6c, 0x63, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, - 0x0e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x5f, 0x6f, 0x70, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x35, 0x0a, 0x0f, 0x43, 0x6f, 0x64, 0x65, 0x47, 0x65, 0x6e, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, - 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, - 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x42, 0x7e, 0x0a, 0x0a, - 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x42, 0x0c, 0x43, 0x6f, 0x64, 0x65, - 0x67, 0x65, 0x6e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2a, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6b, 0x79, 0x6c, 0x65, 0x63, 0x6f, 0x6e, 0x72, 0x6f, - 0x79, 0x2f, 0x73, 0x71, 0x6c, 0x63, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, - 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x58, 0x58, 0xaa, 0x02, 0x06, 0x50, - 0x6c, 0x75, 0x67, 0x69, 0x6e, 0xca, 0x02, 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0xe2, 0x02, - 0x12, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, - 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x62, 0x06, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x33, + 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x72, 0x72, 0x61, 0x79, 0x5f, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x73, + 0x18, 0x0f, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x61, 0x72, 0x72, 0x61, 0x79, 0x42, 0x6f, 0x75, + 0x6e, 0x64, 0x73, 0x22, 0x94, 0x02, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x12, 0x0a, + 0x04, 0x74, 0x65, 0x78, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x65, 0x78, + 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x63, 0x6d, 0x64, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x63, 0x6d, 0x64, 0x12, 0x28, 0x0a, 0x07, 0x63, 0x6f, 0x6c, 0x75, 0x6d, + 0x6e, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, + 0x6e, 0x2e, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x52, 0x07, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, + 0x73, 0x12, 0x2d, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x50, 0x61, 0x72, 0x61, 0x6d, + 0x65, 0x74, 0x65, 0x72, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x73, + 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x06, 0x20, 0x03, + 0x28, 0x09, 0x52, 0x08, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x1a, 0x0a, 0x08, + 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x66, 0x69, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x40, 0x0a, 0x11, 0x69, 0x6e, 0x73, 0x65, + 0x72, 0x74, 0x5f, 0x69, 0x6e, 0x74, 0x6f, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x08, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x49, 0x64, 0x65, + 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x52, 0x11, 0x69, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x5f, + 0x69, 0x6e, 0x74, 0x6f, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x22, 0x4b, 0x0a, 0x09, 0x50, 0x61, + 0x72, 0x61, 0x6d, 0x65, 0x74, 0x65, 0x72, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, + 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x12, + 0x26, 0x0a, 0x06, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x0e, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x52, + 0x06, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x22, 0xde, 0x01, 0x0a, 0x0e, 0x43, 0x6f, 0x64, 0x65, + 0x47, 0x65, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2c, 0x0a, 0x08, 0x73, 0x65, + 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x70, + 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x52, 0x08, + 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x29, 0x0a, 0x07, 0x63, 0x61, 0x74, 0x61, + 0x6c, 0x6f, 0x67, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x70, 0x6c, 0x75, 0x67, + 0x69, 0x6e, 0x2e, 0x43, 0x61, 0x74, 0x61, 0x6c, 0x6f, 0x67, 0x52, 0x07, 0x63, 0x61, 0x74, 0x61, + 0x6c, 0x6f, 0x67, 0x12, 0x27, 0x0a, 0x07, 0x71, 0x75, 0x65, 0x72, 0x69, 0x65, 0x73, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x2e, 0x51, 0x75, + 0x65, 0x72, 0x79, 0x52, 0x07, 0x71, 0x75, 0x65, 0x72, 0x69, 0x65, 0x73, 0x12, 0x22, 0x0a, 0x0c, + 0x73, 0x71, 0x6c, 0x63, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x73, 0x71, 0x6c, 0x63, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, + 0x12, 0x26, 0x0a, 0x0e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, + 0x6e, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, + 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x35, 0x0a, 0x0f, 0x43, 0x6f, 0x64, 0x65, + 0x47, 0x65, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x22, 0x0a, 0x05, 0x66, + 0x69, 0x6c, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x70, 0x6c, 0x75, + 0x67, 0x69, 0x6e, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x42, + 0x7e, 0x0a, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x42, 0x0c, 0x43, + 0x6f, 0x64, 0x65, 0x67, 0x65, 0x6e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2a, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6b, 0x79, 0x6c, 0x65, 0x63, 0x6f, + 0x6e, 0x72, 0x6f, 0x79, 0x2f, 0x73, 0x71, 0x6c, 0x63, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, + 0x61, 0x6c, 0x2f, 0x70, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0xa2, 0x02, 0x03, 0x50, 0x58, 0x58, 0xaa, + 0x02, 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0xca, 0x02, 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, + 0x6e, 0xe2, 0x02, 0x12, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, + 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x06, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/internal/plugin/codegen_vtproto.pb.go b/internal/plugin/codegen_vtproto.pb.go index 81559f4f9b..4ff5c2b504 100644 --- a/internal/plugin/codegen_vtproto.pb.go +++ b/internal/plugin/codegen_vtproto.pb.go @@ -407,6 +407,7 @@ func (m *Column) CloneVT() *Column { Type: m.Type.CloneVT(), IsSqlcSlice: m.IsSqlcSlice, EmbedTable: m.EmbedTable.CloneVT(), + ArrayBounds: m.ArrayBounds, } if len(m.unknownFields) > 0 { r.unknownFields = make([]byte, len(m.unknownFields)) @@ -1135,6 +1136,9 @@ func (this *Column) EqualVT(that *Column) bool { if !this.EmbedTable.EqualVT(that.EmbedTable) { return false } + if this.ArrayBounds != that.ArrayBounds { + return false + } return string(this.unknownFields) == string(that.unknownFields) } @@ -2439,6 +2443,11 @@ func (m *Column) MarshalToSizedBufferVT(dAtA []byte) (int, error) { i -= len(m.unknownFields) copy(dAtA[i:], m.unknownFields) } + if m.ArrayBounds != 0 { + i = encodeVarint(dAtA, i, uint64(m.ArrayBounds)) + i-- + dAtA[i] = 0x78 + } if m.EmbedTable != nil { size, err := m.EmbedTable.MarshalToSizedBufferVT(dAtA[:i]) if err != nil { @@ -3962,6 +3971,11 @@ func (m *Column) MarshalToSizedBufferVTStrict(dAtA []byte) (int, error) { i -= len(m.unknownFields) copy(dAtA[i:], m.unknownFields) } + if m.ArrayBounds != 0 { + i = encodeVarint(dAtA, i, uint64(m.ArrayBounds)) + i-- + dAtA[i] = 0x78 + } if m.EmbedTable != nil { size, err := m.EmbedTable.MarshalToSizedBufferVTStrict(dAtA[:i]) if err != nil { @@ -4844,6 +4858,9 @@ func (m *Column) SizeVT() (n int) { l = m.EmbedTable.SizeVT() n += 1 + l + sov(uint64(l)) } + if m.ArrayBounds != 0 { + n += 1 + sov(uint64(m.ArrayBounds)) + } n += len(m.unknownFields) return n } @@ -8420,6 +8437,25 @@ func (m *Column) UnmarshalVT(dAtA []byte) error { return err } iNdEx = postIndex + case 15: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field ArrayBounds", wireType) + } + m.ArrayBounds = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflow + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.ArrayBounds |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skip(dAtA[iNdEx:]) diff --git a/internal/sql/ast/column_def.go b/internal/sql/ast/column_def.go index 279f97bf48..fc8edf76fa 100644 --- a/internal/sql/ast/column_def.go +++ b/internal/sql/ast/column_def.go @@ -1,12 +1,13 @@ package ast type ColumnDef struct { - Colname string - TypeName *TypeName - IsNotNull bool - IsArray bool - Vals *List - Length *int + Colname string + TypeName *TypeName + IsNotNull bool + IsArray bool + ArrayBounds int + Vals *List + Length *int // From pg.ColumnDef Inhcount int diff --git a/internal/sql/catalog/table.go b/internal/sql/catalog/table.go index 7647ac4375..2eaf59235e 100644 --- a/internal/sql/catalog/table.go +++ b/internal/sql/catalog/table.go @@ -59,6 +59,7 @@ func (table *Table) alterColumnType(cmd *ast.AlterTableCmd) error { if index >= 0 { table.Columns[index].Type = *cmd.Def.TypeName table.Columns[index].IsArray = cmd.Def.IsArray + table.Columns[index].ArrayBounds = cmd.Def.ArrayBounds } return nil } @@ -100,12 +101,13 @@ func (table *Table) setNotNull(cmd *ast.AlterTableCmd) error { // // TODO: Should this just be ast Nodes? type Column struct { - Name string - Type ast.TypeName - IsNotNull bool - IsArray bool - Comment string - Length *int + Name string + Type ast.TypeName + IsNotNull bool + IsArray bool + ArrayBounds int + Comment string + Length *int } // An interface is used to resolve a circular import between the catalog and compiler packages. @@ -264,12 +266,13 @@ func (c *Catalog) createTable(stmt *ast.CreateTableStmt) error { } else { for _, col := range stmt.Cols { tc := &Column{ - Name: col.Colname, - Type: *col.TypeName, - IsNotNull: col.IsNotNull, - IsArray: col.IsArray, - Comment: col.Comment, - Length: col.Length, + Name: col.Colname, + Type: *col.TypeName, + IsNotNull: col.IsNotNull, + IsArray: col.IsArray, + ArrayBounds: col.ArrayBounds, + Comment: col.Comment, + Length: col.Length, } if col.Vals != nil { typeName := ast.TypeName{ diff --git a/protos/plugin/codegen.proto b/protos/plugin/codegen.proto index 297e30c164..18773a2b26 100644 --- a/protos/plugin/codegen.proto +++ b/protos/plugin/codegen.proto @@ -4,10 +4,9 @@ package plugin; option go_package = "github.com/kyleconroy/sqlc/internal/plugin"; -message File -{ - string name = 1 [json_name="name"]; - bytes contents = 2 [json_name="contents"]; +message File { + string name = 1 [json_name = "name"]; + bytes contents = 2 [json_name = "contents"]; } message Override { @@ -15,26 +14,25 @@ message Override { reserved 9; // name of the type to use, e.g. `github.com/segmentio/ksuid.KSUID` or `mymodule.Type` - string code_type = 1 [json_name="code_type"]; + string code_type = 1 [json_name = "code_type"]; // name of the type to use, e.g. `text` - string db_type = 3 [json_name="db_type"]; + string db_type = 3 [json_name = "db_type"]; // True if the override should apply to a nullable database type - bool nullable = 5 [json_name="nullable"]; + bool nullable = 5 [json_name = "nullable"]; // fully qualified name of the column, e.g. `accounts.id` - string column = 6 [json_name="column"]; + string column = 6 [json_name = "column"]; - Identifier table = 7 [json_name="table"]; + Identifier table = 7 [json_name = "table"]; - string column_name = 8 [json_name="column_name"]; + string column_name = 8 [json_name = "column_name"]; ParsedGoType go_type = 10; } -message ParsedGoType -{ +message ParsedGoType { string import_path = 1; string package = 2; string type_name = 3; @@ -42,34 +40,31 @@ message ParsedGoType map struct_tags = 5; } -message Settings -{ +message Settings { // PythonCode message was field 8 // KotlinCode message was field 9 reserved 8, 9; - string version = 1 [json_name="version"]; - string engine = 2 [json_name="engine"]; - repeated string schema = 3 [json_name="schema"]; - repeated string queries = 4 [json_name="queries"]; - map rename = 5 [json_name="rename"]; - repeated Override overrides = 6 [json_name="overrides"]; - Codegen codegen = 12 [json_name="codegen"]; + string version = 1 [json_name = "version"]; + string engine = 2 [json_name = "engine"]; + repeated string schema = 3 [json_name = "schema"]; + repeated string queries = 4 [json_name = "queries"]; + map rename = 5 [json_name = "rename"]; + repeated Override overrides = 6 [json_name = "overrides"]; + Codegen codegen = 12 [json_name = "codegen"]; // TODO: Refactor codegen settings GoCode go = 10; JSONCode json = 11; } -message Codegen -{ - string out = 1 [json_name="out"]; - string plugin = 2 [json_name="plugin"]; - bytes options = 3 [json_name="options"]; +message Codegen { + string out = 1 [json_name = "out"]; + string plugin = 2 [json_name = "plugin"]; + bytes options = 3 [json_name = "options"]; } -message GoCode -{ +message GoCode { bool emit_interface = 1; bool emit_json_tags = 2; bool emit_db_tags = 3; @@ -97,23 +92,20 @@ message GoCode string output_batch_file_name = 24; } -message JSONCode -{ +message JSONCode { string out = 1; string indent = 2; string filename = 3; } -message Catalog -{ +message Catalog { string comment = 1; string default_schema = 2; string name = 3; repeated Schema schemas = 4; } -message Schema -{ +message Schema { string comment = 1; string name = 2; repeated Table tables = 3; @@ -121,35 +113,30 @@ message Schema repeated CompositeType composite_types = 5; } -message CompositeType -{ +message CompositeType { string name = 1; string comment = 2; } -message Enum -{ +message Enum { string name = 1; repeated string vals = 2; string comment = 3; } -message Table -{ +message Table { Identifier rel = 1; repeated Column columns = 2; - string comment = 3; + string comment = 3; } -message Identifier -{ +message Identifier { string catalog = 1; string schema = 2; string name = 3; } -message Column -{ +message Column { string name = 1; bool not_null = 3; bool is_array = 4; @@ -165,36 +152,33 @@ message Column Identifier type = 12; bool is_sqlc_slice = 13; Identifier embed_table = 14; + int32 array_bounds = 15; } -message Query -{ - string text = 1 [json_name="text"]; - string name = 2 [json_name="name"]; - string cmd = 3 [json_name="cmd"]; - repeated Column columns = 4 [json_name="columns"]; - repeated Parameter params = 5 [json_name="parameters"]; - repeated string comments = 6 [json_name="comments"]; - string filename = 7 [json_name="filename"]; - Identifier insert_into_table = 8 [json_name="insert_into_table"]; +message Query { + string text = 1 [json_name = "text"]; + string name = 2 [json_name = "name"]; + string cmd = 3 [json_name = "cmd"]; + repeated Column columns = 4 [json_name = "columns"]; + repeated Parameter params = 5 [json_name = "parameters"]; + repeated string comments = 6 [json_name = "comments"]; + string filename = 7 [json_name = "filename"]; + Identifier insert_into_table = 8 [json_name = "insert_into_table"]; } -message Parameter -{ - int32 number = 1 [json_name="number"]; - Column column = 2 [json_name="column"]; +message Parameter { + int32 number = 1 [json_name = "number"]; + Column column = 2 [json_name = "column"]; } -message CodeGenRequest -{ - Settings settings = 1 [json_name="settings"]; - Catalog catalog = 2 [json_name="catalog"]; - repeated Query queries = 3 [json_name="queries"]; - string sqlc_version = 4 [json_name="sqlc_version"]; - bytes plugin_options = 5 [json_name="plugin_options"]; +message CodeGenRequest { + Settings settings = 1 [json_name = "settings"]; + Catalog catalog = 2 [json_name = "catalog"]; + repeated Query queries = 3 [json_name = "queries"]; + string sqlc_version = 4 [json_name = "sqlc_version"]; + bytes plugin_options = 5 [json_name = "plugin_options"]; } -message CodeGenResponse -{ - repeated File files = 1 [json_name="files"]; +message CodeGenResponse { + repeated File files = 1 [json_name = "files"]; }