From e949b19877e946b804d7799b716c94cf17b06bc7 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Tue, 22 Apr 2025 20:31:15 +0300 Subject: [PATCH 01/22] Initial YDB support: SELECT logic, some convert tests, and YDB engine integration - Added reserved keywords and parsing logic - CREATE TABLE support and tests - SELECT initial support and tests - Initial YDB engine integration and examples --- docker-compose.yml | 13 + examples/authors/sqlc.yaml | 10 + examples/authors/ydb/db.go | 31 + examples/authors/ydb/db_test.go | 102 ++ examples/authors/ydb/models.go | 15 + examples/authors/ydb/query.sql | 19 + examples/authors/ydb/query.sql.go | 133 ++ examples/authors/ydb/schema.sql | 6 + internal/codegen/golang/go_type.go | 2 + internal/codegen/golang/ydb_type.go | 154 ++ internal/compiler/engine.go | 5 + internal/config/config.go | 1 + internal/engine/ydb/catalog.go | 19 + .../ydb/catalog_tests/create_table_test.go | 166 ++ .../engine/ydb/catalog_tests/select_test.go | 386 ++++ internal/engine/ydb/convert.go | 1616 +++++++++++++++++ internal/engine/ydb/parse.go | 93 + internal/engine/ydb/reserved.go | 301 +++ internal/engine/ydb/stdlib.go | 12 + internal/engine/ydb/utils.go | 143 ++ internal/sql/rewrite/parameters.go | 2 + internal/sqltest/local/ydb.go | 117 ++ 22 files changed, 3346 insertions(+) create mode 100644 examples/authors/ydb/db.go create mode 100644 examples/authors/ydb/db_test.go create mode 100644 examples/authors/ydb/models.go create mode 100644 examples/authors/ydb/query.sql create mode 100644 examples/authors/ydb/query.sql.go create mode 100644 examples/authors/ydb/schema.sql create mode 100644 internal/codegen/golang/ydb_type.go create mode 100644 internal/engine/ydb/catalog.go create mode 100644 internal/engine/ydb/catalog_tests/create_table_test.go create mode 100644 internal/engine/ydb/catalog_tests/select_test.go create mode 100755 internal/engine/ydb/convert.go create mode 100755 internal/engine/ydb/parse.go create mode 100644 internal/engine/ydb/reserved.go create mode 100644 internal/engine/ydb/stdlib.go create mode 100755 internal/engine/ydb/utils.go create mode 100644 internal/sqltest/local/ydb.go diff --git a/docker-compose.yml b/docker-compose.yml index f318d1ed93..e7c66b42ae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,3 +19,16 @@ services: POSTGRES_DB: postgres POSTGRES_PASSWORD: mysecretpassword POSTGRES_USER: postgres + + ydb: + image: ydbplatform/local-ydb:latest + ports: + - "2135:2135" + - "2136:2136" + - "8765:8765" + restart: always + environment: + - YDB_USE_IN_MEMORY_PDISKS=true + - GRPC_TLS_PORT=2135 + - GRPC_PORT=2136 + - MON_PORT=8765 diff --git a/examples/authors/sqlc.yaml b/examples/authors/sqlc.yaml index 57f2319ea1..8d6bc3db28 100644 --- a/examples/authors/sqlc.yaml +++ b/examples/authors/sqlc.yaml @@ -43,6 +43,16 @@ sql: go: package: authors out: sqlite +- name: ydb + schema: ydb/schema.sql + queries: ydb/query.sql + engine: ydb + gen: + go: + package: authors + out: ydb + + rules: - name: postgresql-query-too-costly message: "Too costly" diff --git a/examples/authors/ydb/db.go b/examples/authors/ydb/db.go new file mode 100644 index 0000000000..2bb1bfc27d --- /dev/null +++ b/examples/authors/ydb/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 + +package authors + +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/examples/authors/ydb/db_test.go b/examples/authors/ydb/db_test.go new file mode 100644 index 0000000000..181ee64ed1 --- /dev/null +++ b/examples/authors/ydb/db_test.go @@ -0,0 +1,102 @@ +package authors + +import ( + "context" + "testing" + + "github.com/sqlc-dev/sqlc/internal/sqltest/local" + _ "github.com/ydb-platform/ydb-go-sdk/v3" +) + +func TestAuthors(t *testing.T) { + ctx := context.Background() + + test := local.YDB(t, []string{"schema.sql"}) + defer test.DB.Close() + + q := New(test.DB) + + t.Run("ListAuthors", func(t *testing.T) { + authors, err := q.ListAuthors(ctx) + if err != nil { + t.Fatal(err) + } + if len(authors) == 0 { + t.Fatal("expected at least one author, got none") + } + t.Log("Authors:") + for _, a := range authors { + bio := "NULL" + if a.Bio.Valid { + bio = a.Bio.String + } + t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) + } + }) + + t.Run("GetAuthor", func(t *testing.T) { + singleAuthor, err := q.GetAuthor(ctx, 10) + if err != nil { + t.Fatal(err) + } + bio := "NULL" + if singleAuthor.Bio.Valid { + bio = singleAuthor.Bio.String + } + t.Logf("- ID: %d | Name: %s | Bio: %s", singleAuthor.ID, singleAuthor.Name, bio) + }) + + t.Run("GetAuthorByName", func(t *testing.T) { + authors, err := q.GetAuthorsByName(ctx, "Александр Пушкин") + if err != nil { + t.Fatal(err) + } + if len(authors) == 0 { + t.Fatal("expected at least one author with this name, got none") + } + t.Log("Authors with this name:") + for _, a := range authors { + bio := "NULL" + if a.Bio.Valid { + bio = a.Bio.String + } + t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) + } + }) + + t.Run("ListAuthorsWithIdModulo", func(t *testing.T) { + authors, err := q.ListAuthorsWithIdModulo(ctx) + if err != nil { + t.Fatal(err) + } + if len(authors) == 0 { + t.Fatal("expected at least one author with even ID, got none") + } + t.Log("Authors with even IDs:") + for _, a := range authors { + bio := "NULL" + if a.Bio.Valid { + bio = a.Bio.String + } + t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) + } + }) + + t.Run("ListAuthorsWithNullBio", func(t *testing.T) { + authors, err := q.ListAuthorsWithNullBio(ctx) + if err != nil { + t.Fatal(err) + } + if len(authors) == 0 { + t.Fatal("expected at least one author with NULL bio, got none") + } + t.Log("Authors with NULL bio:") + for _, a := range authors { + bio := "NULL" + if a.Bio.Valid { + bio = a.Bio.String + } + t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) + } + }) +} diff --git a/examples/authors/ydb/models.go b/examples/authors/ydb/models.go new file mode 100644 index 0000000000..e899b195b0 --- /dev/null +++ b/examples/authors/ydb/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 + +package authors + +import ( + "database/sql" +) + +type Author struct { + ID uint64 + Name string + Bio sql.NullString +} diff --git a/examples/authors/ydb/query.sql b/examples/authors/ydb/query.sql new file mode 100644 index 0000000000..219d680ba1 --- /dev/null +++ b/examples/authors/ydb/query.sql @@ -0,0 +1,19 @@ +-- name: ListAuthors :many +SELECT * FROM authors; + +-- name: GetAuthor :one +SELECT * FROM authors +WHERE id = $p0; + +-- name: ListAuthorsWithIdModulo :many +SELECT * FROM authors +WHERE id % 2 = 0; + +-- name: GetAuthorsByName :many +SELECT * FROM authors +WHERE name = $p0; + +-- name: ListAuthorsWithNullBio :many +SELECT * FROM authors +WHERE bio IS NULL; + diff --git a/examples/authors/ydb/query.sql.go b/examples/authors/ydb/query.sql.go new file mode 100644 index 0000000000..53ed896128 --- /dev/null +++ b/examples/authors/ydb/query.sql.go @@ -0,0 +1,133 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.27.0 +// source: query.sql + +package authors + +import ( + "context" +) + +const getAuthor = `-- name: GetAuthor :one +SELECT id, name, bio FROM authors +WHERE id = $p0 +` + +func (q *Queries) GetAuthor(ctx context.Context, p0 uint64) (Author, error) { + row := q.db.QueryRowContext(ctx, getAuthor, p0) + var i Author + err := row.Scan(&i.ID, &i.Name, &i.Bio) + return i, err +} + +const getAuthorsByName = `-- name: GetAuthorsByName :many +SELECT id, name, bio FROM authors +WHERE name = $p0 +` + +func (q *Queries) GetAuthorsByName(ctx context.Context, p0 string) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, getAuthorsByName, p0) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listAuthors = `-- name: ListAuthors :many +SELECT id, name, bio FROM authors +` + +func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listAuthorsWithIdModulo = `-- name: ListAuthorsWithIdModulo :many +SELECT id, name, bio FROM authors +WHERE id % 2 = 0 +` + +func (q *Queries) ListAuthorsWithIdModulo(ctx context.Context) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthorsWithIdModulo) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listAuthorsWithNullBio = `-- name: ListAuthorsWithNullBio :many +SELECT id, name, bio FROM authors +WHERE bio IS NULL +` + +func (q *Queries) ListAuthorsWithNullBio(ctx context.Context) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthorsWithNullBio) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} diff --git a/examples/authors/ydb/schema.sql b/examples/authors/ydb/schema.sql new file mode 100644 index 0000000000..ee9329e809 --- /dev/null +++ b/examples/authors/ydb/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE authors ( + id Uint64, + name Utf8 NOT NULL, + bio Utf8, + PRIMARY KEY (id) +); diff --git a/internal/codegen/golang/go_type.go b/internal/codegen/golang/go_type.go index c4aac84dd6..11eb8931df 100644 --- a/internal/codegen/golang/go_type.go +++ b/internal/codegen/golang/go_type.go @@ -89,6 +89,8 @@ func goInnerType(req *plugin.GenerateRequest, options *opts.Options, col *plugin return postgresType(req, options, col) case "sqlite": return sqliteType(req, options, col) + case "ydb": + return YDBType(req, options, col) default: return "interface{}" } diff --git a/internal/codegen/golang/ydb_type.go b/internal/codegen/golang/ydb_type.go new file mode 100644 index 0000000000..8a5b1711b3 --- /dev/null +++ b/internal/codegen/golang/ydb_type.go @@ -0,0 +1,154 @@ +package golang + +import ( + "log" + "strings" + + "github.com/sqlc-dev/sqlc/internal/codegen/golang/opts" + "github.com/sqlc-dev/sqlc/internal/codegen/sdk" + "github.com/sqlc-dev/sqlc/internal/debug" + "github.com/sqlc-dev/sqlc/internal/plugin" +) + +func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string { + columnType := strings.ToLower(sdk.DataType(col.Type)) + notNull := col.NotNull || col.IsArray + emitPointersForNull := options.EmitPointersForNullTypes + + // https://ydb.tech/docs/ru/yql/reference/types/ + switch columnType { + // decimal types + case "bool": + if notNull { + return "bool" + } + if emitPointersForNull { + return "*bool" + } + return "sql.NullBool" + + case "int8": + if notNull { + return "int8" + } + if emitPointersForNull { + return "*int8" + } + // The database/sql package does not have a sql.NullInt8 type, so we + // use the smallest type they have which is NullInt16 + return "sql.NullInt16" + case "int16": + if notNull { + return "int16" + } + if emitPointersForNull { + return "*int16" + } + return "sql.NullInt16" + case "int32": + if notNull { + return "int32" + } + if emitPointersForNull { + return "*int32" + } + return "sql.NullInt32" + case "int64": + if notNull { + return "int64" + } + if emitPointersForNull { + return "*int64" + } + return "sql.NullInt64" + + case "uint8": + if emitPointersForNull { + return "*uint8" + } + return "uint8" + case "uint16": + if emitPointersForNull { + return "*uint16" + } + return "uint16" + case "uint32": + if emitPointersForNull { + return "*uint32" + } + return "uint32" + case "uint64": + if emitPointersForNull { + return "*uint64" + } + return "uint64" + + case "float": + if notNull { + return "float32" + } + if emitPointersForNull { + return "*float32" + } + // The database/sql package does not have a sql.NullFloat32 type, so we + // use the smallest type they have which is NullFloat64 + return "sql.NullFloat64" + case "double": + if notNull { + return "float64" + } + if emitPointersForNull { + return "*float64" + } + return "sql.NullFloat64" + + // string types + case "string", "utf8", "text": + if notNull { + return "string" + } + if emitPointersForNull { + return "*string" + } + return "sql.NullString" + + // serial types + case "smallserial", "serial2": + if notNull { + return "int16" + } + if emitPointersForNull { + return "*int16" + } + return "sql.NullInt16" + + case "serial", "serial4": + if notNull { + return "int32" + } + if emitPointersForNull { + return "*int32" + } + return "sql.NullInt32" + + case "bigserial", "serial8": + if notNull { + return "int64" + } + if emitPointersForNull { + return "*int64" + } + return "sql.NullInt64" + + case "null": + return "sql.Null" + + default: + if debug.Active { + log.Printf("unknown SQLite type: %s\n", columnType) + } + + return "interface{}" + } + +} diff --git a/internal/compiler/engine.go b/internal/compiler/engine.go index f742bfd999..245552b07f 100644 --- a/internal/compiler/engine.go +++ b/internal/compiler/engine.go @@ -11,6 +11,7 @@ import ( "github.com/sqlc-dev/sqlc/internal/engine/postgresql" pganalyze "github.com/sqlc-dev/sqlc/internal/engine/postgresql/analyzer" "github.com/sqlc-dev/sqlc/internal/engine/sqlite" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" "github.com/sqlc-dev/sqlc/internal/opts" "github.com/sqlc-dev/sqlc/internal/sql/catalog" ) @@ -41,6 +42,10 @@ func NewCompiler(conf config.SQL, combo config.CombinedSettings) (*Compiler, err c.parser = sqlite.NewParser() c.catalog = sqlite.NewCatalog() c.selector = newSQLiteSelector() + case config.EngineYDB: + c.parser = ydb.NewParser() + c.catalog = ydb.NewCatalog() + c.selector = newDefaultSelector() case config.EngineMySQL: c.parser = dolphin.NewParser() c.catalog = dolphin.NewCatalog() diff --git a/internal/config/config.go b/internal/config/config.go index 0ff805fccd..f7df94e5f8 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -54,6 +54,7 @@ const ( EngineMySQL Engine = "mysql" EnginePostgreSQL Engine = "postgresql" EngineSQLite Engine = "sqlite" + EngineYDB Engine = "ydb" ) type Config struct { diff --git a/internal/engine/ydb/catalog.go b/internal/engine/ydb/catalog.go new file mode 100644 index 0000000000..f191d936f3 --- /dev/null +++ b/internal/engine/ydb/catalog.go @@ -0,0 +1,19 @@ +package ydb + +import "github.com/sqlc-dev/sqlc/internal/sql/catalog" + + +func NewCatalog() *catalog.Catalog { + def := "main" + return &catalog.Catalog{ + DefaultSchema: def, + Schemas: []*catalog.Schema{ + defaultSchema(def), + }, + Extensions: map[string]struct{}{}, + } +} + +func NewTestCatalog() *catalog.Catalog { + return catalog.New("main") +} diff --git a/internal/engine/ydb/catalog_tests/create_table_test.go b/internal/engine/ydb/catalog_tests/create_table_test.go new file mode 100644 index 0000000000..e98288d75a --- /dev/null +++ b/internal/engine/ydb/catalog_tests/create_table_test.go @@ -0,0 +1,166 @@ +package ydb_test + +import ( + "strconv" + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func TestCreateTable(t *testing.T) { + tests := []struct { + stmt string + s *catalog.Schema + }{ + { + stmt: `CREATE TABLE users ( + id Uint64, + age Int32, + score Float, + PRIMARY KEY (id) + )`, + s: &catalog.Schema{ + Name: "main", + Tables: []*catalog.Table{ + { + Rel: &ast.TableName{Name: "users"}, + Columns: []*catalog.Column{ + { + Name: "id", + Type: ast.TypeName{Name: "Uint64"}, + IsNotNull: true, + }, + { + Name: "age", + Type: ast.TypeName{Name: "Int32"}, + }, + { + Name: "score", + Type: ast.TypeName{Name: "Float"}, + }, + }, + }, + }, + }, + }, + { + stmt: `CREATE TABLE posts ( + id Uint64, + title Utf8 NOT NULL, + content String, + metadata Json, + PRIMARY KEY (id) + )`, + s: &catalog.Schema{ + Name: "main", + Tables: []*catalog.Table{ + { + Rel: &ast.TableName{Name: "posts"}, + Columns: []*catalog.Column{ + { + Name: "id", + Type: ast.TypeName{Name: "Uint64"}, + IsNotNull: true, + }, + { + Name: "title", + Type: ast.TypeName{Name: "Utf8"}, + IsNotNull: true, + }, + { + Name: "content", + Type: ast.TypeName{Name: "String"}, + }, + { + Name: "metadata", + Type: ast.TypeName{Name: "Json"}, + }, + }, + }, + }, + }, + }, + { + stmt: `CREATE TABLE orders ( + id Uuid, + amount Decimal(22,9), + created_at Uint64, + PRIMARY KEY (id) + )`, + s: &catalog.Schema{ + Name: "main", + Tables: []*catalog.Table{ + { + Rel: &ast.TableName{Name: "orders"}, + Columns: []*catalog.Column{ + { + Name: "id", + Type: ast.TypeName{Name: "Uuid"}, + IsNotNull: true, + }, + { + Name: "amount", + Type: ast.TypeName{ + Name: "Decimal", + Names: &ast.List{ + Items: []ast.Node{ + &ast.Integer{Ival: 22}, + &ast.Integer{Ival: 9}, + }, + }, + }, + }, + { + Name: "created_at", + Type: ast.TypeName{Name: "Uint64"}, + }, + }, + }, + }, + }, + }, + } + + p := ydb.NewParser() + for i, tc := range tests { + test := tc + t.Run(strconv.Itoa(i), func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(test.stmt)) + if err != nil { + t.Log(test.stmt) + t.Fatal(err) + } + + c := ydb.NewTestCatalog() + if err := c.Build(stmts); err != nil { + t.Log(test.stmt) + t.Fatal(err) + } + + e := ydb.NewTestCatalog() + if test.s != nil { + var replaced bool + for i := range e.Schemas { + if e.Schemas[i].Name == test.s.Name { + e.Schemas[i] = test.s + replaced = true + break + } + } + if !replaced { + e.Schemas = append(e.Schemas, test.s) + } + } + + if diff := cmp.Diff(e, c, cmpopts.EquateEmpty(), cmpopts.IgnoreUnexported(catalog.Column{})); diff != "" { + t.Log(test.stmt) + t.Errorf("catalog mismatch:\n%s", diff) + } + }) + } +} diff --git a/internal/engine/ydb/catalog_tests/select_test.go b/internal/engine/ydb/catalog_tests/select_test.go new file mode 100644 index 0000000000..95ae49163d --- /dev/null +++ b/internal/engine/ydb/catalog_tests/select_test.go @@ -0,0 +1,386 @@ +package ydb_test + +import ( + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" +) + +func strPtr(s string) *string { + return &s +} + +func TestSelect(t *testing.T) { + tests := []struct { + stmt string + expected ast.Node + }{ + // Basic Types Select + { + stmt: `SELECT 52`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.A_Const{ + Val: &ast.Integer{Ival: 52}, + }, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `SELECT 'hello'`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.A_Const{ + Val: &ast.String{Str: "hello"}, + }, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `SELECT 'it\'s string with quote in it'`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.A_Const{ + Val: &ast.String{Str: `it\'s string with quote in it`}, + }, + }, + }, + }, + }, + }, + }, + }, + { + stmt: "SELECT 3.14", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.A_Const{ + Val: &ast.Float{Str: "3.14"}, + }, + }, + }, + }, + }, + }, + }, + }, + { + stmt: "SELECT NULL", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.Null{}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: "SELECT true", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.Boolean{Boolval: true}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: "SELECT 2+3*4", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.A_Expr{ + Name: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "+"}, + }, + }, + Lexpr: &ast.A_Const{ + Val: &ast.Integer{Ival: 2}, + }, + Rexpr: &ast.A_Expr{ + Name: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "*"}, + }, + }, + Lexpr: &ast.A_Const{ + Val: &ast.Integer{Ival: 3}, + }, + Rexpr: &ast.A_Const{ + Val: &ast.Integer{Ival: 4}, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + + // Select with From Clause tests + { + stmt: `SELECT * FROM users`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.A_Star{}, + }, + }, + }, + }, + }, + }, + FromClause: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{ + Relname: strPtr("users"), + }, + }, + }, + }, + }, + }, + }, + { + stmt: "SELECT id AS identifier FROM users", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Name: strPtr("identifier"), + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + }, + }, + }, + FromClause: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{ + Relname: strPtr("users"), + }, + }, + }, + }, + }, + }, + }, + { + stmt: "SELECT a.b.c FROM table", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "a"}, + &ast.String{Str: "b"}, + &ast.String{Str: "c"}, + }, + }, + }, + }, + }, + }, + FromClause: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{ + Relname: strPtr("table"), + }, + }, + }, + }, + }, + }, + }, + { + stmt: "SELECT id.age, 3.14, 'abc', NULL, false FROM users", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + &ast.String{Str: "age"}, + }, + }, + }, + }, + &ast.ResTarget{ + Val: &ast.A_Const{ + Val: &ast.Float{Str: "3.14"}, + }, + }, + &ast.ResTarget{ + Val: &ast.A_Const{ + Val: &ast.String{Str: "abc"}, + }, + }, + &ast.ResTarget{ + Val: &ast.Null{}, + }, + &ast.ResTarget{ + Val: &ast.Boolean{Boolval: false}, + }, + }, + }, + FromClause: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{ + Relname: strPtr("users"), + }, + }, + }, + }, + }, + }, + }, + { + stmt: `SELECT id, name FROM users WHERE age > 30`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + }, + &ast.ResTarget{ + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "name"}, + }, + }, + }, + }, + }, + }, + FromClause: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{ + Relname: strPtr("users"), + }, + }, + }, + WhereClause: &ast.A_Expr{ + Name: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: ">"}, + }, + }, + Lexpr: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "age"}, + }, + }, + }, + Rexpr: &ast.A_Const{ + Val: &ast.Integer{Ival: 30}, + }, + }, + }, + }, + }, + }, + } + + p := ydb.NewParser() + + for _, tc := range tests { + t.Run(tc.stmt, func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(tc.stmt)) + if err != nil { + t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + } + if len(stmts) == 0 { + t.Fatalf("Запрос %q не распарсен", tc.stmt) + } + + diff := cmp.Diff(tc.expected, &stmts[0], + cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), + // cmpopts.IgnoreFields(ast.SelectStmt{}, "Location"), + cmpopts.IgnoreFields(ast.A_Const{}, "Location"), + cmpopts.IgnoreFields(ast.ResTarget{}, "Location"), + cmpopts.IgnoreFields(ast.ColumnRef{}, "Location"), + cmpopts.IgnoreFields(ast.A_Expr{}, "Location"), + cmpopts.IgnoreFields(ast.RangeVar{}, "Location"), + ) + if diff != "" { + t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + } + }) + } +} diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go new file mode 100755 index 0000000000..341de1a2e9 --- /dev/null +++ b/internal/engine/ydb/convert.go @@ -0,0 +1,1616 @@ +package ydb + +import ( + "log" + "strconv" + "strings" + + "github.com/antlr4-go/antlr/v4" + "github.com/sqlc-dev/sqlc/internal/debug" + "github.com/sqlc-dev/sqlc/internal/sql/ast" + parser "github.com/ydb-platform/yql-parsers/go" +) + +type cc struct { + paramCount int +} + +type node interface { + GetParser() antlr.Parser +} + +func todo(funcname string, n node) *ast.TODO { + if debug.Active { + log.Printf("sqlite.%s: Unknown node type %T\n", funcname, n) + } + return &ast.TODO{} +} + +func identifier(id string) string { + if len(id) >= 2 && id[0] == '"' && id[len(id)-1] == '"' { + unquoted, _ := strconv.Unquote(id) + return unquoted + } + return strings.ToLower(id) +} + +func NewIdentifier(t string) *ast.String { + return &ast.String{Str: identifier(t)} +} + +func (c *cc) convertAlter_table_stmtContext(n *parser.Alter_table_stmtContext) ast.Node { + tableRef := parseTableName(n.Simple_table_ref().Simple_table_ref_core()) + + stmt := &ast.AlterTableStmt{ + Table: tableRef, + Cmds: &ast.List{}, + } + for _, action := range n.AllAlter_table_action() { + if add := action.Alter_table_add_column(); add != nil { + } + } + return stmt +} + +func (c *cc) convertSelectStmtContext(n *parser.Select_stmtContext) ast.Node { + skp := n.Select_kind_parenthesis(0) + if skp == nil { + return nil + } + partial := skp.Select_kind_partial() + if partial == nil { + return nil + } + sk := partial.Select_kind() + if sk == nil { + return nil + } + selectStmt := &ast.SelectStmt{} + + switch { + case sk.Process_core() != nil: + cnode := c.convert(sk.Process_core()) + stmt, ok := cnode.(*ast.SelectStmt) + if !ok { + return nil + } + selectStmt = stmt + case sk.Select_core() != nil: + cnode := c.convert(sk.Select_core()) + stmt, ok := cnode.(*ast.SelectStmt) + if !ok { + return nil + } + selectStmt = stmt + case sk.Reduce_core() != nil: + cnode := c.convert(sk.Reduce_core()) + stmt, ok := cnode.(*ast.SelectStmt) + if !ok { + return nil + } + selectStmt = stmt + } + + // todo: cover process and reduce core, + // todo: cover LIMIT and OFFSET + + return selectStmt +} + +func (c *cc) convertSelectCoreContext(n *parser.Select_coreContext) ast.Node { + stmt := &ast.SelectStmt{} + if n.Opt_set_quantifier() != nil { + oq := n.Opt_set_quantifier() + if oq.DISTINCT() != nil { + // todo: add distinct support + stmt.DistinctClause = &ast.List{} + } + } + resultCols := n.AllResult_column() + if len(resultCols) > 0 { + var items []ast.Node + for _, rc := range resultCols { + resCol, ok := rc.(*parser.Result_columnContext) + if !ok { + continue + } + convNode := c.convertResultColumn(resCol) + if convNode != nil { + items = append(items, convNode) + } + } + stmt.TargetList = &ast.List{ + Items: items, + } + } + jsList := n.AllJoin_source() + if len(n.AllFROM()) > 0 && len(jsList) > 0 { + var fromItems []ast.Node + for _, js := range jsList { + jsCon, ok := js.(*parser.Join_sourceContext) + if !ok { + continue + } + + joinNode := c.convertJoinSource(jsCon) + if joinNode != nil { + fromItems = append(fromItems, joinNode) + } + } + stmt.FromClause = &ast.List{ + Items: fromItems, + } + } + if n.WHERE() != nil { + whereCtx := n.Expr(0) + if whereCtx != nil { + stmt.WhereClause = c.convert(whereCtx) + } + } + return stmt +} + +func (c *cc) convertResultColumn(n *parser.Result_columnContext) ast.Node { + exprCtx := n.Expr() + if exprCtx == nil { + // todo + } + target := &ast.ResTarget{ + Location: n.GetStart().GetStart(), + } + var val ast.Node + iexpr := n.Expr() + switch { + case n.ASTERISK() != nil: + val = c.convertWildCardField(n) + case iexpr != nil: + val = c.convert(iexpr) + } + + if val == nil { + return nil + } + switch { + case n.AS() != nil && n.An_id_or_type() != nil: + name := parseAnIdOrType(n.An_id_or_type()) + target.Name = &name + case n.An_id_as_compat() != nil: + // todo: parse as_compat + } + target.Val = val + return target +} + +func (c *cc) convertJoinSource(n *parser.Join_sourceContext) ast.Node { + fsList := n.AllFlatten_source() + if len(fsList) == 0 { + return nil + } + joinOps := n.AllJoin_op() + joinConstraints := n.AllJoin_constraint() + + // todo: add ANY support + + leftNode := c.convertFlattenSource(fsList[0]) + if leftNode == nil { + return nil + } + for i, jopCtx := range joinOps { + if i+1 >= len(fsList) { + break + } + rightNode := c.convertFlattenSource(fsList[i+1]) + if rightNode == nil { + return leftNode + } + jexpr := &ast.JoinExpr{ + Larg: leftNode, + Rarg: rightNode, + } + if jopCtx.NATURAL() != nil { + jexpr.IsNatural = true + } + // todo: cover semi/only/exclusion/ + switch { + case jopCtx.LEFT() != nil: + jexpr.Jointype = ast.JoinTypeLeft + case jopCtx.RIGHT() != nil: + jexpr.Jointype = ast.JoinTypeRight + case jopCtx.FULL() != nil: + jexpr.Jointype = ast.JoinTypeFull + case jopCtx.INNER() != nil: + jexpr.Jointype = ast.JoinTypeInner + case jopCtx.COMMA() != nil: + jexpr.Jointype = ast.JoinTypeInner + default: + jexpr.Jointype = ast.JoinTypeInner + } + if i < len(joinConstraints) { + if jc := joinConstraints[i]; jc != nil { + switch { + case jc.ON() != nil: + if exprCtx := jc.Expr(); exprCtx != nil { + jexpr.Quals = c.convert(exprCtx) + } + case jc.USING() != nil: + if pureListCtx := jc.Pure_column_or_named_list(); pureListCtx != nil { + var using ast.List + pureItems := pureListCtx.AllPure_column_or_named() + for _, pureCtx := range pureItems { + if anID := pureCtx.An_id(); anID != nil { + using.Items = append(using.Items, NewIdentifier(parseAnId(anID))) + } else if bp := pureCtx.Bind_parameter(); bp != nil { + bindPar := c.convert(bp) + using.Items = append(using.Items, bindPar) + } + } + jexpr.UsingClause = &using + } + } + } + } + leftNode = jexpr + } + return leftNode +} + +func (c *cc) convertFlattenSource(n parser.IFlatten_sourceContext) ast.Node { + if n == nil { + return nil + } + nss := n.Named_single_source() + if nss == nil { + return nil + } + namedSingleSource, ok := nss.(*parser.Named_single_sourceContext) + if !ok { + return nil + } + return c.convertNamedSingleSource(namedSingleSource) +} + +func (c *cc) convertNamedSingleSource(n *parser.Named_single_sourceContext) ast.Node { + ss := n.Single_source() + if ss == nil { + return nil + } + SingleSource, ok := ss.(*parser.Single_sourceContext) + if !ok { + return nil + } + base := c.convertSingleSource(SingleSource) + + if n.AS() != nil && n.An_id() != nil { + aliasText := parseAnId(n.An_id()) + switch source := base.(type) { + case *ast.RangeVar: + source.Alias = &ast.Alias{Aliasname: &aliasText} + case *ast.RangeSubselect: + source.Alias = &ast.Alias{Aliasname: &aliasText} + } + } else if n.An_id_as_compat() != nil { + // todo: parse as_compat + } + return base +} + +func (c *cc) convertSingleSource(n *parser.Single_sourceContext) ast.Node { + if n.Table_ref() != nil { + tableName := n.Table_ref().GetText() // !! debug !! + return &ast.RangeVar{ + Relname: &tableName, + Location: n.GetStart().GetStart(), + } + } + + if n.Select_stmt() != nil { + subquery := c.convert(n.Select_stmt()) + return &ast.RangeSubselect{ + Subquery: subquery, + } + + } + // todo: Values stmt + + return nil +} + +func (c *cc) convertBindParameter(n *parser.Bind_parameterContext) ast.Node { + // !!debug later!! + if n.DOLLAR() != nil { + if n.TRUE() != nil { + return &ast.Boolean{ + Boolval: true, + } + } + if n.FALSE() != nil { + return &ast.Boolean{ + Boolval: false, + } + } + + if an := n.An_id_or_type(); an != nil { + idText := parseAnIdOrType(an) + return &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "@"}}}, + Rexpr: &ast.String{Str: idText}, + Location: n.GetStart().GetStart(), + } + } + c.paramCount++ + return &ast.ParamRef{ + Number: c.paramCount, + Location: n.GetStart().GetStart(), + Dollar: true, + } + } + return &ast.TODO{} +} + +func (c *cc) convertWildCardField(n *parser.Result_columnContext) *ast.ColumnRef { + prefixCtx := n.Opt_id_prefix() + prefix := c.convertOptIdPrefix(prefixCtx) + + items := []ast.Node{} + if prefix != "" { + items = append(items, NewIdentifier(prefix)) + } + + items = append(items, &ast.A_Star{}) + return &ast.ColumnRef{ + Fields: &ast.List{Items: items}, + Location: n.GetStart().GetStart(), + } +} + +func (c *cc) convertOptIdPrefix(ctx parser.IOpt_id_prefixContext) string { + if ctx == nil { + return "" + } + if ctx.An_id() != nil { + return ctx.An_id().GetText() + } + return "" +} + +func (c *cc) convertCreate_table_stmtContext(n *parser.Create_table_stmtContext) ast.Node { + stmt := &ast.CreateTableStmt{ + Name: parseTableName(n.Simple_table_ref().Simple_table_ref_core()), + IfNotExists: n.EXISTS() != nil, + } + for _, idef := range n.AllCreate_table_entry() { + if def, ok := idef.(*parser.Create_table_entryContext); ok { + switch { + case def.Column_schema() != nil: + if colCtx, ok := def.Column_schema().(*parser.Column_schemaContext); ok { + colDef := c.convertColumnSchema(colCtx) + if colDef != nil { + stmt.Cols = append(stmt.Cols, colDef) + } + } + case def.Table_constraint() != nil: + if conCtx, ok := def.Table_constraint().(*parser.Table_constraintContext); ok { + switch { + case conCtx.PRIMARY() != nil && conCtx.KEY() != nil: + for _, cname := range conCtx.AllAn_id() { + for _, col := range stmt.Cols { + if col.Colname == parseAnId(cname) { + col.IsNotNull = true + } + } + } + case conCtx.PARTITION() != nil && conCtx.BY() != nil: + _ = conCtx + // todo: partition by constraint + case conCtx.ORDER() != nil && conCtx.BY() != nil: + _ = conCtx + // todo: order by constraint + } + } + + case def.Table_index() != nil: + if indCtx, ok := def.Table_index().(*parser.Table_indexContext); ok { + _ = indCtx + // todo + } + case def.Family_entry() != nil: + if famCtx, ok := def.Family_entry().(*parser.Family_entryContext); ok { + _ = famCtx + // todo + } + case def.Changefeed() != nil: // таблица ориентированная + if cgfCtx, ok := def.Changefeed().(*parser.ChangefeedContext); ok { + _ = cgfCtx + // todo + } + } + } + } + return stmt +} + +func (c *cc) convertColumnSchema(n *parser.Column_schemaContext) *ast.ColumnDef { + + col := &ast.ColumnDef{} + + if anId := n.An_id_schema(); anId != nil { + col.Colname = identifier(parseAnIdSchema(anId)) + } + if tnb := n.Type_name_or_bind(); tnb != nil { + col.TypeName = c.convertTypeNameOrBind(tnb) + } + if colCons := n.Opt_column_constraints(); colCons != nil { + col.IsNotNull = colCons.NOT() != nil && colCons.NULL() != nil + //todo: cover exprs if needed + } + // todo: family + + return col +} + +func (c *cc) convertTypeNameOrBind(n parser.IType_name_or_bindContext) *ast.TypeName { + if t := n.Type_name(); t != nil { + return c.convertTypeName(t) + } else if b := n.Bind_parameter(); b != nil { + return &ast.TypeName{Name: "BIND:" + identifier(parseAnIdOrType(b.An_id_or_type()))} + } + return nil +} + +func (c *cc) convertTypeName(n parser.IType_nameContext) *ast.TypeName { + if n == nil { + return nil + } + + // Handle composite types + if composite := n.Type_name_composite(); composite != nil { + if node := c.convertTypeNameComposite(composite); node != nil { + if typeName, ok := node.(*ast.TypeName); ok { + return typeName + } + } + } + + // Handle decimal type (e.g., DECIMAL(10,2)) + if decimal := n.Type_name_decimal(); decimal != nil { + if integerOrBinds := decimal.AllInteger_or_bind(); len(integerOrBinds) >= 2 { + return &ast.TypeName{ + Name: "Decimal", + TypeOid: 0, + Names: &ast.List{ + Items: []ast.Node{ + c.convertIntegerOrBind(integerOrBinds[0]), + c.convertIntegerOrBind(integerOrBinds[1]), + }, + }, + } + } + } + + // Handle simple types + if simple := n.Type_name_simple(); simple != nil { + return &ast.TypeName{ + Name: simple.GetText(), + TypeOid: 0, + } + } + + return nil +} + +func (c *cc) convertIntegerOrBind(n parser.IInteger_or_bindContext) ast.Node { + if n == nil { + return nil + } + + if integer := n.Integer(); integer != nil { + val, err := parseIntegerValue(integer.GetText()) + if err != nil { + return &ast.TODO{} + } + return &ast.Integer{Ival: val} + } + + if bind := n.Bind_parameter(); bind != nil { + return c.convertBindParameter(bind.(*parser.Bind_parameterContext)) + } + + return nil +} + +func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.Node { + if n == nil { + return nil + } + + if opt := n.Type_name_optional(); opt != nil { + if typeName := opt.Type_name_or_bind(); typeName != nil { + return &ast.TypeName{ + Name: "Optional", + TypeOid: 0, + Names: &ast.List{ + Items: []ast.Node{c.convertTypeNameOrBind(typeName)}, + }, + } + } + } + + if tuple := n.Type_name_tuple(); tuple != nil { + if typeNames := tuple.AllType_name_or_bind(); len(typeNames) > 0 { + var items []ast.Node + for _, tn := range typeNames { + items = append(items, c.convertTypeNameOrBind(tn)) + } + return &ast.TypeName{ + Name: "Tuple", + TypeOid: 0, + Names: &ast.List{Items: items}, + } + } + } + + if struct_ := n.Type_name_struct(); struct_ != nil { + if structArgs := struct_.AllStruct_arg(); len(structArgs) > 0 { + var items []ast.Node + for _, _ = range structArgs { + // TODO: Handle struct field names and types + items = append(items, &ast.TODO{}) + } + return &ast.TypeName{ + Name: "Struct", + TypeOid: 0, + Names: &ast.List{Items: items}, + } + } + } + + if variant := n.Type_name_variant(); variant != nil { + if variantArgs := variant.AllVariant_arg(); len(variantArgs) > 0 { + var items []ast.Node + for _, _ = range variantArgs { + // TODO: Handle variant arguments + items = append(items, &ast.TODO{}) + } + return &ast.TypeName{ + Name: "Variant", + TypeOid: 0, + Names: &ast.List{Items: items}, + } + } + } + + if list := n.Type_name_list(); list != nil { + if typeName := list.Type_name_or_bind(); typeName != nil { + return &ast.TypeName{ + Name: "List", + TypeOid: 0, + Names: &ast.List{ + Items: []ast.Node{c.convertTypeNameOrBind(typeName)}, + }, + } + } + } + + if stream := n.Type_name_stream(); stream != nil { + if typeName := stream.Type_name_or_bind(); typeName != nil { + return &ast.TypeName{ + Name: "Stream", + TypeOid: 0, + Names: &ast.List{ + Items: []ast.Node{c.convertTypeNameOrBind(typeName)}, + }, + } + } + } + + if flow := n.Type_name_flow(); flow != nil { + if typeName := flow.Type_name_or_bind(); typeName != nil { + return &ast.TypeName{ + Name: "Flow", + TypeOid: 0, + Names: &ast.List{ + Items: []ast.Node{c.convertTypeNameOrBind(typeName)}, + }, + } + } + } + + if dict := n.Type_name_dict(); dict != nil { + if typeNames := dict.AllType_name_or_bind(); len(typeNames) >= 2 { + return &ast.TypeName{ + Name: "Dict", + TypeOid: 0, + Names: &ast.List{ + Items: []ast.Node{ + c.convertTypeNameOrBind(typeNames[0]), + c.convertTypeNameOrBind(typeNames[1]), + }, + }, + } + } + } + + if set := n.Type_name_set(); set != nil { + if typeName := set.Type_name_or_bind(); typeName != nil { + return &ast.TypeName{ + Name: "Set", + TypeOid: 0, + Names: &ast.List{ + Items: []ast.Node{c.convertTypeNameOrBind(typeName)}, + }, + } + } + } + + if enum := n.Type_name_enum(); enum != nil { + if typeTags := enum.AllType_name_tag(); len(typeTags) > 0 { + var items []ast.Node + for _, _ = range typeTags { // todo: Handle enum tags + items = append(items, &ast.TODO{}) + } + return &ast.TypeName{ + Name: "Enum", + TypeOid: 0, + Names: &ast.List{Items: items}, + } + } + } + + if resource := n.Type_name_resource(); resource != nil { + if typeTag := resource.Type_name_tag(); typeTag != nil { + // TODO: Handle resource tag + return &ast.TypeName{ + Name: "Resource", + TypeOid: 0, + Names: &ast.List{ + Items: []ast.Node{&ast.TODO{}}, + }, + } + } + } + + if tagged := n.Type_name_tagged(); tagged != nil { + if typeName := tagged.Type_name_or_bind(); typeName != nil { + if typeTag := tagged.Type_name_tag(); typeTag != nil { + // TODO: Handle tagged type and tag + return &ast.TypeName{ + Name: "Tagged", + TypeOid: 0, + Names: &ast.List{ + Items: []ast.Node{ + c.convertTypeNameOrBind(typeName), + &ast.TODO{}, + }, + }, + } + } + } + } + + if callable := n.Type_name_callable(); callable != nil { + // TODO: Handle callable argument list and return type + return &ast.TypeName{ + Name: "Callable", + TypeOid: 0, + Names: &ast.List{ + Items: []ast.Node{&ast.TODO{}}, + }, + } + } + + return nil +} + +func (c *cc) convertSqlStmtCore(n parser.ISql_stmt_coreContext) ast.Node { + if n == nil { + return nil + } + + if stmt := n.Pragma_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Select_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Named_nodes_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_table_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Drop_table_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Use_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Into_table_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Commit_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Update_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Delete_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Rollback_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Declare_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Import_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Export_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_table_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_external_table_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Do_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Define_action_or_subquery_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.If_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.For_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Values_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_user_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_user_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_group_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_group_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Drop_role_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_object_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_object_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Drop_object_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_external_data_source_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_external_data_source_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Drop_external_data_source_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_replication_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Drop_replication_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_topic_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_topic_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Drop_topic_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Grant_permissions_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Revoke_permissions_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_table_store_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Upsert_object_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_view_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Drop_view_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_replication_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_resource_pool_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_resource_pool_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Drop_resource_pool_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_backup_collection_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_backup_collection_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Drop_backup_collection_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Analyze_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Create_resource_pool_classifier_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_resource_pool_classifier_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Drop_resource_pool_classifier_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Backup_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Restore_stmt(); stmt != nil { + return c.convert(stmt) + } + if stmt := n.Alter_sequence_stmt(); stmt != nil { + return c.convert(stmt) + } + return nil +} + +func (c *cc) convertExpr(n *parser.ExprContext) ast.Node { + if n == nil { + return nil + } + + if tn := n.Type_name_composite(); tn != nil { + return c.convertTypeNameComposite(tn) + } + + orSubs := n.AllOr_subexpr() + if len(orSubs) == 0 { + return nil + } + + orSub, ok := orSubs[0].(*parser.Or_subexprContext) + if !ok { + return nil + } + + left := c.convertOrSubExpr(orSub) + for i := 1; i < len(orSubs); i++ { + orSub, ok = orSubs[i].(*parser.Or_subexprContext) + if !ok { + return nil + } + right := c.convertOrSubExpr(orSub) + left = &ast.BoolExpr{ + Boolop: ast.BoolExprTypeOr, + Args: &ast.List{Items: []ast.Node{left, right}}, + Location: n.GetStart().GetStart(), + } + } + return left +} + +func (c *cc) convertOrSubExpr(n *parser.Or_subexprContext) ast.Node { + if n == nil { + return nil + } + andSubs := n.AllAnd_subexpr() + if len(andSubs) == 0 { + return nil + } + andSub, ok := andSubs[0].(*parser.And_subexprContext) + if !ok { + return nil + } + + left := c.convertAndSubexpr(andSub) + for i := 1; i < len(andSubs); i++ { + andSub, ok = andSubs[i].(*parser.And_subexprContext) + if !ok { + return nil + } + right := c.convertAndSubexpr(andSub) + left = &ast.BoolExpr{ + Boolop: ast.BoolExprTypeAnd, + Args: &ast.List{Items: []ast.Node{left, right}}, + Location: n.GetStart().GetStart(), + } + } + return left +} + +func (c *cc) convertAndSubexpr(n *parser.And_subexprContext) ast.Node { + if n == nil { + return nil + } + + xors := n.AllXor_subexpr() + if len(xors) == 0 { + return nil + } + + xor, ok := xors[0].(*parser.Xor_subexprContext) + if !ok { + return nil + } + + left := c.convertXorSubexpr(xor) + for i := 1; i < len(xors); i++ { + xor, ok = xors[i].(*parser.Xor_subexprContext) + if !ok { + return nil + } + right := c.convertXorSubexpr(xor) + left = &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "XOR"}}}, + Lexpr: left, + Rexpr: right, + Location: n.GetStart().GetStart(), + } + } + return left +} + +func (c *cc) convertXorSubexpr(n *parser.Xor_subexprContext) ast.Node { + if n == nil { + return nil + } + es := n.Eq_subexpr() + if es == nil { + return nil + } + subExpr, ok := es.(*parser.Eq_subexprContext) + if !ok { + return nil + } + base := c.convertEqSubexpr(subExpr) + if cond := n.Cond_expr(); cond != nil { + condCtx, ok := cond.(*parser.Cond_exprContext) + if !ok { + return base + } + + switch { + case condCtx.IN() != nil: + if inExpr := condCtx.In_expr(); inExpr != nil { + return &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "IN"}}}, + Lexpr: base, + Rexpr: c.convert(inExpr), + } + } + case condCtx.BETWEEN() != nil: + if eqSubs := condCtx.AllEq_subexpr(); len(eqSubs) >= 2 { + return &ast.BetweenExpr{ + Expr: base, + Left: c.convert(eqSubs[0]), + Right: c.convert(eqSubs[1]), + Not: condCtx.NOT() != nil, + Location: n.GetStart().GetStart(), + } + } + case condCtx.ISNULL() != nil: + return &ast.NullTest{ + Arg: base, + Nulltesttype: 1, // IS NULL + Location: n.GetStart().GetStart(), + } + case condCtx.NOTNULL() != nil: + return &ast.NullTest{ + Arg: base, + Nulltesttype: 2, // IS NOT NULL + Location: n.GetStart().GetStart(), + } + case condCtx.IS() != nil && condCtx.NULL() != nil: + return &ast.NullTest{ + Arg: base, + Nulltesttype: 1, // IS NULL + Location: n.GetStart().GetStart(), + } + case condCtx.IS() != nil && condCtx.NOT() != nil && condCtx.NULL() != nil: + return &ast.NullTest{ + Arg: base, + Nulltesttype: 2, // IS NOT NULL + Location: n.GetStart().GetStart(), + } + case condCtx.Match_op() != nil: + // debug!!! + matchOp := condCtx.Match_op().GetText() + if eqSubs := condCtx.AllEq_subexpr(); len(eqSubs) >= 1 { + expr := &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: matchOp}}}, + Lexpr: base, + Rexpr: c.convert(eqSubs[0]), + } + if condCtx.ESCAPE() != nil && len(eqSubs) >= 2 { + // todo: Add ESCAPE support + } + return expr + } + case len(condCtx.AllEQUALS()) > 0 || len(condCtx.AllEQUALS2()) > 0 || + len(condCtx.AllNOT_EQUALS()) > 0 || len(condCtx.AllNOT_EQUALS2()) > 0: + // debug!!! + var op string + switch { + case len(condCtx.AllEQUALS()) > 0: + op = "=" + case len(condCtx.AllEQUALS2()) > 0: + op = "==" + case len(condCtx.AllNOT_EQUALS()) > 0: + op = "!=" + case len(condCtx.AllNOT_EQUALS2()) > 0: + op = "<>" + } + if eqSubs := condCtx.AllEq_subexpr(); len(eqSubs) >= 1 { + return &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: op}}}, + Lexpr: base, + Rexpr: c.convert(eqSubs[0]), + } + } + case len(condCtx.AllDistinct_from_op()) > 0: + // debug!!! + distinctOps := condCtx.AllDistinct_from_op() + for _, distinctOp := range distinctOps { + if eqSubs := condCtx.AllEq_subexpr(); len(eqSubs) >= 1 { + not := distinctOp.NOT() != nil + op := "IS DISTINCT FROM" + if not { + op = "IS NOT DISTINCT FROM" + } + return &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: op}}}, + Lexpr: base, + Rexpr: c.convert(eqSubs[0]), + } + } + } + } + } + return base +} + +func (c *cc) convertEqSubexpr(n *parser.Eq_subexprContext) ast.Node { + if n == nil { + return nil + } + neqList := n.AllNeq_subexpr() + if len(neqList) == 0 { + return nil + } + neq, ok := neqList[0].(*parser.Neq_subexprContext) + if !ok { + return nil + } + left := c.convertNeqSubexpr(neq) + ops := c.collectComparisonOps(n) + for i := 1; i < len(neqList); i++ { + neq, ok = neqList[i].(*parser.Neq_subexprContext) + if !ok { + return nil + } + right := c.convertNeqSubexpr(neq) + opText := ops[i-1].GetText() + left = &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, + Lexpr: left, + Rexpr: right, + Location: n.GetStart().GetStart(), + } + } + return left +} + +func (c *cc) collectComparisonOps(n parser.IEq_subexprContext) []antlr.TerminalNode { + var ops []antlr.TerminalNode + for _, child := range n.GetChildren() { + if tn, ok := child.(antlr.TerminalNode); ok { + switch tn.GetText() { + case "<", "<=", ">", ">=": + ops = append(ops, tn) + } + } + } + return ops +} + +func (c *cc) convertNeqSubexpr(n *parser.Neq_subexprContext) ast.Node { + if n == nil { + return nil + } + bitList := n.AllBit_subexpr() + if len(bitList) == 0 { + return nil + } + + bl, ok := bitList[0].(*parser.Bit_subexprContext) + if !ok { + return nil + } + left := c.convertBitSubexpr(bl) + ops := c.collectBitwiseOps(n) + for i := 1; i < len(bitList); i++ { + bl, ok = bitList[i].(*parser.Bit_subexprContext) + if !ok { + return nil + } + right := c.convertBitSubexpr(bl) + opText := ops[i-1].GetText() + left = &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, + Lexpr: left, + Rexpr: right, + Location: n.GetStart().GetStart(), + } + } + + if n.Double_question() != nil { + nextCtx := n.Neq_subexpr() + if nextCtx != nil { + neq, ok2 := nextCtx.(*parser.Neq_subexprContext) + if !ok2 { + return nil + } + right := c.convertNeqSubexpr(neq) + left = &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "??"}}}, + Lexpr: left, + Rexpr: right, + Location: n.GetStart().GetStart(), + } + } + } else { + // !! debug !! + qCount := len(n.AllQUESTION()) + if qCount > 0 { + questionOp := "?" + if qCount > 1 { + questionOp = strings.Repeat("?", qCount) + } + left = &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: questionOp}}}, + Lexpr: left, + Location: n.GetStart().GetStart(), + } + } + } + + return left +} + +func (c *cc) collectBitwiseOps(ctx parser.INeq_subexprContext) []antlr.TerminalNode { + var ops []antlr.TerminalNode + children := ctx.GetChildren() + for _, child := range children { + if tn, ok := child.(antlr.TerminalNode); ok { + txt := tn.GetText() + switch txt { + case "<<", ">>", "<<|", ">>|", "&", "|", "^": + ops = append(ops, tn) + } + } + } + return ops +} + +func (c *cc) convertBitSubexpr(n *parser.Bit_subexprContext) ast.Node { + addList := n.AllAdd_subexpr() + left := c.convertAddSubexpr(addList[0].(*parser.Add_subexprContext)) + + ops := c.collectBitOps(n) + for i := 1; i < len(addList); i++ { + right := c.convertAddSubexpr(addList[i].(*parser.Add_subexprContext)) + opText := ops[i-1].GetText() + left = &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, + Lexpr: left, + Rexpr: right, + Location: n.GetStart().GetStart(), + } + } + return left +} + +func (c *cc) collectBitOps(ctx parser.IBit_subexprContext) []antlr.TerminalNode { + var ops []antlr.TerminalNode + children := ctx.GetChildren() + for _, child := range children { + if tn, ok := child.(antlr.TerminalNode); ok { + txt := tn.GetText() + switch txt { + case "+", "-": + ops = append(ops, tn) + } + } + } + return ops +} + +func (c *cc) convertAddSubexpr(n *parser.Add_subexprContext) ast.Node { + mulList := n.AllMul_subexpr() + left := c.convertMulSubexpr(mulList[0].(*parser.Mul_subexprContext)) + + ops := c.collectAddOps(n) + for i := 1; i < len(mulList); i++ { + right := c.convertMulSubexpr(mulList[i].(*parser.Mul_subexprContext)) + opText := ops[i-1].GetText() + left = &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, + Lexpr: left, + Rexpr: right, + Location: n.GetStart().GetStart(), + } + } + return left +} + +func (c *cc) collectAddOps(ctx parser.IAdd_subexprContext) []antlr.TerminalNode { + var ops []antlr.TerminalNode + for _, child := range ctx.GetChildren() { + if tn, ok := child.(antlr.TerminalNode); ok { + switch tn.GetText() { + case "*", "/", "%": + ops = append(ops, tn) + } + } + } + return ops +} + +func (c *cc) convertMulSubexpr(n *parser.Mul_subexprContext) ast.Node { + conList := n.AllCon_subexpr() + left := c.convertConSubexpr(conList[0].(*parser.Con_subexprContext)) + + for i := 1; i < len(conList); i++ { + right := c.convertConSubexpr(conList[i].(*parser.Con_subexprContext)) + left = &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "||"}}}, + Lexpr: left, + Rexpr: right, + Location: n.GetStart().GetStart(), + } + } + return left +} + +func (c *cc) convertConSubexpr(n *parser.Con_subexprContext) ast.Node { + if opCtx := n.Unary_op(); opCtx != nil { + op := opCtx.GetText() + operand := c.convertUnarySubexpr(n.Unary_subexpr().(*parser.Unary_subexprContext)) + return &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: op}}}, + Rexpr: operand, + Location: n.GetStart().GetStart(), + } + } + return c.convertUnarySubexpr(n.Unary_subexpr().(*parser.Unary_subexprContext)) +} + +func (c *cc) convertUnarySubexpr(n *parser.Unary_subexprContext) ast.Node { + if casual := n.Unary_casual_subexpr(); casual != nil { + return c.convertUnaryCasualSubexpr(casual.(*parser.Unary_casual_subexprContext)) + } + if jsonExpr := n.Json_api_expr(); jsonExpr != nil { + return c.convertJsonApiExpr(jsonExpr.(*parser.Json_api_exprContext)) + } + return nil +} + +func (c *cc) convertJsonApiExpr(n *parser.Json_api_exprContext) ast.Node { + return &ast.TODO{} // todo +} + +func (c *cc) convertUnaryCasualSubexpr(n *parser.Unary_casual_subexprContext) ast.Node { + var baseExpr ast.Node + + if idExpr := n.Id_expr(); idExpr != nil { + baseExpr = c.convertIdExpr(idExpr.(*parser.Id_exprContext)) + } else if atomExpr := n.Atom_expr(); atomExpr != nil { + baseExpr = c.convertAtomExpr(atomExpr.(*parser.Atom_exprContext)) + } + + suffixCtx := n.Unary_subexpr_suffix() + if suffixCtx != nil { + ctx, ok := suffixCtx.(*parser.Unary_subexpr_suffixContext) + if !ok { + return baseExpr + } + baseExpr = c.convertUnarySubexprSuffix(baseExpr, ctx) + } + + return baseExpr +} + +func (c *cc) convertUnarySubexprSuffix(base ast.Node, n *parser.Unary_subexpr_suffixContext) ast.Node { + if n == nil { + return base + } + colRef, ok := base.(*ast.ColumnRef) + if !ok { + return base // todo: cover case when unary subexpr with atomic expr + } + + for i := 0; i < n.GetChildCount(); i++ { + child := n.GetChild(i) + switch v := child.(type) { + case parser.IKey_exprContext: + node := c.convert(v.(*parser.Key_exprContext)) + if node != nil { + colRef.Fields.Items = append(colRef.Fields.Items, node) + } + + case parser.IInvoke_exprContext: + node := c.convert(v.(*parser.Invoke_exprContext)) + if node != nil { + colRef.Fields.Items = append(colRef.Fields.Items, node) + } + case antlr.TerminalNode: + if v.GetText() == "." { + if i+1 < n.GetChildCount() { + next := n.GetChild(i + 1) + switch w := next.(type) { + case parser.IBind_parameterContext: + // !!! debug !!! + node := c.convert(next.(*parser.Bind_parameterContext)) + colRef.Fields.Items = append(colRef.Fields.Items, node) + case antlr.TerminalNode: + // !!! debug !!! + val, err := parseIntegerValue(w.GetText()) + if err != nil { + if debug.Active { + log.Printf("Failed to parse integer value '%s': %v", w.GetText(), err) + } + return &ast.TODO{} + } + node := &ast.A_Const{Val: &ast.Integer{Ival: val}, Location: n.GetStart().GetStart()} + colRef.Fields.Items = append(colRef.Fields.Items, node) + case parser.IAn_id_or_typeContext: + idText := parseAnIdOrType(w) + colRef.Fields.Items = append(colRef.Fields.Items, &ast.String{Str: idText}) + default: + colRef.Fields.Items = append(colRef.Fields.Items, &ast.TODO{}) + } + i++ + } + } + } + } + + if n.COLLATE() != nil && n.An_id() != nil { + // todo: Handle COLLATE + } + return colRef +} + +func (c *cc) convertIdExpr(n *parser.Id_exprContext) ast.Node { + if id := n.Identifier(); id != nil { + return &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + NewIdentifier(id.GetText()), + }, + }, + } + } + return &ast.TODO{} +} + +func (c *cc) convertAtomExpr(n *parser.Atom_exprContext) ast.Node { + switch { + case n.An_id_or_type() != nil: + return NewIdentifier(parseAnIdOrType(n.An_id_or_type())) + case n.Literal_value() != nil: + return c.convertLiteralValue(n.Literal_value().(*parser.Literal_valueContext)) + case n.Bind_parameter() != nil: + return c.convertBindParameter(n.Bind_parameter().(*parser.Bind_parameterContext)) + default: + return &ast.TODO{} + } +} + +func (c *cc) convertLiteralValue(n *parser.Literal_valueContext) ast.Node { + switch { + case n.Integer() != nil: + text := n.Integer().GetText() + val, err := parseIntegerValue(text) + if err != nil { + if debug.Active { + log.Printf("Failed to parse integer value '%s': %v", text, err) + } + return &ast.TODO{} + } + return &ast.A_Const{Val: &ast.Integer{Ival: val}, Location: n.GetStart().GetStart()} + + case n.Real_() != nil: + text := n.Real_().GetText() + return &ast.A_Const{Val: &ast.Float{Str: text}, Location: n.GetStart().GetStart()} + + case n.STRING_VALUE() != nil: // !!! debug !!! (problem with quoted strings) + val := n.STRING_VALUE().GetText() + if len(val) >= 2 { + val = val[1 : len(val)-1] + } + return &ast.A_Const{Val: &ast.String{Str: val}, Location: n.GetStart().GetStart()} + + case n.Bool_value() != nil: + var i bool + if n.Bool_value().TRUE() != nil { + i = true + } + return &ast.Boolean{Boolval: i} + + case n.NULL() != nil: + return &ast.Null{} + + case n.CURRENT_TIME() != nil: + if debug.Active { + log.Printf("TODO: Implement CURRENT_TIME") + } + return &ast.TODO{} + + case n.CURRENT_DATE() != nil: + if debug.Active { + log.Printf("TODO: Implement CURRENT_DATE") + } + return &ast.TODO{} + + case n.CURRENT_TIMESTAMP() != nil: + if debug.Active { + log.Printf("TODO: Implement CURRENT_TIMESTAMP") + } + return &ast.TODO{} + + case n.BLOB() != nil: + blobText := n.BLOB().GetText() + return &ast.A_Const{Val: &ast.String{Str: blobText}, Location: n.GetStart().GetStart()} + + case n.EMPTY_ACTION() != nil: + if debug.Active { + log.Printf("TODO: Implement EMPTY_ACTION") + } + return &ast.TODO{} + + default: + if debug.Active { + log.Printf("Unknown literal value type: %T", n) + } + return &ast.TODO{} + } +} + +func (c *cc) convertSqlStmt(n *parser.Sql_stmtContext) ast.Node { + if n == nil { + return nil + } + // todo: handle explain + if core := n.Sql_stmt_core(); core != nil { + return c.convert(core) + } + + return nil +} + +func (c *cc) convert(node node) ast.Node { + switch n := node.(type) { + case *parser.Sql_stmtContext: + return c.convertSqlStmt(n) + + case *parser.Sql_stmt_coreContext: + return c.convertSqlStmtCore(n) + + case *parser.Create_table_stmtContext: + return c.convertCreate_table_stmtContext(n) + + case *parser.Select_stmtContext: + return c.convertSelectStmtContext(n) + + case *parser.Select_coreContext: + return c.convertSelectCoreContext(n) + + case *parser.Result_columnContext: + return c.convertResultColumn(n) + + case *parser.Join_sourceContext: + return c.convertJoinSource(n) + + case *parser.Flatten_sourceContext: + return c.convertFlattenSource(n) + + case *parser.Named_single_sourceContext: + return c.convertNamedSingleSource(n) + + case *parser.Single_sourceContext: + return c.convertSingleSource(n) + + case *parser.Bind_parameterContext: + return c.convertBindParameter(n) + + case *parser.ExprContext: + return c.convertExpr(n) + + case *parser.Or_subexprContext: + return c.convertOrSubExpr(n) + + case *parser.And_subexprContext: + return c.convertAndSubexpr(n) + + case *parser.Xor_subexprContext: + return c.convertXorSubexpr(n) + + case *parser.Eq_subexprContext: + return c.convertEqSubexpr(n) + + case *parser.Neq_subexprContext: + return c.convertNeqSubexpr(n) + + case *parser.Bit_subexprContext: + return c.convertBitSubexpr(n) + + case *parser.Add_subexprContext: + return c.convertAddSubexpr(n) + + case *parser.Mul_subexprContext: + return c.convertMulSubexpr(n) + + case *parser.Con_subexprContext: + return c.convertConSubexpr(n) + + case *parser.Unary_subexprContext: + return c.convertUnarySubexpr(n) + + case *parser.Unary_casual_subexprContext: + return c.convertUnaryCasualSubexpr(n) + + case *parser.Id_exprContext: + return c.convertIdExpr(n) + + case *parser.Atom_exprContext: + return c.convertAtomExpr(n) + + case *parser.Literal_valueContext: + return c.convertLiteralValue(n) + + case *parser.Json_api_exprContext: + return c.convertJsonApiExpr(n) + + case *parser.Type_name_compositeContext: + return c.convertTypeNameComposite(n) + + case *parser.Type_nameContext: + return c.convertTypeName(n) + + case *parser.Integer_or_bindContext: + return c.convertIntegerOrBind(n) + + case *parser.Type_name_or_bindContext: + return c.convertTypeNameOrBind(n) + + default: + return todo("convert(case=default)", n) + } +} diff --git a/internal/engine/ydb/parse.go b/internal/engine/ydb/parse.go new file mode 100755 index 0000000000..797710988c --- /dev/null +++ b/internal/engine/ydb/parse.go @@ -0,0 +1,93 @@ +package ydb + +import ( + "errors" + "fmt" + "io" + + "github.com/antlr4-go/antlr/v4" + "github.com/sqlc-dev/sqlc/internal/source" + "github.com/sqlc-dev/sqlc/internal/sql/ast" + parser "github.com/ydb-platform/yql-parsers/go" +) + +type errorListener struct { + *antlr.DefaultErrorListener + + err string +} + +func (el *errorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) { + el.err = msg +} + +// func (el *errorListener) ReportAmbiguity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, exact bool, ambigAlts *antlr.BitSet, configs antlr.ATNConfigSet) { +// } +// +// func (el *errorListener) ReportAttemptingFullContext(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, conflictingAlts *antlr.BitSet, configs antlr.ATNConfigSet) { +// } +// +// func (el *errorListener) ReportContextSensitivity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex, prediction int, configs antlr.ATNConfigSet) { +// } + +func NewParser() *Parser { + return &Parser{} +} + +type Parser struct { +} + +func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { + blob, err := io.ReadAll(r) + if err != nil { + return nil, err + } + input := antlr.NewInputStream(string(blob)) + lexer := parser.NewYQLLexer(input) + stream := antlr.NewCommonTokenStream(lexer, 0) + pp := parser.NewYQLParser(stream) + el := &errorListener{} + pp.AddErrorListener(el) + // pp.BuildParseTrees = true + tree := pp.Sql_query() + if el.err != "" { + return nil, errors.New(el.err) + } + pctx, ok := tree.(*parser.Sql_queryContext) + if !ok { + return nil, fmt.Errorf("expected ParserContext; got %T\n ", tree) + } + var stmts []ast.Statement + stmtListCtx := pctx.Sql_stmt_list() + if stmtListCtx != nil { + loc := 0 + for _, stmt := range stmtListCtx.AllSql_stmt() { + converter := &cc{} + out := converter.convert(stmt) + if _, ok := out.(*ast.TODO); ok { + loc = stmt.GetStop().GetStop() + 2 + continue + } + if out != nil { + len := (stmt.GetStop().GetStop() + 1) - loc + stmts = append(stmts, ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: out, + StmtLocation: loc, + StmtLen: len, + }, + }) + loc = stmt.GetStop().GetStop() + 2 + } + } + } + return stmts, nil +} + +func (p *Parser) CommentSyntax() source.CommentSyntax { + return source.CommentSyntax{ + Dash: true, + Hash: false, + SlashStar: true, + } +} diff --git a/internal/engine/ydb/reserved.go b/internal/engine/ydb/reserved.go new file mode 100644 index 0000000000..8db504c0b9 --- /dev/null +++ b/internal/engine/ydb/reserved.go @@ -0,0 +1,301 @@ +package ydb + +import "strings" + + +func (p *Parser) IsReservedKeyword(s string) bool { + switch strings.ToLower(s) { + case "abort": + case "action": + case "add": + case "after": + case "all": + case "alter": + case "analyze": + case "and": + case "ansi": + case "any": + case "array": + case "as": + case "asc": + case "assume": + case "asymmetric": + case "async": + case "at": + case "attach": + case "attributes": + case "autoincrement": + case "automap": + case "backup": + case "batch": + case "collection": + case "before": + case "begin": + case "bernoulli": + case "between": + case "bitcast": + case "by": + case "callable": + case "cascade": + case "case": + case "cast": + case "changefeed": + case "check": + case "classifier": + case "collate": + case "column": + case "columns": + case "commit": + case "compact": + case "conditional": + case "conflict": + case "connect": + case "constraint": + case "consumer": + case "cover": + case "create": + case "cross": + case "cube": + case "current": + case "current_date": + case "current_time": + case "current_timestamp": + case "data": + case "database": + case "decimal": + case "declare": + case "default": + case "deferrable": + case "deferred": + case "define": + case "delete": + case "desc": + case "describe": + case "detach": + case "dict": + case "directory": + case "disable": + case "discard": + case "distinct": + case "do": + case "drop": + case "each": + case "else": + case "empty": + case "empty_action": + case "encrypted": + case "end": + case "enum": + case "erase": + case "error": + case "escape": + case "evaluate": + case "except": + case "exclude": + case "exclusion": + case "exclusive": + case "exists": + case "explain": + case "export": + case "external": + case "fail": + case "false": + case "family": + case "filter": + case "first": + case "flatten": + case "flow": + case "following": + case "for": + case "foreign": + case "from": + case "full": + case "function": + case "glob": + case "global": + case "grant": + case "group": + case "grouping": + case "groups": + case "hash": + case "having": + case "hop": + case "if": + case "ignore": + case "ilike": + case "immediate": + case "import": + case "in": + case "increment": + case "incremental": + case "index": + case "indexed": + case "inherits": + case "initial": + case "initially": + case "inner": + case "insert": + case "instead": + case "intersect": + case "into": + case "is": + case "isnull": + case "join": + case "json_exists": + case "json_query": + case "json_value": + case "key": + case "last": + case "left": + case "legacy": + case "like": + case "limit": + case "list": + case "local": + case "login": + case "manage": + case "match": + case "matches": + case "match_recognize": + case "measures": + case "microseconds": + case "milliseconds": + case "modify": + case "nanoseconds": + case "natural": + case "next": + case "no": + case "nologin": + case "not": + case "notnull": + case "null": + case "nulls": + case "object": + case "of": + case "offset": + case "omit": + case "on": + case "one": + case "only": + case "option": + case "optional": + case "or": + case "order": + case "others": + case "outer": + case "over": + case "owner": + case "parallel": + case "partition": + case "passing": + case "password": + case "past": + case "pattern": + case "per": + case "permute": + case "plan": + case "pool": + case "pragma": + case "preceding": + case "presort": + case "primary": + case "privileges": + case "process": + case "query": + case "queue": + case "raise": + case "range": + case "reduce": + case "references": + case "regexp": + case "reindex": + case "release": + case "remove": + case "rename": + case "repeatable": + case "replace": + case "replication": + case "reset": + case "resource": + case "respect": + case "restart": + case "restore": + case "restrict": + case "result": + case "return": + case "returning": + case "revert": + case "revoke": + case "right": + case "rlike": + case "rollback": + case "rollup": + case "row": + case "rows": + case "sample": + case "savepoint": + case "schema": + case "seconds": + case "seek": + case "select": + case "semi": + case "set": + case "sets": + case "show": + case "tskip": + case "sequence": + case "source": + case "start": + case "stream": + case "struct": + case "subquery": + case "subset": + case "symbols": + case "symmetric": + case "sync": + case "system": + case "table": + case "tables": + case "tablesample": + case "tablestore": + case "tagged": + case "temp": + case "temporary": + case "then": + case "ties": + case "to": + case "topic": + case "transaction": + case "transfer": + case "trigger": + case "true": + case "tuple": + case "type": + case "unbounded": + case "unconditional": + case "union": + case "unique": + case "unknown": + case "unmatched": + case "update": + case "upsert": + case "use": + case "user": + case "using": + case "vacuum": + case "values": + case "variant": + case "view": + case "virtual": + case "when": + case "where": + case "window": + case "with": + case "without": + case "wrapper": + case "xor": + default: + return false + } + return true +} diff --git a/internal/engine/ydb/stdlib.go b/internal/engine/ydb/stdlib.go new file mode 100644 index 0000000000..fd78d7de38 --- /dev/null +++ b/internal/engine/ydb/stdlib.go @@ -0,0 +1,12 @@ +package ydb + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func defaultSchema(name string) *catalog.Schema { + s := &catalog.Schema{Name: name} + s.Funcs = []*catalog.Function{} + + return s +} diff --git a/internal/engine/ydb/utils.go b/internal/engine/ydb/utils.go new file mode 100755 index 0000000000..0fe41d356f --- /dev/null +++ b/internal/engine/ydb/utils.go @@ -0,0 +1,143 @@ +package ydb + +import ( + "strconv" + "strings" + + "github.com/antlr4-go/antlr/v4" + "github.com/sqlc-dev/sqlc/internal/sql/ast" + parser "github.com/ydb-platform/yql-parsers/go" +) + +type objectRefProvider interface { + antlr.ParserRuleContext + Object_ref() parser.IObject_refContext +} + +func parseTableName(ctx objectRefProvider) *ast.TableName { + return parseObjectRef(ctx.Object_ref()) +} + +func parseObjectRef(r parser.IObject_refContext) *ast.TableName { + if r == nil { + return nil + } + ref := r.(*parser.Object_refContext) + + parts := []string{} + + if cl := ref.Cluster_expr(); cl != nil { + parts = append(parts, parseClusterExpr(cl)) + } + + if idOrAt := ref.Id_or_at(); idOrAt != nil { + parts = append(parts, parseIdOrAt(idOrAt)) + } + + objectName := strings.Join(parts, ".") + + return &ast.TableName{ + Schema: "", + Name: identifier(objectName), + } +} + +func parseClusterExpr(ctx parser.ICluster_exprContext) string { + if ctx == nil { + return "" + } + return identifier(ctx.GetText()) +} + +func parseIdOrAt(ctx parser.IId_or_atContext) string { + if ctx == nil { + return "" + } + idOrAt := ctx.(*parser.Id_or_atContext) + + if ao := idOrAt.An_id_or_type(); ao != nil { + return identifier(parseAnIdOrType(ao)) + } + return "" +} + +func parseAnIdOrType(ctx parser.IAn_id_or_typeContext) string { + if ctx == nil { + return "" + } + anId := ctx.(*parser.An_id_or_typeContext) + + if anId.Id_or_type() != nil { + return identifier(parseIdOrType(anId.Id_or_type())) + } + + if anId.STRING_VALUE() != nil { + return identifier(anId.STRING_VALUE().GetText()) + } + + return "" +} + +func parseIdOrType(ctx parser.IId_or_typeContext) string { + if ctx == nil { + return "" + } + Id := ctx.(*parser.Id_or_typeContext) + if Id.Id() != nil { + return identifier(parseIdTable(Id.Id())) + } + + return "" +} + +func parseAnId(ctx parser.IAn_idContext) string { + if id := ctx.Id(); id != nil { + return id.GetText() + } else if str := ctx.STRING_VALUE(); str != nil { + return str.GetText() + } + return "" +} + +func parseAnIdSchema(ctx parser.IAn_id_schemaContext) string { + if ctx == nil { + return "" + } + if id := ctx.Id_schema(); id != nil { + return id.GetText() + } else if str := ctx.STRING_VALUE(); str != nil { + return str.GetText() + } + return "" +} + +func parseIdTable(ctx parser.IIdContext) string { + if ctx == nil { + return "" + } + return ctx.GetText() +} + +func parseIntegerValue(text string) (int64, error) { + text = strings.ToLower(text) + base := 10 + + switch { + case strings.HasPrefix(text, "0x"): + base = 16 + text = strings.TrimPrefix(text, "0x") + + case strings.HasPrefix(text, "0o"): + base = 8 + text = strings.TrimPrefix(text, "0o") + + case strings.HasPrefix(text, "0b"): + base = 2 + text = strings.TrimPrefix(text, "0b") + } + + // debug!!! + text = strings.TrimRight(text, "pulstibn") + + return strconv.ParseInt(text, base, 64) +} diff --git a/internal/sql/rewrite/parameters.go b/internal/sql/rewrite/parameters.go index d1ea1a22cc..9146d17e08 100644 --- a/internal/sql/rewrite/parameters.go +++ b/internal/sql/rewrite/parameters.go @@ -172,6 +172,8 @@ func NamedParameters(engine config.Engine, raw *ast.RawStmt, numbs map[int]bool, replace = "?" } else if engine == config.EngineSQLite { replace = fmt.Sprintf("?%d", argn) + } else if engine == config.EngineYDB { + replace = fmt.Sprintf("$%s", paramName) } else { replace = fmt.Sprintf("$%d", argn) } diff --git a/internal/sqltest/local/ydb.go b/internal/sqltest/local/ydb.go new file mode 100644 index 0000000000..79be58241f --- /dev/null +++ b/internal/sqltest/local/ydb.go @@ -0,0 +1,117 @@ +package local + +import ( + "context" + "database/sql" + "fmt" + "hash/fnv" + "math/rand" + "net" + "os" + "testing" + "time" + + migrate "github.com/sqlc-dev/sqlc/internal/migrations" + "github.com/sqlc-dev/sqlc/internal/sql/sqlpath" + "github.com/ydb-platform/ydb-go-sdk/v3" +) + +func init() { + rand.Seed(time.Now().UnixNano()) +} + +func YDB(t *testing.T, migrations []string) TestYDB { + return link_YDB(t, migrations, true) +} + +func ReadOnlyYDB(t *testing.T, migrations []string) TestYDB { + return link_YDB(t, migrations, false) +} + +type TestYDB struct { + DB *sql.DB + Prefix string +} + +func link_YDB(t *testing.T, migrations []string, rw bool) TestYDB { + t.Helper() + + // 1) Контекст с таймаутом + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + dbuiri := os.Getenv("YDB_SERVER_URI") + if dbuiri == "" { + t.Skip("YDB_SERVER_URI is empty") + } + host, _, err := net.SplitHostPort(dbuiri) + if err != nil { + t.Fatalf("invalid YDB_SERVER_URI: %q", dbuiri) + } + + baseDB := os.Getenv("YDB_DATABASE") + if baseDB == "" { + baseDB = "/local" + } + + // собираем миграции + var seed []string + files, err := sqlpath.Glob(migrations) + if err != nil { + t.Fatal(err) + } + h := fnv.New64() + for _, f := range files { + blob, err := os.ReadFile(f) + if err != nil { + t.Fatal(err) + } + h.Write(blob) + seed = append(seed, migrate.RemoveRollbackStatements(string(blob))) + } + + var name string + if rw { + // name = fmt.Sprintf("sqlc_test_%s", id()) + name = fmt.Sprintf("sqlc_test_%s", "test_new") + } else { + name = fmt.Sprintf("sqlc_test_%x", h.Sum(nil)) + } + prefix := fmt.Sprintf("%s/%s", baseDB, name) + + // 2) Открываем драйвер к корню "/" + rootDSN := fmt.Sprintf("grpc://%s?database=%s", dbuiri, baseDB) + t.Logf("→ Opening root driver: %s", rootDSN) + driver, err := ydb.Open(ctx, rootDSN, + ydb.WithInsecure(), + ydb.WithDiscoveryInterval(time.Hour), + ydb.WithNodeAddressMutator(func(_ string) string { + return host + }), + ) + if err != nil { + t.Fatalf("failed to open root YDB connection: %s", err) + } + + connector, err := ydb.Connector( + driver, + ydb.WithTablePathPrefix(prefix), + ydb.WithAutoDeclare(), + ) + if err != nil { + t.Fatalf("failed to create connector: %s", err) + } + + db := sql.OpenDB(connector) + + t.Log("→ Applying migrations to prefix: ", prefix) + + schemeCtx := ydb.WithQueryMode(ctx, ydb.SchemeQueryMode) + for _, stmt := range seed { + _, err := db.ExecContext(schemeCtx, stmt) + if err != nil { + t.Fatalf("failed to apply migration: %s\nSQL: %s", err, stmt) + } + } + return TestYDB{DB: db, Prefix: prefix} +} From 4e46daafafafbcae0c3e264ff0f6bbc8f31c6bbd Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Sun, 27 Apr 2025 02:00:26 +0300 Subject: [PATCH 02/22] Added almost full INSERT support and basic DELETE (without ON) support --- examples/authors/sqlc.yaml | 82 ++++----- examples/authors/ydb/db_test.go | 97 +++++++++-- examples/authors/ydb/models.go | 6 +- examples/authors/ydb/query.sql | 10 ++ examples/authors/ydb/query.sql.go | 42 +++++ internal/codegen/golang/ydb_type.go | 40 +++-- .../engine/ydb/catalog_tests/insert_test.go | 135 +++++++++++++++ internal/engine/ydb/convert.go | 160 ++++++++++++++++++ internal/sql/ast/delete_stmt.go | 6 + internal/sql/ast/insert_stmt.go | 15 +- internal/sql/ast/on_conflict_action_type.go | 15 ++ internal/sqltest/local/ydb.go | 2 +- 12 files changed, 532 insertions(+), 78 deletions(-) create mode 100644 internal/engine/ydb/catalog_tests/insert_test.go create mode 100644 internal/sql/ast/on_conflict_action_type.go diff --git a/examples/authors/sqlc.yaml b/examples/authors/sqlc.yaml index 8d6bc3db28..30d904875e 100644 --- a/examples/authors/sqlc.yaml +++ b/examples/authors/sqlc.yaml @@ -2,47 +2,47 @@ version: '2' cloud: project: "01HAQMMECEYQYKFJN8MP16QC41" sql: -- name: postgresql - schema: postgresql/schema.sql - queries: postgresql/query.sql - engine: postgresql - database: - uri: "${VET_TEST_EXAMPLES_POSTGRES_AUTHORS}" - analyzer: - database: false - rules: - - sqlc/db-prepare - - postgresql-query-too-costly - gen: - go: - package: authors - sql_package: pgx/v5 - out: postgresql -- name: mysql - schema: mysql/schema.sql - queries: mysql/query.sql - engine: mysql - database: - uri: "${VET_TEST_EXAMPLES_MYSQL_AUTHORS}" - rules: - - sqlc/db-prepare - # - mysql-query-too-costly - gen: - go: - package: authors - out: mysql -- name: sqlite - schema: sqlite/schema.sql - queries: sqlite/query.sql - engine: sqlite - database: - uri: file:authors?mode=memory&cache=shared - rules: - - sqlc/db-prepare - gen: - go: - package: authors - out: sqlite +# - name: postgresql +# schema: postgresql/schema.sql +# queries: postgresql/query.sql +# engine: postgresql +# database: +# uri: "${VET_TEST_EXAMPLES_POSTGRES_AUTHORS}" +# analyzer: +# database: false +# rules: +# - sqlc/db-prepare +# - postgresql-query-too-costly +# gen: +# go: +# package: authors +# sql_package: pgx/v5 +# out: postgresql +# - name: mysql +# schema: mysql/schema.sql +# queries: mysql/query.sql +# engine: mysql +# database: +# uri: "${VET_TEST_EXAMPLES_MYSQL_AUTHORS}" +# rules: +# - sqlc/db-prepare +# # - mysql-query-too-costly +# gen: +# go: +# package: authors +# out: mysql +# - name: sqlite +# schema: sqlite/schema.sql +# queries: sqlite/query.sql +# engine: sqlite +# database: +# uri: file:authors?mode=memory&cache=shared +# rules: +# - sqlc/db-prepare +# gen: +# go: +# package: authors +# out: sqlite - name: ydb schema: ydb/schema.sql queries: ydb/query.sql diff --git a/examples/authors/ydb/db_test.go b/examples/authors/ydb/db_test.go index 181ee64ed1..44e330a2f6 100644 --- a/examples/authors/ydb/db_test.go +++ b/examples/authors/ydb/db_test.go @@ -8,6 +8,10 @@ import ( _ "github.com/ydb-platform/ydb-go-sdk/v3" ) +func ptr(s string) *string { + return &s +} + func TestAuthors(t *testing.T) { ctx := context.Background() @@ -16,6 +20,53 @@ func TestAuthors(t *testing.T) { q := New(test.DB) + t.Run("InsertAuthors", func(t *testing.T) { + authorsToInsert := []CreateOrUpdateAuthorParams{ + {P0: 1, P1: "Лев Толстой", P2: ptr("Русский писатель, автор \"Война и мир\"")}, + {P0: 2, P1: "Александр Пушкин", P2: ptr("Автор \"Евгения Онегина\"")}, + {P0: 3, P1: "Александр Пушкин", P2: ptr("Русский поэт, драматург и прозаик")}, + {P0: 4, P1: "Фёдор Достоевский", P2: ptr("Автор \"Преступление и наказание\"")}, + {P0: 5, P1: "Николай Гоголь", P2: ptr("Автор \"Мёртвые души\"")}, + {P0: 6, P1: "Антон Чехов", P2: nil}, + {P0: 7, P1: "Иван Тургенев", P2: ptr("Автор \"Отцы и дети\"")}, + {P0: 8, P1: "Михаил Лермонтов", P2: nil}, + {P0: 9, P1: "Даниил Хармс", P2: ptr("Абсурдист, писатель и поэт")}, + {P0: 10, P1: "Максим Горький", P2: ptr("Автор \"На дне\"")}, + {P0: 11, P1: "Владимир Маяковский", P2: nil}, + {P0: 12, P1: "Сергей Есенин", P2: ptr("Русский лирик")}, + {P0: 13, P1: "Борис Пастернак", P2: ptr("Автор \"Доктор Живаго\"")}, + } + + for _, author := range authorsToInsert { + if _, err := q.CreateOrUpdateAuthor(ctx, author); err != nil { + t.Fatalf("failed to insert author %q: %v", author.P1, err) + } + } + }) + + t.Run("CreateOrUpdateAuthorReturningBio", func(t *testing.T) { + newBio := "Обновленная биография автора" + arg := CreateOrUpdateAuthorRetunringBioParams{ + P0: 3, + P1: "Тестовый Автор", + P2: &newBio, + } + + returnedBio, err := q.CreateOrUpdateAuthorRetunringBio(ctx, arg) + if err != nil { + t.Fatalf("failed to create or update author: %v", err) + } + + if returnedBio == nil { + t.Fatal("expected non-nil bio, got nil") + } + if *returnedBio != newBio { + t.Fatalf("expected bio %q, got %q", newBio, *returnedBio) + } + + t.Logf("Author created or updated successfully with bio: %s", *returnedBio) + }) + t.Run("ListAuthors", func(t *testing.T) { authors, err := q.ListAuthors(ctx) if err != nil { @@ -26,9 +77,9 @@ func TestAuthors(t *testing.T) { } t.Log("Authors:") for _, a := range authors { - bio := "NULL" - if a.Bio.Valid { - bio = a.Bio.String + bio := "Null" + if a.Bio != nil { + bio = *a.Bio } t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) } @@ -39,9 +90,9 @@ func TestAuthors(t *testing.T) { if err != nil { t.Fatal(err) } - bio := "NULL" - if singleAuthor.Bio.Valid { - bio = singleAuthor.Bio.String + bio := "Null" + if singleAuthor.Bio != nil { + bio = *singleAuthor.Bio } t.Logf("- ID: %d | Name: %s | Bio: %s", singleAuthor.ID, singleAuthor.Name, bio) }) @@ -56,9 +107,9 @@ func TestAuthors(t *testing.T) { } t.Log("Authors with this name:") for _, a := range authors { - bio := "NULL" - if a.Bio.Valid { - bio = a.Bio.String + bio := "Null" + if a.Bio != nil { + bio = *a.Bio } t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) } @@ -74,9 +125,9 @@ func TestAuthors(t *testing.T) { } t.Log("Authors with even IDs:") for _, a := range authors { - bio := "NULL" - if a.Bio.Valid { - bio = a.Bio.String + bio := "Null" + if a.Bio != nil { + bio = *a.Bio } t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) } @@ -92,11 +143,27 @@ func TestAuthors(t *testing.T) { } t.Log("Authors with NULL bio:") for _, a := range authors { - bio := "NULL" - if a.Bio.Valid { - bio = a.Bio.String + bio := "Null" + if a.Bio != nil { + bio = *a.Bio } t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) } }) + + t.Run("Delete All Authors", func(t *testing.T) { + var i uint64 + for i = 1; i <= 13; i++ { + if err := q.DeleteAuthor(ctx, i); err != nil { + t.Fatalf("failed to delete authors: %v", err) + } + } + authors, err := q.ListAuthors(ctx) + if err != nil { + t.Fatal(err) + } + if len(authors) != 0 { + t.Fatalf("expected no authors, got %d", len(authors)) + } + }) } diff --git a/examples/authors/ydb/models.go b/examples/authors/ydb/models.go index e899b195b0..337ea597f4 100644 --- a/examples/authors/ydb/models.go +++ b/examples/authors/ydb/models.go @@ -4,12 +4,8 @@ package authors -import ( - "database/sql" -) - type Author struct { ID uint64 Name string - Bio sql.NullString + Bio *string } diff --git a/examples/authors/ydb/query.sql b/examples/authors/ydb/query.sql index 219d680ba1..20b5eb8d5b 100644 --- a/examples/authors/ydb/query.sql +++ b/examples/authors/ydb/query.sql @@ -17,3 +17,13 @@ WHERE name = $p0; SELECT * FROM authors WHERE bio IS NULL; +-- name: CreateOrUpdateAuthor :execresult +UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2); + +-- name: CreateOrUpdateAuthorRetunringBio :one +UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) RETURNING bio; + +-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $p0; + diff --git a/examples/authors/ydb/query.sql.go b/examples/authors/ydb/query.sql.go index 53ed896128..289cbb7741 100644 --- a/examples/authors/ydb/query.sql.go +++ b/examples/authors/ydb/query.sql.go @@ -7,8 +7,50 @@ package authors import ( "context" + "database/sql" ) +const createOrUpdateAuthor = `-- name: CreateOrUpdateAuthor :execresult +UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) +` + +type CreateOrUpdateAuthorParams struct { + P0 uint64 + P1 string + P2 *string +} + +func (q *Queries) CreateOrUpdateAuthor(ctx context.Context, arg CreateOrUpdateAuthorParams) (sql.Result, error) { + return q.db.ExecContext(ctx, createOrUpdateAuthor, arg.P0, arg.P1, arg.P2) +} + +const createOrUpdateAuthorRetunringBio = `-- name: CreateOrUpdateAuthorRetunringBio :one +UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) RETURNING bio +` + +type CreateOrUpdateAuthorRetunringBioParams struct { + P0 uint64 + P1 string + P2 *string +} + +func (q *Queries) CreateOrUpdateAuthorRetunringBio(ctx context.Context, arg CreateOrUpdateAuthorRetunringBioParams) (*string, error) { + row := q.db.QueryRowContext(ctx, createOrUpdateAuthorRetunringBio, arg.P0, arg.P1, arg.P2) + var bio *string + err := row.Scan(&bio) + return bio, err +} + +const deleteAuthor = `-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $p0 +` + +func (q *Queries) DeleteAuthor(ctx context.Context, p0 uint64) error { + _, err := q.db.ExecContext(ctx, deleteAuthor, p0) + return err +} + const getAuthor = `-- name: GetAuthor :one SELECT id, name, bio FROM authors WHERE id = $p0 diff --git a/internal/codegen/golang/ydb_type.go b/internal/codegen/golang/ydb_type.go index 8a5b1711b3..aba149ab03 100644 --- a/internal/codegen/golang/ydb_type.go +++ b/internal/codegen/golang/ydb_type.go @@ -16,6 +16,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col emitPointersForNull := options.EmitPointersForNullTypes // https://ydb.tech/docs/ru/yql/reference/types/ + // ydb-go-sdk doesn't support sql.Null* yet switch columnType { // decimal types case "bool": @@ -25,7 +26,8 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col if emitPointersForNull { return "*bool" } - return "sql.NullBool" + // return "sql.NullBool" + return "*bool" case "int8": if notNull { @@ -34,9 +36,10 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col if emitPointersForNull { return "*int8" } - // The database/sql package does not have a sql.NullInt8 type, so we - // use the smallest type they have which is NullInt16 - return "sql.NullInt16" + // // The database/sql package does not have a sql.NullInt8 type, so we + // // use the smallest type they have which is NullInt16 + // return "sql.NullInt16" + return "*int8" case "int16": if notNull { return "int16" @@ -44,7 +47,8 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col if emitPointersForNull { return "*int16" } - return "sql.NullInt16" + // return "sql.NullInt16" + return "*int16" case "int32": if notNull { return "int32" @@ -52,7 +56,8 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col if emitPointersForNull { return "*int32" } - return "sql.NullInt32" + // return "sql.NullInt32" + return "*int32" case "int64": if notNull { return "int64" @@ -60,7 +65,8 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col if emitPointersForNull { return "*int64" } - return "sql.NullInt64" + // return "sql.NullInt64" + return "*int64" case "uint8": if emitPointersForNull { @@ -92,7 +98,8 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } // The database/sql package does not have a sql.NullFloat32 type, so we // use the smallest type they have which is NullFloat64 - return "sql.NullFloat64" + // return "sql.NullFloat64" + return "*float32" case "double": if notNull { return "float64" @@ -100,7 +107,8 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col if emitPointersForNull { return "*float64" } - return "sql.NullFloat64" + // return "sql.NullFloat64" + return "*float64" // string types case "string", "utf8", "text": @@ -110,7 +118,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col if emitPointersForNull { return "*string" } - return "sql.NullString" + return "*string" // serial types case "smallserial", "serial2": @@ -120,7 +128,8 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col if emitPointersForNull { return "*int16" } - return "sql.NullInt16" + // return "sql.NullInt16" + return "*int16" case "serial", "serial4": if notNull { @@ -129,7 +138,8 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col if emitPointersForNull { return "*int32" } - return "sql.NullInt32" + // return "sql.NullInt32" + return "*int32" case "bigserial", "serial8": if notNull { @@ -138,10 +148,12 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col if emitPointersForNull { return "*int64" } - return "sql.NullInt64" + // return "sql.NullInt64" + return "*int64" case "null": - return "sql.Null" + // return "sql.Null" + return "interface{}" default: if debug.Active { diff --git a/internal/engine/ydb/catalog_tests/insert_test.go b/internal/engine/ydb/catalog_tests/insert_test.go new file mode 100644 index 0000000000..0164a6302f --- /dev/null +++ b/internal/engine/ydb/catalog_tests/insert_test.go @@ -0,0 +1,135 @@ +package ydb_test + +import ( + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" +) + +func TestInsert(t *testing.T) { + tests := []struct { + stmt string + expected ast.Node + }{ + { + stmt: "INSERT INTO users (id, name) VALUES (1, 'Alice') RETURNING *", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.InsertStmt{ + Relation: &ast.RangeVar{Relname: strPtr("users")}, + Cols: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{Name: strPtr("id")}, + &ast.ResTarget{Name: strPtr("name")}, + }, + }, + SelectStmt: &ast.SelectStmt{ + ValuesLists: &ast.List{ + Items: []ast.Node{ + &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.Integer{Ival: 1}}, + &ast.A_Const{Val: &ast.String{Str: "Alice"}}, + }, + }, + }, + }, + }, + OnConflictClause: &ast.OnConflictClause{}, + ReturningList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{&ast.A_Star{}}}, + }, + }, + }, + }, + }, + }, + }, + }, + { + stmt: "INSERT OR IGNORE INTO users (id) VALUES (3) RETURNING id, name", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.InsertStmt{ + Relation: &ast.RangeVar{Relname: strPtr("users")}, + Cols: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{Name: strPtr("id")}, + }, + }, + SelectStmt: &ast.SelectStmt{ + ValuesLists: &ast.List{ + Items: []ast.Node{ + &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.Integer{Ival: 3}}, + }, + }, + }, + }, + }, + OnConflictClause: &ast.OnConflictClause{ + Action: ast.OnConflictAction_INSERT_OR_IGNORE, + }, + ReturningList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}}, + }, + &ast.ResTarget{ + Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "name"}}}}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: "UPSERT INTO users (id) VALUES (4) RETURNING id", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.InsertStmt{ + Relation: &ast.RangeVar{Relname: strPtr("users")}, + Cols: &ast.List{Items: []ast.Node{&ast.ResTarget{Name: strPtr("id")}}}, + SelectStmt: &ast.SelectStmt{ValuesLists: &ast.List{Items: []ast.Node{&ast.List{Items: []ast.Node{&ast.A_Const{Val: &ast.Integer{Ival: 4}}}}}}}, + OnConflictClause: &ast.OnConflictClause{Action: ast.OnConflictAction_UPSERT}, + ReturningList: &ast.List{Items: []ast.Node{&ast.ResTarget{Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}}}}}, + }, + }, + }, + }, + } + + p := ydb.NewParser() + for _, tc := range tests { + t.Run(tc.stmt, func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(tc.stmt)) + if err != nil { + t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + } + if len(stmts) == 0 { + t.Fatalf("Запрос %q не распарсен", tc.stmt) + } + + diff := cmp.Diff(tc.expected, &stmts[0], + cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), + cmpopts.IgnoreFields(ast.A_Const{}, "Location"), + cmpopts.IgnoreFields(ast.ResTarget{}, "Location"), + cmpopts.IgnoreFields(ast.ColumnRef{}, "Location"), + cmpopts.IgnoreFields(ast.A_Expr{}, "Location"), + cmpopts.IgnoreFields(ast.RangeVar{}, "Location"), + ) + if diff != "" { + t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + } + }) + } +} diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index 341de1a2e9..40e0341411 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -38,6 +38,154 @@ func NewIdentifier(t string) *ast.String { return &ast.String{Str: identifier(t)} } +func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { + batch := n.BATCH() != nil + + tableName := identifier(n.Simple_table_ref().Simple_table_ref_core().GetText()) + rel := &ast.RangeVar{Relname: &tableName} + + var where ast.Node + if n.WHERE() != nil && n.Expr() != nil { + where = c.convert(n.Expr()) + } + if n.ON() != nil && n.Into_values_source() != nil { + // todo: handle delete with into values source + } + + returning := &ast.List{} + if ret := n.Returning_columns_list(); ret != nil { + returning = c.convert(ret).(*ast.List) + } + + stmts := &ast.DeleteStmt{ + Relations: &ast.List{Items: []ast.Node{rel}}, + WhereClause: where, + ReturningList: returning, + Batch: batch, + } + + return stmts +} + +func (c *cc) convertInto_table_stmtContext(n *parser.Into_table_stmtContext) ast.Node { + tableName := identifier(n.Into_simple_table_ref().Simple_table_ref().Simple_table_ref_core().GetText()) + rel := &ast.RangeVar{Relname: &tableName} + + onConflict := &ast.OnConflictClause{} + switch { + case n.INSERT() != nil && n.OR() != nil && n.ABORT() != nil: + onConflict.Action = ast.OnConflictAction_INSERT_OR_ABORT + case n.INSERT() != nil && n.OR() != nil && n.REVERT() != nil: + onConflict.Action = ast.OnConflictAction_INSERT_OR_REVERT + case n.INSERT() != nil && n.OR() != nil && n.IGNORE() != nil: + onConflict.Action = ast.OnConflictAction_INSERT_OR_IGNORE + case n.UPSERT() != nil: + onConflict.Action = ast.OnConflictAction_UPSERT + case n.REPLACE() != nil: + onConflict.Action = ast.OnConflictAction_REPLACE + } + + var cols *ast.List + var source ast.Node + if nVal := n.Into_values_source(); nVal != nil { + if nVal.DEFAULT() != nil && nVal.VALUES() != nil { + // todo: handle default values when implemented + } + if pureCols := nVal.Pure_column_list(); pureCols != nil { + cols = &ast.List{} + for _, anID := range pureCols.AllAn_id() { + name := identifier(parseAnId(anID)) + cols.Items = append(cols.Items, &ast.ResTarget{ + Name: &name, + }) + } + } + + valSource := nVal.Values_source() + if valSource != nil { + switch { + case valSource.Values_stmt() != nil: + source = &ast.SelectStmt{ + ValuesLists: c.convert(valSource.Values_stmt()).(*ast.List), + FromClause: &ast.List{}, + TargetList: &ast.List{}, + } + + case valSource.Select_stmt() != nil: + source = c.convert(valSource.Select_stmt()) + } + } + } + + returning := &ast.List{} + if ret := n.Returning_columns_list(); ret != nil { + returning = c.convert(ret).(*ast.List) + } + + stmts := &ast.InsertStmt{ + Relation: rel, + Cols: cols, + SelectStmt: source, + OnConflictClause: onConflict, + ReturningList: returning, + } + + return stmts +} + +func (c *cc) convertValues_stmtContext(n *parser.Values_stmtContext) ast.Node { + mainList := &ast.List{} + + for _, rowCtx := range n.Values_source_row_list().AllValues_source_row() { + rowList := &ast.List{} + exprListCtx := rowCtx.Expr_list().(*parser.Expr_listContext) + + for _, exprCtx := range exprListCtx.AllExpr() { + if converted := c.convert(exprCtx); converted != nil { + rowList.Items = append(rowList.Items, converted) + } + } + + mainList.Items = append(mainList.Items, rowList) + + } + + return mainList +} + +func (c *cc) convertReturning_columns_listContext(n *parser.Returning_columns_listContext) ast.Node { + list := &ast.List{Items: []ast.Node{}} + + if n.ASTERISK() != nil { + target := &ast.ResTarget{ + Indirection: &ast.List{}, + Val: &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{&ast.A_Star{}}}, + Location: n.ASTERISK().GetSymbol().GetStart(), + }, + Location: n.ASTERISK().GetSymbol().GetStart(), + } + list.Items = append(list.Items, target) + return list + } + + for _, idCtx := range n.AllAn_id() { + target := &ast.ResTarget{ + Indirection: &ast.List{}, + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{NewIdentifier(parseAnId(idCtx))}, + }, + Location: idCtx.GetStart().GetStart(), + }, + Location: idCtx.GetStart().GetStart(), + } + list.Items = append(list.Items, target) + } + + return list +} + func (c *cc) convertAlter_table_stmtContext(n *parser.Alter_table_stmtContext) ast.Node { tableRef := parseTableName(n.Simple_table_ref().Simple_table_ref_core()) @@ -1610,6 +1758,18 @@ func (c *cc) convert(node node) ast.Node { case *parser.Type_name_or_bindContext: return c.convertTypeNameOrBind(n) + case *parser.Into_table_stmtContext: + return c.convertInto_table_stmtContext(n) + + case *parser.Values_stmtContext: + return c.convertValues_stmtContext(n) + + case *parser.Returning_columns_listContext: + return c.convertReturning_columns_listContext(n) + + case *parser.Delete_stmtContext: + return c.convertDelete_stmtContext(n) + default: return todo("convert(case=default)", n) } diff --git a/internal/sql/ast/delete_stmt.go b/internal/sql/ast/delete_stmt.go index d77f043a12..c6fbc8149f 100644 --- a/internal/sql/ast/delete_stmt.go +++ b/internal/sql/ast/delete_stmt.go @@ -7,6 +7,9 @@ type DeleteStmt struct { LimitCount Node ReturningList *List WithClause *WithClause + + // YDB specific + Batch bool } func (n *DeleteStmt) Pos() int { @@ -22,6 +25,9 @@ func (n *DeleteStmt) Format(buf *TrackedBuffer) { buf.astFormat(n.WithClause) buf.WriteString(" ") } + if n.Batch { + buf.WriteString("BATCH ") + } buf.WriteString("DELETE FROM ") if items(n.Relations) { diff --git a/internal/sql/ast/insert_stmt.go b/internal/sql/ast/insert_stmt.go index 3cdf854091..7be5a183c9 100644 --- a/internal/sql/ast/insert_stmt.go +++ b/internal/sql/ast/insert_stmt.go @@ -24,7 +24,18 @@ func (n *InsertStmt) Format(buf *TrackedBuffer) { buf.WriteString(" ") } - buf.WriteString("INSERT INTO ") + switch n.OnConflictClause.Action { + case OnConflictAction_INSERT_OR_ABORT: + buf.WriteString("INSERT OR ABORT INTO ") + case OnConflictAction_INSERT_OR_REVERT: + buf.WriteString("INSERT OR REVERT INTO ") + case OnConflictAction_INSERT_OR_IGNORE: + buf.WriteString("INSERT OR IGNORE INTO ") + case OnConflictAction_UPSERT: + buf.WriteString("UPSERT INTO ") + default: + buf.WriteString("INSERT INTO ") + } if n.Relation != nil { buf.astFormat(n.Relation) } @@ -38,7 +49,7 @@ func (n *InsertStmt) Format(buf *TrackedBuffer) { buf.astFormat(n.SelectStmt) } - if n.OnConflictClause != nil { + if n.OnConflictClause != nil && n.OnConflictClause.Action < 4 { buf.WriteString(" ON CONFLICT DO NOTHING ") } diff --git a/internal/sql/ast/on_conflict_action_type.go b/internal/sql/ast/on_conflict_action_type.go new file mode 100644 index 0000000000..c149fe8d04 --- /dev/null +++ b/internal/sql/ast/on_conflict_action_type.go @@ -0,0 +1,15 @@ +package ast + +const ( + OnConflictAction_ON_CONFLICT_ACTION_UNDEFINED OnConflictAction = 0 + OnConflictAction_ONCONFLICT_NONE OnConflictAction = 1 + OnConflictAction_ONCONFLICT_NOTHING OnConflictAction = 2 + OnConflictAction_ONCONFLICT_UPDATE OnConflictAction = 3 + + // YQL-specific + OnConflictAction_INSERT_OR_ABORT OnConflictAction = 4 + OnConflictAction_INSERT_OR_REVERT OnConflictAction = 5 + OnConflictAction_INSERT_OR_IGNORE OnConflictAction = 6 + OnConflictAction_UPSERT OnConflictAction = 7 + OnConflictAction_REPLACE OnConflictAction = 8 +) diff --git a/internal/sqltest/local/ydb.go b/internal/sqltest/local/ydb.go index 79be58241f..2064b063dd 100644 --- a/internal/sqltest/local/ydb.go +++ b/internal/sqltest/local/ydb.go @@ -54,7 +54,6 @@ func link_YDB(t *testing.T, migrations []string, rw bool) TestYDB { baseDB = "/local" } - // собираем миграции var seed []string files, err := sqlpath.Glob(migrations) if err != nil { @@ -97,6 +96,7 @@ func link_YDB(t *testing.T, migrations []string, rw bool) TestYDB { driver, ydb.WithTablePathPrefix(prefix), ydb.WithAutoDeclare(), + ydb.WithNumericArgs(), ) if err != nil { t.Fatalf("failed to create connector: %s", err) From 3a4f818c50827e387ae895afb424fe6bed4e8cf2 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Mon, 28 Apr 2025 21:39:23 +0300 Subject: [PATCH 03/22] Added UPDATE and DELETE full logic. Updated examples in example/authors --- examples/authors/ydb/db_test.go | 40 +++---- examples/authors/ydb/query.sql | 11 +- examples/authors/ydb/query.sql.go | 56 ++++----- go.mod | 5 + go.sum | 112 +++++++++++++++++- internal/engine/ydb/convert.go | 191 +++++++++++++++++++++++++----- internal/sql/ast/delete_stmt.go | 32 ++++- internal/sql/ast/insert_stmt.go | 2 + internal/sql/ast/update_stmt.go | 23 ++++ internal/sql/astutils/rewrite.go | 4 + internal/sql/astutils/walk.go | 12 ++ 11 files changed, 391 insertions(+), 97 deletions(-) diff --git a/examples/authors/ydb/db_test.go b/examples/authors/ydb/db_test.go index 44e330a2f6..76b37306ef 100644 --- a/examples/authors/ydb/db_test.go +++ b/examples/authors/ydb/db_test.go @@ -46,13 +46,13 @@ func TestAuthors(t *testing.T) { t.Run("CreateOrUpdateAuthorReturningBio", func(t *testing.T) { newBio := "Обновленная биография автора" - arg := CreateOrUpdateAuthorRetunringBioParams{ + arg := CreateOrUpdateAuthorReturningBioParams{ P0: 3, P1: "Тестовый Автор", P2: &newBio, } - returnedBio, err := q.CreateOrUpdateAuthorRetunringBio(ctx, arg) + returnedBio, err := q.CreateOrUpdateAuthorReturningBio(ctx, arg) if err != nil { t.Fatalf("failed to create or update author: %v", err) } @@ -67,6 +67,24 @@ func TestAuthors(t *testing.T) { t.Logf("Author created or updated successfully with bio: %s", *returnedBio) }) + t.Run("Update Author", func(t *testing.T) { + arg := UpdateAuthorByIDParams{ + P0: "Максим Горький", + P1: ptr("Обновленная биография"), + P2: 10, + } + + singleAuthor, err := q.UpdateAuthorByID(ctx, arg) + if err != nil { + t.Fatal(err) + } + bio := "Null" + if singleAuthor.Bio != nil { + bio = *singleAuthor.Bio + } + t.Logf("- ID: %d | Name: %s | Bio: %s", singleAuthor.ID, singleAuthor.Name, bio) + }) + t.Run("ListAuthors", func(t *testing.T) { authors, err := q.ListAuthors(ctx) if err != nil { @@ -115,24 +133,6 @@ func TestAuthors(t *testing.T) { } }) - t.Run("ListAuthorsWithIdModulo", func(t *testing.T) { - authors, err := q.ListAuthorsWithIdModulo(ctx) - if err != nil { - t.Fatal(err) - } - if len(authors) == 0 { - t.Fatal("expected at least one author with even ID, got none") - } - t.Log("Authors with even IDs:") - for _, a := range authors { - bio := "Null" - if a.Bio != nil { - bio = *a.Bio - } - t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) - } - }) - t.Run("ListAuthorsWithNullBio", func(t *testing.T) { authors, err := q.ListAuthorsWithNullBio(ctx) if err != nil { diff --git a/examples/authors/ydb/query.sql b/examples/authors/ydb/query.sql index 20b5eb8d5b..67ce89a6a7 100644 --- a/examples/authors/ydb/query.sql +++ b/examples/authors/ydb/query.sql @@ -5,10 +5,6 @@ SELECT * FROM authors; SELECT * FROM authors WHERE id = $p0; --- name: ListAuthorsWithIdModulo :many -SELECT * FROM authors -WHERE id % 2 = 0; - -- name: GetAuthorsByName :many SELECT * FROM authors WHERE name = $p0; @@ -20,10 +16,11 @@ WHERE bio IS NULL; -- name: CreateOrUpdateAuthor :execresult UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2); --- name: CreateOrUpdateAuthorRetunringBio :one +-- name: CreateOrUpdateAuthorReturningBio :one UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) RETURNING bio; -- name: DeleteAuthor :exec -DELETE FROM authors -WHERE id = $p0; +DELETE FROM authors WHERE id = $p0; +-- name: UpdateAuthorByID :one +UPDATE authors SET name = $p0, bio = $p1 WHERE id = $p2 RETURNING *; diff --git a/examples/authors/ydb/query.sql.go b/examples/authors/ydb/query.sql.go index 289cbb7741..64126bf254 100644 --- a/examples/authors/ydb/query.sql.go +++ b/examples/authors/ydb/query.sql.go @@ -24,26 +24,25 @@ func (q *Queries) CreateOrUpdateAuthor(ctx context.Context, arg CreateOrUpdateAu return q.db.ExecContext(ctx, createOrUpdateAuthor, arg.P0, arg.P1, arg.P2) } -const createOrUpdateAuthorRetunringBio = `-- name: CreateOrUpdateAuthorRetunringBio :one +const createOrUpdateAuthorReturningBio = `-- name: CreateOrUpdateAuthorReturningBio :one UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) RETURNING bio ` -type CreateOrUpdateAuthorRetunringBioParams struct { +type CreateOrUpdateAuthorReturningBioParams struct { P0 uint64 P1 string P2 *string } -func (q *Queries) CreateOrUpdateAuthorRetunringBio(ctx context.Context, arg CreateOrUpdateAuthorRetunringBioParams) (*string, error) { - row := q.db.QueryRowContext(ctx, createOrUpdateAuthorRetunringBio, arg.P0, arg.P1, arg.P2) +func (q *Queries) CreateOrUpdateAuthorReturningBio(ctx context.Context, arg CreateOrUpdateAuthorReturningBioParams) (*string, error) { + row := q.db.QueryRowContext(ctx, createOrUpdateAuthorReturningBio, arg.P0, arg.P1, arg.P2) var bio *string err := row.Scan(&bio) return bio, err } const deleteAuthor = `-- name: DeleteAuthor :exec -DELETE FROM authors -WHERE id = $p0 +DELETE FROM authors WHERE id = $p0 ` func (q *Queries) DeleteAuthor(ctx context.Context, p0 uint64) error { @@ -118,34 +117,6 @@ func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) { return items, nil } -const listAuthorsWithIdModulo = `-- name: ListAuthorsWithIdModulo :many -SELECT id, name, bio FROM authors -WHERE id % 2 = 0 -` - -func (q *Queries) ListAuthorsWithIdModulo(ctx context.Context) ([]Author, error) { - rows, err := q.db.QueryContext(ctx, listAuthorsWithIdModulo) - if err != nil { - return nil, err - } - defer rows.Close() - var items []Author - for rows.Next() { - var i Author - if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Close(); err != nil { - return nil, err - } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil -} - const listAuthorsWithNullBio = `-- name: ListAuthorsWithNullBio :many SELECT id, name, bio FROM authors WHERE bio IS NULL @@ -173,3 +144,20 @@ func (q *Queries) ListAuthorsWithNullBio(ctx context.Context) ([]Author, error) } return items, nil } + +const updateAuthorByID = `-- name: UpdateAuthorByID :one +UPDATE authors SET name = $p0, bio = $p1 WHERE id = $p2 RETURNING id, name, bio +` + +type UpdateAuthorByIDParams struct { + P0 string + P1 *string + P2 uint64 +} + +func (q *Queries) UpdateAuthorByID(ctx context.Context, arg UpdateAuthorByIDParams) (Author, error) { + row := q.db.QueryRowContext(ctx, updateAuthorByID, arg.P0, arg.P1, arg.P2) + var i Author + err := row.Scan(&i.ID, &i.Name, &i.Bio) + return i, err +} diff --git a/go.mod b/go.mod index 34aaa12c5f..ebd7884d70 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,8 @@ require ( github.com/tetratelabs/wazero v1.9.0 github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 github.com/xeipuuv/gojsonschema v1.2.0 + github.com/ydb-platform/ydb-go-sdk/v3 v3.108.0 + github.com/ydb-platform/yql-parsers v0.0.0-20250309001738-7d693911f333 golang.org/x/sync v0.16.0 google.golang.org/grpc v1.75.0 google.golang.org/protobuf v1.36.8 @@ -35,6 +37,7 @@ require ( cel.dev/expr v0.24.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect + github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jackc/chunkreader/v2 v2.0.1 // indirect @@ -45,6 +48,7 @@ require ( github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgtype v1.14.0 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect + github.com/jonboulle/clockwork v0.3.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb // indirect @@ -56,6 +60,7 @@ require ( github.com/wasilibs/wazero-helpers v0.0.0-20240620070341-3dff1577cd52 // indirect github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect + github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect diff --git a/go.sum b/go.sum index fd8d405059..910c0e9fca 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,24 @@ cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY= cel.dev/expr v0.24.0/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw= +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= @@ -20,8 +32,15 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= @@ -33,19 +52,43 @@ github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI6 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= +github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/cel-go v0.26.1 h1:iPbVVEdkhTX++hpe3lzSk7D3G3QSYqLGoHOcEio+UXQ= github.com/google/cel-go v0.26.1/go.mod h1:A9O8OU9rdvrK5MQyrqfIxo1a0u4g3sF8KB6PUIaryMM= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs= github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= @@ -101,6 +144,8 @@ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg= +github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -143,10 +188,14 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rekby/fixenv v0.6.1 h1:jUFiSPpajT4WY2cYuc++7Y1zWrnCxnovGCIX72PZniM= +github.com/rekby/fixenv v0.6.1/go.mod h1:/b5LRc06BYJtslRtHKxsPWFT/ySpHV+rWvzTg+XWk4c= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/riza-io/grpc-go v0.2.0 h1:2HxQKFVE7VuYstcJ8zqpN84VnAoJ4dCL6YFhJewNcHQ= github.com/riza-io/grpc-go v0.2.0/go.mod h1:2bDvR9KkKC3KhtlSHfR3dAXjUMT86kg4UfWFyVGWqi8= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= @@ -175,8 +224,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tetratelabs/wazero v1.9.0 h1:IcZ56OuxrtaEz8UYNRHBrUa9bYeX9oVY93KspZZBf/I= github.com/tetratelabs/wazero v1.9.0/go.mod h1:TSbcXCfFP0L2FGkRPxHphadXPjo1T6W+CseNNY7EkjM= github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 h1:mJdDDPblDfPe7z7go8Dvv1AJQDI3eQ/5xith3q2mFlo= @@ -189,6 +238,12 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77 h1:LY6cI8cP4B9rrpTleZk95+08kl2gF4rixG7+V/dwL6Q= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= +github.com/ydb-platform/ydb-go-sdk/v3 v3.108.0 h1:TwWSp3gRMcja/hRpOofncLvgxAXCmzpz5cGtmdaoITw= +github.com/ydb-platform/ydb-go-sdk/v3 v3.108.0/go.mod h1:l5sSv153E18VvYcsmr51hok9Sjc16tEC8AXGbwrk+ho= +github.com/ydb-platform/yql-parsers v0.0.0-20250309001738-7d693911f333 h1:KFtJwlPdOxWjCKXX0jFJ8k1FlbqbRbUW3k/kYSZX7SA= +github.com/ydb-platform/yql-parsers v0.0.0-20250309001738-7d693911f333/go.mod h1:vrPJPS8cdPSV568YcXhB4bUwhyV8bmWKqmQ5c5Xi99o= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= @@ -202,6 +257,7 @@ go.opentelemetry.io/otel/sdk/metric v1.37.0 h1:90lI228XrB9jCMuSdA0673aubgRobVZFh go.opentelemetry.io/otel/sdk/metric v1.37.0/go.mod h1:cNen4ZWfiD37l5NhS+Keb5RXVWZWpRE+9WyVCpbo5ps= go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4= go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= @@ -213,6 +269,8 @@ go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0 go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= @@ -238,23 +296,39 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM= golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o= golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w= golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw= golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -265,7 +339,10 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA= @@ -280,8 +357,11 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -298,13 +378,38 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7 h1:FiusG7LWj+4byqhbvmB+Q93B/mOxJLN2DTozDuZm4EU= google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7/go.mod h1:kXqgZtrWaf6qS3jZOCnCH7WYfrvFjkC51bM8fz3RsCA= google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7 h1:pFyd6EwwL2TqFf8emdthzeX+gZE1ElRq3iM8pui4KBY= google.golang.org/genproto/googleapis/rpc v0.0.0-20250707201910-8d1bb00bc6a7/go.mod h1:qQ0YXyHHx3XkvlzUtpXDkS29lDSafHMZBAZDc03LQ3A= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/grpc v1.75.0 h1:+TW+dqTd2Biwe6KKfhE5JpiYIBWq865PhKGSXiivqt4= google.golang.org/grpc v1.75.0/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc= google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= @@ -318,11 +423,14 @@ gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24 gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= modernc.org/cc/v4 v4.26.2 h1:991HMkLjJzYBIfha6ECZdjrIYz2/1ayr+FL8GN+CNzM= modernc.org/cc/v4 v4.26.2/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0= diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index 40e0341411..8e447254b1 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -48,8 +48,37 @@ func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { if n.WHERE() != nil && n.Expr() != nil { where = c.convert(n.Expr()) } + var cols *ast.List + var source ast.Node if n.ON() != nil && n.Into_values_source() != nil { - // todo: handle delete with into values source + nVal := n.Into_values_source() + + // todo: handle default values when implemented + + if pureCols := nVal.Pure_column_list(); pureCols != nil { + cols = &ast.List{} + for _, anID := range pureCols.AllAn_id() { + name := identifier(parseAnId(anID)) + cols.Items = append(cols.Items, &ast.ResTarget{ + Name: &name, + }) + } + } + + valSource := nVal.Values_source() + if valSource != nil { + switch { + case valSource.Values_stmt() != nil: + source = &ast.SelectStmt{ + ValuesLists: c.convert(valSource.Values_stmt()).(*ast.List), + FromClause: &ast.List{}, + TargetList: &ast.List{}, + } + + case valSource.Select_stmt() != nil: + source = c.convert(valSource.Select_stmt()) + } + } } returning := &ast.List{} @@ -62,6 +91,125 @@ func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { WhereClause: where, ReturningList: returning, Batch: batch, + OnCols: cols, + OnSelectStmt: source, + } + + return stmts +} + +func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { + batch := n.BATCH() != nil + + tableName := identifier(n.Simple_table_ref().Simple_table_ref_core().GetText()) + rel := &ast.RangeVar{Relname: &tableName} + + var where ast.Node + var setList *ast.List + var cols *ast.List + var source ast.Node + + if n.SET() != nil && n.Set_clause_choice() != nil { + nSet := n.Set_clause_choice() + setList = &ast.List{Items: []ast.Node{}} + + switch { + case nSet.Set_clause_list() != nil: + for _, clause := range nSet.Set_clause_list().AllSet_clause() { + targetCtx := clause.Set_target() + columnName := identifier(targetCtx.Column_name().GetText()) + expr := c.convert(clause.Expr()) + resTarget := &ast.ResTarget{ + Name: &columnName, + Val: expr, + } + setList.Items = append(setList.Items, resTarget) + } + + case nSet.Multiple_column_assignment() != nil: + multiAssign := nSet.Multiple_column_assignment() + targetsCtx := multiAssign.Set_target_list() + valuesCtx := multiAssign.Simple_values_source() + + var colNames []string + for _, target := range targetsCtx.AllSet_target() { + targetCtx := target.(*parser.Set_targetContext) + colNames = append(colNames, targetCtx.Column_name().GetText()) + } + + var rowExpr *ast.RowExpr + if exprList := valuesCtx.Expr_list(); exprList != nil { + rowExpr = &ast.RowExpr{ + Args: &ast.List{}, + } + for _, expr := range exprList.AllExpr() { + rowExpr.Args.Items = append(rowExpr.Args.Items, c.convert(expr)) + } + } + + for i, colName := range colNames { + name := identifier(colName) + setList.Items = append(setList.Items, &ast.ResTarget{ + Name: &name, + Val: &ast.MultiAssignRef{ + Source: rowExpr, + Colno: i + 1, + Ncolumns: len(colNames), + }, + }) + } + } + + if n.WHERE() != nil && n.Expr() != nil { + where = c.convert(n.Expr()) + } + } else if n.ON() != nil && n.Into_values_source() != nil { + + // todo: handle default values when implemented + + nVal := n.Into_values_source() + + if pureCols := nVal.Pure_column_list(); pureCols != nil { + cols = &ast.List{} + for _, anID := range pureCols.AllAn_id() { + name := identifier(parseAnId(anID)) + cols.Items = append(cols.Items, &ast.ResTarget{ + Name: &name, + }) + } + } + + valSource := nVal.Values_source() + if valSource != nil { + switch { + case valSource.Values_stmt() != nil: + source = &ast.SelectStmt{ + ValuesLists: c.convert(valSource.Values_stmt()).(*ast.List), + FromClause: &ast.List{}, + TargetList: &ast.List{}, + } + + case valSource.Select_stmt() != nil: + source = c.convert(valSource.Select_stmt()) + } + } + } + + returning := &ast.List{} + if ret := n.Returning_columns_list(); ret != nil { + returning = c.convert(ret).(*ast.List) + } + + stmts := &ast.UpdateStmt{ + Relations: &ast.List{Items: []ast.Node{rel}}, + TargetList: setList, + WhereClause: where, + ReturningList: returning, + FromClause: &ast.List{}, + WithClause: nil, + Batch: batch, + OnCols: cols, + OnSelectStmt: source, } return stmts @@ -88,9 +236,8 @@ func (c *cc) convertInto_table_stmtContext(n *parser.Into_table_stmtContext) ast var cols *ast.List var source ast.Node if nVal := n.Into_values_source(); nVal != nil { - if nVal.DEFAULT() != nil && nVal.VALUES() != nil { - // todo: handle default values when implemented - } + // todo: handle default values when implemented + if pureCols := nVal.Pure_column_list(); pureCols != nil { cols = &ast.List{} for _, anID := range pureCols.AllAn_id() { @@ -186,20 +333,6 @@ func (c *cc) convertReturning_columns_listContext(n *parser.Returning_columns_li return list } -func (c *cc) convertAlter_table_stmtContext(n *parser.Alter_table_stmtContext) ast.Node { - tableRef := parseTableName(n.Simple_table_ref().Simple_table_ref_core()) - - stmt := &ast.AlterTableStmt{ - Table: tableRef, - Cmds: &ast.List{}, - } - for _, action := range n.AllAlter_table_action() { - if add := action.Alter_table_add_column(); add != nil { - } - } - return stmt -} - func (c *cc) convertSelectStmtContext(n *parser.Select_stmtContext) ast.Node { skp := n.Select_kind_parenthesis(0) if skp == nil { @@ -299,10 +432,7 @@ func (c *cc) convertSelectCoreContext(n *parser.Select_coreContext) ast.Node { } func (c *cc) convertResultColumn(n *parser.Result_columnContext) ast.Node { - exprCtx := n.Expr() - if exprCtx == nil { - // todo - } + // todo: support opt_id_prefix target := &ast.ResTarget{ Location: n.GetStart().GetStart(), } @@ -322,7 +452,7 @@ func (c *cc) convertResultColumn(n *parser.Result_columnContext) ast.Node { case n.AS() != nil && n.An_id_or_type() != nil: name := parseAnIdOrType(n.An_id_or_type()) target.Name = &name - case n.An_id_as_compat() != nil: + case n.An_id_as_compat() != nil: //nolint // todo: parse as_compat } target.Val = val @@ -436,7 +566,7 @@ func (c *cc) convertNamedSingleSource(n *parser.Named_single_sourceContext) ast. case *ast.RangeSubselect: source.Alias = &ast.Alias{Aliasname: &aliasText} } - } else if n.An_id_as_compat() != nil { + } else if n.An_id_as_compat() != nil { //nolint // todo: parse as_compat } return base @@ -700,7 +830,7 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast. if struct_ := n.Type_name_struct(); struct_ != nil { if structArgs := struct_.AllStruct_arg(); len(structArgs) > 0 { var items []ast.Node - for _, _ = range structArgs { + for range structArgs { // TODO: Handle struct field names and types items = append(items, &ast.TODO{}) } @@ -715,7 +845,7 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast. if variant := n.Type_name_variant(); variant != nil { if variantArgs := variant.AllVariant_arg(); len(variantArgs) > 0 { var items []ast.Node - for _, _ = range variantArgs { + for range variantArgs { // TODO: Handle variant arguments items = append(items, &ast.TODO{}) } @@ -793,7 +923,7 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast. if enum := n.Type_name_enum(); enum != nil { if typeTags := enum.AllType_name_tag(); len(typeTags) > 0 { var items []ast.Node - for _, _ = range typeTags { // todo: Handle enum tags + for range typeTags { // todo: Handle enum tags items = append(items, &ast.TODO{}) } return &ast.TypeName{ @@ -1195,7 +1325,7 @@ func (c *cc) convertXorSubexpr(n *parser.Xor_subexprContext) ast.Node { Lexpr: base, Rexpr: c.convert(eqSubs[0]), } - if condCtx.ESCAPE() != nil && len(eqSubs) >= 2 { + if condCtx.ESCAPE() != nil && len(eqSubs) >= 2 { //nolint // todo: Add ESCAPE support } return expr @@ -1549,7 +1679,7 @@ func (c *cc) convertUnarySubexprSuffix(base ast.Node, n *parser.Unary_subexpr_su } } - if n.COLLATE() != nil && n.An_id() != nil { + if n.COLLATE() != nil && n.An_id() != nil { //nolint // todo: Handle COLLATE } return colRef @@ -1770,6 +1900,9 @@ func (c *cc) convert(node node) ast.Node { case *parser.Delete_stmtContext: return c.convertDelete_stmtContext(n) + case *parser.Update_stmtContext: + return c.convertUpdate_stmtContext(n) + default: return todo("convert(case=default)", n) } diff --git a/internal/sql/ast/delete_stmt.go b/internal/sql/ast/delete_stmt.go index c6fbc8149f..8bc2b89e9d 100644 --- a/internal/sql/ast/delete_stmt.go +++ b/internal/sql/ast/delete_stmt.go @@ -1,15 +1,22 @@ package ast +import ( + "fmt" +) + type DeleteStmt struct { - Relations *List - UsingClause *List - WhereClause Node - LimitCount Node + Relations *List + UsingClause *List + WhereClause Node + LimitCount Node + ReturningList *List WithClause *WithClause // YDB specific - Batch bool + Batch bool + OnCols *List + OnSelectStmt Node } func (n *DeleteStmt) Pos() int { @@ -17,6 +24,7 @@ func (n *DeleteStmt) Pos() int { } func (n *DeleteStmt) Format(buf *TrackedBuffer) { + fmt.Println("DeleteStmt.Format") if n == nil { return } @@ -39,6 +47,20 @@ func (n *DeleteStmt) Format(buf *TrackedBuffer) { buf.astFormat(n.WhereClause) } + if items(n.OnCols) || set(n.OnSelectStmt) { + buf.WriteString(" ON ") + + if items(n.OnCols) { + buf.WriteString("(") + buf.astFormat(n.OnCols) + buf.WriteString(") ") + } + + if set(n.OnSelectStmt) { + buf.astFormat(n.OnSelectStmt) + } + } + if set(n.LimitCount) { buf.WriteString(" LIMIT ") buf.astFormat(n.LimitCount) diff --git a/internal/sql/ast/insert_stmt.go b/internal/sql/ast/insert_stmt.go index 7be5a183c9..954fb4665c 100644 --- a/internal/sql/ast/insert_stmt.go +++ b/internal/sql/ast/insert_stmt.go @@ -33,6 +33,8 @@ func (n *InsertStmt) Format(buf *TrackedBuffer) { buf.WriteString("INSERT OR IGNORE INTO ") case OnConflictAction_UPSERT: buf.WriteString("UPSERT INTO ") + case OnConflictAction_REPLACE: + buf.WriteString("REPLACE INTO ") default: buf.WriteString("INSERT INTO ") } diff --git a/internal/sql/ast/update_stmt.go b/internal/sql/ast/update_stmt.go index efd496ad75..ea3e5bc65f 100644 --- a/internal/sql/ast/update_stmt.go +++ b/internal/sql/ast/update_stmt.go @@ -10,6 +10,11 @@ type UpdateStmt struct { LimitCount Node ReturningList *List WithClause *WithClause + + // YDB specific + Batch bool + OnCols *List + OnSelectStmt Node } func (n *UpdateStmt) Pos() int { @@ -25,6 +30,10 @@ func (n *UpdateStmt) Format(buf *TrackedBuffer) { buf.WriteString(" ") } + if n.Batch { + buf.WriteString("BATCH ") + } + buf.WriteString("UPDATE ") if items(n.Relations) { buf.astFormat(n.Relations) @@ -100,6 +109,20 @@ func (n *UpdateStmt) Format(buf *TrackedBuffer) { buf.astFormat(n.WhereClause) } + if items(n.OnCols) || set(n.OnSelectStmt) { + buf.WriteString(" ON ") + + if items(n.OnCols) { + buf.WriteString("(") + buf.astFormat(n.OnCols) + buf.WriteString(") ") + } + + if set(n.OnSelectStmt) { + buf.astFormat(n.OnSelectStmt) + } + } + if set(n.LimitCount) { buf.WriteString(" LIMIT ") buf.astFormat(n.LimitCount) diff --git a/internal/sql/astutils/rewrite.go b/internal/sql/astutils/rewrite.go index 93c5be3cfb..f5c8028ab6 100644 --- a/internal/sql/astutils/rewrite.go +++ b/internal/sql/astutils/rewrite.go @@ -685,6 +685,8 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. a.apply(n, "Relations", nil, n.Relations) a.apply(n, "UsingClause", nil, n.UsingClause) a.apply(n, "WhereClause", nil, n.WhereClause) + a.apply(n, "Cols", nil, n.OnCols) + a.apply(n, "SelectStmt", nil, n.OnSelectStmt) a.apply(n, "ReturningList", nil, n.ReturningList) a.apply(n, "WithClause", nil, n.WithClause) @@ -1159,6 +1161,8 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. a.apply(n, "TargetList", nil, n.TargetList) a.apply(n, "WhereClause", nil, n.WhereClause) a.apply(n, "FromClause", nil, n.FromClause) + a.apply(n, "Cols", nil, n.OnCols) + a.apply(n, "SelectStmt", nil, n.OnSelectStmt) a.apply(n, "ReturningList", nil, n.ReturningList) a.apply(n, "WithClause", nil, n.WithClause) diff --git a/internal/sql/astutils/walk.go b/internal/sql/astutils/walk.go index 0943379f03..2f28ba0243 100644 --- a/internal/sql/astutils/walk.go +++ b/internal/sql/astutils/walk.go @@ -1068,6 +1068,12 @@ func Walk(f Visitor, node ast.Node) { if n.WhereClause != nil { Walk(f, n.WhereClause) } + if n.OnCols != nil { + Walk(f, n.OnCols) + } + if n.OnSelectStmt != nil { + Walk(f, n.OnSelectStmt) + } if n.LimitCount != nil { Walk(f, n.LimitCount) } @@ -2041,6 +2047,12 @@ func Walk(f Visitor, node ast.Node) { if n.FromClause != nil { Walk(f, n.FromClause) } + if n.OnCols != nil { + Walk(f, n.OnCols) + } + if n.OnSelectStmt != nil { + Walk(f, n.OnSelectStmt) + } if n.LimitCount != nil { Walk(f, n.LimitCount) } From e980d194e4ddda2fcab2c598d5c50b1d7e7ddf02 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Mon, 28 Apr 2025 22:24:11 +0300 Subject: [PATCH 04/22] Added some examples and README for demo --- Makefile | 15 +++++++++-- examples/authors/ydb/README.md | 47 ++++++++++++++++++++++++++++++++++ internal/sqltest/local/ydb.go | 4 +-- 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 examples/authors/ydb/README.md diff --git a/Makefile b/Makefile index b8745e57dc..18d6ca91b5 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build build-endtoend test test-ci test-examples test-endtoend start psql mysqlsh proto +.PHONY: build build-endtoend test test-ci test-examples test-endtoend start psql mysqlsh proto sqlc-dev ydb test-examples-ydb gen-examples-ydb build: go build ./... @@ -18,13 +18,21 @@ vet: test-examples: go test --tags=examples ./... +ydb-examples: sqlc-dev ydb gen-examples-ydb test-examples-ydb + +test-examples-ydb: + YDB_SERVER_URI=localhost:2136 go test -v ./examples/authors/ydb/... -count=1 + +gen-examples-ydb: + cd examples/authors/ && SQLCDEBUG=1 ~/bin/sqlc-dev generate && cd ../.. + build-endtoend: cd ./internal/endtoend/testdata && go build ./... test-ci: test-examples build-endtoend vet sqlc-dev: - go build -o ~/bin/sqlc-dev ./cmd/sqlc/ + go build -x -v -o ~/bin/sqlc-dev ./cmd/sqlc/ sqlc-pg-gen: go build -o ~/bin/sqlc-pg-gen ./internal/tools/sqlc-pg-gen @@ -38,6 +46,9 @@ test-json-process-plugin: start: docker compose up -d +ydb: + docker compose up -d ydb + fmt: go fmt ./... diff --git a/examples/authors/ydb/README.md b/examples/authors/ydb/README.md new file mode 100644 index 0000000000..9e77fc7886 --- /dev/null +++ b/examples/authors/ydb/README.md @@ -0,0 +1,47 @@ +# Инструкция по генерации + +В файлах `schema.sql` и `query.sql` записаны, соответственно, схема базы данных и запросы, из которых вы хотите сгенерировать код к базе данных. +В `db_test.go` находятся тесты для последних сгенерированных команд. +Ниже находятся команды для генерации и запуска тестов. + +--- + +### 1. Создание бинарника sqlc + +```bash +make sqlc-dev +``` + +### 2. Запуск YDB через Docker Compose + +```bash +make ydb +``` + +### 3. Генерация кода для примеров для YDB + +```bash +make gen-examples-ydb +``` + +### 4. Запуск тестов примеров для YDB + +```bash +make test-examples-ydb +``` + +### 5. Полный цикл: сборка, генерация, тестирование (удобно одной командой) + +```bash +make ydb-examples +``` + +Эта команда выполнит: + +- Сборку `sqlc-dev` +- Запуск контейнера YDB +- Генерацию примеров +- Тестирование примеров + +--- + diff --git a/internal/sqltest/local/ydb.go b/internal/sqltest/local/ydb.go index 2064b063dd..8703b170b5 100644 --- a/internal/sqltest/local/ydb.go +++ b/internal/sqltest/local/ydb.go @@ -36,7 +36,8 @@ type TestYDB struct { func link_YDB(t *testing.T, migrations []string, rw bool) TestYDB { t.Helper() - // 1) Контекст с таймаутом + time.Sleep(1 * time.Second) // wait for YDB to start + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() @@ -78,7 +79,6 @@ func link_YDB(t *testing.T, migrations []string, rw bool) TestYDB { } prefix := fmt.Sprintf("%s/%s", baseDB, name) - // 2) Открываем драйвер к корню "/" rootDSN := fmt.Sprintf("grpc://%s?database=%s", dbuiri, baseDB) t.Logf("→ Opening root driver: %s", rootDSN) driver, err := ydb.Open(ctx, rootDSN, From 3013c844b36546a0f1436d489ff8ca7c9e27911c Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Sat, 17 May 2025 22:26:14 +0300 Subject: [PATCH 05/22] Supported some more YQL constructions: USE ... PRAGMA CREATE USER CREATE GROUP COMMIT RESTORE also added some new tests and debugged old code for mistakes --- internal/codegen/golang/ydb_type.go | 7 +- .../ydb/catalog_tests/create_group_test.go | 110 +++++ .../ydb/catalog_tests/create_user_test.go | 129 ++++++ .../engine/ydb/catalog_tests/delete_test.go | 200 +++++++++ .../engine/ydb/catalog_tests/insert_test.go | 15 +- .../engine/ydb/catalog_tests/pragma_test.go | 118 +++++ .../engine/ydb/catalog_tests/select_test.go | 15 +- .../engine/ydb/catalog_tests/update_test.go | 185 ++++++++ internal/engine/ydb/convert.go | 407 +++++++++++++++++- internal/engine/ydb/utils.go | 2 + internal/sql/ast/create_role_stmt.go | 3 + internal/sql/ast/delete_stmt.go | 5 - internal/sql/ast/param_ref.go | 7 + internal/sql/ast/pragma_stmt.go | 43 ++ internal/sql/ast/role_spec.go | 2 + internal/sql/ast/use_stmt.go | 11 + internal/sql/astutils/rewrite.go | 12 +- internal/sql/astutils/walk.go | 23 +- 18 files changed, 1266 insertions(+), 28 deletions(-) create mode 100644 internal/engine/ydb/catalog_tests/create_group_test.go create mode 100644 internal/engine/ydb/catalog_tests/create_user_test.go create mode 100644 internal/engine/ydb/catalog_tests/delete_test.go create mode 100644 internal/engine/ydb/catalog_tests/pragma_test.go create mode 100644 internal/engine/ydb/catalog_tests/update_test.go create mode 100644 internal/sql/ast/pragma_stmt.go create mode 100644 internal/sql/ast/use_stmt.go diff --git a/internal/codegen/golang/ydb_type.go b/internal/codegen/golang/ydb_type.go index aba149ab03..e9e5c46344 100644 --- a/internal/codegen/golang/ydb_type.go +++ b/internal/codegen/golang/ydb_type.go @@ -49,7 +49,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } // return "sql.NullInt16" return "*int16" - case "int32": + case "int", "int32": //ydb doesn't have int type, but we need it to support untyped constants if notNull { return "int32" } @@ -155,9 +155,12 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col // return "sql.Null" return "interface{}" + case "any": + return "interface{}" + default: if debug.Active { - log.Printf("unknown SQLite type: %s\n", columnType) + log.Printf("unknown YDB type: %s\n", columnType) } return "interface{}" diff --git a/internal/engine/ydb/catalog_tests/create_group_test.go b/internal/engine/ydb/catalog_tests/create_group_test.go new file mode 100644 index 0000000000..724e912168 --- /dev/null +++ b/internal/engine/ydb/catalog_tests/create_group_test.go @@ -0,0 +1,110 @@ +package ydb_test + +import ( + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" +) + +func TestCreateGroup(t *testing.T) { + tests := []struct { + stmt string + expected ast.Node + }{ + { + stmt: `CREATE GROUP group1`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.CreateRoleStmt{ + StmtType: ast.RoleStmtType(3), // CREATE GROUP + Role: strPtr("group1"), + Options: &ast.List{}, + }, + }, + }, + }, + { + stmt: `CREATE GROUP group1 WITH USER alice`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.CreateRoleStmt{ + StmtType: ast.RoleStmtType(3), + Role: strPtr("group1"), + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("rolemembers"), + Arg: &ast.List{ + Items: []ast.Node{ + &ast.RoleSpec{ + Roletype: ast.RoleSpecType(1), + Rolename: strPtr("alice"), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `CREATE GROUP group1 WITH USER alice, bebik`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.CreateRoleStmt{ + StmtType: ast.RoleStmtType(3), + Role: strPtr("group1"), + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("rolemembers"), + Arg: &ast.List{ + Items: []ast.Node{ + &ast.RoleSpec{ + Roletype: ast.RoleSpecType(1), + Rolename: strPtr("alice"), + }, + &ast.RoleSpec{ + Roletype: ast.RoleSpecType(1), + Rolename: strPtr("bebik"), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + + p := ydb.NewParser() + for _, tc := range tests { + t.Run(tc.stmt, func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(tc.stmt)) + if err != nil { + t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + } + if len(stmts) == 0 { + t.Fatalf("Запрос %q не распарсен", tc.stmt) + } + + diff := cmp.Diff(tc.expected, &stmts[0], + cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), + cmpopts.IgnoreFields(ast.DefElem{}, "Location"), + cmpopts.IgnoreFields(ast.RoleSpec{}, "Location"), + cmpopts.IgnoreFields(ast.A_Const{}, "Location"), + ) + if diff != "" { + t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + } + }) + } +} diff --git a/internal/engine/ydb/catalog_tests/create_user_test.go b/internal/engine/ydb/catalog_tests/create_user_test.go new file mode 100644 index 0000000000..be53e9dd79 --- /dev/null +++ b/internal/engine/ydb/catalog_tests/create_user_test.go @@ -0,0 +1,129 @@ +package ydb_test + +import ( + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" +) + +func TestCreateUser(t *testing.T) { + tests := []struct { + stmt string + expected ast.Node + }{ + { + stmt: `CREATE USER alice`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.CreateRoleStmt{ + StmtType: ast.RoleStmtType(2), // CREATE USER + Role: strPtr("alice"), + Options: &ast.List{}, + }, + }, + }, + }, + { + stmt: `CREATE USER bob PASSWORD 'secret'`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.CreateRoleStmt{ + StmtType: ast.RoleStmtType(2), + Role: strPtr("bob"), + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("password"), + Arg: &ast.String{Str: "secret"}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `CREATE USER charlie LOGIN`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.CreateRoleStmt{ + StmtType: ast.RoleStmtType(2), + Role: strPtr("charlie"), + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("login"), + Arg: &ast.Boolean{Boolval: true}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `CREATE USER dave NOLOGIN`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.CreateRoleStmt{ + StmtType: ast.RoleStmtType(2), + Role: strPtr("dave"), + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("nologin"), + Arg: &ast.Boolean{Boolval: false}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `CREATE USER bjorn HASH 'abc123'`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.CreateRoleStmt{ + StmtType: ast.RoleStmtType(2), + Role: strPtr("bjorn"), + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("hash"), + Arg: &ast.String{Str: "abc123"}, + }, + }, + }, + }, + }, + }, + }, + } + + p := ydb.NewParser() + for _, tc := range tests { + t.Run(tc.stmt, func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(tc.stmt)) + if err != nil { + t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + } + if len(stmts) == 0 { + t.Fatalf("Запрос %q не распарсен", tc.stmt) + } + + diff := cmp.Diff(tc.expected, &stmts[0], + cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), + cmpopts.IgnoreFields(ast.A_Const{}, "Location"), + cmpopts.IgnoreFields(ast.DefElem{}, "Location"), + ) + if diff != "" { + t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + } + }) + } +} diff --git a/internal/engine/ydb/catalog_tests/delete_test.go b/internal/engine/ydb/catalog_tests/delete_test.go new file mode 100644 index 0000000000..b75591a9ef --- /dev/null +++ b/internal/engine/ydb/catalog_tests/delete_test.go @@ -0,0 +1,200 @@ +package ydb_test + +import ( + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" +) + +func TestDelete(t *testing.T) { + tests := []struct { + stmt string + expected ast.Node + }{ + { + stmt: "DELETE FROM users WHERE id = 1 RETURNING id", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.DeleteStmt{ + Relations: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{Relname: strPtr("users")}, + }, + }, + WhereClause: &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "="}}}, + Lexpr: &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}, + }, + Rexpr: &ast.A_Const{ + Val: &ast.Integer{Ival: 1}, + }, + }, + ReturningList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Indirection: &ast.List{}, + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{&ast.String{Str: "id"}}, + }, + }, + }, + }, + }, + Batch: false, + OnCols: nil, + OnSelectStmt: nil, + }, + }, + }, + }, + { + stmt: "BATCH DELETE FROM users WHERE is_deleted = true RETURNING *", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.DeleteStmt{ + Relations: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{Relname: strPtr("users")}, + }, + }, + WhereClause: &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "="}}}, + Lexpr: &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "is_deleted"}}}, + }, + Rexpr: &ast.A_Const{ + Val: &ast.Boolean{Boolval: true}, + }, + }, + ReturningList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Indirection: &ast.List{}, + Val: &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{&ast.A_Star{}}}, + }, + }, + }, + }, + Batch: true, + OnCols: nil, + OnSelectStmt: nil, + }, + }, + }, + }, + { + stmt: "DELETE FROM users ON (id) VALUES (5) RETURNING id", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.DeleteStmt{ + Relations: &ast.List{Items: []ast.Node{&ast.RangeVar{Relname: strPtr("users")}}}, + OnCols: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{Name: strPtr("id")}, + }, + }, + OnSelectStmt: &ast.SelectStmt{ + ValuesLists: &ast.List{ + Items: []ast.Node{ + &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.Integer{Ival: 5}}, + }, + }, + }, + }, + FromClause: &ast.List{}, + TargetList: &ast.List{}, + }, + ReturningList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Indirection: &ast.List{}, + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + }, + }, + }, + Batch: false, + WhereClause: nil, + }, + }, + }, + }, + { + stmt: "DELETE FROM users ON (id) SELECT 1 AS id RETURNING id", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.DeleteStmt{ + Relations: &ast.List{Items: []ast.Node{&ast.RangeVar{Relname: strPtr("users")}}}, + OnCols: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{Name: strPtr("id")}, + }, + }, + OnSelectStmt: &ast.SelectStmt{ + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Name: strPtr("id"), + Val: &ast.A_Const{Val: &ast.Integer{Ival: 1}}, + }, + }, + }, + FromClause: &ast.List{}, + }, + ReturningList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Indirection: &ast.List{}, + Val: &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}, + }, + }, + }, + }, + Batch: false, + WhereClause: nil, + }, + }, + }, + }, + } + + p := ydb.NewParser() + for _, tc := range tests { + t.Run(tc.stmt, func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(tc.stmt)) + if err != nil { + t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + } + if len(stmts) == 0 { + t.Fatalf("Запрос %q не распарсен", tc.stmt) + } + + diff := cmp.Diff(tc.expected, &stmts[0], + cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), + cmpopts.IgnoreFields(ast.A_Const{}, "Location"), + cmpopts.IgnoreFields(ast.ResTarget{}, "Location"), + cmpopts.IgnoreFields(ast.ColumnRef{}, "Location"), + cmpopts.IgnoreFields(ast.A_Expr{}, "Location"), + cmpopts.IgnoreFields(ast.RangeVar{}, "Location"), + ) + if diff != "" { + t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + } + }) + } +} diff --git a/internal/engine/ydb/catalog_tests/insert_test.go b/internal/engine/ydb/catalog_tests/insert_test.go index 0164a6302f..40f116a3ba 100644 --- a/internal/engine/ydb/catalog_tests/insert_test.go +++ b/internal/engine/ydb/catalog_tests/insert_test.go @@ -38,11 +38,14 @@ func TestInsert(t *testing.T) { }, }, }, + TargetList: &ast.List{}, + FromClause: &ast.List{}, }, OnConflictClause: &ast.OnConflictClause{}, ReturningList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ + Indirection: &ast.List{}, Val: &ast.ColumnRef{ Fields: &ast.List{Items: []ast.Node{&ast.A_Star{}}}, }, @@ -74,6 +77,8 @@ func TestInsert(t *testing.T) { }, }, }, + TargetList: &ast.List{}, + FromClause: &ast.List{}, }, OnConflictClause: &ast.OnConflictClause{ Action: ast.OnConflictAction_INSERT_OR_IGNORE, @@ -81,10 +86,12 @@ func TestInsert(t *testing.T) { ReturningList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ - Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}}, + Indirection: &ast.List{}, + Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}}, }, &ast.ResTarget{ - Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "name"}}}}, + Indirection: &ast.List{}, + Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "name"}}}}, }, }, }, @@ -99,9 +106,9 @@ func TestInsert(t *testing.T) { Stmt: &ast.InsertStmt{ Relation: &ast.RangeVar{Relname: strPtr("users")}, Cols: &ast.List{Items: []ast.Node{&ast.ResTarget{Name: strPtr("id")}}}, - SelectStmt: &ast.SelectStmt{ValuesLists: &ast.List{Items: []ast.Node{&ast.List{Items: []ast.Node{&ast.A_Const{Val: &ast.Integer{Ival: 4}}}}}}}, + SelectStmt: &ast.SelectStmt{ValuesLists: &ast.List{Items: []ast.Node{&ast.List{Items: []ast.Node{&ast.A_Const{Val: &ast.Integer{Ival: 4}}}}}}, TargetList: &ast.List{}, FromClause: &ast.List{}}, OnConflictClause: &ast.OnConflictClause{Action: ast.OnConflictAction_UPSERT}, - ReturningList: &ast.List{Items: []ast.Node{&ast.ResTarget{Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}}}}}, + ReturningList: &ast.List{Items: []ast.Node{&ast.ResTarget{Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}}, Indirection: &ast.List{}}}}, }, }, }, diff --git a/internal/engine/ydb/catalog_tests/pragma_test.go b/internal/engine/ydb/catalog_tests/pragma_test.go new file mode 100644 index 0000000000..9db4406c53 --- /dev/null +++ b/internal/engine/ydb/catalog_tests/pragma_test.go @@ -0,0 +1,118 @@ +package ydb_test + +import ( + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" +) + +func TestPragma(t *testing.T) { + tests := []struct { + stmt string + expected ast.Node + }{ + { + stmt: `PRAGMA AutoCommit`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.Pragma_stmt{ + Name: &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.String{Str: "autocommit"}}, + }, + }, + }, + }, + }, + }, + { + stmt: `PRAGMA TablePathPrefix = "home/yql"`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.Pragma_stmt{ + Name: &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.String{Str: "tablepathprefix"}}, + }, + }, + Equals: true, + Values: &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.String{Str: "home/yql"}}, + }, + }, + }, + }, + }, + }, + { + stmt: `PRAGMA Warning("disable", "1101")`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.Pragma_stmt{ + Name: &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.String{Str: "warning"}}, + }, + }, + Equals: false, + Values: &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.String{Str: "disable"}}, + &ast.A_Const{Val: &ast.String{Str: "1101"}}, + }, + }, + }, + }, + }, + }, + { + stmt: `PRAGMA yson.AutoConvert = true`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.Pragma_stmt{ + Name: &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.String{Str: "yson"}}, + &ast.A_Const{Val: &ast.String{Str: "autoconvert"}}, + }, + }, + Equals: true, + Values: &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.Boolean{Boolval: true}}, + }, + }, + }, + }, + }, + }, + } + + p := ydb.NewParser() + for _, tc := range tests { + t.Run(tc.stmt, func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(tc.stmt)) + if err != nil { + t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + } + if len(stmts) == 0 { + t.Fatalf("Запрос %q не распарсен", tc.stmt) + } + + diff := cmp.Diff(tc.expected, &stmts[0], + cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), + cmpopts.IgnoreFields(ast.Pragma_stmt{}, "Location"), + cmpopts.IgnoreFields(ast.ColumnRef{}, "Location"), + cmpopts.IgnoreFields(ast.A_Const{}, "Location"), + ) + if diff != "" { + t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + } + }) + } +} diff --git a/internal/engine/ydb/catalog_tests/select_test.go b/internal/engine/ydb/catalog_tests/select_test.go index 95ae49163d..47794ce81f 100644 --- a/internal/engine/ydb/catalog_tests/select_test.go +++ b/internal/engine/ydb/catalog_tests/select_test.go @@ -34,6 +34,7 @@ func TestSelect(t *testing.T) { }, }, }, + FromClause: &ast.List{}, }, }, }, @@ -52,6 +53,7 @@ func TestSelect(t *testing.T) { }, }, }, + FromClause: &ast.List{}, }, }, }, @@ -70,6 +72,7 @@ func TestSelect(t *testing.T) { }, }, }, + FromClause: &ast.List{}, }, }, }, @@ -88,6 +91,7 @@ func TestSelect(t *testing.T) { }, }, }, + FromClause: &ast.List{}, }, }, }, @@ -104,6 +108,7 @@ func TestSelect(t *testing.T) { }, }, }, + FromClause: &ast.List{}, }, }, }, @@ -116,10 +121,13 @@ func TestSelect(t *testing.T) { TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ - Val: &ast.Boolean{Boolval: true}, + Val: &ast.A_Const{ + Val: &ast.Boolean{Boolval: true}, + }, }, }, }, + FromClause: &ast.List{}, }, }, }, @@ -158,6 +166,7 @@ func TestSelect(t *testing.T) { }, }, }, + FromClause: &ast.List{}, }, }, }, @@ -285,7 +294,9 @@ func TestSelect(t *testing.T) { Val: &ast.Null{}, }, &ast.ResTarget{ - Val: &ast.Boolean{Boolval: false}, + Val: &ast.A_Const{ + Val: &ast.Boolean{Boolval: false}, + }, }, }, }, diff --git a/internal/engine/ydb/catalog_tests/update_test.go b/internal/engine/ydb/catalog_tests/update_test.go new file mode 100644 index 0000000000..57c90bc2a4 --- /dev/null +++ b/internal/engine/ydb/catalog_tests/update_test.go @@ -0,0 +1,185 @@ +package ydb_test + +import ( + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" +) + +func TestUpdate(t *testing.T) { + tests := []struct { + stmt string + expected ast.Node + }{ + { + stmt: "UPDATE users SET name = 'Bob' WHERE id = 1 RETURNING id;", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.UpdateStmt{ + Relations: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{Relname: strPtr("users")}, + }, + }, + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Name: strPtr("name"), + Val: &ast.A_Const{ + Val: &ast.String{Str: "Bob"}, + }, + }, + }, + }, + WhereClause: &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "="}}}, + Lexpr: &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}, + }, + Rexpr: &ast.A_Const{ + Val: &ast.Integer{Ival: 1}, + }, + }, + ReturningList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Indirection: &ast.List{}, + Val: &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}, + }, + }, + }, + }, + FromClause: &ast.List{}, + WithClause: nil, + Batch: false, + OnCols: nil, + OnSelectStmt: nil, + }, + }, + }, + }, + { + stmt: "BATCH UPDATE users SET name = 'Charlie' WHERE id = 2 RETURNING *", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.UpdateStmt{ + Relations: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{Relname: strPtr("users")}, + }, + }, + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Name: strPtr("name"), + Val: &ast.A_Const{Val: &ast.String{Str: "Charlie"}}, + }, + }, + }, + WhereClause: &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "="}}}, + Lexpr: &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}, + }, + Rexpr: &ast.A_Const{ + Val: &ast.Integer{Ival: 2}, + }, + }, + ReturningList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Indirection: &ast.List{}, + Val: &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{&ast.A_Star{}}}, + }, + }, + }, + }, + FromClause: &ast.List{}, + WithClause: nil, + Batch: true, + OnCols: nil, + OnSelectStmt: nil, + }, + }, + }, + }, + { + stmt: "UPDATE users ON (id) VALUES (5) RETURNING id", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.UpdateStmt{ + Relations: &ast.List{Items: []ast.Node{&ast.RangeVar{Relname: strPtr("users")}}}, + OnCols: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{Name: strPtr("id")}, + }, + }, + OnSelectStmt: &ast.SelectStmt{ + ValuesLists: &ast.List{ + Items: []ast.Node{ + &ast.List{ + Items: []ast.Node{ + &ast.A_Const{Val: &ast.Integer{Ival: 5}}, + }, + }, + }, + }, + FromClause: &ast.List{}, + TargetList: &ast.List{}, + }, + ReturningList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Indirection: &ast.List{}, + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + }, + }, + }, + FromClause: &ast.List{}, + WithClause: nil, + Batch: false, + TargetList: nil, + WhereClause: nil, + }, + }, + }, + }, + } + + p := ydb.NewParser() + for _, tc := range tests { + t.Run(tc.stmt, func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(tc.stmt)) + if err != nil { + t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + } + if len(stmts) == 0 { + t.Fatalf("Запрос %q не распарсен", tc.stmt) + } + + diff := cmp.Diff(tc.expected, &stmts[0], + cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), + cmpopts.IgnoreFields(ast.A_Const{}, "Location"), + cmpopts.IgnoreFields(ast.ResTarget{}, "Location"), + cmpopts.IgnoreFields(ast.ColumnRef{}, "Location"), + cmpopts.IgnoreFields(ast.A_Expr{}, "Location"), + cmpopts.IgnoreFields(ast.RangeVar{}, "Location"), + ) + if diff != "" { + t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + } + }) + } +} diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index 8e447254b1..6fd2fe0ea3 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -21,7 +21,7 @@ type node interface { func todo(funcname string, n node) *ast.TODO { if debug.Active { - log.Printf("sqlite.%s: Unknown node type %T\n", funcname, n) + log.Printf("ydb.%s: Unknown node type %T\n", funcname, n) } return &ast.TODO{} } @@ -34,10 +34,280 @@ func identifier(id string) string { return strings.ToLower(id) } +func stripQuotes(s string) string { + if len(s) >= 2 && (s[0] == '\'' || s[0] == '"') && s[0] == s[len(s)-1] { + return s[1 : len(s)-1] + } + return s +} + func NewIdentifier(t string) *ast.String { return &ast.String{Str: identifier(t)} } +func (c *cc) convertCreate_group_stmtContext(n *parser.Create_group_stmtContext) ast.Node { + if n.CREATE() == nil || n.GROUP() == nil || len(n.AllRole_name()) == 0 { + return todo("Create_group_stmtContext", n) + } + groupName := c.convert(n.Role_name(0)) + + stmt := &ast.CreateRoleStmt{ + StmtType: ast.RoleStmtType(3), + Options: &ast.List{}, + } + + paramFlag := true + switch v := groupName.(type) { + case *ast.A_Const: + switch val := v.Val.(type) { + case *ast.String: + paramFlag = false + stmt.Role = &val.Str + case *ast.Boolean: + stmt.BindRole = groupName + default: + return todo("convertCreate_group_stmtContext", n) + } + case *ast.ParamRef, *ast.A_Expr: + stmt.BindRole = groupName + default: + return todo("convertCreate_group_stmtContext", n) + } + + if debug.Active && paramFlag { + log.Printf("YDB does not currently support parameters in the CREATE GROUP statement") + } + + if n.WITH() != nil && n.USER() != nil && len(n.AllRole_name()) > 1 { + defname := "rolemembers" + optionList := &ast.List{} + for _, role := range n.AllRole_name()[1:] { + roleNode := c.convert(role) + roleSpec := &ast.RoleSpec{ + Roletype: ast.RoleSpecType(1), + Location: role.GetStart().GetStart(), + } + isParam := true + switch v := roleNode.(type) { + case *ast.A_Const: + switch val := v.Val.(type) { + case *ast.String: + isParam = false + roleSpec.Rolename = &val.Str + case *ast.Boolean: + roleSpec.BindRolename = roleNode + default: + return todo("convertCreate_group_stmtContext", n) + } + case *ast.ParamRef, *ast.A_Expr: + roleSpec.BindRolename = roleNode + default: + return todo("convertCreate_group_stmtContext", n) + } + + if debug.Active && isParam && !paramFlag { + log.Printf("YDB does not currently support parameters in the CREATE GROUP statement") + } + + optionList.Items = append(optionList.Items, roleSpec) + } + + stmt.Options.Items = append(stmt.Options.Items, &ast.DefElem{ + Defname: &defname, + Arg: optionList, + Location: n.GetStart().GetStart(), + }) + } + + return stmt +} + +func (c *cc) convertUse_stmtContext(n *parser.Use_stmtContext) ast.Node { + if n.USE() != nil && n.Cluster_expr() != nil { + clusterExpr := c.convert(n.Cluster_expr()) + stmt := &ast.UseStmt{ + Xpr: clusterExpr, + Location: n.GetStart().GetStart(), + } + return stmt + } + return todo("convertUse_stmtContext", n) +} + +func (c *cc) convertCluster_exprContext(n *parser.Cluster_exprContext) ast.Node { + var node ast.Node + + switch { + case n.Pure_column_or_named() != nil: + pureCtx := n.Pure_column_or_named() + if anID := pureCtx.An_id(); anID != nil { + name := parseAnId(anID) + node = &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{NewIdentifier(name)}}, + Location: anID.GetStart().GetStart(), + } + } else if bp := pureCtx.Bind_parameter(); bp != nil { + node = c.convert(bp) + } + case n.ASTERISK() != nil: + node = &ast.A_Star{} + default: + return todo("convertCluster_exprContext", n) + } + + if n.An_id() != nil && n.COLON() != nil { + name := parseAnId(n.An_id()) + return &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: ":"}}}, + Lexpr: &ast.String{Str: name}, + Rexpr: node, + Location: n.GetStart().GetStart(), + } + } + + return node +} + +func (c *cc) convertCreate_user_stmtContext(n *parser.Create_user_stmtContext) ast.Node { + if n.CREATE() == nil || n.USER() == nil || n.Role_name() == nil { + return todo("convertCreate_user_stmtContext", n) + } + roleNode := c.convert(n.Role_name()) + + stmt := &ast.CreateRoleStmt{ + StmtType: ast.RoleStmtType(2), + Options: &ast.List{}, + } + + paramFlag := true + switch v := roleNode.(type) { + case *ast.A_Const: + switch val := v.Val.(type) { + case *ast.String: + paramFlag = false + stmt.Role = &val.Str + case *ast.Boolean: + stmt.BindRole = roleNode + default: + return todo("convertCreate_user_stmtContext", n) + } + case *ast.ParamRef, *ast.A_Expr: + stmt.BindRole = roleNode + default: + return todo("convertCreate_user_stmtContext", n) + } + + if debug.Active && paramFlag { + log.Printf("YDB does not currently support parameters in the CREATE USER statement") + } + + if len(n.AllUser_option()) > 0 { + options := []ast.Node{} + for _, opt := range n.AllUser_option() { + if node := c.convert(opt); node != nil { + options = append(options, node) + } + } + if len(options) > 0 { + stmt.Options = &ast.List{Items: options} + } + } + return stmt +} + +func (c *cc) convertUser_optionContext(n *parser.User_optionContext) ast.Node { + switch { + case n.Authentication_option() != nil: + aOpt := n.Authentication_option() + if pOpt := aOpt.Password_option(); pOpt != nil { + if pOpt.PASSWORD() != nil { + name := "password" + pValue := pOpt.Password_value() + var password ast.Node + if pValue.STRING_VALUE() != nil { + password = &ast.String{Str: stripQuotes(pValue.STRING_VALUE().GetText())} + } else { + password = &ast.Null{} + } + return &ast.DefElem{ + Defname: &name, + Arg: password, + Location: pOpt.GetStart().GetStart(), + } + } + } else if hOpt := aOpt.Hash_option(); hOpt != nil { + if debug.Active { + log.Printf("YDB does not currently support HASH in CREATE USER statement") + } + var pass string + if hOpt.HASH() != nil && hOpt.STRING_VALUE() != nil { + pass = stripQuotes(hOpt.STRING_VALUE().GetText()) + } + name := "hash" + return &ast.DefElem{ + Defname: &name, + Arg: &ast.String{Str: pass}, + Location: hOpt.GetStart().GetStart(), + } + } + + case n.Login_option() != nil: + lOpt := n.Login_option() + var name string + if lOpt.LOGIN() != nil { + name = "login" + } else if lOpt.NOLOGIN() != nil { + name = "nologin" + } + return &ast.DefElem{ + Defname: &name, + Arg: &ast.Boolean{Boolval: lOpt.LOGIN() != nil}, + Location: lOpt.GetStart().GetStart(), + } + default: + return todo("convertUser_optionContext", n) + } + return nil +} + +func (c *cc) convertRole_nameContext(n *parser.Role_nameContext) ast.Node { + switch { + case n.An_id_or_type() != nil: + name := parseAnIdOrType(n.An_id_or_type()) + return &ast.A_Const{Val: NewIdentifier(name), Location: n.GetStart().GetStart()} + case n.Bind_parameter() != nil: + bindPar := c.convert(n.Bind_parameter()) + return bindPar + } + return todo("convertRole_nameContext", n) +} + +func (c *cc) convertCommit_stmtContext(n *parser.Commit_stmtContext) ast.Node { + if n.COMMIT() != nil { + return &ast.TransactionStmt{Kind: ast.TransactionStmtKind(3)} + } + return todo("convertCommit_stmtContext", n) +} + +func (c *cc) convertRollback_stmtContext(n *parser.Rollback_stmtContext) ast.Node { + if n.ROLLBACK() != nil { + return &ast.TransactionStmt{Kind: ast.TransactionStmtKind(4)} + } + return todo("convertRollback_stmtContext", n) +} + +func (c *cc) convertDrop_table_stmtContext(n *parser.Drop_table_stmtContext) ast.Node { + if n.DROP() != nil && (n.TABLESTORE() != nil || (n.EXTERNAL() != nil && n.TABLE() != nil) || n.TABLE() != nil) { + name := parseTableName(n.Simple_table_ref().Simple_table_ref_core()) + stmt := &ast.DropTableStmt{ + IfExists: n.IF() != nil && n.EXISTS() != nil, + Tables: []*ast.TableName{name}, + } + return stmt + } + return todo("convertDrop_Table_stmtContxt", n) +} + func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { batch := n.BATCH() != nil @@ -52,9 +322,7 @@ func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { var source ast.Node if n.ON() != nil && n.Into_values_source() != nil { nVal := n.Into_values_source() - // todo: handle default values when implemented - if pureCols := nVal.Pure_column_list(); pureCols != nil { cols = &ast.List{} for _, anID := range pureCols.AllAn_id() { @@ -98,7 +366,85 @@ func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { return stmts } +func (c *cc) convertPragma_stmtContext(n *parser.Pragma_stmtContext) ast.Node { + if n.PRAGMA() != nil && n.An_id() != nil { + prefix := "" + if p := n.Opt_id_prefix_or_type(); p != nil { + prefix = parseAnIdOrType(p.An_id_or_type()) + } + items := []ast.Node{} + if prefix != "" { + items = append(items, &ast.A_Const{Val: NewIdentifier(prefix)}) + } + + name := parseAnId(n.An_id()) + items = append(items, &ast.A_Const{Val: NewIdentifier(name)}) + + stmt := &ast.Pragma_stmt{ + Name: &ast.List{Items: items}, + Location: n.An_id().GetStart().GetStart(), + } + + if n.EQUALS() != nil { + stmt.Equals = true + if val := n.Pragma_value(0); val != nil { + stmt.Values = &ast.List{Items: []ast.Node{c.convert(val)}} + } + } else if lp := n.LPAREN(); lp != nil { + values := []ast.Node{} + for _, v := range n.AllPragma_value() { + values = append(values, c.convert(v)) + } + stmt.Values = &ast.List{Items: values} + } + + return stmt + } + return todo("convertPragma_stmtContext", n) +} + +func (c *cc) convertPragma_valueContext(n *parser.Pragma_valueContext) ast.Node { + switch { + case n.Signed_number() != nil: + if n.Signed_number().Integer() != nil { + text := n.Signed_number().GetText() + val, err := parseIntegerValue(text) + if err != nil { + if debug.Active { + log.Printf("Failed to parse integer value '%s': %v", text, err) + } + return &ast.TODO{} + } + return &ast.A_Const{Val: &ast.Integer{Ival: val}, Location: n.GetStart().GetStart()} + } + if n.Signed_number().Real_() != nil { + text := n.Signed_number().GetText() + return &ast.A_Const{Val: &ast.Float{Str: text}, Location: n.GetStart().GetStart()} + } + case n.STRING_VALUE() != nil: + val := n.STRING_VALUE().GetText() + if len(val) >= 2 { + val = val[1 : len(val)-1] + } + return &ast.A_Const{Val: &ast.String{Str: val}, Location: n.GetStart().GetStart()} + case n.Bool_value() != nil: + var i bool + if n.Bool_value().TRUE() != nil { + i = true + } + return &ast.A_Const{Val: &ast.Boolean{Boolval: i}, Location: n.GetStart().GetStart()} + case n.Bind_parameter() != nil: + bindPar := c.convert(n.Bind_parameter()) + return bindPar + } + + return todo("convertPragma_valueContext", n) +} + func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { + if n.UPDATE() == nil { + return nil + } batch := n.BATCH() != nil tableName := identifier(n.Simple_table_ref().Simple_table_ref_core().GetText()) @@ -205,8 +551,8 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { TargetList: setList, WhereClause: where, ReturningList: returning, - FromClause: &ast.List{}, - WithClause: nil, + FromClause: &ast.List{}, + WithClause: nil, Batch: batch, OnCols: cols, OnSelectStmt: source, @@ -379,7 +725,10 @@ func (c *cc) convertSelectStmtContext(n *parser.Select_stmtContext) ast.Node { } func (c *cc) convertSelectCoreContext(n *parser.Select_coreContext) ast.Node { - stmt := &ast.SelectStmt{} + stmt := &ast.SelectStmt{ + TargetList: &ast.List{}, + FromClause: &ast.List{}, + } if n.Opt_set_quantifier() != nil { oq := n.Opt_set_quantifier() if oq.DISTINCT() != nil { @@ -460,6 +809,9 @@ func (c *cc) convertResultColumn(n *parser.Result_columnContext) ast.Node { } func (c *cc) convertJoinSource(n *parser.Join_sourceContext) ast.Node { + if n == nil { + return nil + } fsList := n.AllFlatten_source() if len(fsList) == 0 { return nil @@ -597,14 +949,10 @@ func (c *cc) convertBindParameter(n *parser.Bind_parameterContext) ast.Node { // !!debug later!! if n.DOLLAR() != nil { if n.TRUE() != nil { - return &ast.Boolean{ - Boolval: true, - } + return &ast.A_Const{Val: &ast.Boolean{Boolval: true}, Location: n.GetStart().GetStart()} } if n.FALSE() != nil { - return &ast.Boolean{ - Boolval: false, - } + return &ast.A_Const{Val: &ast.Boolean{Boolval: false}, Location: n.GetStart().GetStart()} } if an := n.An_id_or_type(); an != nil { @@ -1740,7 +2088,7 @@ func (c *cc) convertLiteralValue(n *parser.Literal_valueContext) ast.Node { if n.Bool_value().TRUE() != nil { i = true } - return &ast.Boolean{Boolval: i} + return &ast.A_Const{Val: &ast.Boolean{Boolval: i}, Location: n.GetStart().GetStart()} case n.NULL() != nil: return &ast.Null{} @@ -1903,6 +2251,39 @@ func (c *cc) convert(node node) ast.Node { case *parser.Update_stmtContext: return c.convertUpdate_stmtContext(n) + case *parser.Drop_table_stmtContext: + return c.convertDrop_table_stmtContext(n) + + case *parser.Commit_stmtContext: + return c.convertCommit_stmtContext(n) + + case *parser.Rollback_stmtContext: + return c.convertRollback_stmtContext(n) + + case *parser.Pragma_valueContext: + return c.convertPragma_valueContext(n) + + case *parser.Pragma_stmtContext: + return c.convertPragma_stmtContext(n) + + case *parser.Use_stmtContext: + return c.convertUse_stmtContext(n) + + case *parser.Cluster_exprContext: + return c.convertCluster_exprContext(n) + + case *parser.Create_user_stmtContext: + return c.convertCreate_user_stmtContext(n) + + case *parser.Role_nameContext: + return c.convertRole_nameContext(n) + + case *parser.User_optionContext: + return c.convertUser_optionContext(n) + + case *parser.Create_group_stmtContext: + return c.convertCreate_group_stmtContext(n) + default: return todo("convert(case=default)", n) } diff --git a/internal/engine/ydb/utils.go b/internal/engine/ydb/utils.go index 0fe41d356f..5201e6c9dd 100755 --- a/internal/engine/ydb/utils.go +++ b/internal/engine/ydb/utils.go @@ -14,6 +14,8 @@ type objectRefProvider interface { Object_ref() parser.IObject_refContext } + + func parseTableName(ctx objectRefProvider) *ast.TableName { return parseObjectRef(ctx.Object_ref()) } diff --git a/internal/sql/ast/create_role_stmt.go b/internal/sql/ast/create_role_stmt.go index 144540863e..44565fb64c 100644 --- a/internal/sql/ast/create_role_stmt.go +++ b/internal/sql/ast/create_role_stmt.go @@ -4,6 +4,9 @@ type CreateRoleStmt struct { StmtType RoleStmtType Role *string Options *List + + // YDB specific + BindRole Node } func (n *CreateRoleStmt) Pos() int { diff --git a/internal/sql/ast/delete_stmt.go b/internal/sql/ast/delete_stmt.go index 8bc2b89e9d..715f976ae6 100644 --- a/internal/sql/ast/delete_stmt.go +++ b/internal/sql/ast/delete_stmt.go @@ -1,9 +1,5 @@ package ast -import ( - "fmt" -) - type DeleteStmt struct { Relations *List UsingClause *List @@ -24,7 +20,6 @@ func (n *DeleteStmt) Pos() int { } func (n *DeleteStmt) Format(buf *TrackedBuffer) { - fmt.Println("DeleteStmt.Format") if n == nil { return } diff --git a/internal/sql/ast/param_ref.go b/internal/sql/ast/param_ref.go index 8bd724993d..6ffe8cc5f0 100644 --- a/internal/sql/ast/param_ref.go +++ b/internal/sql/ast/param_ref.go @@ -6,6 +6,9 @@ type ParamRef struct { Number int Location int Dollar bool + + // YDB specific + Plike bool } func (n *ParamRef) Pos() int { @@ -16,5 +19,9 @@ func (n *ParamRef) Format(buf *TrackedBuffer) { if n == nil { return } + if n.Plike { + fmt.Fprintf(buf, "$p%d", n.Number) + return + } fmt.Fprintf(buf, "$%d", n.Number) } diff --git a/internal/sql/ast/pragma_stmt.go b/internal/sql/ast/pragma_stmt.go new file mode 100644 index 0000000000..46dc40dbf5 --- /dev/null +++ b/internal/sql/ast/pragma_stmt.go @@ -0,0 +1,43 @@ +package ast + +// YDB specific +type Pragma_stmt struct { + Name Node + Cols *List + Equals bool + Values *List + Location int +} + +func (n *Pragma_stmt) Pos() int { + return n.Location +} + +func (n *Pragma_stmt) Format(buf *TrackedBuffer) { + if n == nil { + return + } + + buf.WriteString("PRAGMA ") + if n.Name != nil { + buf.astFormat(n.Name) + } + if n.Cols != nil { + buf.astFormat(n.Cols) + } + + if n.Equals { + buf.WriteString(" = ") + } + + if n.Values != nil { + if n.Equals { + buf.astFormat(n.Values) + } else { + buf.WriteString("(") + buf.astFormat(n.Values) + buf.WriteString(")") + } + } + +} diff --git a/internal/sql/ast/role_spec.go b/internal/sql/ast/role_spec.go index fba4cecf7d..5b7c871c54 100644 --- a/internal/sql/ast/role_spec.go +++ b/internal/sql/ast/role_spec.go @@ -4,6 +4,8 @@ type RoleSpec struct { Roletype RoleSpecType Rolename *string Location int + + BindRolename Node } func (n *RoleSpec) Pos() int { diff --git a/internal/sql/ast/use_stmt.go b/internal/sql/ast/use_stmt.go new file mode 100644 index 0000000000..dee393c321 --- /dev/null +++ b/internal/sql/ast/use_stmt.go @@ -0,0 +1,11 @@ +package ast + +// YDB specific +type UseStmt struct { + Xpr Node + Location int +} + +func (n *UseStmt) Pos() int { + return n.Location +} diff --git a/internal/sql/astutils/rewrite.go b/internal/sql/astutils/rewrite.go index f5c8028ab6..8e8eefbff4 100644 --- a/internal/sql/astutils/rewrite.go +++ b/internal/sql/astutils/rewrite.go @@ -605,7 +605,9 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. a.apply(n, "Params", nil, n.Params) case *ast.CreateRoleStmt: + a.apply(n, "BindRole", nil, n.BindRole) a.apply(n, "Options", nil, n.Options) + case *ast.CreateSchemaStmt: a.apply(n, "Authrole", nil, n.Authrole) @@ -924,6 +926,11 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. case *ast.PartitionSpec: a.apply(n, "PartParams", nil, n.PartParams) + case *ast.Pragma_stmt: + a.apply(n, "Pragma", nil, n.Name) + a.apply(n, "Args", nil, n.Cols) + a.apply(n, "Options", nil, n.Values) + case *ast.PrepareStmt: a.apply(n, "Argtypes", nil, n.Argtypes) a.apply(n, "Query", nil, n.Query) @@ -1029,7 +1036,7 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. a.apply(n, "Val", nil, n.Val) case *ast.RoleSpec: - // pass + a.apply(n, "BindRolename", nil, n.BindRolename) case *ast.RowCompareExpr: a.apply(n, "Xpr", nil, n.Xpr) @@ -1166,6 +1173,9 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. a.apply(n, "ReturningList", nil, n.ReturningList) a.apply(n, "WithClause", nil, n.WithClause) + case *ast.UseStmt: + a.apply(n, "Xpr", nil, n.Xpr) + case *ast.VacuumStmt: a.apply(n, "Relation", nil, n.Relation) a.apply(n, "VaCols", nil, n.VaCols) diff --git a/internal/sql/astutils/walk.go b/internal/sql/astutils/walk.go index 2f28ba0243..e7b78d126b 100644 --- a/internal/sql/astutils/walk.go +++ b/internal/sql/astutils/walk.go @@ -898,6 +898,9 @@ func Walk(f Visitor, node ast.Node) { } case *ast.CreateRoleStmt: + if n.BindRole != nil { + Walk(f, n.BindRole) + } if n.Options != nil { Walk(f, n.Options) } @@ -1516,6 +1519,17 @@ func Walk(f Visitor, node ast.Node) { Walk(f, n.PartParams) } + case *ast.Pragma_stmt: + if n.Name != nil { + Walk(f, n.Name) + } + if n.Cols != nil { + Walk(f, n.Cols) + } + if n.Values != nil { + Walk(f, n.Values) + } + case *ast.PrepareStmt: if n.Argtypes != nil { Walk(f, n.Argtypes) @@ -1758,7 +1772,9 @@ func Walk(f Visitor, node ast.Node) { } case *ast.RoleSpec: - // pass + if n.BindRolename != nil { + Walk(f, n.BindRolename) + } case *ast.RowCompareExpr: if n.Xpr != nil { @@ -2063,6 +2079,11 @@ func Walk(f Visitor, node ast.Node) { Walk(f, n.WithClause) } + case *ast.UseStmt: + if n.Xpr != nil { + Walk(f, n.Xpr) + } + case *ast.VacuumStmt: if n.Relation != nil { Walk(f, n.Relation) From e687cf6d78ab4d61d5ff0788c46869c76719b259 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Mon, 19 May 2025 18:35:44 +0300 Subject: [PATCH 06/22] ADDED DROP/ALTER USER/GROUP --- .../ydb/catalog_tests/alter_group_test.go | 122 ++++++++++ .../ydb/catalog_tests/alter_user_test.go | 153 +++++++++++++ .../ydb/catalog_tests/drop_role_test.go | 87 +++++++ internal/engine/ydb/convert.go | 213 ++++++++++++++++-- internal/engine/ydb/utils.go | 29 +++ 5 files changed, 583 insertions(+), 21 deletions(-) create mode 100644 internal/engine/ydb/catalog_tests/alter_group_test.go create mode 100644 internal/engine/ydb/catalog_tests/alter_user_test.go create mode 100644 internal/engine/ydb/catalog_tests/drop_role_test.go diff --git a/internal/engine/ydb/catalog_tests/alter_group_test.go b/internal/engine/ydb/catalog_tests/alter_group_test.go new file mode 100644 index 0000000000..eef9f919e9 --- /dev/null +++ b/internal/engine/ydb/catalog_tests/alter_group_test.go @@ -0,0 +1,122 @@ +package ydb_test + +import ( + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" +) + +func TestAlterGroup(t *testing.T) { + tests := []struct { + stmt string + expected ast.Node + }{ + { + stmt: `ALTER GROUP admins RENAME TO superusers`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.AlterRoleStmt{ + Role: &ast.RoleSpec{ + Rolename: strPtr("admins"), + Roletype: ast.RoleSpecType(1), + }, + Action: 1, + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("rename"), + Defaction: ast.DefElemAction(1), + Arg: &ast.String{Str: "superusers"}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `ALTER GROUP devs ADD USER alice, bob, carol`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.AlterRoleStmt{ + Role: &ast.RoleSpec{ + Rolename: strPtr("devs"), + Roletype: ast.RoleSpecType(1), + }, + Action: 1, + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("rolemembers"), + Defaction: ast.DefElemAction(3), + Arg: &ast.List{ + Items: []ast.Node{ + &ast.RoleSpec{Rolename: strPtr("alice"), Roletype: ast.RoleSpecType(1)}, + &ast.RoleSpec{Rolename: strPtr("bob"), Roletype: ast.RoleSpecType(1)}, + &ast.RoleSpec{Rolename: strPtr("carol"), Roletype: ast.RoleSpecType(1)}, + }, + }, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `ALTER GROUP ops DROP USER dan, erin`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.AlterRoleStmt{ + Role: &ast.RoleSpec{ + Rolename: strPtr("ops"), + Roletype: ast.RoleSpecType(1), + }, + Action: 1, + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("rolemembers"), + Defaction: ast.DefElemAction(4), + Arg: &ast.List{ + Items: []ast.Node{ + &ast.RoleSpec{Rolename: strPtr("dan"), Roletype: ast.RoleSpecType(1)}, + &ast.RoleSpec{Rolename: strPtr("erin"), Roletype: ast.RoleSpecType(1)}, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } + + p := ydb.NewParser() + for _, tc := range tests { + t.Run(tc.stmt, func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(tc.stmt)) + if err != nil { + t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + } + if len(stmts) == 0 { + t.Fatalf("Запрос %q не распарсен", tc.stmt) + } + + diff := cmp.Diff(tc.expected, &stmts[0], + cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), + cmpopts.IgnoreFields(ast.DefElem{}, "Location"), + cmpopts.IgnoreFields(ast.RoleSpec{}, "Location"), + cmpopts.IgnoreFields(ast.A_Const{}, "Location"), + ) + if diff != "" { + t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + } + }) + } +} diff --git a/internal/engine/ydb/catalog_tests/alter_user_test.go b/internal/engine/ydb/catalog_tests/alter_user_test.go new file mode 100644 index 0000000000..dd4dc5bb93 --- /dev/null +++ b/internal/engine/ydb/catalog_tests/alter_user_test.go @@ -0,0 +1,153 @@ +package ydb_test + +import ( + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" +) + +func TestAlterUser(t *testing.T) { + tests := []struct { + stmt string + expected ast.Node + }{ + { + stmt: `ALTER USER alice RENAME TO queen`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.AlterRoleStmt{ + Role: &ast.RoleSpec{ + Rolename: strPtr("alice"), + Roletype: ast.RoleSpecType(1), + }, + Action: 1, + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("rename"), + Arg: &ast.String{Str: "queen"}, + Defaction: ast.DefElemAction(1), + }, + }, + }, + }, + }, + }, + }, + { + stmt: `ALTER USER bob LOGIN`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.AlterRoleStmt{ + Role: &ast.RoleSpec{ + Rolename: strPtr("bob"), + Roletype: ast.RoleSpecType(1), + }, + Action: 1, + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("login"), + Arg: &ast.Boolean{Boolval: true}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `ALTER USER charlie NOLOGIN`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.AlterRoleStmt{ + Role: &ast.RoleSpec{ + Rolename: strPtr("charlie"), + Roletype: ast.RoleSpecType(1), + }, + Action: 1, + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("nologin"), + Arg: &ast.Boolean{Boolval: false}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `ALTER USER dave PASSWORD 'qwerty'`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.AlterRoleStmt{ + Role: &ast.RoleSpec{ + Rolename: strPtr("dave"), + Roletype: ast.RoleSpecType(1), + }, + Action: 1, + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("password"), + Arg: &ast.String{Str: "qwerty"}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `ALTER USER elena HASH 'abc123'`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.AlterRoleStmt{ + Role: &ast.RoleSpec{ + Rolename: strPtr("elena"), + Roletype: ast.RoleSpecType(1), + }, + Action: 1, + Options: &ast.List{ + Items: []ast.Node{ + &ast.DefElem{ + Defname: strPtr("hash"), + Arg: &ast.String{Str: "abc123"}, + }, + }, + }, + }, + }, + }, + }, + } + + p := ydb.NewParser() + for _, tc := range tests { + t.Run(tc.stmt, func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(tc.stmt)) + if err != nil { + t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + } + if len(stmts) == 0 { + t.Fatalf("Запрос %q не распарсен", tc.stmt) + } + + diff := cmp.Diff(tc.expected, &stmts[0], + cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), + cmpopts.IgnoreFields(ast.DefElem{}, "Location"), + cmpopts.IgnoreFields(ast.RoleSpec{}, "Location"), + cmpopts.IgnoreFields(ast.A_Const{}, "Location"), + ) + if diff != "" { + t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + } + }) + } +} diff --git a/internal/engine/ydb/catalog_tests/drop_role_test.go b/internal/engine/ydb/catalog_tests/drop_role_test.go new file mode 100644 index 0000000000..1d7c6a7658 --- /dev/null +++ b/internal/engine/ydb/catalog_tests/drop_role_test.go @@ -0,0 +1,87 @@ +package ydb_test + +import ( + "strings" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/sqlc-dev/sqlc/internal/engine/ydb" + "github.com/sqlc-dev/sqlc/internal/sql/ast" +) + +func TestDropRole(t *testing.T) { + tests := []struct { + stmt string + expected ast.Node + }{ + { + stmt: `DROP USER user1;`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.DropRoleStmt{ + MissingOk: false, + Roles: &ast.List{ + Items: []ast.Node{ + &ast.RoleSpec{Rolename: strPtr("user1"), Roletype: ast.RoleSpecType(1)}, + }, + }, + }, + }, + }, + }, + { + stmt: "DROP USER IF EXISTS admin, user2", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.DropRoleStmt{ + MissingOk: true, + Roles: &ast.List{ + Items: []ast.Node{ + &ast.RoleSpec{Rolename: strPtr("admin"), Roletype: ast.RoleSpecType(1)}, + &ast.RoleSpec{Rolename: strPtr("user2"), Roletype: ast.RoleSpecType(1)}, + }, + }, + }, + }, + }, + }, + { + stmt: "DROP GROUP team1, team2", + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.DropRoleStmt{ + MissingOk: false, + Roles: &ast.List{ + Items: []ast.Node{ + &ast.RoleSpec{Rolename: strPtr("team1"), Roletype: ast.RoleSpecType(1)}, + &ast.RoleSpec{Rolename: strPtr("team2"), Roletype: ast.RoleSpecType(1)}, + }, + }, + }, + }, + }, + }, + } + + p := ydb.NewParser() + for _, tc := range tests { + t.Run(tc.stmt, func(t *testing.T) { + stmts, err := p.Parse(strings.NewReader(tc.stmt)) + if err != nil { + t.Fatalf("Error parsing %q: %v", tc.stmt, err) + } + if len(stmts) == 0 { + t.Fatalf("Statement %q was not parsed", tc.stmt) + } + + diff := cmp.Diff(tc.expected, &stmts[0], + cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), + cmpopts.IgnoreFields(ast.RoleSpec{}, "Location"), + ) + if diff != "" { + t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) + } + }) + } +} diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index 6fd2fe0ea3..4dab9189a4 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -45,6 +45,186 @@ func NewIdentifier(t string) *ast.String { return &ast.String{Str: identifier(t)} } +func (c *cc) convertDrop_role_stmtCOntext(n *parser.Drop_role_stmtContext) ast.Node { + if n.DROP() == nil || (n.USER() == nil && n.GROUP() == nil) || len(n.AllRole_name()) == 0 { + return todo("Drop_role_stmtContext", n) + } + + stmt := &ast.DropRoleStmt{ + MissingOk: n.IF() != nil && n.EXISTS() != nil, + Roles: &ast.List{}, + } + + for _, role := range n.AllRole_name() { + member, isParam, _ := c.extractRoleSpec(role, ast.RoleSpecType(1)) + if member == nil { + return todo("Drop_role_stmtContext", n) + } + + if debug.Active && isParam { + log.Printf("YDB does not currently support parameters in the DROP ROLE statement") + } + + stmt.Roles.Items = append(stmt.Roles.Items, member) + } + + return stmt +} + +func (c *cc) convertAlter_group_stmtContext(n *parser.Alter_group_stmtContext) ast.Node { + if n.ALTER() == nil || n.GROUP() == nil || len(n.AllRole_name()) == 0 { + return todo("convertAlter_group_stmtContext", n) + } + role, paramFlag, _ := c.extractRoleSpec(n.Role_name(0), ast.RoleSpecType(1)) + if role == nil { + return todo("convertAlter_group_stmtContext", n) + } + + if debug.Active && paramFlag { + log.Printf("YDB does not currently support parameters in the ALTER GROUP statement") + } + + stmt := &ast.AlterRoleStmt{ + Role: role, + Action: 1, + Options: &ast.List{}, + } + + switch { + case n.RENAME() != nil && n.TO() != nil && len(n.AllRole_name()) > 1: + newName := c.convert(n.Role_name(1)) + action := "rename" + + defElem := &ast.DefElem{ + Defname: &action, + Defaction: ast.DefElemAction(1), + Location: n.Role_name(1).GetStart().GetStart(), + } + + bindFlag := true + switch v := newName.(type) { + case *ast.A_Const: + switch val := v.Val.(type) { + case *ast.String: + bindFlag = false + defElem.Arg = val + case *ast.Boolean: + defElem.Arg = val + default: + return todo("convertAlter_group_stmtContext", n) + } + case *ast.ParamRef, *ast.A_Expr: + defElem.Arg = newName + default: + return todo("convertAlter_group_stmtContext", n) + } + + if debug.Active && !paramFlag && bindFlag { + log.Printf("YDB does not currently support parameters in the ALTER GROUP statement") + } + + stmt.Options.Items = append(stmt.Options.Items, defElem) + + case (n.ADD() != nil || n.DROP() != nil) && len(n.AllRole_name()) > 1: + defname := "rolemembers" + optionList := &ast.List{} + for _, role := range n.AllRole_name()[1:] { + member, isParam, _ := c.extractRoleSpec(role, ast.RoleSpecType(1)) + if member == nil { + return todo("convertAlter_group_stmtContext", n) + } + + if debug.Active && isParam && !paramFlag { + log.Printf("YDB does not currently support parameters in the ALTER GROUP statement") + } + + optionList.Items = append(optionList.Items, member) + } + + var action ast.DefElemAction + if n.ADD() != nil { + action = 3 + } else { + action = 4 + } + + stmt.Options.Items = append(stmt.Options.Items, &ast.DefElem{ + Defname: &defname, + Arg: optionList, + Defaction: action, + Location: n.GetStart().GetStart(), + }) + } + + return stmt +} + +func (c *cc) convertAlter_user_stmtContext(n *parser.Alter_user_stmtContext) ast.Node { + if n.ALTER() == nil || n.USER() == nil || len(n.AllRole_name()) == 0 { + return todo("Alter_user_stmtContext", n) + } + + role, paramFlag, _ := c.extractRoleSpec(n.Role_name(0), ast.RoleSpecType(1)) + if role == nil { + return todo("convertAlter_group_stmtContext", n) + } + + if debug.Active && paramFlag { + log.Printf("YDB does not currently support parameters in the ALTER USER statement") + } + + stmt := &ast.AlterRoleStmt{ + Role: role, + Action: 1, + Options: &ast.List{}, + } + + switch { + case n.RENAME() != nil && n.TO() != nil && len(n.AllRole_name()) > 1: + newName := c.convert(n.Role_name(1)) + action := "rename" + + defElem := &ast.DefElem{ + Defname: &action, + Defaction: ast.DefElemAction(1), + Location: n.Role_name(1).GetStart().GetStart(), + } + + bindFlag := true + switch v := newName.(type) { + case *ast.A_Const: + switch val := v.Val.(type) { + case *ast.String: + bindFlag = false + defElem.Arg = val + case *ast.Boolean: + defElem.Arg = val + default: + return todo("Alter_user_stmtContext", n) + } + case *ast.ParamRef, *ast.A_Expr: + defElem.Arg = newName + default: + return todo("Alter_user_stmtContext", n) + } + + if debug.Active && !paramFlag && bindFlag { + log.Printf("YDB does not currently support parameters in the ALTER USER statement") + } + + stmt.Options.Items = append(stmt.Options.Items, defElem) + + case len(n.AllUser_option()) > 0: + for _, opt := range n.AllUser_option() { + if node := c.convert(opt); node != nil { + stmt.Options.Items = append(stmt.Options.Items, node) + } + } + } + + return stmt +} + func (c *cc) convertCreate_group_stmtContext(n *parser.Create_group_stmtContext) ast.Node { if n.CREATE() == nil || n.GROUP() == nil || len(n.AllRole_name()) == 0 { return todo("Create_group_stmtContext", n) @@ -82,26 +262,8 @@ func (c *cc) convertCreate_group_stmtContext(n *parser.Create_group_stmtContext) defname := "rolemembers" optionList := &ast.List{} for _, role := range n.AllRole_name()[1:] { - roleNode := c.convert(role) - roleSpec := &ast.RoleSpec{ - Roletype: ast.RoleSpecType(1), - Location: role.GetStart().GetStart(), - } - isParam := true - switch v := roleNode.(type) { - case *ast.A_Const: - switch val := v.Val.(type) { - case *ast.String: - isParam = false - roleSpec.Rolename = &val.Str - case *ast.Boolean: - roleSpec.BindRolename = roleNode - default: - return todo("convertCreate_group_stmtContext", n) - } - case *ast.ParamRef, *ast.A_Expr: - roleSpec.BindRolename = roleNode - default: + member, isParam, _ := c.extractRoleSpec(role, ast.RoleSpecType(1)) + if member == nil { return todo("convertCreate_group_stmtContext", n) } @@ -109,7 +271,7 @@ func (c *cc) convertCreate_group_stmtContext(n *parser.Create_group_stmtContext) log.Printf("YDB does not currently support parameters in the CREATE GROUP statement") } - optionList.Items = append(optionList.Items, roleSpec) + optionList.Items = append(optionList.Items, member) } stmt.Options.Items = append(stmt.Options.Items, &ast.DefElem{ @@ -2284,6 +2446,15 @@ func (c *cc) convert(node node) ast.Node { case *parser.Create_group_stmtContext: return c.convertCreate_group_stmtContext(n) + case *parser.Alter_user_stmtContext: + return c.convertAlter_user_stmtContext(n) + + case *parser.Alter_group_stmtContext: + return c.convertAlter_group_stmtContext(n) + + case *parser.Drop_role_stmtContext: + return c.convertDrop_role_stmtCOntext(n) + default: return todo("convert(case=default)", n) } diff --git a/internal/engine/ydb/utils.go b/internal/engine/ydb/utils.go index 5201e6c9dd..0748de8bdf 100755 --- a/internal/engine/ydb/utils.go +++ b/internal/engine/ydb/utils.go @@ -143,3 +143,32 @@ func parseIntegerValue(text string) (int64, error) { return strconv.ParseInt(text, base, 64) } + +func (c *cc) extractRoleSpec(n parser.IRole_nameContext, roletype ast.RoleSpecType) (*ast.RoleSpec, bool, ast.Node) { + roleNode := c.convert(n) + + roleSpec := &ast.RoleSpec{ + Roletype: roletype, + Location: n.GetStart().GetStart(), + } + + isParam := true + switch v := roleNode.(type) { + case *ast.A_Const: + switch val := v.Val.(type) { + case *ast.String: + roleSpec.Rolename = &val.Str + isParam = false + case *ast.Boolean: + roleSpec.BindRolename = roleNode + default: + return nil, false, nil + } + case *ast.ParamRef, *ast.A_Expr: + roleSpec.BindRolename = roleNode + default: + return nil, false, nil + } + + return roleSpec, isParam, roleNode +} From 0293f6afc046ca9fc7e590a38f1e2edc111d41e3 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Wed, 21 May 2025 01:22:26 +0300 Subject: [PATCH 07/22] Added Funcs support! --- examples/authors/sqlc.yaml | 82 +++--- examples/authors/ydb/db.go | 2 +- examples/authors/ydb/models.go | 2 +- examples/authors/ydb/query.sql.go | 2 +- internal/engine/ydb/convert.go | 376 ++++++++++++++++-------- internal/engine/ydb/lib/aggregate.go | 330 +++++++++++++++++++++ internal/engine/ydb/lib/basic.go | 203 +++++++++++++ internal/engine/ydb/parse.go | 11 +- internal/engine/ydb/stdlib.go | 10 +- internal/engine/ydb/utils.go | 26 +- internal/sql/ast/insert_stmt.go | 29 +- internal/sql/ast/recursive_func_call.go | 33 +++ internal/sql/astutils/rewrite.go | 9 +- internal/sql/astutils/walk.go | 20 ++ 14 files changed, 950 insertions(+), 185 deletions(-) create mode 100644 internal/engine/ydb/lib/aggregate.go create mode 100644 internal/engine/ydb/lib/basic.go create mode 100644 internal/sql/ast/recursive_func_call.go diff --git a/examples/authors/sqlc.yaml b/examples/authors/sqlc.yaml index 30d904875e..8d6bc3db28 100644 --- a/examples/authors/sqlc.yaml +++ b/examples/authors/sqlc.yaml @@ -2,47 +2,47 @@ version: '2' cloud: project: "01HAQMMECEYQYKFJN8MP16QC41" sql: -# - name: postgresql -# schema: postgresql/schema.sql -# queries: postgresql/query.sql -# engine: postgresql -# database: -# uri: "${VET_TEST_EXAMPLES_POSTGRES_AUTHORS}" -# analyzer: -# database: false -# rules: -# - sqlc/db-prepare -# - postgresql-query-too-costly -# gen: -# go: -# package: authors -# sql_package: pgx/v5 -# out: postgresql -# - name: mysql -# schema: mysql/schema.sql -# queries: mysql/query.sql -# engine: mysql -# database: -# uri: "${VET_TEST_EXAMPLES_MYSQL_AUTHORS}" -# rules: -# - sqlc/db-prepare -# # - mysql-query-too-costly -# gen: -# go: -# package: authors -# out: mysql -# - name: sqlite -# schema: sqlite/schema.sql -# queries: sqlite/query.sql -# engine: sqlite -# database: -# uri: file:authors?mode=memory&cache=shared -# rules: -# - sqlc/db-prepare -# gen: -# go: -# package: authors -# out: sqlite +- name: postgresql + schema: postgresql/schema.sql + queries: postgresql/query.sql + engine: postgresql + database: + uri: "${VET_TEST_EXAMPLES_POSTGRES_AUTHORS}" + analyzer: + database: false + rules: + - sqlc/db-prepare + - postgresql-query-too-costly + gen: + go: + package: authors + sql_package: pgx/v5 + out: postgresql +- name: mysql + schema: mysql/schema.sql + queries: mysql/query.sql + engine: mysql + database: + uri: "${VET_TEST_EXAMPLES_MYSQL_AUTHORS}" + rules: + - sqlc/db-prepare + # - mysql-query-too-costly + gen: + go: + package: authors + out: mysql +- name: sqlite + schema: sqlite/schema.sql + queries: sqlite/query.sql + engine: sqlite + database: + uri: file:authors?mode=memory&cache=shared + rules: + - sqlc/db-prepare + gen: + go: + package: authors + out: sqlite - name: ydb schema: ydb/schema.sql queries: ydb/query.sql diff --git a/examples/authors/ydb/db.go b/examples/authors/ydb/db.go index 2bb1bfc27d..e2b0a86b13 100644 --- a/examples/authors/ydb/db.go +++ b/examples/authors/ydb/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.29.0 package authors diff --git a/examples/authors/ydb/models.go b/examples/authors/ydb/models.go index 337ea597f4..8edcdc7b33 100644 --- a/examples/authors/ydb/models.go +++ b/examples/authors/ydb/models.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.29.0 package authors diff --git a/examples/authors/ydb/query.sql.go b/examples/authors/ydb/query.sql.go index 64126bf254..e244f62c54 100644 --- a/examples/authors/ydb/query.sql.go +++ b/examples/authors/ydb/query.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.27.0 +// sqlc v1.29.0 // source: query.sql package authors diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index 4dab9189a4..b4d9490d0b 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -13,6 +13,15 @@ import ( type cc struct { paramCount int + content string +} + +func (c *cc) pos(token antlr.Token) int { + if token == nil { + return 0 + } + runeIdx := token.GetStart() + return byteOffsetFromRuneIndex(c.content, runeIdx) } type node interface { @@ -52,7 +61,7 @@ func (c *cc) convertDrop_role_stmtCOntext(n *parser.Drop_role_stmtContext) ast.N stmt := &ast.DropRoleStmt{ MissingOk: n.IF() != nil && n.EXISTS() != nil, - Roles: &ast.List{}, + Roles: &ast.List{}, } for _, role := range n.AllRole_name() { @@ -98,7 +107,7 @@ func (c *cc) convertAlter_group_stmtContext(n *parser.Alter_group_stmtContext) a defElem := &ast.DefElem{ Defname: &action, Defaction: ast.DefElemAction(1), - Location: n.Role_name(1).GetStart().GetStart(), + Location: c.pos(n.Role_name(1).GetStart()), } bindFlag := true @@ -152,7 +161,7 @@ func (c *cc) convertAlter_group_stmtContext(n *parser.Alter_group_stmtContext) a Defname: &defname, Arg: optionList, Defaction: action, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), }) } @@ -187,7 +196,7 @@ func (c *cc) convertAlter_user_stmtContext(n *parser.Alter_user_stmtContext) ast defElem := &ast.DefElem{ Defname: &action, Defaction: ast.DefElemAction(1), - Location: n.Role_name(1).GetStart().GetStart(), + Location: c.pos(n.Role_name(1).GetStart()), } bindFlag := true @@ -277,7 +286,7 @@ func (c *cc) convertCreate_group_stmtContext(n *parser.Create_group_stmtContext) stmt.Options.Items = append(stmt.Options.Items, &ast.DefElem{ Defname: &defname, Arg: optionList, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), }) } @@ -289,7 +298,7 @@ func (c *cc) convertUse_stmtContext(n *parser.Use_stmtContext) ast.Node { clusterExpr := c.convert(n.Cluster_expr()) stmt := &ast.UseStmt{ Xpr: clusterExpr, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } return stmt } @@ -306,7 +315,7 @@ func (c *cc) convertCluster_exprContext(n *parser.Cluster_exprContext) ast.Node name := parseAnId(anID) node = &ast.ColumnRef{ Fields: &ast.List{Items: []ast.Node{NewIdentifier(name)}}, - Location: anID.GetStart().GetStart(), + Location: c.pos(anID.GetStart()), } } else if bp := pureCtx.Bind_parameter(); bp != nil { node = c.convert(bp) @@ -323,7 +332,7 @@ func (c *cc) convertCluster_exprContext(n *parser.Cluster_exprContext) ast.Node Name: &ast.List{Items: []ast.Node{&ast.String{Str: ":"}}}, Lexpr: &ast.String{Str: name}, Rexpr: node, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } @@ -394,7 +403,7 @@ func (c *cc) convertUser_optionContext(n *parser.User_optionContext) ast.Node { return &ast.DefElem{ Defname: &name, Arg: password, - Location: pOpt.GetStart().GetStart(), + Location: c.pos(pOpt.GetStart()), } } } else if hOpt := aOpt.Hash_option(); hOpt != nil { @@ -409,7 +418,7 @@ func (c *cc) convertUser_optionContext(n *parser.User_optionContext) ast.Node { return &ast.DefElem{ Defname: &name, Arg: &ast.String{Str: pass}, - Location: hOpt.GetStart().GetStart(), + Location: c.pos(hOpt.GetStart()), } } @@ -424,7 +433,7 @@ func (c *cc) convertUser_optionContext(n *parser.User_optionContext) ast.Node { return &ast.DefElem{ Defname: &name, Arg: &ast.Boolean{Boolval: lOpt.LOGIN() != nil}, - Location: lOpt.GetStart().GetStart(), + Location: c.pos(lOpt.GetStart()), } default: return todo("convertUser_optionContext", n) @@ -436,7 +445,7 @@ func (c *cc) convertRole_nameContext(n *parser.Role_nameContext) ast.Node { switch { case n.An_id_or_type() != nil: name := parseAnIdOrType(n.An_id_or_type()) - return &ast.A_Const{Val: NewIdentifier(name), Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: NewIdentifier(name), Location: c.pos(n.GetStart())} case n.Bind_parameter() != nil: bindPar := c.convert(n.Bind_parameter()) return bindPar @@ -490,7 +499,8 @@ func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { for _, anID := range pureCols.AllAn_id() { name := identifier(parseAnId(anID)) cols.Items = append(cols.Items, &ast.ResTarget{ - Name: &name, + Name: &name, + Location: c.pos(anID.GetStart()), }) } } @@ -544,7 +554,7 @@ func (c *cc) convertPragma_stmtContext(n *parser.Pragma_stmtContext) ast.Node { stmt := &ast.Pragma_stmt{ Name: &ast.List{Items: items}, - Location: n.An_id().GetStart().GetStart(), + Location: c.pos(n.An_id().GetStart()), } if n.EQUALS() != nil { @@ -577,24 +587,24 @@ func (c *cc) convertPragma_valueContext(n *parser.Pragma_valueContext) ast.Node } return &ast.TODO{} } - return &ast.A_Const{Val: &ast.Integer{Ival: val}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.Integer{Ival: val}, Location: c.pos(n.GetStart())} } if n.Signed_number().Real_() != nil { text := n.Signed_number().GetText() - return &ast.A_Const{Val: &ast.Float{Str: text}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.Float{Str: text}, Location: c.pos(n.GetStart())} } case n.STRING_VALUE() != nil: val := n.STRING_VALUE().GetText() if len(val) >= 2 { val = val[1 : len(val)-1] } - return &ast.A_Const{Val: &ast.String{Str: val}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.String{Str: val}, Location: c.pos(n.GetStart())} case n.Bool_value() != nil: var i bool if n.Bool_value().TRUE() != nil { i = true } - return &ast.A_Const{Val: &ast.Boolean{Boolval: i}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.Boolean{Boolval: i}, Location: c.pos(n.GetStart())} case n.Bind_parameter() != nil: bindPar := c.convert(n.Bind_parameter()) return bindPar @@ -628,8 +638,9 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { columnName := identifier(targetCtx.Column_name().GetText()) expr := c.convert(clause.Expr()) resTarget := &ast.ResTarget{ - Name: &columnName, - Val: expr, + Name: &columnName, + Val: expr, + Location: c.pos(clause.Expr().GetStart()), } setList.Items = append(setList.Items, resTarget) } @@ -664,6 +675,7 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { Colno: i + 1, Ncolumns: len(colNames), }, + Location: c.pos(targetsCtx.Set_target(i).GetStart()), }) } } @@ -682,7 +694,8 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { for _, anID := range pureCols.AllAn_id() { name := identifier(parseAnId(anID)) cols.Items = append(cols.Items, &ast.ResTarget{ - Name: &name, + Name: &name, + Location: c.pos(anID.GetStart()), }) } } @@ -725,7 +738,10 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { func (c *cc) convertInto_table_stmtContext(n *parser.Into_table_stmtContext) ast.Node { tableName := identifier(n.Into_simple_table_ref().Simple_table_ref().Simple_table_ref_core().GetText()) - rel := &ast.RangeVar{Relname: &tableName} + rel := &ast.RangeVar{ + Relname: &tableName, + Location: c.pos(n.Into_simple_table_ref().GetStart()), + } onConflict := &ast.OnConflictClause{} switch { @@ -751,7 +767,8 @@ func (c *cc) convertInto_table_stmtContext(n *parser.Into_table_stmtContext) ast for _, anID := range pureCols.AllAn_id() { name := identifier(parseAnId(anID)) cols.Items = append(cols.Items, &ast.ResTarget{ - Name: &name, + Name: &name, + Location: c.pos(anID.GetStart()), }) } } @@ -816,9 +833,9 @@ func (c *cc) convertReturning_columns_listContext(n *parser.Returning_columns_li Indirection: &ast.List{}, Val: &ast.ColumnRef{ Fields: &ast.List{Items: []ast.Node{&ast.A_Star{}}}, - Location: n.ASTERISK().GetSymbol().GetStart(), + Location: c.pos(n.ASTERISK().GetSymbol()), }, - Location: n.ASTERISK().GetSymbol().GetStart(), + Location: c.pos(n.ASTERISK().GetSymbol()), } list.Items = append(list.Items, target) return list @@ -831,9 +848,9 @@ func (c *cc) convertReturning_columns_listContext(n *parser.Returning_columns_li Fields: &ast.List{ Items: []ast.Node{NewIdentifier(parseAnId(idCtx))}, }, - Location: idCtx.GetStart().GetStart(), + Location: c.pos(idCtx.GetStart()), }, - Location: idCtx.GetStart().GetStart(), + Location: c.pos(idCtx.GetStart()), } list.Items = append(list.Items, target) } @@ -945,7 +962,7 @@ func (c *cc) convertSelectCoreContext(n *parser.Select_coreContext) ast.Node { func (c *cc) convertResultColumn(n *parser.Result_columnContext) ast.Node { // todo: support opt_id_prefix target := &ast.ResTarget{ - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } var val ast.Node iexpr := n.Expr() @@ -1091,7 +1108,7 @@ func (c *cc) convertSingleSource(n *parser.Single_sourceContext) ast.Node { tableName := n.Table_ref().GetText() // !! debug !! return &ast.RangeVar{ Relname: &tableName, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } @@ -1111,10 +1128,10 @@ func (c *cc) convertBindParameter(n *parser.Bind_parameterContext) ast.Node { // !!debug later!! if n.DOLLAR() != nil { if n.TRUE() != nil { - return &ast.A_Const{Val: &ast.Boolean{Boolval: true}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.Boolean{Boolval: true}, Location: c.pos(n.GetStart())} } if n.FALSE() != nil { - return &ast.A_Const{Val: &ast.Boolean{Boolval: false}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.Boolean{Boolval: false}, Location: c.pos(n.GetStart())} } if an := n.An_id_or_type(); an != nil { @@ -1122,13 +1139,13 @@ func (c *cc) convertBindParameter(n *parser.Bind_parameterContext) ast.Node { return &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: "@"}}}, Rexpr: &ast.String{Str: idText}, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } c.paramCount++ return &ast.ParamRef{ Number: c.paramCount, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), Dollar: true, } } @@ -1147,7 +1164,7 @@ func (c *cc) convertWildCardField(n *parser.Result_columnContext) *ast.ColumnRef items = append(items, &ast.A_Star{}) return &ast.ColumnRef{ Fields: &ast.List{Items: items}, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } @@ -1250,7 +1267,6 @@ func (c *cc) convertTypeName(n parser.IType_nameContext) *ast.TypeName { return nil } - // Handle composite types if composite := n.Type_name_composite(); composite != nil { if node := c.convertTypeNameComposite(composite); node != nil { if typeName, ok := node.(*ast.TypeName); ok { @@ -1259,7 +1275,6 @@ func (c *cc) convertTypeName(n parser.IType_nameContext) *ast.TypeName { } } - // Handle decimal type (e.g., DECIMAL(10,2)) if decimal := n.Type_name_decimal(); decimal != nil { if integerOrBinds := decimal.AllInteger_or_bind(); len(integerOrBinds) >= 2 { return &ast.TypeName{ @@ -1697,7 +1712,7 @@ func (c *cc) convertExpr(n *parser.ExprContext) ast.Node { left = &ast.BoolExpr{ Boolop: ast.BoolExprTypeOr, Args: &ast.List{Items: []ast.Node{left, right}}, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } return left @@ -1726,7 +1741,7 @@ func (c *cc) convertOrSubExpr(n *parser.Or_subexprContext) ast.Node { left = &ast.BoolExpr{ Boolop: ast.BoolExprTypeAnd, Args: &ast.List{Items: []ast.Node{left, right}}, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } return left @@ -1758,7 +1773,7 @@ func (c *cc) convertAndSubexpr(n *parser.And_subexprContext) ast.Node { Name: &ast.List{Items: []ast.Node{&ast.String{Str: "XOR"}}}, Lexpr: left, Rexpr: right, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } return left @@ -1799,32 +1814,32 @@ func (c *cc) convertXorSubexpr(n *parser.Xor_subexprContext) ast.Node { Left: c.convert(eqSubs[0]), Right: c.convert(eqSubs[1]), Not: condCtx.NOT() != nil, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } case condCtx.ISNULL() != nil: return &ast.NullTest{ Arg: base, Nulltesttype: 1, // IS NULL - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } case condCtx.NOTNULL() != nil: return &ast.NullTest{ Arg: base, Nulltesttype: 2, // IS NOT NULL - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } case condCtx.IS() != nil && condCtx.NULL() != nil: return &ast.NullTest{ Arg: base, Nulltesttype: 1, // IS NULL - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } case condCtx.IS() != nil && condCtx.NOT() != nil && condCtx.NULL() != nil: return &ast.NullTest{ Arg: base, Nulltesttype: 2, // IS NOT NULL - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } case condCtx.Match_op() != nil: // debug!!! @@ -1908,7 +1923,7 @@ func (c *cc) convertEqSubexpr(n *parser.Eq_subexprContext) ast.Node { Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, Lexpr: left, Rexpr: right, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } return left @@ -1953,7 +1968,7 @@ func (c *cc) convertNeqSubexpr(n *parser.Neq_subexprContext) ast.Node { Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, Lexpr: left, Rexpr: right, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } @@ -1969,7 +1984,7 @@ func (c *cc) convertNeqSubexpr(n *parser.Neq_subexprContext) ast.Node { Name: &ast.List{Items: []ast.Node{&ast.String{Str: "??"}}}, Lexpr: left, Rexpr: right, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } } else { @@ -1983,7 +1998,7 @@ func (c *cc) convertNeqSubexpr(n *parser.Neq_subexprContext) ast.Node { left = &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: questionOp}}}, Lexpr: left, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } } @@ -2018,7 +2033,7 @@ func (c *cc) convertBitSubexpr(n *parser.Bit_subexprContext) ast.Node { Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, Lexpr: left, Rexpr: right, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } return left @@ -2051,7 +2066,7 @@ func (c *cc) convertAddSubexpr(n *parser.Add_subexprContext) ast.Node { Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, Lexpr: left, Rexpr: right, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } return left @@ -2080,7 +2095,7 @@ func (c *cc) convertMulSubexpr(n *parser.Mul_subexprContext) ast.Node { Name: &ast.List{Items: []ast.Node{&ast.String{Str: "||"}}}, Lexpr: left, Rexpr: right, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } return left @@ -2093,7 +2108,7 @@ func (c *cc) convertConSubexpr(n *parser.Con_subexprContext) ast.Node { return &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: op}}}, Rexpr: operand, - Location: n.GetStart().GetStart(), + Location: c.pos(n.GetStart()), } } return c.convertUnarySubexpr(n.Unary_subexpr().(*parser.Unary_subexprContext)) @@ -2110,89 +2125,211 @@ func (c *cc) convertUnarySubexpr(n *parser.Unary_subexprContext) ast.Node { } func (c *cc) convertJsonApiExpr(n *parser.Json_api_exprContext) ast.Node { - return &ast.TODO{} // todo + return todo("Json_api_exprContext", n) } func (c *cc) convertUnaryCasualSubexpr(n *parser.Unary_casual_subexprContext) ast.Node { - var baseExpr ast.Node + var current ast.Node + switch { + case n.Id_expr() != nil: + current = c.convertIdExpr(n.Id_expr().(*parser.Id_exprContext)) + case n.Atom_expr() != nil: + current = c.convertAtomExpr(n.Atom_expr().(*parser.Atom_exprContext)) + default: + return todo("Unary_casual_subexprContext", n) + } - if idExpr := n.Id_expr(); idExpr != nil { - baseExpr = c.convertIdExpr(idExpr.(*parser.Id_exprContext)) - } else if atomExpr := n.Atom_expr(); atomExpr != nil { - baseExpr = c.convertAtomExpr(atomExpr.(*parser.Atom_exprContext)) + if suffix := n.Unary_subexpr_suffix(); suffix != nil { + current = c.processSuffixChain(current, suffix.(*parser.Unary_subexpr_suffixContext)) } - suffixCtx := n.Unary_subexpr_suffix() - if suffixCtx != nil { - ctx, ok := suffixCtx.(*parser.Unary_subexpr_suffixContext) - if !ok { - return baseExpr + return current +} + +func (c *cc) processSuffixChain(base ast.Node, suffix *parser.Unary_subexpr_suffixContext) ast.Node { + current := base + for i := 0; i < suffix.GetChildCount(); i++ { + child := suffix.GetChild(i) + switch elem := child.(type) { + case *parser.Key_exprContext: + current = c.handleKeySuffix(current, elem) + case *parser.Invoke_exprContext: + current = c.handleInvokeSuffix(current, elem, i) + case antlr.TerminalNode: + if elem.GetText() == "." { + current = c.handleDotSuffix(current, suffix, &i) + } } - baseExpr = c.convertUnarySubexprSuffix(baseExpr, ctx) } - - return baseExpr + return current } -func (c *cc) convertUnarySubexprSuffix(base ast.Node, n *parser.Unary_subexpr_suffixContext) ast.Node { - if n == nil { - return base +func (c *cc) handleKeySuffix(base ast.Node, keyCtx *parser.Key_exprContext) ast.Node { + keyNode := c.convertKey_exprContext(keyCtx) + ind, ok := keyNode.(*ast.A_Indirection) + if !ok { + return todo("Key_exprContext", keyCtx) } - colRef, ok := base.(*ast.ColumnRef) + + if indirection, ok := base.(*ast.A_Indirection); ok { + indirection.Indirection.Items = append(indirection.Indirection.Items, ind.Indirection.Items...) + return indirection + } + + return &ast.A_Indirection{ + Arg: base, + Indirection: &ast.List{ + Items: []ast.Node{keyNode}, + }, + } +} + +func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprContext, idx int) ast.Node { + funcCall, ok := c.convertInvoke_exprContext(invokeCtx).(*ast.FuncCall) if !ok { - return base // todo: cover case when unary subexpr with atomic expr + return todo("Invoke_exprContext", invokeCtx) } - for i := 0; i < n.GetChildCount(); i++ { - child := n.GetChild(i) - switch v := child.(type) { - case parser.IKey_exprContext: - node := c.convert(v.(*parser.Key_exprContext)) - if node != nil { - colRef.Fields.Items = append(colRef.Fields.Items, node) - } + if idx == 0 { + switch baseNode := base.(type) { + case *ast.ColumnRef: + if len(baseNode.Fields.Items) > 0 { + var nameParts []string + for _, item := range baseNode.Fields.Items { + if s, ok := item.(*ast.String); ok { + nameParts = append(nameParts, s.Str) + } + } + funcName := strings.Join(nameParts, ".") - case parser.IInvoke_exprContext: - node := c.convert(v.(*parser.Invoke_exprContext)) - if node != nil { - colRef.Fields.Items = append(colRef.Fields.Items, node) - } - case antlr.TerminalNode: - if v.GetText() == "." { - if i+1 < n.GetChildCount() { - next := n.GetChild(i + 1) - switch w := next.(type) { - case parser.IBind_parameterContext: - // !!! debug !!! - node := c.convert(next.(*parser.Bind_parameterContext)) - colRef.Fields.Items = append(colRef.Fields.Items, node) - case antlr.TerminalNode: - // !!! debug !!! - val, err := parseIntegerValue(w.GetText()) - if err != nil { - if debug.Active { - log.Printf("Failed to parse integer value '%s': %v", w.GetText(), err) - } - return &ast.TODO{} - } - node := &ast.A_Const{Val: &ast.Integer{Ival: val}, Location: n.GetStart().GetStart()} - colRef.Fields.Items = append(colRef.Fields.Items, node) - case parser.IAn_id_or_typeContext: - idText := parseAnIdOrType(w) - colRef.Fields.Items = append(colRef.Fields.Items, &ast.String{Str: idText}) - default: - colRef.Fields.Items = append(colRef.Fields.Items, &ast.TODO{}) + if funcName == "coalesce" { + return &ast.CoalesceExpr{ + Args: funcCall.Args, + Location: baseNode.Location, } - i++ } + + funcCall.Func = &ast.FuncName{Name: funcName} + funcCall.Funcname.Items = append(funcCall.Funcname.Items, &ast.String{Str: funcName}) + + return funcCall } + default: + return todo("Invoke_exprContext", invokeCtx) + } + } + + stmt := &ast.RecursiveFuncCall{ + Func: base, + Funcname: funcCall.Funcname, + AggStar: funcCall.AggStar, + Location: funcCall.Location, + Args: funcCall.Args, + AggDistinct: funcCall.AggDistinct, + } + stmt.Funcname.Items = append(stmt.Funcname.Items, base) + return stmt +} + +func (c *cc) handleDotSuffix(base ast.Node, suffix *parser.Unary_subexpr_suffixContext, idx *int) ast.Node { + if *idx+1 >= suffix.GetChildCount() { + return base + } + + next := suffix.GetChild(*idx + 1) + *idx++ + + var field ast.Node + switch v := next.(type) { + case *parser.Bind_parameterContext: + field = c.convertBindParameter(v) + case *parser.An_id_or_typeContext: + field = &ast.String{Str: parseAnIdOrType(v)} + case antlr.TerminalNode: + if val, err := parseIntegerValue(v.GetText()); err == nil { + field = &ast.A_Const{Val: &ast.Integer{Ival: val}} + } else { + return &ast.TODO{} } } - if n.COLLATE() != nil && n.An_id() != nil { //nolint - // todo: Handle COLLATE + if field == nil { + return base } - return colRef + + if cr, ok := base.(*ast.ColumnRef); ok { + cr.Fields.Items = append(cr.Fields.Items, field) + return cr + } + return &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{base, field}}, + } +} + +func (c *cc) convertKey_exprContext(n *parser.Key_exprContext) ast.Node { + if n.LBRACE_SQUARE() == nil || n.RBRACE_SQUARE() == nil || n.Expr() == nil { + return todo("Key_exprContext", n) + } + + stmt := &ast.A_Indirection{ + Indirection: &ast.List{}, + } + + expr := c.convert(n.Expr()) + + stmt.Indirection.Items = append(stmt.Indirection.Items, &ast.A_Indices{ + Uidx: expr, + }) + + return stmt +} + +func (c *cc) convertInvoke_exprContext(n *parser.Invoke_exprContext) ast.Node { + if n.LPAREN() == nil || n.RPAREN() == nil { + return todo("Invoke_exprContext", n) + } + + distinct := false + if n.Opt_set_quantifier() != nil { + distinct = n.Opt_set_quantifier().DISTINCT() != nil + } + + stmt := &ast.FuncCall{ + AggDistinct: distinct, + Funcname: &ast.List{}, + AggOrder: &ast.List{}, + Args: &ast.List{}, + Location: c.pos(n.GetStart()), + } + + if nList := n.Named_expr_list(); nList != nil { + for _, namedExpr := range nList.AllNamed_expr() { + name := parseAnIdOrType(namedExpr.An_id_or_type()) + expr := c.convert(namedExpr.Expr()) + + var res ast.Node + if rt, ok := expr.(*ast.ResTarget); ok { + if name != "" { + rt.Name = &name + } + res = rt + } else if name != "" { + res = &ast.ResTarget{ + Name: &name, + Val: expr, + Location: c.pos(namedExpr.Expr().GetStart()), + } + } else { + res = expr + } + + stmt.Args.Items = append(stmt.Args.Items, res) + } + } else if n.ASTERISK() != nil { + stmt.AggStar = true + } + + return stmt } func (c *cc) convertIdExpr(n *parser.Id_exprContext) ast.Node { @@ -2203,6 +2340,7 @@ func (c *cc) convertIdExpr(n *parser.Id_exprContext) ast.Node { NewIdentifier(id.GetText()), }, }, + Location: c.pos(id.GetStart()), } } return &ast.TODO{} @@ -2210,6 +2348,8 @@ func (c *cc) convertIdExpr(n *parser.Id_exprContext) ast.Node { func (c *cc) convertAtomExpr(n *parser.Atom_exprContext) ast.Node { switch { + case n.An_id_or_type() != nil && n.NAMESPACE() != nil: + return NewIdentifier(parseAnIdOrType(n.An_id_or_type()) + "::" + parseIdOrType(n.Id_or_type())) case n.An_id_or_type() != nil: return NewIdentifier(parseAnIdOrType(n.An_id_or_type())) case n.Literal_value() != nil: @@ -2232,25 +2372,25 @@ func (c *cc) convertLiteralValue(n *parser.Literal_valueContext) ast.Node { } return &ast.TODO{} } - return &ast.A_Const{Val: &ast.Integer{Ival: val}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.Integer{Ival: val}, Location: c.pos(n.GetStart())} case n.Real_() != nil: text := n.Real_().GetText() - return &ast.A_Const{Val: &ast.Float{Str: text}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.Float{Str: text}, Location: c.pos(n.GetStart())} case n.STRING_VALUE() != nil: // !!! debug !!! (problem with quoted strings) val := n.STRING_VALUE().GetText() if len(val) >= 2 { val = val[1 : len(val)-1] } - return &ast.A_Const{Val: &ast.String{Str: val}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.String{Str: val}, Location: c.pos(n.GetStart())} case n.Bool_value() != nil: var i bool if n.Bool_value().TRUE() != nil { i = true } - return &ast.A_Const{Val: &ast.Boolean{Boolval: i}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.Boolean{Boolval: i}, Location: c.pos(n.GetStart())} case n.NULL() != nil: return &ast.Null{} @@ -2275,7 +2415,7 @@ func (c *cc) convertLiteralValue(n *parser.Literal_valueContext) ast.Node { case n.BLOB() != nil: blobText := n.BLOB().GetText() - return &ast.A_Const{Val: &ast.String{Str: blobText}, Location: n.GetStart().GetStart()} + return &ast.A_Const{Val: &ast.String{Str: blobText}, Location: c.pos(n.GetStart())} case n.EMPTY_ACTION() != nil: if debug.Active { diff --git a/internal/engine/ydb/lib/aggregate.go b/internal/engine/ydb/lib/aggregate.go new file mode 100644 index 0000000000..dfb3924e90 --- /dev/null +++ b/internal/engine/ydb/lib/aggregate.go @@ -0,0 +1,330 @@ +package lib + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func AggregateFunctions() []*catalog.Function { + var funcs []*catalog.Function + + // COUNT(*) + funcs = append(funcs, &catalog.Function{ + Name: "COUNT", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }) + + // COUNT(T) и COUNT(T?) + for _, typ := range types { + funcs = append(funcs, &catalog.Function{ + Name: "COUNT", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }) + funcs = append(funcs, &catalog.Function{ + Name: "COUNT", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}, Mode: ast.FuncParamVariadic}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }) + } + + // MIN и MAX + for _, typ := range types { + funcs = append(funcs, &catalog.Function{ + Name: "MIN", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: true, + }) + funcs = append(funcs, &catalog.Function{ + Name: "MAX", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: true, + }) + } + + // SUM для unsigned типов + for _, typ := range unsignedTypes { + funcs = append(funcs, &catalog.Function{ + Name: "SUM", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }) + } + + // SUM для signed типов + for _, typ := range signedTypes { + funcs = append(funcs, &catalog.Function{ + Name: "SUM", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }) + } + + // SUM для float/double + for _, typ := range []string{"float", "double"} { + funcs = append(funcs, &catalog.Function{ + Name: "SUM", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: true, + }) + } + + // AVG для целочисленных типов + for _, typ := range append(unsignedTypes, signedTypes...) { + funcs = append(funcs, &catalog.Function{ + Name: "AVG", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }) + } + + // AVG для float/double + for _, typ := range []string{"float", "double"} { + funcs = append(funcs, &catalog.Function{ + Name: "AVG", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: true, + }) + } + + // COUNT_IF + funcs = append(funcs, &catalog.Function{ + Name: "COUNT_IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }) + + // SUM_IF для unsigned + for _, typ := range unsignedTypes { + funcs = append(funcs, &catalog.Function{ + Name: "SUM_IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }) + } + + // SUM_IF для signed + for _, typ := range signedTypes { + funcs = append(funcs, &catalog.Function{ + Name: "SUM_IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }) + } + + // SUM_IF для float/double + for _, typ := range []string{"float", "double"} { + funcs = append(funcs, &catalog.Function{ + Name: "SUM_IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: true, + }) + } + + // AVG_IF для целочисленных + for _, typ := range append(unsignedTypes, signedTypes...) { + funcs = append(funcs, &catalog.Function{ + Name: "AVG_IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }) + } + + // AVG_IF для float/double + for _, typ := range []string{"float", "double"} { + funcs = append(funcs, &catalog.Function{ + Name: "AVG_IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: true, + }) + } + + // SOME + for _, typ := range types { + funcs = append(funcs, &catalog.Function{ + Name: "SOME", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: true, + }) + } + + // AGGREGATE_LIST и AGGREGATE_LIST_DISTINCT + for _, typ := range types { + funcs = append(funcs, &catalog.Function{ + Name: "AGGREGATE_LIST", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "List<" + typ + ">"}, + }) + funcs = append(funcs, &catalog.Function{ + Name: "AGGREGATE_LIST_DISTINCT", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "List<" + typ + ">"}, + }) + } + + // BOOL_AND, BOOL_OR, BOOL_XOR + boolAggrs := []string{"BOOL_AND", "BOOL_OR", "BOOL_XOR"} + for _, name := range boolAggrs { + funcs = append(funcs, &catalog.Function{ + Name: name, + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }) + } + + // BIT_AND, BIT_OR, BIT_XOR + bitAggrs := []string{"BIT_AND", "BIT_OR", "BIT_XOR"} + for _, typ := range append(unsignedTypes, signedTypes...) { + for _, name := range bitAggrs { + funcs = append(funcs, &catalog.Function{ + Name: name, + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: true, + }) + } + } + + // STDDEV и VARIANCE + stdDevVariants := []struct { + name string + returnType string + }{ + {"STDDEV", "Double"}, + {"VARIANCE", "Double"}, + {"STDDEV_SAMPLE", "Double"}, + {"VARIANCE_SAMPLE", "Double"}, + {"STDDEV_POPULATION", "Double"}, + {"VARIANCE_POPULATION", "Double"}, + } + for _, variant := range stdDevVariants { + funcs = append(funcs, &catalog.Function{ + Name: variant.name, + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: variant.returnType}, + ReturnTypeNullable: true, + }) + } + + // CORRELATION и COVARIANCE + corrCovar := []string{"CORRELATION", "COVARIANCE", "COVARIANCE_SAMPLE", "COVARIANCE_POPULATION"} + for _, name := range corrCovar { + funcs = append(funcs, &catalog.Function{ + Name: name, + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }) + } + + // HISTOGRAM + funcs = append(funcs, &catalog.Function{ + Name: "HISTOGRAM", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "HistogramStruct"}, + ReturnTypeNullable: true, + }) + + // TOP и BOTTOM + topBottom := []string{"TOP", "BOTTOM"} + for _, name := range topBottom { + for _, typ := range types { + funcs = append(funcs, &catalog.Function{ + Name: name, + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "List<" + typ + ">"}, + }) + } + } + + // MAX_BY и MIN_BY + minMaxBy := []string{"MAX_BY", "MIN_BY"} + for _, name := range minMaxBy { + for _, typ := range types { + funcs = append(funcs, &catalog.Function{ + Name: name, + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: true, + }) + } + } + + // ... (добавьте другие агрегатные функции по аналогии) + + return funcs +} diff --git a/internal/engine/ydb/lib/basic.go b/internal/engine/ydb/lib/basic.go new file mode 100644 index 0000000000..08c0011787 --- /dev/null +++ b/internal/engine/ydb/lib/basic.go @@ -0,0 +1,203 @@ +package lib + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +var types = []string{ + "bool", + "int8", "int16", "int32", "int64", + "uint8", "uint16", "uint32", "uint64", + "float", "double", + "string", "utf8", + "any", +} + +var ( + unsignedTypes = []string{"uint8", "uint16", "uint32", "uint64"} + signedTypes = []string{"int8", "int16", "int32", "int64"} + numericTypes = append(append(unsignedTypes, signedTypes...), "float", "double") +) + +func BasicFunctions() []*catalog.Function { + var funcs []*catalog.Function + + for _, typ := range types { + // COALESCE, NVL + funcs = append(funcs, &catalog.Function{ + Name: "COALESCE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: typ}}, + { + Type: &ast.TypeName{Name: typ}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: false, + }) + funcs = append(funcs, &catalog.Function{ + Name: "NVL", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: typ}}, + { + Type: &ast.TypeName{Name: typ}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: false, + }) + + // IF(Bool, T, T) -> T + funcs = append(funcs, &catalog.Function{ + Name: "IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + ReturnTypeNullable: false, + }) + + // LENGTH, LEN + funcs = append(funcs, &catalog.Function{ + Name: "LENGTH", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + ReturnTypeNullable: true, + }) + funcs = append(funcs, &catalog.Function{ + Name: "LEN", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + ReturnTypeNullable: true, + }) + + // StartsWith, EndsWith + funcs = append(funcs, &catalog.Function{ + Name: "StartsWith", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }) + funcs = append(funcs, &catalog.Function{ + Name: "EndsWith", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }) + + // ABS(T) -> T + } + + // SUBSTRING + funcs = append(funcs, &catalog.Function{ + Name: "Substring", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }) + funcs = append(funcs, &catalog.Function{ + Name: "Substring", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }) + funcs = append(funcs, &catalog.Function{ + Name: "Substring", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }) + + // FIND / RFIND + for _, name := range []string{"FIND", "RFIND"} { + for _, typ := range []string{"String", "Utf8"} { + funcs = append(funcs, &catalog.Function{ + Name: name, + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }) + funcs = append(funcs, &catalog.Function{ + Name: name, + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }) + } + } + + for _, typ := range numericTypes { + funcs = append(funcs, &catalog.Function{ + Name: "Abs", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: typ}}, + }, + ReturnType: &ast.TypeName{Name: typ}, + }) + } + + // NANVL + funcs = append(funcs, &catalog.Function{ + Name: "NANVL", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Float"}}, + {Type: &ast.TypeName{Name: "Float"}}, + }, + ReturnType: &ast.TypeName{Name: "Float"}, + }) + funcs = append(funcs, &catalog.Function{ + Name: "NANVL", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }) + + // Random* + funcs = append(funcs, &catalog.Function{ + Name: "Random", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Double"}, + }) + funcs = append(funcs, &catalog.Function{ + Name: "RandomNumber", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }) + funcs = append(funcs, &catalog.Function{ + Name: "RandomUuid", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Uuid"}, + }) + + // todo: add all remain functions + + return funcs +} diff --git a/internal/engine/ydb/parse.go b/internal/engine/ydb/parse.go index 797710988c..1c263924a5 100755 --- a/internal/engine/ydb/parse.go +++ b/internal/engine/ydb/parse.go @@ -42,7 +42,8 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { if err != nil { return nil, err } - input := antlr.NewInputStream(string(blob)) + content := string(blob) + input := antlr.NewInputStream(content) lexer := parser.NewYQLLexer(input) stream := antlr.NewCommonTokenStream(lexer, 0) pp := parser.NewYQLParser(stream) @@ -62,14 +63,14 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { if stmtListCtx != nil { loc := 0 for _, stmt := range stmtListCtx.AllSql_stmt() { - converter := &cc{} + converter := &cc{content: string(blob)} out := converter.convert(stmt) if _, ok := out.(*ast.TODO); ok { - loc = stmt.GetStop().GetStop() + 2 + loc = byteOffset(content, stmt.GetStop().GetStop() + 2) continue } if out != nil { - len := (stmt.GetStop().GetStop() + 1) - loc + len := byteOffset(content, stmt.GetStop().GetStop() + 1) - loc stmts = append(stmts, ast.Statement{ Raw: &ast.RawStmt{ Stmt: out, @@ -77,7 +78,7 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { StmtLen: len, }, }) - loc = stmt.GetStop().GetStop() + 2 + loc = byteOffset(content, stmt.GetStop().GetStop() + 2) } } } diff --git a/internal/engine/ydb/stdlib.go b/internal/engine/ydb/stdlib.go index fd78d7de38..21dc21242b 100644 --- a/internal/engine/ydb/stdlib.go +++ b/internal/engine/ydb/stdlib.go @@ -1,12 +1,18 @@ package ydb import ( + "github.com/sqlc-dev/sqlc/internal/engine/ydb/lib" "github.com/sqlc-dev/sqlc/internal/sql/catalog" ) func defaultSchema(name string) *catalog.Schema { - s := &catalog.Schema{Name: name} - s.Funcs = []*catalog.Function{} + s := &catalog.Schema{ + Name: name, + Funcs: make([]*catalog.Function, 0, 128), + } + + s.Funcs = append(s.Funcs, lib.BasicFunctions()...) + s.Funcs = append(s.Funcs, lib.AggregateFunctions()...) return s } diff --git a/internal/engine/ydb/utils.go b/internal/engine/ydb/utils.go index 0748de8bdf..3847ee5055 100755 --- a/internal/engine/ydb/utils.go +++ b/internal/engine/ydb/utils.go @@ -3,6 +3,7 @@ package ydb import ( "strconv" "strings" + "unicode/utf8" "github.com/antlr4-go/antlr/v4" "github.com/sqlc-dev/sqlc/internal/sql/ast" @@ -14,8 +15,6 @@ type objectRefProvider interface { Object_ref() parser.IObject_refContext } - - func parseTableName(ctx objectRefProvider) *ast.TableName { return parseObjectRef(ctx.Object_ref()) } @@ -172,3 +171,26 @@ func (c *cc) extractRoleSpec(n parser.IRole_nameContext, roletype ast.RoleSpecTy return roleSpec, isParam, roleNode } + +func byteOffset(s string, runeIndex int) int { + count := 0 + for i := range s { + if count == runeIndex { + return i + } + count++ + } + return len(s) +} + +func byteOffsetFromRuneIndex(s string, runeIndex int) int { + if runeIndex <= 0 { + return 0 + } + bytePos := 0 + for i := 0; i < runeIndex && bytePos < len(s); i++ { + _, size := utf8.DecodeRuneInString(s[bytePos:]) + bytePos += size + } + return bytePos +} diff --git a/internal/sql/ast/insert_stmt.go b/internal/sql/ast/insert_stmt.go index 954fb4665c..b3e7c60809 100644 --- a/internal/sql/ast/insert_stmt.go +++ b/internal/sql/ast/insert_stmt.go @@ -23,19 +23,22 @@ func (n *InsertStmt) Format(buf *TrackedBuffer) { buf.astFormat(n.WithClause) buf.WriteString(" ") } - - switch n.OnConflictClause.Action { - case OnConflictAction_INSERT_OR_ABORT: - buf.WriteString("INSERT OR ABORT INTO ") - case OnConflictAction_INSERT_OR_REVERT: - buf.WriteString("INSERT OR REVERT INTO ") - case OnConflictAction_INSERT_OR_IGNORE: - buf.WriteString("INSERT OR IGNORE INTO ") - case OnConflictAction_UPSERT: - buf.WriteString("UPSERT INTO ") - case OnConflictAction_REPLACE: - buf.WriteString("REPLACE INTO ") - default: + if n.OnConflictClause != nil { + switch n.OnConflictClause.Action { + case OnConflictAction_INSERT_OR_ABORT: + buf.WriteString("INSERT OR ABORT INTO ") + case OnConflictAction_INSERT_OR_REVERT: + buf.WriteString("INSERT OR REVERT INTO ") + case OnConflictAction_INSERT_OR_IGNORE: + buf.WriteString("INSERT OR IGNORE INTO ") + case OnConflictAction_UPSERT: + buf.WriteString("UPSERT INTO ") + case OnConflictAction_REPLACE: + buf.WriteString("REPLACE INTO ") + default: + buf.WriteString("INSERT INTO ") + } + } else { buf.WriteString("INSERT INTO ") } if n.Relation != nil { diff --git a/internal/sql/ast/recursive_func_call.go b/internal/sql/ast/recursive_func_call.go new file mode 100644 index 0000000000..1c7c0a8125 --- /dev/null +++ b/internal/sql/ast/recursive_func_call.go @@ -0,0 +1,33 @@ +package ast + +type RecursiveFuncCall struct { + Func Node + Funcname *List + Args *List + AggOrder *List + AggFilter Node + AggWithinGroup bool + AggStar bool + AggDistinct bool + FuncVariadic bool + Over *WindowDef + Location int +} + +func (n *RecursiveFuncCall) Pos() int { + return n.Location +} + +func (n *RecursiveFuncCall) Format(buf *TrackedBuffer) { + if n == nil { + return + } + buf.astFormat(n.Func) + buf.WriteString("(") + if n.AggStar { + buf.WriteString("*") + } else { + buf.astFormat(n.Args) + } + buf.WriteString(")") +} diff --git a/internal/sql/astutils/rewrite.go b/internal/sql/astutils/rewrite.go index 8e8eefbff4..bcc7c17e40 100644 --- a/internal/sql/astutils/rewrite.go +++ b/internal/sql/astutils/rewrite.go @@ -607,7 +607,6 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. case *ast.CreateRoleStmt: a.apply(n, "BindRole", nil, n.BindRole) a.apply(n, "Options", nil, n.Options) - case *ast.CreateSchemaStmt: a.apply(n, "Authrole", nil, n.Authrole) @@ -1014,6 +1013,14 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. a.apply(n, "Roles", nil, n.Roles) a.apply(n, "Newrole", nil, n.Newrole) + case *ast.RecursiveFuncCall: + a.apply(n, "Func", nil, n.Func) + a.apply(n, "Funcname", nil, n.Funcname) + a.apply(n, "Args", nil, n.Args) + a.apply(n, "AggOrder", nil, n.AggOrder) + a.apply(n, "AggFilter", nil, n.AggFilter) + a.apply(n, "Over", nil, n.Over) + case *ast.RefreshMatViewStmt: a.apply(n, "Relation", nil, n.Relation) diff --git a/internal/sql/astutils/walk.go b/internal/sql/astutils/walk.go index e7b78d126b..dfc313fda1 100644 --- a/internal/sql/astutils/walk.go +++ b/internal/sql/astutils/walk.go @@ -1734,6 +1734,26 @@ func Walk(f Visitor, node ast.Node) { Walk(f, n.Newrole) } + case *ast.RecursiveFuncCall: + if n.Func != nil { + Walk(f, n.Func) + } + if n.Funcname != nil { + Walk(f, n.Funcname) + } + if n.Args != nil { + Walk(f, n.Args) + } + if n.AggOrder != nil { + Walk(f, n.AggOrder) + } + if n.AggFilter != nil { + Walk(f, n.AggFilter) + } + if n.Over != nil { + Walk(f, n.Over) + } + case *ast.RefreshMatViewStmt: if n.Relation != nil { Walk(f, n.Relation) From fc8c9322c5de37b185d43ce1debc4749daa72dd9 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Wed, 21 May 2025 10:14:09 +0300 Subject: [PATCH 08/22] Added examples for funcs codegen --- examples/authors/sqlc.yaml | 1 + examples/authors/ydb/models.go | 6 +-- examples/authors/ydb/query.sql | 6 +++ examples/authors/ydb/query.sql.go | 62 ++++++++++++++++++++++++++----- examples/authors/ydb/schema.sql | 8 ++-- 5 files changed, 67 insertions(+), 16 deletions(-) diff --git a/examples/authors/sqlc.yaml b/examples/authors/sqlc.yaml index 8d6bc3db28..143cb608b0 100644 --- a/examples/authors/sqlc.yaml +++ b/examples/authors/sqlc.yaml @@ -51,6 +51,7 @@ sql: go: package: authors out: ydb + emit_json_tags: true rules: diff --git a/examples/authors/ydb/models.go b/examples/authors/ydb/models.go index 8edcdc7b33..12b4f3a604 100644 --- a/examples/authors/ydb/models.go +++ b/examples/authors/ydb/models.go @@ -5,7 +5,7 @@ package authors type Author struct { - ID uint64 - Name string - Bio *string + ID uint64 `json:"id"` + Name string `json:"name"` + Bio *string `json:"bio"` } diff --git a/examples/authors/ydb/query.sql b/examples/authors/ydb/query.sql index 67ce89a6a7..bf672042c5 100644 --- a/examples/authors/ydb/query.sql +++ b/examples/authors/ydb/query.sql @@ -13,6 +13,12 @@ WHERE name = $p0; SELECT * FROM authors WHERE bio IS NULL; +-- name: Count :one +SELECT COUNT(*) FROM authors; + +-- name: COALESCE :many +SELECT id, name, COALESCE(bio, 'Null value!') FROM authors; + -- name: CreateOrUpdateAuthor :execresult UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2); diff --git a/examples/authors/ydb/query.sql.go b/examples/authors/ydb/query.sql.go index e244f62c54..45d86c96fd 100644 --- a/examples/authors/ydb/query.sql.go +++ b/examples/authors/ydb/query.sql.go @@ -10,14 +10,58 @@ import ( "database/sql" ) +const cOALESCE = `-- name: COALESCE :many +SELECT id, name, COALESCE(bio, 'Null value!') FROM authors +` + +type COALESCERow struct { + ID uint64 `json:"id"` + Name string `json:"name"` + Bio string `json:"bio"` +} + +func (q *Queries) COALESCE(ctx context.Context) ([]COALESCERow, error) { + rows, err := q.db.QueryContext(ctx, cOALESCE) + if err != nil { + return nil, err + } + defer rows.Close() + var items []COALESCERow + for rows.Next() { + var i COALESCERow + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const count = `-- name: Count :one +SELECT COUNT(*) FROM authors +` + +func (q *Queries) Count(ctx context.Context) (uint64, error) { + row := q.db.QueryRowContext(ctx, count) + var count uint64 + err := row.Scan(&count) + return count, err +} + const createOrUpdateAuthor = `-- name: CreateOrUpdateAuthor :execresult UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) ` type CreateOrUpdateAuthorParams struct { - P0 uint64 - P1 string - P2 *string + P0 uint64 `json:"p0"` + P1 string `json:"p1"` + P2 *string `json:"p2"` } func (q *Queries) CreateOrUpdateAuthor(ctx context.Context, arg CreateOrUpdateAuthorParams) (sql.Result, error) { @@ -29,9 +73,9 @@ UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) RETURNING bio ` type CreateOrUpdateAuthorReturningBioParams struct { - P0 uint64 - P1 string - P2 *string + P0 uint64 `json:"p0"` + P1 string `json:"p1"` + P2 *string `json:"p2"` } func (q *Queries) CreateOrUpdateAuthorReturningBio(ctx context.Context, arg CreateOrUpdateAuthorReturningBioParams) (*string, error) { @@ -150,9 +194,9 @@ UPDATE authors SET name = $p0, bio = $p1 WHERE id = $p2 RETURNING id, name, bio ` type UpdateAuthorByIDParams struct { - P0 string - P1 *string - P2 uint64 + P0 string `json:"p0"` + P1 *string `json:"p1"` + P2 uint64 `json:"p2"` } func (q *Queries) UpdateAuthorByID(ctx context.Context, arg UpdateAuthorByIDParams) (Author, error) { diff --git a/examples/authors/ydb/schema.sql b/examples/authors/ydb/schema.sql index ee9329e809..5207fb3b1e 100644 --- a/examples/authors/ydb/schema.sql +++ b/examples/authors/ydb/schema.sql @@ -1,6 +1,6 @@ CREATE TABLE authors ( - id Uint64, - name Utf8 NOT NULL, - bio Utf8, - PRIMARY KEY (id) + id Uint64, + name Utf8 NOT NULL, + bio Utf8, + PRIMARY KEY (id) ); From d0e1550c3fb736ca7447d287f78939a8ca9963ff Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Tue, 27 May 2025 14:19:48 +0300 Subject: [PATCH 09/22] Upgraded jwt to 4.5.2 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ebd7884d70..b3e8647b6c 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( cel.dev/expr v0.24.0 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect - github.com/golang-jwt/jwt/v4 v4.5.0 // indirect + github.com/golang-jwt/jwt/v4 v4.5.2 // indirect github.com/google/uuid v1.6.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jackc/chunkreader/v2 v2.0.1 // indirect diff --git a/go.sum b/go.sum index 910c0e9fca..8094d57fc2 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,8 @@ github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI6 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI= +github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= From 0b1752a833ddc0131dfd2ae07c0d7889c11acf16 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov <150552906+1NepuNep1@users.noreply.github.com> Date: Tue, 2 Sep 2025 15:53:01 +0300 Subject: [PATCH 10/22] First ydb-go-sdk generation version (See #4) (#6) This PR adds native YDB Go SDK support to sqlc for YDB database engine, moving from the standard database/sql interface to the YDB-specific SDK. The implementation includes code generation templates, configuration updates, and example adaptations. Adds YDB Go SDK as a new SQL package option (ydb-go-sdk) Implements YDB-specific code generation templates for queries, interfaces, and database connections Updates configuration schema to support YDB as an engine option --- docker-compose.yml | 2 + examples/authors/sqlc.yaml | 1 + examples/authors/ydb/db.go | 17 +- examples/authors/ydb/db_test.go | 95 +------- examples/authors/ydb/query.sql | 29 +-- examples/authors/ydb/query.sql.go | 222 ++++++------------ go.mod | 4 +- go.sum | 4 + internal/codegen/golang/driver.go | 2 + internal/codegen/golang/gen.go | 9 + internal/codegen/golang/imports.go | 30 ++- internal/codegen/golang/opts/enum.go | 10 + internal/codegen/golang/query.go | 54 +++++ .../codegen/golang/templates/template.tmpl | 6 + .../golang/templates/ydb-go-sdk/dbCode.tmpl | 24 ++ .../templates/ydb-go-sdk/interfaceCode.tmpl | 36 +++ .../templates/ydb-go-sdk/queryCode.tmpl | 145 ++++++++++++ internal/config/v_two.json | 3 +- internal/sqltest/local/ydb.go | 90 +++---- 19 files changed, 446 insertions(+), 337 deletions(-) create mode 100644 internal/codegen/golang/templates/ydb-go-sdk/dbCode.tmpl create mode 100644 internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl create mode 100644 internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl diff --git a/docker-compose.yml b/docker-compose.yml index e7c66b42ae..255527a3d1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,8 +27,10 @@ services: - "2136:2136" - "8765:8765" restart: always + hostname: localhost environment: - YDB_USE_IN_MEMORY_PDISKS=true - GRPC_TLS_PORT=2135 - GRPC_PORT=2136 - MON_PORT=8765 + diff --git a/examples/authors/sqlc.yaml b/examples/authors/sqlc.yaml index 143cb608b0..49fe62ff76 100644 --- a/examples/authors/sqlc.yaml +++ b/examples/authors/sqlc.yaml @@ -52,6 +52,7 @@ sql: package: authors out: ydb emit_json_tags: true + sql_package: ydb-go-sdk rules: diff --git a/examples/authors/ydb/db.go b/examples/authors/ydb/db.go index e2b0a86b13..c3b16b4481 100644 --- a/examples/authors/ydb/db.go +++ b/examples/authors/ydb/db.go @@ -6,14 +6,15 @@ package authors import ( "context" - "database/sql" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" ) 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 + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) } func New(db DBTX) *Queries { @@ -23,9 +24,3 @@ func New(db DBTX) *Queries { type Queries struct { db DBTX } - -func (q *Queries) WithTx(tx *sql.Tx) *Queries { - return &Queries{ - db: tx, - } -} diff --git a/examples/authors/ydb/db_test.go b/examples/authors/ydb/db_test.go index 76b37306ef..6ab15913f0 100644 --- a/examples/authors/ydb/db_test.go +++ b/examples/authors/ydb/db_test.go @@ -6,6 +6,7 @@ import ( "github.com/sqlc-dev/sqlc/internal/sqltest/local" _ "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/query" ) func ptr(s string) *string { @@ -15,10 +16,10 @@ func ptr(s string) *string { func TestAuthors(t *testing.T) { ctx := context.Background() - test := local.YDB(t, []string{"schema.sql"}) - defer test.DB.Close() + db := local.YDB(t, []string{"schema.sql"}) + defer db.Close(ctx) - q := New(test.DB) + q := New(db.Query()) t.Run("InsertAuthors", func(t *testing.T) { authorsToInsert := []CreateOrUpdateAuthorParams{ @@ -38,53 +39,12 @@ func TestAuthors(t *testing.T) { } for _, author := range authorsToInsert { - if _, err := q.CreateOrUpdateAuthor(ctx, author); err != nil { + if err := q.CreateOrUpdateAuthor(ctx, author, query.WithIdempotent()); err != nil { t.Fatalf("failed to insert author %q: %v", author.P1, err) } } }) - t.Run("CreateOrUpdateAuthorReturningBio", func(t *testing.T) { - newBio := "Обновленная биография автора" - arg := CreateOrUpdateAuthorReturningBioParams{ - P0: 3, - P1: "Тестовый Автор", - P2: &newBio, - } - - returnedBio, err := q.CreateOrUpdateAuthorReturningBio(ctx, arg) - if err != nil { - t.Fatalf("failed to create or update author: %v", err) - } - - if returnedBio == nil { - t.Fatal("expected non-nil bio, got nil") - } - if *returnedBio != newBio { - t.Fatalf("expected bio %q, got %q", newBio, *returnedBio) - } - - t.Logf("Author created or updated successfully with bio: %s", *returnedBio) - }) - - t.Run("Update Author", func(t *testing.T) { - arg := UpdateAuthorByIDParams{ - P0: "Максим Горький", - P1: ptr("Обновленная биография"), - P2: 10, - } - - singleAuthor, err := q.UpdateAuthorByID(ctx, arg) - if err != nil { - t.Fatal(err) - } - bio := "Null" - if singleAuthor.Bio != nil { - bio = *singleAuthor.Bio - } - t.Logf("- ID: %d | Name: %s | Bio: %s", singleAuthor.ID, singleAuthor.Name, bio) - }) - t.Run("ListAuthors", func(t *testing.T) { authors, err := q.ListAuthors(ctx) if err != nil { @@ -115,46 +75,10 @@ func TestAuthors(t *testing.T) { t.Logf("- ID: %d | Name: %s | Bio: %s", singleAuthor.ID, singleAuthor.Name, bio) }) - t.Run("GetAuthorByName", func(t *testing.T) { - authors, err := q.GetAuthorsByName(ctx, "Александр Пушкин") - if err != nil { - t.Fatal(err) - } - if len(authors) == 0 { - t.Fatal("expected at least one author with this name, got none") - } - t.Log("Authors with this name:") - for _, a := range authors { - bio := "Null" - if a.Bio != nil { - bio = *a.Bio - } - t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) - } - }) - - t.Run("ListAuthorsWithNullBio", func(t *testing.T) { - authors, err := q.ListAuthorsWithNullBio(ctx) - if err != nil { - t.Fatal(err) - } - if len(authors) == 0 { - t.Fatal("expected at least one author with NULL bio, got none") - } - t.Log("Authors with NULL bio:") - for _, a := range authors { - bio := "Null" - if a.Bio != nil { - bio = *a.Bio - } - t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) - } - }) - t.Run("Delete All Authors", func(t *testing.T) { var i uint64 for i = 1; i <= 13; i++ { - if err := q.DeleteAuthor(ctx, i); err != nil { + if err := q.DeleteAuthor(ctx, i, query.WithIdempotent()); err != nil { t.Fatalf("failed to delete authors: %v", err) } } @@ -166,4 +90,11 @@ func TestAuthors(t *testing.T) { t.Fatalf("expected no authors, got %d", len(authors)) } }) + + t.Run("Drop Table Authors", func(t *testing.T) { + err := q.DropTable(ctx) + if err != nil { + t.Fatal(err) + } + }) } diff --git a/examples/authors/ydb/query.sql b/examples/authors/ydb/query.sql index bf672042c5..804150615d 100644 --- a/examples/authors/ydb/query.sql +++ b/examples/authors/ydb/query.sql @@ -1,32 +1,15 @@ --- name: ListAuthors :many -SELECT * FROM authors; - -- name: GetAuthor :one SELECT * FROM authors -WHERE id = $p0; +WHERE id = $p0 LIMIT 1; --- name: GetAuthorsByName :many -SELECT * FROM authors -WHERE name = $p0; - --- name: ListAuthorsWithNullBio :many -SELECT * FROM authors -WHERE bio IS NULL; - --- name: Count :one -SELECT COUNT(*) FROM authors; - --- name: COALESCE :many -SELECT id, name, COALESCE(bio, 'Null value!') FROM authors; +-- name: ListAuthors :many +SELECT * FROM authors ORDER BY name; --- name: CreateOrUpdateAuthor :execresult +-- name: CreateOrUpdateAuthor :exec UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2); --- name: CreateOrUpdateAuthorReturningBio :one -UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) RETURNING bio; - -- name: DeleteAuthor :exec DELETE FROM authors WHERE id = $p0; --- name: UpdateAuthorByID :one -UPDATE authors SET name = $p0, bio = $p1 WHERE id = $p2 RETURNING *; +-- name: DropTable :exec +DROP TABLE IF EXISTS authors; \ No newline at end of file diff --git a/examples/authors/ydb/query.sql.go b/examples/authors/ydb/query.sql.go index 45d86c96fd..7459482b3a 100644 --- a/examples/authors/ydb/query.sql.go +++ b/examples/authors/ydb/query.sql.go @@ -7,54 +7,13 @@ package authors import ( "context" - "database/sql" -) - -const cOALESCE = `-- name: COALESCE :many -SELECT id, name, COALESCE(bio, 'Null value!') FROM authors -` - -type COALESCERow struct { - ID uint64 `json:"id"` - Name string `json:"name"` - Bio string `json:"bio"` -} -func (q *Queries) COALESCE(ctx context.Context) ([]COALESCERow, error) { - rows, err := q.db.QueryContext(ctx, cOALESCE) - if err != nil { - return nil, err - } - defer rows.Close() - var items []COALESCERow - for rows.Next() { - var i COALESCERow - if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Close(); err != nil { - return nil, err - } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil -} - -const count = `-- name: Count :one -SELECT COUNT(*) FROM authors -` - -func (q *Queries) Count(ctx context.Context) (uint64, error) { - row := q.db.QueryRowContext(ctx, count) - var count uint64 - err := row.Scan(&count) - return count, err -} + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) -const createOrUpdateAuthor = `-- name: CreateOrUpdateAuthor :execresult +const createOrUpdateAuthor = `-- name: CreateOrUpdateAuthor :exec UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) ` @@ -64,144 +23,97 @@ type CreateOrUpdateAuthorParams struct { P2 *string `json:"p2"` } -func (q *Queries) CreateOrUpdateAuthor(ctx context.Context, arg CreateOrUpdateAuthorParams) (sql.Result, error) { - return q.db.ExecContext(ctx, createOrUpdateAuthor, arg.P0, arg.P1, arg.P2) -} - -const createOrUpdateAuthorReturningBio = `-- name: CreateOrUpdateAuthorReturningBio :one -UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) RETURNING bio -` - -type CreateOrUpdateAuthorReturningBioParams struct { - P0 uint64 `json:"p0"` - P1 string `json:"p1"` - P2 *string `json:"p2"` -} - -func (q *Queries) CreateOrUpdateAuthorReturningBio(ctx context.Context, arg CreateOrUpdateAuthorReturningBioParams) (*string, error) { - row := q.db.QueryRowContext(ctx, createOrUpdateAuthorReturningBio, arg.P0, arg.P1, arg.P2) - var bio *string - err := row.Scan(&bio) - return bio, err +func (q *Queries) CreateOrUpdateAuthor(ctx context.Context, arg CreateOrUpdateAuthorParams, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, createOrUpdateAuthor, + append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ + "$p0": arg.P0, + "$p1": arg.P1, + "$p2": arg.P2, + })))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil } const deleteAuthor = `-- name: DeleteAuthor :exec DELETE FROM authors WHERE id = $p0 ` -func (q *Queries) DeleteAuthor(ctx context.Context, p0 uint64) error { - _, err := q.db.ExecContext(ctx, deleteAuthor, p0) - return err -} - -const getAuthor = `-- name: GetAuthor :one -SELECT id, name, bio FROM authors -WHERE id = $p0 -` - -func (q *Queries) GetAuthor(ctx context.Context, p0 uint64) (Author, error) { - row := q.db.QueryRowContext(ctx, getAuthor, p0) - var i Author - err := row.Scan(&i.ID, &i.Name, &i.Bio) - return i, err +func (q *Queries) DeleteAuthor(ctx context.Context, p0 uint64, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, deleteAuthor, + append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ + "$p0": p0, + })))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil } -const getAuthorsByName = `-- name: GetAuthorsByName :many -SELECT id, name, bio FROM authors -WHERE name = $p0 +const dropTable = `-- name: DropTable :exec +DROP TABLE IF EXISTS authors ` -func (q *Queries) GetAuthorsByName(ctx context.Context, p0 string) ([]Author, error) { - rows, err := q.db.QueryContext(ctx, getAuthorsByName, p0) +func (q *Queries) DropTable(ctx context.Context, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, dropTable, opts...) if err != nil { - return nil, err - } - defer rows.Close() - var items []Author - for rows.Next() { - var i Author - if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { - return nil, err - } - items = append(items, i) - } - if err := rows.Close(); err != nil { - return nil, err + return xerrors.WithStackTrace(err) } - if err := rows.Err(); err != nil { - return nil, err - } - return items, nil + return nil } -const listAuthors = `-- name: ListAuthors :many +const getAuthor = `-- name: GetAuthor :one SELECT id, name, bio FROM authors +WHERE id = $p0 LIMIT 1 ` -func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) { - rows, err := q.db.QueryContext(ctx, listAuthors) +func (q *Queries) GetAuthor(ctx context.Context, p0 uint64, opts ...query.ExecuteOption) (Author, error) { + row, err := q.db.QueryRow(ctx, getAuthor, + append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ + "$p0": p0, + })))..., + ) + var i Author if err != nil { - return nil, err - } - defer rows.Close() - var items []Author - for rows.Next() { - var i Author - if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { - return nil, err - } - items = append(items, i) + return i, xerrors.WithStackTrace(err) } - if err := rows.Close(); err != nil { - return nil, err - } - if err := rows.Err(); err != nil { - return nil, err + err = row.Scan(&i.ID, &i.Name, &i.Bio) + if err != nil { + return i, xerrors.WithStackTrace(err) } - return items, nil + return i, nil } -const listAuthorsWithNullBio = `-- name: ListAuthorsWithNullBio :many -SELECT id, name, bio FROM authors -WHERE bio IS NULL +const listAuthors = `-- name: ListAuthors :many +SELECT id, name, bio FROM authors ORDER BY name ` -func (q *Queries) ListAuthorsWithNullBio(ctx context.Context) ([]Author, error) { - rows, err := q.db.QueryContext(ctx, listAuthorsWithNullBio) +func (q *Queries) ListAuthors(ctx context.Context, opts ...query.ExecuteOption) ([]Author, error) { + result, err := q.db.Query(ctx, listAuthors, opts...) if err != nil { - return nil, err + return nil, xerrors.WithStackTrace(err) } - defer rows.Close() var items []Author - for rows.Next() { - var i Author - if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { - return nil, err + for set, err := range result.ResultSets(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + for row, err := range set.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Author + if err := row.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) } - items = append(items, i) - } - if err := rows.Close(); err != nil { - return nil, err } - if err := rows.Err(); err != nil { - return nil, err + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) } return items, nil } - -const updateAuthorByID = `-- name: UpdateAuthorByID :one -UPDATE authors SET name = $p0, bio = $p1 WHERE id = $p2 RETURNING id, name, bio -` - -type UpdateAuthorByIDParams struct { - P0 string `json:"p0"` - P1 *string `json:"p1"` - P2 uint64 `json:"p2"` -} - -func (q *Queries) UpdateAuthorByID(ctx context.Context, arg UpdateAuthorByIDParams) (Author, error) { - row := q.db.QueryRowContext(ctx, updateAuthorByID, arg.P0, arg.P1, arg.P2) - var i Author - err := row.Scan(&i.ID, &i.Name, &i.Bio) - return i, err -} diff --git a/go.mod b/go.mod index b3e8647b6c..c72f29b6b1 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/tetratelabs/wazero v1.9.0 github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 github.com/xeipuuv/gojsonschema v1.2.0 - github.com/ydb-platform/ydb-go-sdk/v3 v3.108.0 + github.com/ydb-platform/ydb-go-sdk/v3 v3.115.3 github.com/ydb-platform/yql-parsers v0.0.0-20250309001738-7d693911f333 golang.org/x/sync v0.16.0 google.golang.org/grpc v1.75.0 @@ -48,7 +48,7 @@ require ( github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/pgtype v1.14.0 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect - github.com/jonboulle/clockwork v0.3.0 // indirect + github.com/jonboulle/clockwork v0.5.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb // indirect diff --git a/go.sum b/go.sum index 8094d57fc2..53cb8e8aec 100644 --- a/go.sum +++ b/go.sum @@ -146,6 +146,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg= github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= +github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I= +github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -242,6 +244,8 @@ github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77 h1:LY github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= github.com/ydb-platform/ydb-go-sdk/v3 v3.108.0 h1:TwWSp3gRMcja/hRpOofncLvgxAXCmzpz5cGtmdaoITw= github.com/ydb-platform/ydb-go-sdk/v3 v3.108.0/go.mod h1:l5sSv153E18VvYcsmr51hok9Sjc16tEC8AXGbwrk+ho= +github.com/ydb-platform/ydb-go-sdk/v3 v3.115.3 h1:SFeSK2c+PmiToyNIhr143u+YDzLhl/kboXwKLYDk0O4= +github.com/ydb-platform/ydb-go-sdk/v3 v3.115.3/go.mod h1:Pp1w2xxUoLQ3NCNAwV7pvDq0TVQOdtAqs+ZiC+i8r14= github.com/ydb-platform/yql-parsers v0.0.0-20250309001738-7d693911f333 h1:KFtJwlPdOxWjCKXX0jFJ8k1FlbqbRbUW3k/kYSZX7SA= github.com/ydb-platform/yql-parsers v0.0.0-20250309001738-7d693911f333/go.mod h1:vrPJPS8cdPSV568YcXhB4bUwhyV8bmWKqmQ5c5Xi99o= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= diff --git a/internal/codegen/golang/driver.go b/internal/codegen/golang/driver.go index 5e3a533dcc..6e0596172f 100644 --- a/internal/codegen/golang/driver.go +++ b/internal/codegen/golang/driver.go @@ -8,6 +8,8 @@ func parseDriver(sqlPackage string) opts.SQLDriver { return opts.SQLDriverPGXV4 case opts.SQLPackagePGXV5: return opts.SQLDriverPGXV5 + case opts.SQLPackageYDBGoSDK: + return opts.SQLDriverYDBGoSDK default: return opts.SQLDriverLibPQ } diff --git a/internal/codegen/golang/gen.go b/internal/codegen/golang/gen.go index 7df56a0a41..4b48f34bde 100644 --- a/internal/codegen/golang/gen.go +++ b/internal/codegen/golang/gen.go @@ -209,6 +209,15 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum, return nil, errors.New(":batch* commands are only supported by pgx") } + if tctx.SQLDriver.IsYDBGoSDK() { + for _, q := range queries { + switch q.Cmd { + case metadata.CmdExecResult, metadata.CmdExecRows, metadata.CmdExecLastId: + return nil, fmt.Errorf("%s is not supported by ydb-go-sdk", q.Cmd) + } + } + } + funcMap := template.FuncMap{ "lowerTitle": sdk.LowerTitle, "comment": sdk.DoubleSlashComment, diff --git a/internal/codegen/golang/imports.go b/internal/codegen/golang/imports.go index ccca4f603c..17e426b8f9 100644 --- a/internal/codegen/golang/imports.go +++ b/internal/codegen/golang/imports.go @@ -132,6 +132,8 @@ func (i *importer) dbImports() fileImports { case opts.SQLDriverPGXV5: pkg = append(pkg, ImportSpec{Path: "github.com/jackc/pgx/v5/pgconn"}) pkg = append(pkg, ImportSpec{Path: "github.com/jackc/pgx/v5"}) + case opts.SQLDriverYDBGoSDK: + pkg = append(pkg, ImportSpec{Path: "github.com/ydb-platform/ydb-go-sdk/v3/query"}) default: std = append(std, ImportSpec{Path: "database/sql"}) if i.Options.EmitPreparedQueries { @@ -177,7 +179,9 @@ func buildImports(options *opts.Options, queries []Query, uses func(string) bool case opts.SQLDriverPGXV5: pkg[ImportSpec{Path: "github.com/jackc/pgx/v5/pgconn"}] = struct{}{} default: - std["database/sql"] = struct{}{} + if !sqlpkg.IsYDBGoSDK() { + std["database/sql"] = struct{}{} + } } } } @@ -267,6 +271,11 @@ func (i *importer) interfaceImports() fileImports { }) std["context"] = struct{}{} + + sqlpkg := parseDriver(i.Options.SqlPackage) + if sqlpkg.IsYDBGoSDK() { + pkg[ImportSpec{Path: "github.com/ydb-platform/ydb-go-sdk/v3/query"}] = struct{}{} + } return sortedImports(std, pkg) } @@ -395,13 +404,28 @@ func (i *importer) queryImports(filename string) fileImports { } sqlpkg := parseDriver(i.Options.SqlPackage) - if sqlcSliceScan() && !sqlpkg.IsPGX() { + if sqlcSliceScan() && !sqlpkg.IsPGX() && !sqlpkg.IsYDBGoSDK() { std["strings"] = struct{}{} } - if sliceScan() && !sqlpkg.IsPGX() { + if sliceScan() && !sqlpkg.IsPGX() && !sqlpkg.IsYDBGoSDK() { pkg[ImportSpec{Path: "github.com/lib/pq"}] = struct{}{} } + if sqlpkg.IsYDBGoSDK() { + hasParams := false + for _, q := range gq { + if !q.Arg.isEmpty() { + hasParams = true + break + } + } + if hasParams { + pkg[ImportSpec{Path: "github.com/ydb-platform/ydb-go-sdk/v3"}] = struct{}{} + } + pkg[ImportSpec{Path: "github.com/ydb-platform/ydb-go-sdk/v3/query"}] = struct{}{} + pkg[ImportSpec{Path: "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors"}] = struct{}{} + } + if i.Options.WrapErrors { std["fmt"] = struct{}{} } diff --git a/internal/codegen/golang/opts/enum.go b/internal/codegen/golang/opts/enum.go index 40457d040a..4d57a080a8 100644 --- a/internal/codegen/golang/opts/enum.go +++ b/internal/codegen/golang/opts/enum.go @@ -8,12 +8,14 @@ const ( SQLPackagePGXV4 string = "pgx/v4" SQLPackagePGXV5 string = "pgx/v5" SQLPackageStandard string = "database/sql" + SQLPackageYDBGoSDK string = "ydb-go-sdk" ) var validPackages = map[string]struct{}{ string(SQLPackagePGXV4): {}, string(SQLPackagePGXV5): {}, string(SQLPackageStandard): {}, + string(SQLPackageYDBGoSDK): {}, } func validatePackage(sqlPackage string) error { @@ -28,6 +30,7 @@ const ( SQLDriverPGXV5 = "github.com/jackc/pgx/v5" SQLDriverLibPQ = "github.com/lib/pq" SQLDriverGoSQLDriverMySQL = "github.com/go-sql-driver/mysql" + SQLDriverYDBGoSDK = "github.com/ydb-platform/ydb-go-sdk/v3" ) var validDrivers = map[string]struct{}{ @@ -35,6 +38,7 @@ var validDrivers = map[string]struct{}{ string(SQLDriverPGXV5): {}, string(SQLDriverLibPQ): {}, string(SQLDriverGoSQLDriverMySQL): {}, + string(SQLDriverYDBGoSDK): {}, } func validateDriver(sqlDriver string) error { @@ -52,12 +56,18 @@ func (d SQLDriver) IsGoSQLDriverMySQL() bool { return d == SQLDriverGoSQLDriverMySQL } +func (d SQLDriver) IsYDBGoSDK() bool { + return d == SQLDriverYDBGoSDK +} + func (d SQLDriver) Package() string { switch d { case SQLDriverPGXV4: return SQLPackagePGXV4 case SQLDriverPGXV5: return SQLPackagePGXV5 + case SQLDriverYDBGoSDK: + return SQLPackageYDBGoSDK default: return SQLPackageStandard } diff --git a/internal/codegen/golang/query.go b/internal/codegen/golang/query.go index 3b4fb2fa1a..02a09c3870 100644 --- a/internal/codegen/golang/query.go +++ b/internal/codegen/golang/query.go @@ -39,6 +39,10 @@ func (v QueryValue) isEmpty() bool { return v.Typ == "" && v.Name == "" && v.Struct == nil } +func (v QueryValue) IsEmpty() bool { + return v.isEmpty() +} + type Argument struct { Name string Type string @@ -254,6 +258,56 @@ func (v QueryValue) VariableForField(f Field) string { return v.Name + "." + f.Name } +func addDollarPrefix(name string) string { + if name == "" { + return name + } + if strings.HasPrefix(name, "$") { + return name + } + return "$" + name +} + +// YDBParamMapEntries returns entries for a map[string]any literal for YDB parameters. +func (v QueryValue) YDBParamMapEntries() string { + if v.isEmpty() { + return "" + } + + var parts []string + for _, field := range v.getParameterFields() { + if field.Column != nil && field.Column.IsNamedParam { + name := field.Column.GetName() + if name != "" { + key := fmt.Sprintf("%q", addDollarPrefix(name)) + variable := v.VariableForField(field) + parts = append(parts, key+": "+escape(variable)) + } + } + } + + if len(parts) == 0 { + return "" + } + + parts = append(parts, "") + return "\n" + strings.Join(parts, ",\n") +} + +func (v QueryValue) getParameterFields() []Field { + if v.Struct == nil { + return []Field{ + { + Name: v.Name, + DBName: v.DBName, + Type: v.Typ, + Column: v.Column, + }, + } + } + return v.Struct.Fields +} + // A struct used to generate methods and fields on the Queries struct type Query struct { Cmd string diff --git a/internal/codegen/golang/templates/template.tmpl b/internal/codegen/golang/templates/template.tmpl index afd50c01ac..f74b796349 100644 --- a/internal/codegen/golang/templates/template.tmpl +++ b/internal/codegen/golang/templates/template.tmpl @@ -25,6 +25,8 @@ import ( {{if .SQLDriver.IsPGX }} {{- template "dbCodeTemplatePgx" .}} +{{else if .SQLDriver.IsYDBGoSDK }} + {{- template "dbCodeTemplateYDB" .}} {{else}} {{- template "dbCodeTemplateStd" .}} {{end}} @@ -57,6 +59,8 @@ import ( {{define "interfaceCode"}} {{if .SQLDriver.IsPGX }} {{- template "interfaceCodePgx" .}} + {{else if .SQLDriver.IsYDBGoSDK }} + {{- template "interfaceCodeYDB" .}} {{else}} {{- template "interfaceCodeStd" .}} {{end}} @@ -188,6 +192,8 @@ import ( {{define "queryCode"}} {{if .SQLDriver.IsPGX }} {{- template "queryCodePgx" .}} +{{else if .SQLDriver.IsYDBGoSDK }} + {{- template "queryCodeYDB" .}} {{else}} {{- template "queryCodeStd" .}} {{end}} diff --git a/internal/codegen/golang/templates/ydb-go-sdk/dbCode.tmpl b/internal/codegen/golang/templates/ydb-go-sdk/dbCode.tmpl new file mode 100644 index 0000000000..f79831d2e2 --- /dev/null +++ b/internal/codegen/golang/templates/ydb-go-sdk/dbCode.tmpl @@ -0,0 +1,24 @@ +{{define "dbCodeTemplateYDB"}} +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +{{ if .EmitMethodsWithDBArgument}} +func New() *Queries { + return &Queries{} +{{- else -}} +func New(db DBTX) *Queries { + return &Queries{db: db} +{{- end}} +} + +type Queries struct { + {{if not .EmitMethodsWithDBArgument}} + db DBTX + {{end}} +} + +{{end}} diff --git a/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl b/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl new file mode 100644 index 0000000000..f9c06cc705 --- /dev/null +++ b/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl @@ -0,0 +1,36 @@ +{{define "interfaceCodeYDB"}} + type Querier interface { + {{- $dbtxParam := .EmitMethodsWithDBArgument -}} + {{- range .GoQueries}} + {{- if and (eq .Cmd ":one") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} + {{.MethodName}}(ctx context.Context, db DBTX, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ({{.Ret.DefineType}}, error) + {{- else if eq .Cmd ":one"}} + {{range .Comments}}//{{.}} + {{end -}} + {{.MethodName}}(ctx context.Context, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ({{.Ret.DefineType}}, error) + {{- end}} + {{- if and (eq .Cmd ":many") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} + {{.MethodName}}(ctx context.Context, db DBTX, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) + {{- else if eq .Cmd ":many"}} + {{range .Comments}}//{{.}} + {{end -}} + {{.MethodName}}(ctx context.Context, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) + {{- end}} + {{- if and (eq .Cmd ":exec") ($dbtxParam) }} + {{range .Comments}}//{{.}} + {{end -}} + {{.MethodName}}(ctx context.Context, db DBTX, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) error + {{- else if eq .Cmd ":exec"}} + {{range .Comments}}//{{.}} + {{end -}} + {{.MethodName}}(ctx context.Context, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) error + {{- end}} + {{- end}} + } + + var _ Querier = (*Queries)(nil) +{{end}} diff --git a/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl b/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl new file mode 100644 index 0000000000..ecd78b1344 --- /dev/null +++ b/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl @@ -0,0 +1,145 @@ +{{define "queryCodeYDB"}} +{{range .GoQueries}} +{{if $.OutputQuery .SourceName}} +const {{.ConstantName}} = {{$.Q}}-- name: {{.MethodName}} {{.Cmd}} +{{escape .SQL}} +{{$.Q}} + +{{if .Arg.EmitStruct}} +type {{.Arg.Type}} struct { {{- range .Arg.UniqueFields}} + {{.Name}} {{.Type}} {{if .Tag}}{{$.Q}}{{.Tag}}{{$.Q}}{{end}} + {{- end}} +} +{{end}} + +{{if .Ret.EmitStruct}} +type {{.Ret.Type}} struct { {{- range .Ret.Struct.Fields}} + {{.Name}} {{.Type}} {{if .Tag}}{{$.Q}}{{.Tag}}{{$.Q}}{{end}} + {{- end}} +} +{{end}} + +{{if eq .Cmd ":one"}} +{{range .Comments}}//{{.}} +{{end -}} +func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ({{.Ret.DefineType}}, error) { + {{- $dbArg := "q.db" }}{{- if $.EmitMethodsWithDBArgument }}{{- $dbArg = "db" }}{{- end -}} + {{- if .Arg.IsEmpty }} + row, err := {{$dbArg}}.QueryRow(ctx, {{.ConstantName}}, opts...) + {{- else }} + row, err := {{$dbArg}}.QueryRow(ctx, {{.ConstantName}}, + append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ {{.Arg.YDBParamMapEntries}} })))..., + ) + {{- end }} + {{- if or (ne .Arg.Pair .Ret.Pair) (ne .Arg.DefineType .Ret.DefineType) }} + var {{.Ret.Name}} {{.Ret.Type}} + {{- end}} + if err != nil { + {{- if $.WrapErrors}} + return {{.Ret.ReturnName}}, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) + {{- else }} + return {{.Ret.ReturnName}}, xerrors.WithStackTrace(err) + {{- end }} + } + err = row.Scan({{.Ret.Scan}}) + {{- if $.WrapErrors}} + if err != nil { + return {{.Ret.ReturnName}}, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) + } + {{- else }} + if err != nil { + return {{.Ret.ReturnName}}, xerrors.WithStackTrace(err) + } + {{- end}} + return {{.Ret.ReturnName}}, nil +} +{{end}} + +{{if eq .Cmd ":many"}} +{{range .Comments}}//{{.}} +{{end -}} +func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) { + {{- $dbArg := "q.db" }}{{- if $.EmitMethodsWithDBArgument }}{{- $dbArg = "db" }}{{- end -}} + {{- if .Arg.IsEmpty }} + result, err := {{$dbArg}}.Query(ctx, {{.ConstantName}}, opts...) + {{- else }} + result, err := {{$dbArg}}.Query(ctx, {{.ConstantName}}, + append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ {{.Arg.YDBParamMapEntries}} })))..., + ) + {{- end }} + if err != nil { + {{- if $.WrapErrors}} + return nil, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) + {{- else }} + return nil, xerrors.WithStackTrace(err) + {{- end }} + } + {{- if $.EmitEmptySlices}} + items := []{{.Ret.DefineType}}{} + {{else}} + var items []{{.Ret.DefineType}} + {{end -}} + for set, err := range result.ResultSets(ctx) { + if err != nil { + {{- if $.WrapErrors}} + return nil, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) + {{- else }} + return nil, xerrors.WithStackTrace(err) + {{- end }} + } + for row, err := range set.Rows(ctx) { + if err != nil { + {{- if $.WrapErrors}} + return nil, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) + {{- else }} + return nil, xerrors.WithStackTrace(err) + {{- end }} + } + var {{.Ret.Name}} {{.Ret.Type}} + if err := row.Scan({{.Ret.Scan}}); err != nil { + {{- if $.WrapErrors}} + return nil, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) + {{- else }} + return nil, xerrors.WithStackTrace(err) + {{- end }} + } + items = append(items, {{.Ret.ReturnName}}) + } + } + if err := result.Close(ctx); err != nil { + {{- if $.WrapErrors}} + return nil, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) + {{- else }} + return nil, xerrors.WithStackTrace(err) + {{- end }} + } + return items, nil +} +{{end}} + +{{if eq .Cmd ":exec"}} +{{range .Comments}}//{{.}} +{{end -}} +func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) error { + {{- $dbArg := "q.db" }}{{- if $.EmitMethodsWithDBArgument }}{{- $dbArg = "db" }}{{- end -}} + {{- if .Arg.IsEmpty }} + err := {{$dbArg}}.Exec(ctx, {{.ConstantName}}, opts...) + {{- else }} + err := {{$dbArg}}.Exec(ctx, {{.ConstantName}}, + append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ {{.Arg.YDBParamMapEntries}} })))..., + ) + {{- end }} + if err != nil { + {{- if $.WrapErrors }} + return xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) + {{- else }} + return xerrors.WithStackTrace(err) + {{- end }} + } + return nil +} +{{end}} + +{{end}} +{{end}} +{{end}} diff --git a/internal/config/v_two.json b/internal/config/v_two.json index acf914997d..fd7084d6e8 100644 --- a/internal/config/v_two.json +++ b/internal/config/v_two.json @@ -38,7 +38,8 @@ "enum": [ "postgresql", "mysql", - "sqlite" + "sqlite", + "ydb" ] }, "schema": { diff --git a/internal/sqltest/local/ydb.go b/internal/sqltest/local/ydb.go index 8703b170b5..e3e51e3716 100644 --- a/internal/sqltest/local/ydb.go +++ b/internal/sqltest/local/ydb.go @@ -2,11 +2,8 @@ package local import ( "context" - "database/sql" "fmt" - "hash/fnv" "math/rand" - "net" "os" "testing" "time" @@ -14,104 +11,77 @@ import ( migrate "github.com/sqlc-dev/sqlc/internal/migrations" "github.com/sqlc-dev/sqlc/internal/sql/sqlpath" "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/query" ) func init() { rand.Seed(time.Now().UnixNano()) } -func YDB(t *testing.T, migrations []string) TestYDB { - return link_YDB(t, migrations, true) +func YDB(t *testing.T, migrations []string) *ydb.Driver { + return link_YDB(t, migrations, true, false) } -func ReadOnlyYDB(t *testing.T, migrations []string) TestYDB { - return link_YDB(t, migrations, false) +func YDBTLS(t *testing.T, migrations []string) *ydb.Driver { + return link_YDB(t, migrations, true, true) } -type TestYDB struct { - DB *sql.DB - Prefix string +func ReadOnlyYDB(t *testing.T, migrations []string) *ydb.Driver { + return link_YDB(t, migrations, false, false) } -func link_YDB(t *testing.T, migrations []string, rw bool) TestYDB { - t.Helper() - - time.Sleep(1 * time.Second) // wait for YDB to start +func ReadOnlyYDBTLS(t *testing.T, migrations []string) *ydb.Driver { + return link_YDB(t, migrations, false, true) +} +func link_YDB(t *testing.T, migrations []string, rw bool, tls bool) *ydb.Driver { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() + t.Helper() + dbuiri := os.Getenv("YDB_SERVER_URI") if dbuiri == "" { t.Skip("YDB_SERVER_URI is empty") } - host, _, err := net.SplitHostPort(dbuiri) - if err != nil { - t.Fatalf("invalid YDB_SERVER_URI: %q", dbuiri) - } baseDB := os.Getenv("YDB_DATABASE") if baseDB == "" { baseDB = "/local" } - var seed []string - files, err := sqlpath.Glob(migrations) - if err != nil { - t.Fatal(err) - } - h := fnv.New64() - for _, f := range files { - blob, err := os.ReadFile(f) - if err != nil { - t.Fatal(err) - } - h.Write(blob) - seed = append(seed, migrate.RemoveRollbackStatements(string(blob))) - } - - var name string - if rw { - // name = fmt.Sprintf("sqlc_test_%s", id()) - name = fmt.Sprintf("sqlc_test_%s", "test_new") + var connectionString string + if tls { + connectionString = fmt.Sprintf("grpcs://%s%s", dbuiri, baseDB) } else { - name = fmt.Sprintf("sqlc_test_%x", h.Sum(nil)) + connectionString = fmt.Sprintf("grpc://%s%s", dbuiri, baseDB) } - prefix := fmt.Sprintf("%s/%s", baseDB, name) - rootDSN := fmt.Sprintf("grpc://%s?database=%s", dbuiri, baseDB) - t.Logf("→ Opening root driver: %s", rootDSN) - driver, err := ydb.Open(ctx, rootDSN, + db, err := ydb.Open(ctx, connectionString, ydb.WithInsecure(), ydb.WithDiscoveryInterval(time.Hour), - ydb.WithNodeAddressMutator(func(_ string) string { - return host - }), ) if err != nil { - t.Fatalf("failed to open root YDB connection: %s", err) + t.Fatalf("failed to open YDB connection: %s", err) } - connector, err := ydb.Connector( - driver, - ydb.WithTablePathPrefix(prefix), - ydb.WithAutoDeclare(), - ydb.WithNumericArgs(), - ) + files, err := sqlpath.Glob(migrations) if err != nil { - t.Fatalf("failed to create connector: %s", err) + t.Fatal(err) } - db := sql.OpenDB(connector) - - t.Log("→ Applying migrations to prefix: ", prefix) + for _, f := range files { + blob, err := os.ReadFile(f) + if err != nil { + t.Fatal(err) + } + stmt := migrate.RemoveRollbackStatements(string(blob)) - schemeCtx := ydb.WithQueryMode(ctx, ydb.SchemeQueryMode) - for _, stmt := range seed { - _, err := db.ExecContext(schemeCtx, stmt) + err = db.Query().Exec(ctx, stmt, query.WithTxControl(query.EmptyTxControl())) if err != nil { t.Fatalf("failed to apply migration: %s\nSQL: %s", err, stmt) } } - return TestYDB{DB: db, Prefix: prefix} + + return db } From 4eb8ff53c644d423e0527c66a61a2f10e1b0676d Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Wed, 3 Sep 2025 12:57:49 +0300 Subject: [PATCH 11/22] Bump sqlc version in examples/authors/ydb to v1.30.0 --- examples/authors/ydb/db.go | 2 +- examples/authors/ydb/models.go | 2 +- examples/authors/ydb/query.sql.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/authors/ydb/db.go b/examples/authors/ydb/db.go index c3b16b4481..9a15b333ce 100644 --- a/examples/authors/ydb/db.go +++ b/examples/authors/ydb/db.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.29.0 +// sqlc v1.30.0 package authors diff --git a/examples/authors/ydb/models.go b/examples/authors/ydb/models.go index 12b4f3a604..2806beacfe 100644 --- a/examples/authors/ydb/models.go +++ b/examples/authors/ydb/models.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.29.0 +// sqlc v1.30.0 package authors diff --git a/examples/authors/ydb/query.sql.go b/examples/authors/ydb/query.sql.go index 7459482b3a..3233b705d3 100644 --- a/examples/authors/ydb/query.sql.go +++ b/examples/authors/ydb/query.sql.go @@ -1,6 +1,6 @@ // Code generated by sqlc. DO NOT EDIT. // versions: -// sqlc v1.29.0 +// sqlc v1.30.0 // source: query.sql package authors From 14b60c501a7ace05dd0089df8d6e2661a0fabe2e Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Wed, 3 Sep 2025 14:25:40 +0300 Subject: [PATCH 12/22] Rewrited comments and testdata to eng --- examples/authors/ydb/README.md | 47 ------------------- examples/authors/ydb/db_test.go | 28 +++++------ .../ydb/catalog_tests/alter_group_test.go | 6 +-- .../ydb/catalog_tests/alter_user_test.go | 10 ++-- .../ydb/catalog_tests/create_group_test.go | 6 +-- .../ydb/catalog_tests/create_user_test.go | 6 +-- .../engine/ydb/catalog_tests/delete_test.go | 6 +-- .../ydb/catalog_tests/drop_role_test.go | 4 +- .../engine/ydb/catalog_tests/insert_test.go | 6 +-- .../engine/ydb/catalog_tests/pragma_test.go | 6 +-- .../engine/ydb/catalog_tests/select_test.go | 6 +-- .../engine/ydb/catalog_tests/update_test.go | 6 +-- 12 files changed, 45 insertions(+), 92 deletions(-) delete mode 100644 examples/authors/ydb/README.md diff --git a/examples/authors/ydb/README.md b/examples/authors/ydb/README.md deleted file mode 100644 index 9e77fc7886..0000000000 --- a/examples/authors/ydb/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Инструкция по генерации - -В файлах `schema.sql` и `query.sql` записаны, соответственно, схема базы данных и запросы, из которых вы хотите сгенерировать код к базе данных. -В `db_test.go` находятся тесты для последних сгенерированных команд. -Ниже находятся команды для генерации и запуска тестов. - ---- - -### 1. Создание бинарника sqlc - -```bash -make sqlc-dev -``` - -### 2. Запуск YDB через Docker Compose - -```bash -make ydb -``` - -### 3. Генерация кода для примеров для YDB - -```bash -make gen-examples-ydb -``` - -### 4. Запуск тестов примеров для YDB - -```bash -make test-examples-ydb -``` - -### 5. Полный цикл: сборка, генерация, тестирование (удобно одной командой) - -```bash -make ydb-examples -``` - -Эта команда выполнит: - -- Сборку `sqlc-dev` -- Запуск контейнера YDB -- Генерацию примеров -- Тестирование примеров - ---- - diff --git a/examples/authors/ydb/db_test.go b/examples/authors/ydb/db_test.go index 6ab15913f0..ab5324e76d 100644 --- a/examples/authors/ydb/db_test.go +++ b/examples/authors/ydb/db_test.go @@ -23,19 +23,19 @@ func TestAuthors(t *testing.T) { t.Run("InsertAuthors", func(t *testing.T) { authorsToInsert := []CreateOrUpdateAuthorParams{ - {P0: 1, P1: "Лев Толстой", P2: ptr("Русский писатель, автор \"Война и мир\"")}, - {P0: 2, P1: "Александр Пушкин", P2: ptr("Автор \"Евгения Онегина\"")}, - {P0: 3, P1: "Александр Пушкин", P2: ptr("Русский поэт, драматург и прозаик")}, - {P0: 4, P1: "Фёдор Достоевский", P2: ptr("Автор \"Преступление и наказание\"")}, - {P0: 5, P1: "Николай Гоголь", P2: ptr("Автор \"Мёртвые души\"")}, - {P0: 6, P1: "Антон Чехов", P2: nil}, - {P0: 7, P1: "Иван Тургенев", P2: ptr("Автор \"Отцы и дети\"")}, - {P0: 8, P1: "Михаил Лермонтов", P2: nil}, - {P0: 9, P1: "Даниил Хармс", P2: ptr("Абсурдист, писатель и поэт")}, - {P0: 10, P1: "Максим Горький", P2: ptr("Автор \"На дне\"")}, - {P0: 11, P1: "Владимир Маяковский", P2: nil}, - {P0: 12, P1: "Сергей Есенин", P2: ptr("Русский лирик")}, - {P0: 13, P1: "Борис Пастернак", P2: ptr("Автор \"Доктор Живаго\"")}, + {P0: 1, P1: "Leo Tolstoy", P2: ptr("Russian writer, author of \"War and Peace\"")}, + {P0: 2, P1: "Alexander Pushkin", P2: ptr("Author of \"Eugene Onegin\"")}, + {P0: 3, P1: "Alexander Pushkin", P2: ptr("Russian poet, playwright, and prose writer")}, + {P0: 4, P1: "Fyodor Dostoevsky", P2: ptr("Author of \"Crime and Punishment\"")}, + {P0: 5, P1: "Nikolai Gogol", P2: ptr("Author of \"Dead Souls\"")}, + {P0: 6, P1: "Anton Chekhov", P2: nil}, + {P0: 7, P1: "Ivan Turgenev", P2: ptr("Author of \"Fathers and Sons\"")}, + {P0: 8, P1: "Mikhail Lermontov", P2: nil}, + {P0: 9, P1: "Daniil Kharms", P2: ptr("Absurdist, writer and poet")}, + {P0: 10, P1: "Maxim Gorky", P2: ptr("Author of \"At the Bottom\"")}, + {P0: 11, P1: "Vladimir Mayakovsky", P2: nil}, + {P0: 12, P1: "Sergei Yesenin", P2: ptr("Russian lyric poet")}, + {P0: 13, P1: "Boris Pasternak", P2: ptr("Author of \"Doctor Zhivago\"")}, } for _, author := range authorsToInsert { @@ -79,7 +79,7 @@ func TestAuthors(t *testing.T) { var i uint64 for i = 1; i <= 13; i++ { if err := q.DeleteAuthor(ctx, i, query.WithIdempotent()); err != nil { - t.Fatalf("failed to delete authors: %v", err) + t.Fatalf("failed to delete author: %v", err) } } authors, err := q.ListAuthors(ctx) diff --git a/internal/engine/ydb/catalog_tests/alter_group_test.go b/internal/engine/ydb/catalog_tests/alter_group_test.go index eef9f919e9..297d9b326a 100644 --- a/internal/engine/ydb/catalog_tests/alter_group_test.go +++ b/internal/engine/ydb/catalog_tests/alter_group_test.go @@ -102,10 +102,10 @@ func TestAlterGroup(t *testing.T) { t.Run(tc.stmt, func(t *testing.T) { stmts, err := p.Parse(strings.NewReader(tc.stmt)) if err != nil { - t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + t.Fatalf("Failed to parse query %q: %v", tc.stmt, err) } if len(stmts) == 0 { - t.Fatalf("Запрос %q не распарсен", tc.stmt) + t.Fatalf("Query %q was not parsed", tc.stmt) } diff := cmp.Diff(tc.expected, &stmts[0], @@ -115,7 +115,7 @@ func TestAlterGroup(t *testing.T) { cmpopts.IgnoreFields(ast.A_Const{}, "Location"), ) if diff != "" { - t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) } }) } diff --git a/internal/engine/ydb/catalog_tests/alter_user_test.go b/internal/engine/ydb/catalog_tests/alter_user_test.go index dd4dc5bb93..64a9891e8c 100644 --- a/internal/engine/ydb/catalog_tests/alter_user_test.go +++ b/internal/engine/ydb/catalog_tests/alter_user_test.go @@ -28,8 +28,8 @@ func TestAlterUser(t *testing.T) { Options: &ast.List{ Items: []ast.Node{ &ast.DefElem{ - Defname: strPtr("rename"), - Arg: &ast.String{Str: "queen"}, + Defname: strPtr("rename"), + Arg: &ast.String{Str: "queen"}, Defaction: ast.DefElemAction(1), }, }, @@ -133,10 +133,10 @@ func TestAlterUser(t *testing.T) { t.Run(tc.stmt, func(t *testing.T) { stmts, err := p.Parse(strings.NewReader(tc.stmt)) if err != nil { - t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + t.Fatalf("Failed to parse query %q: %v", tc.stmt, err) } if len(stmts) == 0 { - t.Fatalf("Запрос %q не распарсен", tc.stmt) + t.Fatalf("Query %q was not parsed", tc.stmt) } diff := cmp.Diff(tc.expected, &stmts[0], @@ -146,7 +146,7 @@ func TestAlterUser(t *testing.T) { cmpopts.IgnoreFields(ast.A_Const{}, "Location"), ) if diff != "" { - t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) } }) } diff --git a/internal/engine/ydb/catalog_tests/create_group_test.go b/internal/engine/ydb/catalog_tests/create_group_test.go index 724e912168..bc8d8369fd 100644 --- a/internal/engine/ydb/catalog_tests/create_group_test.go +++ b/internal/engine/ydb/catalog_tests/create_group_test.go @@ -90,10 +90,10 @@ func TestCreateGroup(t *testing.T) { t.Run(tc.stmt, func(t *testing.T) { stmts, err := p.Parse(strings.NewReader(tc.stmt)) if err != nil { - t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + t.Fatalf("Failed to parse query %q: %v", tc.stmt, err) } if len(stmts) == 0 { - t.Fatalf("Запрос %q не распарсен", tc.stmt) + t.Fatalf("Query %q was not parsed", tc.stmt) } diff := cmp.Diff(tc.expected, &stmts[0], @@ -103,7 +103,7 @@ func TestCreateGroup(t *testing.T) { cmpopts.IgnoreFields(ast.A_Const{}, "Location"), ) if diff != "" { - t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) } }) } diff --git a/internal/engine/ydb/catalog_tests/create_user_test.go b/internal/engine/ydb/catalog_tests/create_user_test.go index be53e9dd79..108d282c7c 100644 --- a/internal/engine/ydb/catalog_tests/create_user_test.go +++ b/internal/engine/ydb/catalog_tests/create_user_test.go @@ -110,10 +110,10 @@ func TestCreateUser(t *testing.T) { t.Run(tc.stmt, func(t *testing.T) { stmts, err := p.Parse(strings.NewReader(tc.stmt)) if err != nil { - t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + t.Fatalf("Failed to parse query %q: %v", tc.stmt, err) } if len(stmts) == 0 { - t.Fatalf("Запрос %q не распарсен", tc.stmt) + t.Fatalf("Query %q was not parsed", tc.stmt) } diff := cmp.Diff(tc.expected, &stmts[0], @@ -122,7 +122,7 @@ func TestCreateUser(t *testing.T) { cmpopts.IgnoreFields(ast.DefElem{}, "Location"), ) if diff != "" { - t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) } }) } diff --git a/internal/engine/ydb/catalog_tests/delete_test.go b/internal/engine/ydb/catalog_tests/delete_test.go index b75591a9ef..ab7b709be9 100644 --- a/internal/engine/ydb/catalog_tests/delete_test.go +++ b/internal/engine/ydb/catalog_tests/delete_test.go @@ -178,10 +178,10 @@ func TestDelete(t *testing.T) { t.Run(tc.stmt, func(t *testing.T) { stmts, err := p.Parse(strings.NewReader(tc.stmt)) if err != nil { - t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + t.Fatalf("Failed to parse query %q: %v", tc.stmt, err) } if len(stmts) == 0 { - t.Fatalf("Запрос %q не распарсен", tc.stmt) + t.Fatalf("Query %q was not parsed", tc.stmt) } diff := cmp.Diff(tc.expected, &stmts[0], @@ -193,7 +193,7 @@ func TestDelete(t *testing.T) { cmpopts.IgnoreFields(ast.RangeVar{}, "Location"), ) if diff != "" { - t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) } }) } diff --git a/internal/engine/ydb/catalog_tests/drop_role_test.go b/internal/engine/ydb/catalog_tests/drop_role_test.go index 1d7c6a7658..224be53ed1 100644 --- a/internal/engine/ydb/catalog_tests/drop_role_test.go +++ b/internal/engine/ydb/catalog_tests/drop_role_test.go @@ -69,10 +69,10 @@ func TestDropRole(t *testing.T) { t.Run(tc.stmt, func(t *testing.T) { stmts, err := p.Parse(strings.NewReader(tc.stmt)) if err != nil { - t.Fatalf("Error parsing %q: %v", tc.stmt, err) + t.Fatalf("Failed to parse query %q: %v", tc.stmt, err) } if len(stmts) == 0 { - t.Fatalf("Statement %q was not parsed", tc.stmt) + t.Fatalf("Query %q was not parsed", tc.stmt) } diff := cmp.Diff(tc.expected, &stmts[0], diff --git a/internal/engine/ydb/catalog_tests/insert_test.go b/internal/engine/ydb/catalog_tests/insert_test.go index 40f116a3ba..4dea2ceccb 100644 --- a/internal/engine/ydb/catalog_tests/insert_test.go +++ b/internal/engine/ydb/catalog_tests/insert_test.go @@ -120,10 +120,10 @@ func TestInsert(t *testing.T) { t.Run(tc.stmt, func(t *testing.T) { stmts, err := p.Parse(strings.NewReader(tc.stmt)) if err != nil { - t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + t.Fatalf("Failed to parse query %q: %v", tc.stmt, err) } if len(stmts) == 0 { - t.Fatalf("Запрос %q не распарсен", tc.stmt) + t.Fatalf("Query %q was not parsed", tc.stmt) } diff := cmp.Diff(tc.expected, &stmts[0], @@ -135,7 +135,7 @@ func TestInsert(t *testing.T) { cmpopts.IgnoreFields(ast.RangeVar{}, "Location"), ) if diff != "" { - t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) } }) } diff --git a/internal/engine/ydb/catalog_tests/pragma_test.go b/internal/engine/ydb/catalog_tests/pragma_test.go index 9db4406c53..fef5f76f88 100644 --- a/internal/engine/ydb/catalog_tests/pragma_test.go +++ b/internal/engine/ydb/catalog_tests/pragma_test.go @@ -98,10 +98,10 @@ func TestPragma(t *testing.T) { t.Run(tc.stmt, func(t *testing.T) { stmts, err := p.Parse(strings.NewReader(tc.stmt)) if err != nil { - t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + t.Fatalf("Failed to parse query %q: %v", tc.stmt, err) } if len(stmts) == 0 { - t.Fatalf("Запрос %q не распарсен", tc.stmt) + t.Fatalf("Query %q was not parsed", tc.stmt) } diff := cmp.Diff(tc.expected, &stmts[0], @@ -111,7 +111,7 @@ func TestPragma(t *testing.T) { cmpopts.IgnoreFields(ast.A_Const{}, "Location"), ) if diff != "" { - t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) } }) } diff --git a/internal/engine/ydb/catalog_tests/select_test.go b/internal/engine/ydb/catalog_tests/select_test.go index 47794ce81f..fa7b22677c 100644 --- a/internal/engine/ydb/catalog_tests/select_test.go +++ b/internal/engine/ydb/catalog_tests/select_test.go @@ -374,10 +374,10 @@ func TestSelect(t *testing.T) { t.Run(tc.stmt, func(t *testing.T) { stmts, err := p.Parse(strings.NewReader(tc.stmt)) if err != nil { - t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + t.Fatalf("Failed to parse query %q: %v", tc.stmt, err) } if len(stmts) == 0 { - t.Fatalf("Запрос %q не распарсен", tc.stmt) + t.Fatalf("Query %q was not parsed", tc.stmt) } diff := cmp.Diff(tc.expected, &stmts[0], @@ -390,7 +390,7 @@ func TestSelect(t *testing.T) { cmpopts.IgnoreFields(ast.RangeVar{}, "Location"), ) if diff != "" { - t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) } }) } diff --git a/internal/engine/ydb/catalog_tests/update_test.go b/internal/engine/ydb/catalog_tests/update_test.go index 57c90bc2a4..f4f00a92bc 100644 --- a/internal/engine/ydb/catalog_tests/update_test.go +++ b/internal/engine/ydb/catalog_tests/update_test.go @@ -163,10 +163,10 @@ func TestUpdate(t *testing.T) { t.Run(tc.stmt, func(t *testing.T) { stmts, err := p.Parse(strings.NewReader(tc.stmt)) if err != nil { - t.Fatalf("Ошибка парсинга запроса %q: %v", tc.stmt, err) + t.Fatalf("Failed to parse query %q: %v", tc.stmt, err) } if len(stmts) == 0 { - t.Fatalf("Запрос %q не распарсен", tc.stmt) + t.Fatalf("Query %q was not parsed", tc.stmt) } diff := cmp.Diff(tc.expected, &stmts[0], @@ -178,7 +178,7 @@ func TestUpdate(t *testing.T) { cmpopts.IgnoreFields(ast.RangeVar{}, "Location"), ) if diff != "" { - t.Errorf("Несовпадение AST (-ожидалось +получено):\n%s", diff) + t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) } }) } From f2d7aeab4c99eea98c10825672c10a3124fbdfea Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov <150552906+1NepuNep1@users.noreply.github.com> Date: Mon, 8 Sep 2025 13:23:38 +0300 Subject: [PATCH 13/22] Expanding YQL Syntax support in sqlc engine (Refactored SELECT (Supported DISTINCT, HAVING, GROUP BY, ORDER BY, LIMIT, OFFSET, UNION), added ALTER TABLE, DO stmt) (#10) * Added ALTER TABLE support * Added DO stmt support * Fixed DO stmt generation * Refactored SELECT logic. Supported DISTINCT, HAVING, GROUP BY, ORDER BY, LIMIT, OFFSET, UNION * Fixed style and types * Refactored DO stmt style & added some additional converts --------- Co-authored-by: Viktor Pentyukhov --- .../engine/ydb/catalog_tests/delete_test.go | 17 +- .../engine/ydb/catalog_tests/insert_test.go | 21 +- .../engine/ydb/catalog_tests/select_test.go | 364 +++++++++++++- .../engine/ydb/catalog_tests/update_test.go | 5 + internal/engine/ydb/convert.go | 469 +++++++++++++++--- internal/engine/ydb/utils.go | 29 +- 6 files changed, 830 insertions(+), 75 deletions(-) diff --git a/internal/engine/ydb/catalog_tests/delete_test.go b/internal/engine/ydb/catalog_tests/delete_test.go index ab7b709be9..1885deb9ce 100644 --- a/internal/engine/ydb/catalog_tests/delete_test.go +++ b/internal/engine/ydb/catalog_tests/delete_test.go @@ -101,6 +101,7 @@ func TestDelete(t *testing.T) { }, }, OnSelectStmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, ValuesLists: &ast.List{ Items: []ast.Node{ &ast.List{ @@ -110,8 +111,12 @@ func TestDelete(t *testing.T) { }, }, }, - FromClause: &ast.List{}, - TargetList: &ast.List{}, + FromClause: &ast.List{}, + TargetList: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, ReturningList: &ast.List{ Items: []ast.Node{ @@ -145,6 +150,7 @@ func TestDelete(t *testing.T) { }, }, OnSelectStmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -153,7 +159,12 @@ func TestDelete(t *testing.T) { }, }, }, - FromClause: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, ReturningList: &ast.List{ Items: []ast.Node{ diff --git a/internal/engine/ydb/catalog_tests/insert_test.go b/internal/engine/ydb/catalog_tests/insert_test.go index 4dea2ceccb..c60d0920da 100644 --- a/internal/engine/ydb/catalog_tests/insert_test.go +++ b/internal/engine/ydb/catalog_tests/insert_test.go @@ -28,6 +28,7 @@ func TestInsert(t *testing.T) { }, }, SelectStmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, ValuesLists: &ast.List{ Items: []ast.Node{ &ast.List{ @@ -40,6 +41,10 @@ func TestInsert(t *testing.T) { }, TargetList: &ast.List{}, FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, OnConflictClause: &ast.OnConflictClause{}, ReturningList: &ast.List{ @@ -68,6 +73,7 @@ func TestInsert(t *testing.T) { }, }, SelectStmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, ValuesLists: &ast.List{ Items: []ast.Node{ &ast.List{ @@ -79,6 +85,10 @@ func TestInsert(t *testing.T) { }, TargetList: &ast.List{}, FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, OnConflictClause: &ast.OnConflictClause{ Action: ast.OnConflictAction_INSERT_OR_IGNORE, @@ -106,7 +116,16 @@ func TestInsert(t *testing.T) { Stmt: &ast.InsertStmt{ Relation: &ast.RangeVar{Relname: strPtr("users")}, Cols: &ast.List{Items: []ast.Node{&ast.ResTarget{Name: strPtr("id")}}}, - SelectStmt: &ast.SelectStmt{ValuesLists: &ast.List{Items: []ast.Node{&ast.List{Items: []ast.Node{&ast.A_Const{Val: &ast.Integer{Ival: 4}}}}}}, TargetList: &ast.List{}, FromClause: &ast.List{}}, + SelectStmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, + ValuesLists: &ast.List{Items: []ast.Node{&ast.List{Items: []ast.Node{&ast.A_Const{Val: &ast.Integer{Ival: 4}}}}}}, + TargetList: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, + }, OnConflictClause: &ast.OnConflictClause{Action: ast.OnConflictAction_UPSERT}, ReturningList: &ast.List{Items: []ast.Node{&ast.ResTarget{Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}}, Indirection: &ast.List{}}}}, }, diff --git a/internal/engine/ydb/catalog_tests/select_test.go b/internal/engine/ydb/catalog_tests/select_test.go index fa7b22677c..f01171f12a 100644 --- a/internal/engine/ydb/catalog_tests/select_test.go +++ b/internal/engine/ydb/catalog_tests/select_test.go @@ -25,6 +25,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -34,7 +35,12 @@ func TestSelect(t *testing.T) { }, }, }, - FromClause: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -44,6 +50,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -53,7 +60,12 @@ func TestSelect(t *testing.T) { }, }, }, - FromClause: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -63,6 +75,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -72,7 +85,12 @@ func TestSelect(t *testing.T) { }, }, }, - FromClause: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -82,6 +100,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -91,7 +110,12 @@ func TestSelect(t *testing.T) { }, }, }, - FromClause: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -101,6 +125,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -108,7 +133,12 @@ func TestSelect(t *testing.T) { }, }, }, - FromClause: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -118,6 +148,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -127,7 +158,12 @@ func TestSelect(t *testing.T) { }, }, }, - FromClause: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -137,6 +173,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -166,7 +203,12 @@ func TestSelect(t *testing.T) { }, }, }, - FromClause: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -178,6 +220,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -198,6 +241,11 @@ func TestSelect(t *testing.T) { }, }, }, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -207,6 +255,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -228,6 +277,11 @@ func TestSelect(t *testing.T) { }, }, }, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -237,6 +291,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -259,6 +314,11 @@ func TestSelect(t *testing.T) { }, }, }, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -268,6 +328,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -307,6 +368,11 @@ func TestSelect(t *testing.T) { }, }, }, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -316,6 +382,7 @@ func TestSelect(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, TargetList: &ast.List{ Items: []ast.Node{ &ast.ResTarget{ @@ -362,6 +429,287 @@ func TestSelect(t *testing.T) { Val: &ast.Integer{Ival: 30}, }, }, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, + }, + }, + }, + }, + { + stmt: `(SELECT 1) UNION ALL (SELECT 2)`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, + TargetList: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, + Op: ast.Union, + All: true, + Larg: &ast.SelectStmt{ + DistinctClause: &ast.List{}, + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.A_Const{ + Val: &ast.Integer{Ival: 1}, + }, + }, + }, + }, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, + }, + Rarg: &ast.SelectStmt{ + DistinctClause: &ast.List{}, + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.A_Const{ + Val: &ast.Integer{Ival: 2}, + }, + }, + }, + }, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, + }, + }, + }, + }, + }, + { + stmt: `SELECT id FROM users ORDER BY id DESC`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + }, + }, + }, + FromClause: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{ + Relname: strPtr("users"), + }, + }, + }, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + LockingClause: &ast.List{}, + SortClause: &ast.List{ + Items: []ast.Node{ + &ast.SortBy{ + Node: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + SortbyDir: ast.SortByDirDesc, + UseOp: &ast.List{}, + }, + }, + }, + }, + }, + }, + }, + { + stmt: `SELECT id FROM users LIMIT 10 OFFSET 5`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + }, + }, + }, + FromClause: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{ + Relname: strPtr("users"), + }, + }, + }, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, + LimitCount: &ast.A_Const{ + Val: &ast.Integer{Ival: 10}, + }, + LimitOffset: &ast.A_Const{ + Val: &ast.Integer{Ival: 5}, + }, + }, + }, + }, + }, + { + stmt: `SELECT id FROM users WHERE id > 10 GROUP BY id HAVING id > 10`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + }, + }, + }, + FromClause: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{ + Relname: strPtr("users"), + }, + }, + }, + GroupClause: &ast.List{ + Items: []ast.Node{ + &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + }, + }, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, + WhereClause: &ast.A_Expr{ + Name: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: ">"}, + }, + }, + Lexpr: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + Rexpr: &ast.A_Const{ + Val: &ast.Integer{Ival: 10}, + }, + }, + HavingClause: &ast.A_Expr{ + Name: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: ">"}, + }, + }, + Lexpr: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + Rexpr: &ast.A_Const{ + Val: &ast.Integer{Ival: 10}, + }, + }, + }, + }, + }, + }, + { + stmt: `SELECT id FROM users GROUP BY ROLLUP (id)`, + expected: &ast.Statement{ + Raw: &ast.RawStmt{ + Stmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, + TargetList: &ast.List{ + Items: []ast.Node{ + &ast.ResTarget{ + Val: &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + }, + }, + }, + FromClause: &ast.List{ + Items: []ast.Node{ + &ast.RangeVar{ + Relname: strPtr("users"), + }, + }, + }, + GroupClause: &ast.List{ + Items: []ast.Node{ + &ast.GroupingSet{ + Kind: 1, // T_GroupingSet: ROLLUP + Content: &ast.List{ + Items: []ast.Node{ + &ast.ColumnRef{ + Fields: &ast.List{ + Items: []ast.Node{ + &ast.String{Str: "id"}, + }, + }, + }, + }, + }, + }, + }, + }, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, }, }, @@ -382,12 +730,12 @@ func TestSelect(t *testing.T) { diff := cmp.Diff(tc.expected, &stmts[0], cmpopts.IgnoreFields(ast.RawStmt{}, "StmtLocation", "StmtLen"), - // cmpopts.IgnoreFields(ast.SelectStmt{}, "Location"), cmpopts.IgnoreFields(ast.A_Const{}, "Location"), cmpopts.IgnoreFields(ast.ResTarget{}, "Location"), cmpopts.IgnoreFields(ast.ColumnRef{}, "Location"), cmpopts.IgnoreFields(ast.A_Expr{}, "Location"), cmpopts.IgnoreFields(ast.RangeVar{}, "Location"), + cmpopts.IgnoreFields(ast.SortBy{}, "Location"), ) if diff != "" { t.Errorf("AST mismatch for %q (-expected +got):\n%s", tc.stmt, diff) diff --git a/internal/engine/ydb/catalog_tests/update_test.go b/internal/engine/ydb/catalog_tests/update_test.go index f4f00a92bc..b7ebeb3d6a 100644 --- a/internal/engine/ydb/catalog_tests/update_test.go +++ b/internal/engine/ydb/catalog_tests/update_test.go @@ -121,6 +121,7 @@ func TestUpdate(t *testing.T) { }, }, OnSelectStmt: &ast.SelectStmt{ + DistinctClause: &ast.List{}, ValuesLists: &ast.List{ Items: []ast.Node{ &ast.List{ @@ -132,6 +133,10 @@ func TestUpdate(t *testing.T) { }, FromClause: &ast.List{}, TargetList: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, ReturningList: &ast.List{ Items: []ast.Node{ diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index b4d9490d0b..250dc467e0 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -54,7 +54,7 @@ func NewIdentifier(t string) *ast.String { return &ast.String{Str: identifier(t)} } -func (c *cc) convertDrop_role_stmtCOntext(n *parser.Drop_role_stmtContext) ast.Node { +func (c *cc) convertDrop_role_stmtContext(n *parser.Drop_role_stmtContext) ast.Node { if n.DROP() == nil || (n.USER() == nil && n.GROUP() == nil) || len(n.AllRole_name()) == 0 { return todo("Drop_role_stmtContext", n) } @@ -467,6 +467,145 @@ func (c *cc) convertRollback_stmtContext(n *parser.Rollback_stmtContext) ast.Nod return todo("convertRollback_stmtContext", n) } +func (c *cc) convertAlter_table_stmtContext(n *parser.Alter_table_stmtContext) ast.Node { + if n.ALTER() == nil || n.TABLE() == nil || n.Simple_table_ref() == nil || len(n.AllAlter_table_action()) == 0 { + return todo("convertAlter_table_stmtContext", n) + } + + stmt := &ast.AlterTableStmt{ + Table: parseTableName(n.Simple_table_ref().Simple_table_ref_core()), + Cmds: &ast.List{}, + } + + for _, action := range n.AllAlter_table_action() { + if action == nil { + continue + } + + switch { + case action.Alter_table_add_column() != nil: + ac := action.Alter_table_add_column() + if ac.ADD() != nil && ac.Column_schema() != nil { + columnDef := c.convertColumnSchema(ac.Column_schema().(*parser.Column_schemaContext)) + stmt.Cmds.Items = append(stmt.Cmds.Items, &ast.AlterTableCmd{ + Name: &columnDef.Colname, + Subtype: ast.AT_AddColumn, + Def: columnDef, + }) + } + case action.Alter_table_drop_column() != nil: + ac := action.Alter_table_drop_column() + if ac.DROP() != nil && ac.An_id() != nil { + name := parseAnId(ac.An_id()) + stmt.Cmds.Items = append(stmt.Cmds.Items, &ast.AlterTableCmd{ + Name: &name, + Subtype: ast.AT_DropColumn, + }) + } + case action.Alter_table_alter_column_drop_not_null() != nil: + ac := action.Alter_table_alter_column_drop_not_null() + if ac.DROP() != nil && ac.NOT() != nil && ac.NULL() != nil && ac.An_id() != nil { + name := parseAnId(ac.An_id()) + stmt.Cmds.Items = append(stmt.Cmds.Items, &ast.AlterTableCmd{ + Name: &name, + Subtype: ast.AT_DropNotNull, + }) + } + case action.Alter_table_rename_to() != nil: + ac := action.Alter_table_rename_to() + if ac.RENAME() != nil && ac.TO() != nil && ac.An_id_table() != nil { + // TODO: Returning here may be incorrect if there are multiple specs + newName := parseAnIdTable(ac.An_id_table()) + return &ast.RenameTableStmt{ + Table: stmt.Table, + NewName: &newName, + } + } + case action.Alter_table_add_index() != nil, + action.Alter_table_drop_index() != nil, + action.Alter_table_add_column_family() != nil, + action.Alter_table_alter_column_family() != nil, + action.Alter_table_set_table_setting_uncompat() != nil, + action.Alter_table_set_table_setting_compat() != nil, + action.Alter_table_reset_table_setting() != nil, + action.Alter_table_add_changefeed() != nil, + action.Alter_table_alter_changefeed() != nil, + action.Alter_table_drop_changefeed() != nil, + action.Alter_table_rename_index_to() != nil, + action.Alter_table_alter_index() != nil: + // All these actions do not change column schema relevant to sqlc; no-op. + // Intentionally ignored. + } + } + + return stmt +} + +func (c *cc) convertDo_stmtContext(n *parser.Do_stmtContext) ast.Node { + if n.DO() == nil || (n.Call_action() == nil && n.Inline_action() == nil) { + return todo("convertDo_stmtContext", n) + } + + switch { + case n.Call_action() != nil: + return c.convert(n.Call_action()) + + case n.Inline_action() != nil: + return c.convert(n.Inline_action()) + } + + return todo("convertDo_stmtContext", n) +} + +func (c *cc) convertCall_actionContext(n *parser.Call_actionContext) ast.Node { + if n == nil { + return nil + } + if n.LPAREN() != nil && n.RPAREN() != nil { + funcCall := &ast.FuncCall{ + Funcname: &ast.List{}, + Args: &ast.List{}, + AggOrder: &ast.List{}, + } + + if n.Bind_parameter() != nil { + funcCall.Funcname.Items = append(funcCall.Funcname.Items, c.convert(n.Bind_parameter())) + } else if n.EMPTY_ACTION() != nil { + funcCall.Funcname.Items = append(funcCall.Funcname.Items, &ast.String{Str: "EMPTY_ACTION"}) + } + + if n.Expr_list() != nil { + for _, expr := range n.Expr_list().AllExpr() { + funcCall.Args.Items = append(funcCall.Args.Items, c.convert(expr)) + } + } + + return &ast.DoStmt{ + Args: &ast.List{Items: []ast.Node{funcCall}}, + } + } + return todo("convertCall_actionContext", n) +} + +func (c *cc) convertInline_actionContext(n *parser.Inline_actionContext) ast.Node { + if n == nil { + return nil + } + if n.BEGIN() != nil && n.END() != nil && n.DO() != nil { + args := &ast.List{} + if defineBody := n.Define_action_or_subquery_body(); defineBody != nil { + cores := defineBody.AllSql_stmt_core() + for _, stmtCore := range cores { + if converted := c.convert(stmtCore); converted != nil { + args.Items = append(args.Items, converted) + } + } + } + return &ast.DoStmt{Args: args} + } + return todo("convertInline_actionContext", n) +} + func (c *cc) convertDrop_table_stmtContext(n *parser.Drop_table_stmtContext) ast.Node { if n.DROP() != nil && (n.TABLESTORE() != nil || (n.EXTERNAL() != nil && n.TABLE() != nil) || n.TABLE() != nil) { name := parseTableName(n.Simple_table_ref().Simple_table_ref_core()) @@ -509,12 +648,9 @@ func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { if valSource != nil { switch { case valSource.Values_stmt() != nil: - source = &ast.SelectStmt{ - ValuesLists: c.convert(valSource.Values_stmt()).(*ast.List), - FromClause: &ast.List{}, - TargetList: &ast.List{}, - } - + stmt := emptySelectStmt() + stmt.ValuesLists = c.convert(valSource.Values_stmt()).(*ast.List) + source = stmt case valSource.Select_stmt() != nil: source = c.convert(valSource.Select_stmt()) } @@ -704,12 +840,9 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { if valSource != nil { switch { case valSource.Values_stmt() != nil: - source = &ast.SelectStmt{ - ValuesLists: c.convert(valSource.Values_stmt()).(*ast.List), - FromClause: &ast.List{}, - TargetList: &ast.List{}, - } - + stmt := emptySelectStmt() + stmt.ValuesLists = c.convert(valSource.Values_stmt()).(*ast.List) + source = stmt case valSource.Select_stmt() != nil: source = c.convert(valSource.Select_stmt()) } @@ -777,12 +910,9 @@ func (c *cc) convertInto_table_stmtContext(n *parser.Into_table_stmtContext) ast if valSource != nil { switch { case valSource.Values_stmt() != nil: - source = &ast.SelectStmt{ - ValuesLists: c.convert(valSource.Values_stmt()).(*ast.List), - FromClause: &ast.List{}, - TargetList: &ast.List{}, - } - + stmt := emptySelectStmt() + stmt.ValuesLists = c.convert(valSource.Values_stmt()).(*ast.List) + source = stmt case valSource.Select_stmt() != nil: source = c.convert(valSource.Select_stmt()) } @@ -859,60 +989,106 @@ func (c *cc) convertReturning_columns_listContext(n *parser.Returning_columns_li } func (c *cc) convertSelectStmtContext(n *parser.Select_stmtContext) ast.Node { + if len(n.AllSelect_kind_parenthesis()) == 0 { + return todo("convertSelectStmtContext", n) + } + skp := n.Select_kind_parenthesis(0) if skp == nil { - return nil + return todo("convertSelectStmtContext", skp) } - partial := skp.Select_kind_partial() - if partial == nil { - return nil + + stmt := c.convertSelectKindParenthesis(skp) + left, ok := stmt.(*ast.SelectStmt) + if left == nil || !ok { + return todo("convertSelectKindParenthesis", skp) } + + kinds := n.AllSelect_kind_parenthesis() + ops := n.AllSelect_op() + + for i := 1; i < len(kinds); i++ { + stmt := c.convertSelectKindParenthesis(kinds[i]) + right, ok := stmt.(*ast.SelectStmt) + if right == nil || !ok { + return todo("convertSelectKindParenthesis", kinds[i]) + } + + var op ast.SetOperation + var all bool + if i-1 < len(ops) && ops[i-1] != nil { + so := ops[i-1] + switch { + case so.UNION() != nil: + op = ast.Union + case so.INTERSECT() != nil: + log.Fatalf("YDB: INTERSECT is not implemented yet") + case so.EXCEPT() != nil: + log.Fatalf("YDB: EXCEPT is not implemented yet") + default: + op = ast.None + } + all = so.ALL() != nil + } + larg := left + left = emptySelectStmt() + left.Op = op + left.All = all + left.Larg = larg + left.Rarg = right + } + + return left +} + +func (c *cc) convertSelectKindParenthesis(n parser.ISelect_kind_parenthesisContext) ast.Node { + if n == nil || n.Select_kind_partial() == nil { + return todo("convertSelectKindParenthesis", n) + } + partial := n.Select_kind_partial() + sk := partial.Select_kind() if sk == nil { - return nil + return todo("convertSelectKind", sk) } - selectStmt := &ast.SelectStmt{} + var base ast.Node switch { - case sk.Process_core() != nil: - cnode := c.convert(sk.Process_core()) - stmt, ok := cnode.(*ast.SelectStmt) - if !ok { - return nil - } - selectStmt = stmt case sk.Select_core() != nil: - cnode := c.convert(sk.Select_core()) - stmt, ok := cnode.(*ast.SelectStmt) - if !ok { - return nil - } - selectStmt = stmt + base = c.convertSelectCoreContext(sk.Select_core()) + case sk.Process_core() != nil: + log.Fatalf("PROCESS is not supported in YDB engine") case sk.Reduce_core() != nil: - cnode := c.convert(sk.Reduce_core()) - stmt, ok := cnode.(*ast.SelectStmt) - if !ok { - return nil - } - selectStmt = stmt + log.Fatalf("REDUCE is not supported in YDB engine") + } + stmt, ok := base.(*ast.SelectStmt) + if !ok || stmt == nil { + return todo("convertSelectKindParenthesis", sk.Select_core()) } - // todo: cover process and reduce core, - // todo: cover LIMIT and OFFSET + // TODO: handle INTO RESULT clause - return selectStmt + if partial.LIMIT() != nil { + exprs := partial.AllExpr() + if len(exprs) >= 1 { + stmt.LimitCount = c.convert(exprs[0]) + } + if partial.OFFSET() != nil { + if len(exprs) >= 2 { + stmt.LimitOffset = c.convert(exprs[1]) + } + } + } + + return stmt } -func (c *cc) convertSelectCoreContext(n *parser.Select_coreContext) ast.Node { - stmt := &ast.SelectStmt{ - TargetList: &ast.List{}, - FromClause: &ast.List{}, - } +func (c *cc) convertSelectCoreContext(n parser.ISelect_coreContext) ast.Node { + stmt := emptySelectStmt() if n.Opt_set_quantifier() != nil { oq := n.Opt_set_quantifier() if oq.DISTINCT() != nil { - // todo: add distinct support - stmt.DistinctClause = &ast.List{} + stmt.DistinctClause.Items = append(stmt.DistinctClause.Items, &ast.TODO{}) // trick to handle distinct } } resultCols := n.AllResult_column() @@ -932,8 +1108,14 @@ func (c *cc) convertSelectCoreContext(n *parser.Select_coreContext) ast.Node { Items: items, } } + + // TODO: handle WITHOUT clause + jsList := n.AllJoin_source() - if len(n.AllFROM()) > 0 && len(jsList) > 0 { + if len(n.AllFROM()) > 1 { + log.Fatalf("YDB: Only one FROM clause is allowed") + } + if len(jsList) > 0 { var fromItems []ast.Node for _, js := range jsList { jsCon, ok := js.(*parser.Join_sourceContext) @@ -950,15 +1132,137 @@ func (c *cc) convertSelectCoreContext(n *parser.Select_coreContext) ast.Node { Items: fromItems, } } + + exprIdx := 0 if n.WHERE() != nil { - whereCtx := n.Expr(0) - if whereCtx != nil { + if whereCtx := n.Expr(exprIdx); whereCtx != nil { stmt.WhereClause = c.convert(whereCtx) } + exprIdx++ + } + if n.HAVING() != nil { + if havingCtx := n.Expr(exprIdx); havingCtx != nil { + stmt.HavingClause = c.convert(havingCtx) + } + exprIdx++ + } + + if gbc := n.Group_by_clause(); gbc != nil { + if gel := gbc.Grouping_element_list(); gel != nil { + var groups []ast.Node + for _, ne := range gel.AllGrouping_element() { + groups = append(groups, c.convert(ne)) + } + if len(groups) > 0 { + stmt.GroupClause = &ast.List{Items: groups} + } + } + } + + if ext := n.Ext_order_by_clause(); ext != nil { + if ob := ext.Order_by_clause(); ob != nil && ob.ORDER() != nil && ob.BY() != nil { + // TODO: ASSUME ORDER BY + if sl := ob.Sort_specification_list(); sl != nil { + var orderItems []ast.Node + for _, sp := range sl.AllSort_specification() { + ss, ok := sp.(*parser.Sort_specificationContext) + if !ok || ss == nil { + continue + } + expr := c.convert(ss.Expr()) + dir := ast.SortByDirDefault + if ss.ASC() != nil { + dir = ast.SortByDirAsc + } else if ss.DESC() != nil { + dir = ast.SortByDirDesc + } + orderItems = append(orderItems, &ast.SortBy{ + Node: expr, + SortbyDir: dir, + SortbyNulls: ast.SortByNullsUndefined, + UseOp: &ast.List{}, + Location: c.pos(ss.GetStart()), + }) + } + if len(orderItems) > 0 { + stmt.SortClause = &ast.List{Items: orderItems} + } + } + } } return stmt } +func (c *cc) convertGrouping_elementContext(n parser.IGrouping_elementContext) ast.Node { + if n == nil { + return todo("convertGrouping_elementContext", n) + } + if ogs := n.Ordinary_grouping_set(); ogs != nil { + return c.convert(ogs) + } + if rl := n.Rollup_list(); rl != nil { + return c.convert(rl) + } + if cl := n.Cube_list(); cl != nil { + return c.convert(cl) + } + if gss := n.Grouping_sets_specification(); gss != nil { + return c.convert(gss) + } + return todo("convertGrouping_elementContext", n) +} + +func (c *cc) convertOrdinary_grouping_setContext(n *parser.Ordinary_grouping_setContext) ast.Node { + if n == nil || n.Named_expr() == nil { + return todo("convertOrdinary_grouping_setContext", n) + } + + return c.convert(n.Named_expr()) +} + +func (c *cc) convertRollup_listContext(n *parser.Rollup_listContext) ast.Node { + if n == nil || n.ROLLUP() == nil || n.LPAREN() == nil || n.RPAREN() == nil { + return todo("convertRollup_listContext", n) + } + + var items []ast.Node + if list := n.Ordinary_grouping_set_list(); list != nil { + for _, ogs := range list.AllOrdinary_grouping_set() { + items = append(items, c.convert(ogs)) + } + } + return &ast.GroupingSet{Kind: 1, Content: &ast.List{Items: items}} +} + +func (c *cc) convertCube_listContext(n *parser.Cube_listContext) ast.Node { + if n == nil || n.CUBE() == nil || n.LPAREN() == nil || n.RPAREN() == nil { + return todo("convertCube_listContext", n) + } + + var items []ast.Node + if list := n.Ordinary_grouping_set_list(); list != nil { + for _, ogs := range list.AllOrdinary_grouping_set() { + items = append(items, c.convert(ogs)) + } + } + + return &ast.GroupingSet{Kind: 2, Content: &ast.List{Items: items}} +} + +func (c *cc) convertGrouping_sets_specificationContext(n *parser.Grouping_sets_specificationContext) ast.Node { + if n == nil || n.GROUPING() == nil || n.SETS() == nil || n.LPAREN() == nil || n.RPAREN() == nil { + return todo("convertGrouping_sets_specificationContext", n) + } + + var items []ast.Node + if gel := n.Grouping_element_list(); gel != nil { + for _, ge := range gel.AllGrouping_element() { + items = append(items, c.convert(ge)) + } + } + return &ast.GroupingSet{Kind: 3, Content: &ast.List{Items: items}} +} + func (c *cc) convertResultColumn(n *parser.Result_columnContext) ast.Node { // todo: support opt_id_prefix target := &ast.ResTarget{ @@ -1683,6 +1987,22 @@ func (c *cc) convertSqlStmtCore(n parser.ISql_stmt_coreContext) ast.Node { return nil } +func (c *cc) convertNamed_exprContext(n *parser.Named_exprContext) ast.Node { + if n == nil || n.Expr() == nil { + return todo("convertNamed_exprContext", n) + } + expr := c.convert(n.Expr()) + if n.AS() != nil && n.An_id_or_type() != nil { + name := parseAnIdOrType(n.An_id_or_type()) + return &ast.ResTarget{ + Name: &name, + Val: expr, + Location: c.pos(n.Expr().GetStart()), + } + } + return expr +} + func (c *cc) convertExpr(n *parser.ExprContext) ast.Node { if n == nil { return nil @@ -2457,9 +2777,6 @@ func (c *cc) convert(node node) ast.Node { case *parser.Select_stmtContext: return c.convertSelectStmtContext(n) - case *parser.Select_coreContext: - return c.convertSelectCoreContext(n) - case *parser.Result_columnContext: return c.convertResultColumn(n) @@ -2553,6 +2870,12 @@ func (c *cc) convert(node node) ast.Node { case *parser.Update_stmtContext: return c.convertUpdate_stmtContext(n) + case *parser.Alter_table_stmtContext: + return c.convertAlter_table_stmtContext(n) + + case *parser.Do_stmtContext: + return c.convertDo_stmtContext(n) + case *parser.Drop_table_stmtContext: return c.convertDrop_table_stmtContext(n) @@ -2593,7 +2916,31 @@ func (c *cc) convert(node node) ast.Node { return c.convertAlter_group_stmtContext(n) case *parser.Drop_role_stmtContext: - return c.convertDrop_role_stmtCOntext(n) + return c.convertDrop_role_stmtContext(n) + + case *parser.Grouping_elementContext: + return c.convertGrouping_elementContext(n) + + case *parser.Ordinary_grouping_setContext: + return c.convertOrdinary_grouping_setContext(n) + + case *parser.Rollup_listContext: + return c.convertRollup_listContext(n) + + case *parser.Cube_listContext: + return c.convertCube_listContext(n) + + case *parser.Grouping_sets_specificationContext: + return c.convertGrouping_sets_specificationContext(n) + + case *parser.Named_exprContext: + return c.convertNamed_exprContext(n) + + case *parser.Call_actionContext: + return c.convertCall_actionContext(n) + + case *parser.Inline_actionContext: + return c.convertInline_actionContext(n) default: return todo("convert(case=default)", n) diff --git a/internal/engine/ydb/utils.go b/internal/engine/ydb/utils.go index 3847ee5055..f2023e8ba9 100755 --- a/internal/engine/ydb/utils.go +++ b/internal/engine/ydb/utils.go @@ -85,7 +85,7 @@ func parseIdOrType(ctx parser.IId_or_typeContext) string { } Id := ctx.(*parser.Id_or_typeContext) if Id.Id() != nil { - return identifier(parseIdTable(Id.Id())) + return identifier(parseId(Id.Id())) } return "" @@ -112,13 +112,25 @@ func parseAnIdSchema(ctx parser.IAn_id_schemaContext) string { return "" } -func parseIdTable(ctx parser.IIdContext) string { +func parseId(ctx parser.IIdContext) string { if ctx == nil { return "" } return ctx.GetText() } +func parseAnIdTable(ctx parser.IAn_id_tableContext) string { + if ctx == nil { + return "" + } + if id := ctx.Id_table(); id != nil { + return id.GetText() + } else if str := ctx.STRING_VALUE(); str != nil { + return str.GetText() + } + return "" +} + func parseIntegerValue(text string) (int64, error) { text = strings.ToLower(text) base := 10 @@ -194,3 +206,16 @@ func byteOffsetFromRuneIndex(s string, runeIndex int) int { } return bytePos } + +func emptySelectStmt() *ast.SelectStmt { + return &ast.SelectStmt{ + DistinctClause: &ast.List{}, + TargetList: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + ValuesLists: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, + } +} From 296cca76fbbfeb4405f3ad13e2439fc3526e3ca4 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov <150552906+1NepuNep1@users.noreply.github.com> Date: Tue, 9 Sep 2025 14:45:14 +0300 Subject: [PATCH 14/22] Made new params building logic & got rid off .Query handle (#11) * Made new params building logic & got rid off .Query handle (replaced it with QueryResultSet) * Cosmetics * Bug fixes --------- Co-authored-by: Viktor Pentyukhov --- examples/authors/ydb/query.sql.go | 51 +++++---- internal/codegen/golang/query.go | 101 ++++++++++++++++++ .../templates/ydb-go-sdk/queryCode.tmpl | 43 +++----- internal/codegen/golang/ydb_type.go | 18 ++++ .../ydb/catalog_tests/create_table_test.go | 2 +- internal/engine/ydb/convert.go | 2 +- 6 files changed, 167 insertions(+), 50 deletions(-) diff --git a/examples/authors/ydb/query.sql.go b/examples/authors/ydb/query.sql.go index 3233b705d3..e9b6b332a4 100644 --- a/examples/authors/ydb/query.sql.go +++ b/examples/authors/ydb/query.sql.go @@ -25,11 +25,15 @@ type CreateOrUpdateAuthorParams struct { func (q *Queries) CreateOrUpdateAuthor(ctx context.Context, arg CreateOrUpdateAuthorParams, opts ...query.ExecuteOption) error { err := q.db.Exec(ctx, createOrUpdateAuthor, - append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ - "$p0": arg.P0, - "$p1": arg.P1, - "$p2": arg.P2, - })))..., + append(opts, + query.WithParameters( + ydb.ParamsBuilder(). + Param("$p0").Uint64(arg.P0). + Param("$p1").Text(arg.P1). + Param("$p2").BeginOptional().Text(arg.P2).EndOptional(). + Build(), + ), + )..., ) if err != nil { return xerrors.WithStackTrace(err) @@ -43,9 +47,13 @@ DELETE FROM authors WHERE id = $p0 func (q *Queries) DeleteAuthor(ctx context.Context, p0 uint64, opts ...query.ExecuteOption) error { err := q.db.Exec(ctx, deleteAuthor, - append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ - "$p0": p0, - })))..., + append(opts, + query.WithParameters( + ydb.ParamsBuilder(). + Param("$p0").Uint64(p0). + Build(), + ), + )..., ) if err != nil { return xerrors.WithStackTrace(err) @@ -72,9 +80,13 @@ WHERE id = $p0 LIMIT 1 func (q *Queries) GetAuthor(ctx context.Context, p0 uint64, opts ...query.ExecuteOption) (Author, error) { row, err := q.db.QueryRow(ctx, getAuthor, - append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ - "$p0": p0, - })))..., + append(opts, + query.WithParameters( + ydb.ParamsBuilder(). + Param("$p0").Uint64(p0). + Build(), + ), + )..., ) var i Author if err != nil { @@ -92,25 +104,20 @@ SELECT id, name, bio FROM authors ORDER BY name ` func (q *Queries) ListAuthors(ctx context.Context, opts ...query.ExecuteOption) ([]Author, error) { - result, err := q.db.Query(ctx, listAuthors, opts...) + result, err := q.db.QueryResultSet(ctx, listAuthors, opts...) if err != nil { return nil, xerrors.WithStackTrace(err) } var items []Author - for set, err := range result.ResultSets(ctx) { + for row, err := range result.Rows(ctx) { if err != nil { return nil, xerrors.WithStackTrace(err) } - for row, err := range set.Rows(ctx) { - if err != nil { - return nil, xerrors.WithStackTrace(err) - } - var i Author - if err := row.Scan(&i.ID, &i.Name, &i.Bio); err != nil { - return nil, xerrors.WithStackTrace(err) - } - items = append(items, i) + var i Author + if err := row.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, xerrors.WithStackTrace(err) } + items = append(items, i) } if err := result.Close(ctx); err != nil { return nil, xerrors.WithStackTrace(err) diff --git a/internal/codegen/golang/query.go b/internal/codegen/golang/query.go index 02a09c3870..7cda1b7c2b 100644 --- a/internal/codegen/golang/query.go +++ b/internal/codegen/golang/query.go @@ -5,6 +5,7 @@ import ( "strings" "github.com/sqlc-dev/sqlc/internal/codegen/golang/opts" + "github.com/sqlc-dev/sqlc/internal/codegen/sdk" "github.com/sqlc-dev/sqlc/internal/metadata" "github.com/sqlc-dev/sqlc/internal/plugin" ) @@ -294,6 +295,106 @@ func (v QueryValue) YDBParamMapEntries() string { return "\n" + strings.Join(parts, ",\n") } +// ydbBuilderMethodForColumnType maps a YDB column data type to a ParamsBuilder method name. +func ydbBuilderMethodForColumnType(dbType string) string { + switch strings.ToLower(dbType) { + case "bool": + return "Bool" + case "uint64": + return "Uint64" + case "int64": + return "Int64" + case "uint32": + return "Uint32" + case "int32": + return "Int32" + case "uint16": + return "Uint16" + case "int16": + return "Int16" + case "uint8": + return "Uint8" + case "int8": + return "Int8" + case "float": + return "Float" + case "double": + return "Double" + case "json": + return "JSON" + case "jsondocument": + return "JSONDocument" + case "utf8", "text", "string": + return "Text" + case "date": + return "Date" + case "date32": + return "Date32" + case "datetime": + return "Datetime" + case "timestamp": + return "Timestamp" + case "tzdate": + return "TzDate" + case "tzdatetime": + return "TzDatetime" + case "tztimestamp": + return "TzTimestamp" + + //TODO: support other types + default: + return "" + } +} + +// YDBParamsBuilder emits Go code that constructs YDB params using ParamsBuilder. +func (v QueryValue) YDBParamsBuilder() string { + if v.isEmpty() { + return "" + } + + var lines []string + + for _, field := range v.getParameterFields() { + if field.Column != nil && field.Column.IsNamedParam { + name := field.Column.GetName() + if name == "" { + continue + } + paramName := fmt.Sprintf("%q", addDollarPrefix(name)) + variable := escape(v.VariableForField(field)) + + var method string + if field.Column != nil && field.Column.Type != nil { + method = ydbBuilderMethodForColumnType(sdk.DataType(field.Column.Type)) + } + + goType := field.Type + isPtr := strings.HasPrefix(goType, "*") + if isPtr { + goType = strings.TrimPrefix(goType, "*") + } + + if method == "" { + panic(fmt.Sprintf("unknown YDB column type for param %s (goType=%s)", name, goType)) + } + + if isPtr { + lines = append(lines, fmt.Sprintf("\t\t\tParam(%s).BeginOptional().%s(%s).EndOptional().", paramName, method, variable)) + } else { + lines = append(lines, fmt.Sprintf("\t\t\tParam(%s).%s(%s).", paramName, method, variable)) + } + } + } + + if len(lines) == 0 { + return "" + } + + params := strings.Join(lines, "\n") + return fmt.Sprintf("\nquery.WithParameters(\n\t\tydb.ParamsBuilder().\n%s\n\t\t\tBuild(),\n\t\t),\n", params) +} + func (v QueryValue) getParameterFields() []Field { if v.Struct == nil { return []Field{ diff --git a/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl b/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl index ecd78b1344..c56fc953f8 100644 --- a/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl +++ b/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl @@ -27,8 +27,8 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBA {{- if .Arg.IsEmpty }} row, err := {{$dbArg}}.QueryRow(ctx, {{.ConstantName}}, opts...) {{- else }} - row, err := {{$dbArg}}.QueryRow(ctx, {{.ConstantName}}, - append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ {{.Arg.YDBParamMapEntries}} })))..., + row, err := {{$dbArg}}.QueryRow(ctx, {{.ConstantName}}, + append(opts, {{.Arg.YDBParamsBuilder}})..., ) {{- end }} {{- if or (ne .Arg.Pair .Ret.Pair) (ne .Arg.DefineType .Ret.DefineType) }} @@ -61,10 +61,10 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBA func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) { {{- $dbArg := "q.db" }}{{- if $.EmitMethodsWithDBArgument }}{{- $dbArg = "db" }}{{- end -}} {{- if .Arg.IsEmpty }} - result, err := {{$dbArg}}.Query(ctx, {{.ConstantName}}, opts...) + result, err := {{$dbArg}}.QueryResultSet(ctx, {{.ConstantName}}, opts...) {{- else }} - result, err := {{$dbArg}}.Query(ctx, {{.ConstantName}}, - append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ {{.Arg.YDBParamMapEntries}} })))..., + result, err := {{$dbArg}}.QueryResultSet(ctx, {{.ConstantName}}, + append(opts, {{.Arg.YDBParamsBuilder}})..., ) {{- end }} if err != nil { @@ -79,7 +79,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBA {{else}} var items []{{.Ret.DefineType}} {{end -}} - for set, err := range result.ResultSets(ctx) { + for row, err := range result.Rows(ctx) { if err != nil { {{- if $.WrapErrors}} return nil, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) @@ -87,24 +87,15 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBA return nil, xerrors.WithStackTrace(err) {{- end }} } - for row, err := range set.Rows(ctx) { - if err != nil { - {{- if $.WrapErrors}} - return nil, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) - {{- else }} - return nil, xerrors.WithStackTrace(err) - {{- end }} - } - var {{.Ret.Name}} {{.Ret.Type}} - if err := row.Scan({{.Ret.Scan}}); err != nil { - {{- if $.WrapErrors}} - return nil, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) - {{- else }} - return nil, xerrors.WithStackTrace(err) - {{- end }} - } - items = append(items, {{.Ret.ReturnName}}) - } + var {{.Ret.Name}} {{.Ret.Type}} + if err := row.Scan({{.Ret.Scan}}); err != nil { + {{- if $.WrapErrors}} + return nil, xerrors.WithStackTrace(fmt.Errorf("query {{.MethodName}}: %w", err)) + {{- else }} + return nil, xerrors.WithStackTrace(err) + {{- end }} + } + items = append(items, {{.Ret.ReturnName}}) } if err := result.Close(ctx); err != nil { {{- if $.WrapErrors}} @@ -125,8 +116,8 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBA {{- if .Arg.IsEmpty }} err := {{$dbArg}}.Exec(ctx, {{.ConstantName}}, opts...) {{- else }} - err := {{$dbArg}}.Exec(ctx, {{.ConstantName}}, - append(opts, query.WithParameters(ydb.ParamsFromMap(map[string]any{ {{.Arg.YDBParamMapEntries}} })))..., + err := {{$dbArg}}.Exec(ctx, {{.ConstantName}}, + append(opts, {{.Arg.YDBParamsBuilder}})..., ) {{- end }} if err != nil { diff --git a/internal/codegen/golang/ydb_type.go b/internal/codegen/golang/ydb_type.go index e9e5c46344..0ef665aee1 100644 --- a/internal/codegen/golang/ydb_type.go +++ b/internal/codegen/golang/ydb_type.go @@ -151,6 +151,24 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col // return "sql.NullInt64" return "*int64" + case "json", "jsondocument": + if notNull { + return "string" + } + if emitPointersForNull { + return "*string" + } + return "*string" + + case "date", "date32", "datetime", "timestamp", "tzdate", "tztimestamp", "tzdatetime": + if notNull { + return "time.Time" + } + if emitPointersForNull { + return "*time.Time" + } + return "*time.Time" + case "null": // return "sql.Null" return "interface{}" diff --git a/internal/engine/ydb/catalog_tests/create_table_test.go b/internal/engine/ydb/catalog_tests/create_table_test.go index e98288d75a..7761118927 100644 --- a/internal/engine/ydb/catalog_tests/create_table_test.go +++ b/internal/engine/ydb/catalog_tests/create_table_test.go @@ -106,7 +106,7 @@ func TestCreateTable(t *testing.T) { { Name: "amount", Type: ast.TypeName{ - Name: "Decimal", + Name: "decimal", Names: &ast.List{ Items: []ast.Node{ &ast.Integer{Ival: 22}, diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index 250dc467e0..e173cf287e 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -1582,7 +1582,7 @@ func (c *cc) convertTypeName(n parser.IType_nameContext) *ast.TypeName { if decimal := n.Type_name_decimal(); decimal != nil { if integerOrBinds := decimal.AllInteger_or_bind(); len(integerOrBinds) >= 2 { return &ast.TypeName{ - Name: "Decimal", + Name: "decimal", TypeOid: 0, Names: &ast.List{ Items: []ast.Node{ From 1379e43d2e5b508d0afed705e133cbd1db94dbd5 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov <150552906+1NepuNep1@users.noreply.github.com> Date: Tue, 23 Sep 2025 12:27:49 +0300 Subject: [PATCH 15/22] Rewrited convert to Visitor Interface from ANTLR4 + fixed some types casts & error texts (#12) * Rewrited ydb convert to Visitor Interface + validated type casts and error texts --- go.mod | 2 +- go.sum | 8 +- internal/engine/ydb/convert.go | 1805 +++++++++++++++++--------------- internal/engine/ydb/parse.go | 5 +- internal/engine/ydb/utils.go | 78 +- 5 files changed, 1053 insertions(+), 845 deletions(-) diff --git a/go.mod b/go.mod index c72f29b6b1..4b755a4baa 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/wasilibs/go-pgquery v0.0.0-20250409022910-10ac41983c07 github.com/xeipuuv/gojsonschema v1.2.0 github.com/ydb-platform/ydb-go-sdk/v3 v3.115.3 - github.com/ydb-platform/yql-parsers v0.0.0-20250309001738-7d693911f333 + github.com/ydb-platform/yql-parsers v0.0.0-20250911122629-e8a65d734cbd golang.org/x/sync v0.16.0 google.golang.org/grpc v1.75.0 google.golang.org/protobuf v1.36.8 diff --git a/go.sum b/go.sum index 53cb8e8aec..eb68917f04 100644 --- a/go.sum +++ b/go.sum @@ -144,8 +144,6 @@ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= -github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg= -github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8= github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I= github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -242,12 +240,10 @@ github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17 github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77 h1:LY6cI8cP4B9rrpTleZk95+08kl2gF4rixG7+V/dwL6Q= github.com/ydb-platform/ydb-go-genproto v0.0.0-20241112172322-ea1f63298f77/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= -github.com/ydb-platform/ydb-go-sdk/v3 v3.108.0 h1:TwWSp3gRMcja/hRpOofncLvgxAXCmzpz5cGtmdaoITw= -github.com/ydb-platform/ydb-go-sdk/v3 v3.108.0/go.mod h1:l5sSv153E18VvYcsmr51hok9Sjc16tEC8AXGbwrk+ho= github.com/ydb-platform/ydb-go-sdk/v3 v3.115.3 h1:SFeSK2c+PmiToyNIhr143u+YDzLhl/kboXwKLYDk0O4= github.com/ydb-platform/ydb-go-sdk/v3 v3.115.3/go.mod h1:Pp1w2xxUoLQ3NCNAwV7pvDq0TVQOdtAqs+ZiC+i8r14= -github.com/ydb-platform/yql-parsers v0.0.0-20250309001738-7d693911f333 h1:KFtJwlPdOxWjCKXX0jFJ8k1FlbqbRbUW3k/kYSZX7SA= -github.com/ydb-platform/yql-parsers v0.0.0-20250309001738-7d693911f333/go.mod h1:vrPJPS8cdPSV568YcXhB4bUwhyV8bmWKqmQ5c5Xi99o= +github.com/ydb-platform/yql-parsers v0.0.0-20250911122629-e8a65d734cbd h1:ZfUkkZ1m5JCAw7jHQavecv+gKJWA6SNxuKLqHQ5/988= +github.com/ydb-platform/yql-parsers v0.0.0-20250911122629-e8a65d734cbd/go.mod h1:vrPJPS8cdPSV568YcXhB4bUwhyV8bmWKqmQ5c5Xi99o= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index e173cf287e..8b67191ce6 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -12,8 +12,8 @@ import ( ) type cc struct { - paramCount int - content string + parser.BaseYQLVisitor + content string } func (c *cc) pos(token antlr.Token) int { @@ -54,9 +54,9 @@ func NewIdentifier(t string) *ast.String { return &ast.String{Str: identifier(t)} } -func (c *cc) convertDrop_role_stmtContext(n *parser.Drop_role_stmtContext) ast.Node { +func (c *cc) VisitDrop_role_stmt(n *parser.Drop_role_stmtContext) interface{} { if n.DROP() == nil || (n.USER() == nil && n.GROUP() == nil) || len(n.AllRole_name()) == 0 { - return todo("Drop_role_stmtContext", n) + return todo("VisitDrop_role_stmt", n) } stmt := &ast.DropRoleStmt{ @@ -67,7 +67,7 @@ func (c *cc) convertDrop_role_stmtContext(n *parser.Drop_role_stmtContext) ast.N for _, role := range n.AllRole_name() { member, isParam, _ := c.extractRoleSpec(role, ast.RoleSpecType(1)) if member == nil { - return todo("Drop_role_stmtContext", n) + return todo("VisitDrop_role_stmt", role) } if debug.Active && isParam { @@ -80,13 +80,13 @@ func (c *cc) convertDrop_role_stmtContext(n *parser.Drop_role_stmtContext) ast.N return stmt } -func (c *cc) convertAlter_group_stmtContext(n *parser.Alter_group_stmtContext) ast.Node { +func (c *cc) VisitAlter_group_stmt(n *parser.Alter_group_stmtContext) interface{} { if n.ALTER() == nil || n.GROUP() == nil || len(n.AllRole_name()) == 0 { - return todo("convertAlter_group_stmtContext", n) + return todo("VisitAlter_group_stmt", n) } role, paramFlag, _ := c.extractRoleSpec(n.Role_name(0), ast.RoleSpecType(1)) if role == nil { - return todo("convertAlter_group_stmtContext", n) + return todo("VisitAlter_group_stmt", n) } if debug.Active && paramFlag { @@ -101,7 +101,10 @@ func (c *cc) convertAlter_group_stmtContext(n *parser.Alter_group_stmtContext) a switch { case n.RENAME() != nil && n.TO() != nil && len(n.AllRole_name()) > 1: - newName := c.convert(n.Role_name(1)) + newName, ok := n.Role_name(1).Accept(c).(ast.Node) + if !ok { + return todo("VisitAlter_group_stmt", n.Role_name(1)) + } action := "rename" defElem := &ast.DefElem{ @@ -120,12 +123,12 @@ func (c *cc) convertAlter_group_stmtContext(n *parser.Alter_group_stmtContext) a case *ast.Boolean: defElem.Arg = val default: - return todo("convertAlter_group_stmtContext", n) + return todo("VisitAlter_group_stmt", n.Role_name(1)) } case *ast.ParamRef, *ast.A_Expr: defElem.Arg = newName default: - return todo("convertAlter_group_stmtContext", n) + return todo("VisitAlter_group_stmt", n.Role_name(1)) } if debug.Active && !paramFlag && bindFlag { @@ -140,7 +143,7 @@ func (c *cc) convertAlter_group_stmtContext(n *parser.Alter_group_stmtContext) a for _, role := range n.AllRole_name()[1:] { member, isParam, _ := c.extractRoleSpec(role, ast.RoleSpecType(1)) if member == nil { - return todo("convertAlter_group_stmtContext", n) + return todo("VisitAlter_group_stmt", role) } if debug.Active && isParam && !paramFlag { @@ -161,21 +164,21 @@ func (c *cc) convertAlter_group_stmtContext(n *parser.Alter_group_stmtContext) a Defname: &defname, Arg: optionList, Defaction: action, - Location: c.pos(n.GetStart()), + Location: c.pos(n.Role_name(1).GetStart()), }) } return stmt } -func (c *cc) convertAlter_user_stmtContext(n *parser.Alter_user_stmtContext) ast.Node { +func (c *cc) VisitAlter_user_stmt(n *parser.Alter_user_stmtContext) interface{} { if n.ALTER() == nil || n.USER() == nil || len(n.AllRole_name()) == 0 { - return todo("Alter_user_stmtContext", n) + return todo("VisitAlter_user_stmt", n) } role, paramFlag, _ := c.extractRoleSpec(n.Role_name(0), ast.RoleSpecType(1)) if role == nil { - return todo("convertAlter_group_stmtContext", n) + return todo("VisitAlter_group_stmt", n) } if debug.Active && paramFlag { @@ -190,7 +193,10 @@ func (c *cc) convertAlter_user_stmtContext(n *parser.Alter_user_stmtContext) ast switch { case n.RENAME() != nil && n.TO() != nil && len(n.AllRole_name()) > 1: - newName := c.convert(n.Role_name(1)) + newName, ok := n.Role_name(1).Accept(c).(ast.Node) + if !ok { + return todo("VisitAlter_user_stmt", n.Role_name(1)) + } action := "rename" defElem := &ast.DefElem{ @@ -209,12 +215,12 @@ func (c *cc) convertAlter_user_stmtContext(n *parser.Alter_user_stmtContext) ast case *ast.Boolean: defElem.Arg = val default: - return todo("Alter_user_stmtContext", n) + return todo("VisitAlter_user_stmt", n.Role_name(1)) } case *ast.ParamRef, *ast.A_Expr: defElem.Arg = newName default: - return todo("Alter_user_stmtContext", n) + return todo("VisitAlter_user_stmt", n.Role_name(1)) } if debug.Active && !paramFlag && bindFlag { @@ -225,7 +231,11 @@ func (c *cc) convertAlter_user_stmtContext(n *parser.Alter_user_stmtContext) ast case len(n.AllUser_option()) > 0: for _, opt := range n.AllUser_option() { - if node := c.convert(opt); node != nil { + if temp := opt.Accept(c); temp != nil { + var node, ok = temp.(ast.Node) + if !ok { + return todo("VisitAlter_user_stmt", opt) + } stmt.Options.Items = append(stmt.Options.Items, node) } } @@ -234,11 +244,14 @@ func (c *cc) convertAlter_user_stmtContext(n *parser.Alter_user_stmtContext) ast return stmt } -func (c *cc) convertCreate_group_stmtContext(n *parser.Create_group_stmtContext) ast.Node { +func (c *cc) VisitCreate_group_stmt(n *parser.Create_group_stmtContext) interface{} { if n.CREATE() == nil || n.GROUP() == nil || len(n.AllRole_name()) == 0 { - return todo("Create_group_stmtContext", n) + return todo("VisitCreate_group_stmt", n) + } + groupName, ok := n.Role_name(0).Accept(c).(ast.Node) + if !ok { + return todo("VisitCreate_group_stmt", n.Role_name(0)) } - groupName := c.convert(n.Role_name(0)) stmt := &ast.CreateRoleStmt{ StmtType: ast.RoleStmtType(3), @@ -255,12 +268,12 @@ func (c *cc) convertCreate_group_stmtContext(n *parser.Create_group_stmtContext) case *ast.Boolean: stmt.BindRole = groupName default: - return todo("convertCreate_group_stmtContext", n) + return todo("VisitCreate_group_stmt", n.Role_name(0)) } case *ast.ParamRef, *ast.A_Expr: stmt.BindRole = groupName default: - return todo("convertCreate_group_stmtContext", n) + return todo("VisitCreate_group_stmt", n.Role_name(0)) } if debug.Active && paramFlag { @@ -273,7 +286,7 @@ func (c *cc) convertCreate_group_stmtContext(n *parser.Create_group_stmtContext) for _, role := range n.AllRole_name()[1:] { member, isParam, _ := c.extractRoleSpec(role, ast.RoleSpecType(1)) if member == nil { - return todo("convertCreate_group_stmtContext", n) + return todo("VisitCreate_group_stmt", role) } if debug.Active && isParam && !paramFlag { @@ -286,26 +299,29 @@ func (c *cc) convertCreate_group_stmtContext(n *parser.Create_group_stmtContext) stmt.Options.Items = append(stmt.Options.Items, &ast.DefElem{ Defname: &defname, Arg: optionList, - Location: c.pos(n.GetStart()), + Location: c.pos(n.Role_name(1).GetStart()), }) } return stmt } -func (c *cc) convertUse_stmtContext(n *parser.Use_stmtContext) ast.Node { +func (c *cc) VisitUse_stmt(n *parser.Use_stmtContext) interface{} { if n.USE() != nil && n.Cluster_expr() != nil { - clusterExpr := c.convert(n.Cluster_expr()) + clusterExpr, ok := n.Cluster_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitUse_stmt", n.Cluster_expr()) + } stmt := &ast.UseStmt{ Xpr: clusterExpr, - Location: c.pos(n.GetStart()), + Location: c.pos(n.Cluster_expr().GetStart()), } return stmt } - return todo("convertUse_stmtContext", n) + return todo("VisitUse_stmt", n) } -func (c *cc) convertCluster_exprContext(n *parser.Cluster_exprContext) ast.Node { +func (c *cc) VisitCluster_expr(n *parser.Cluster_exprContext) interface{} { var node ast.Node switch { @@ -318,12 +334,16 @@ func (c *cc) convertCluster_exprContext(n *parser.Cluster_exprContext) ast.Node Location: c.pos(anID.GetStart()), } } else if bp := pureCtx.Bind_parameter(); bp != nil { - node = c.convert(bp) + temp, ok := bp.Accept(c).(ast.Node) + if !ok { + return todo("VisitCluster_expr", bp) + } + node = temp } case n.ASTERISK() != nil: node = &ast.A_Star{} default: - return todo("convertCluster_exprContext", n) + return todo("VisitCluster_expr", n) } if n.An_id() != nil && n.COLON() != nil { @@ -339,11 +359,14 @@ func (c *cc) convertCluster_exprContext(n *parser.Cluster_exprContext) ast.Node return node } -func (c *cc) convertCreate_user_stmtContext(n *parser.Create_user_stmtContext) ast.Node { +func (c *cc) VisitCreate_user_stmt(n *parser.Create_user_stmtContext) interface{} { if n.CREATE() == nil || n.USER() == nil || n.Role_name() == nil { - return todo("convertCreate_user_stmtContext", n) + return todo("VisitCreate_user_stmt", n) + } + roleNode, ok := n.Role_name().Accept(c).(ast.Node) + if !ok { + return todo("VisitCreate_user_stmt", n.Role_name()) } - roleNode := c.convert(n.Role_name()) stmt := &ast.CreateRoleStmt{ StmtType: ast.RoleStmtType(2), @@ -360,12 +383,12 @@ func (c *cc) convertCreate_user_stmtContext(n *parser.Create_user_stmtContext) a case *ast.Boolean: stmt.BindRole = roleNode default: - return todo("convertCreate_user_stmtContext", n) + return todo("VisitCreate_user_stmt", n.Role_name()) } case *ast.ParamRef, *ast.A_Expr: stmt.BindRole = roleNode default: - return todo("convertCreate_user_stmtContext", n) + return todo("VisitCreate_user_stmt", n.Role_name()) } if debug.Active && paramFlag { @@ -375,7 +398,11 @@ func (c *cc) convertCreate_user_stmtContext(n *parser.Create_user_stmtContext) a if len(n.AllUser_option()) > 0 { options := []ast.Node{} for _, opt := range n.AllUser_option() { - if node := c.convert(opt); node != nil { + if temp := opt.Accept(c); temp != nil { + node, ok := temp.(ast.Node) + if !ok { + return todo("VisitCreate_user_stmt", opt) + } options = append(options, node) } } @@ -386,7 +413,7 @@ func (c *cc) convertCreate_user_stmtContext(n *parser.Create_user_stmtContext) a return stmt } -func (c *cc) convertUser_optionContext(n *parser.User_optionContext) ast.Node { +func (c *cc) VisitUser_option(n *parser.User_optionContext) interface{} { switch { case n.Authentication_option() != nil: aOpt := n.Authentication_option() @@ -436,40 +463,43 @@ func (c *cc) convertUser_optionContext(n *parser.User_optionContext) ast.Node { Location: c.pos(lOpt.GetStart()), } default: - return todo("convertUser_optionContext", n) + return todo("VisitUser_option", n) } - return nil + return todo("VisitUser_option", n) } -func (c *cc) convertRole_nameContext(n *parser.Role_nameContext) ast.Node { +func (c *cc) VisitRole_name(n *parser.Role_nameContext) interface{} { switch { case n.An_id_or_type() != nil: name := parseAnIdOrType(n.An_id_or_type()) - return &ast.A_Const{Val: NewIdentifier(name), Location: c.pos(n.GetStart())} + return &ast.A_Const{Val: NewIdentifier(name), Location: c.pos(n.An_id_or_type().GetStart())} case n.Bind_parameter() != nil: - bindPar := c.convert(n.Bind_parameter()) + bindPar, ok := n.Bind_parameter().Accept(c).(ast.Node) + if !ok { + return todo("VisitRole_name", n.Bind_parameter()) + } return bindPar } - return todo("convertRole_nameContext", n) + return todo("VisitRole_name", n) } -func (c *cc) convertCommit_stmtContext(n *parser.Commit_stmtContext) ast.Node { +func (c *cc) VisitCommit_stmt(n *parser.Commit_stmtContext) interface{} { if n.COMMIT() != nil { return &ast.TransactionStmt{Kind: ast.TransactionStmtKind(3)} } - return todo("convertCommit_stmtContext", n) + return todo("VisitCommit_stmt", n) } -func (c *cc) convertRollback_stmtContext(n *parser.Rollback_stmtContext) ast.Node { +func (c *cc) VisitRollback_stmt(n *parser.Rollback_stmtContext) interface{} { if n.ROLLBACK() != nil { return &ast.TransactionStmt{Kind: ast.TransactionStmtKind(4)} } - return todo("convertRollback_stmtContext", n) + return todo("VisitRollback_stmt", n) } -func (c *cc) convertAlter_table_stmtContext(n *parser.Alter_table_stmtContext) ast.Node { +func (c *cc) VisitAlter_table_stmt(n *parser.Alter_table_stmtContext) interface{} { if n.ALTER() == nil || n.TABLE() == nil || n.Simple_table_ref() == nil || len(n.AllAlter_table_action()) == 0 { - return todo("convertAlter_table_stmtContext", n) + return todo("VisitAlter_table_stmt", n) } stmt := &ast.AlterTableStmt{ @@ -486,7 +516,14 @@ func (c *cc) convertAlter_table_stmtContext(n *parser.Alter_table_stmtContext) a case action.Alter_table_add_column() != nil: ac := action.Alter_table_add_column() if ac.ADD() != nil && ac.Column_schema() != nil { - columnDef := c.convertColumnSchema(ac.Column_schema().(*parser.Column_schemaContext)) + temp, ok := ac.Column_schema().Accept(c).(ast.Node) + if !ok { + return todo("VisitAlter_table_stmt", ac.Column_schema()) + } + columnDef, ok := temp.(*ast.ColumnDef) + if !ok { + return todo("VisitAlter_table_stmt", ac.Column_schema()) + } stmt.Cmds.Items = append(stmt.Cmds.Items, &ast.AlterTableCmd{ Name: &columnDef.Colname, Subtype: ast.AT_AddColumn, @@ -514,7 +551,7 @@ func (c *cc) convertAlter_table_stmtContext(n *parser.Alter_table_stmtContext) a case action.Alter_table_rename_to() != nil: ac := action.Alter_table_rename_to() if ac.RENAME() != nil && ac.TO() != nil && ac.An_id_table() != nil { - // TODO: Returning here may be incorrect if there are multiple specs + // FIXME: Returning here may be incorrect if there are multiple specs newName := parseAnIdTable(ac.An_id_table()) return &ast.RenameTableStmt{ Table: stmt.Table, @@ -541,25 +578,33 @@ func (c *cc) convertAlter_table_stmtContext(n *parser.Alter_table_stmtContext) a return stmt } -func (c *cc) convertDo_stmtContext(n *parser.Do_stmtContext) ast.Node { +func (c *cc) VisitDo_stmt(n *parser.Do_stmtContext) interface{} { if n.DO() == nil || (n.Call_action() == nil && n.Inline_action() == nil) { - return todo("convertDo_stmtContext", n) + return todo("VisitDo_stmt", n) } switch { case n.Call_action() != nil: - return c.convert(n.Call_action()) + result, ok := n.Call_action().Accept(c).(ast.Node) + if !ok { + return todo("VisitDo_stmt", n.Call_action()) + } + return result case n.Inline_action() != nil: - return c.convert(n.Inline_action()) + result, ok := n.Inline_action().Accept(c).(ast.Node) + if !ok { + return todo("VisitDo_stmt", n.Inline_action()) + } + return result } - return todo("convertDo_stmtContext", n) + return todo("VisitDo_stmt", n) } -func (c *cc) convertCall_actionContext(n *parser.Call_actionContext) ast.Node { +func (c *cc) VisitCall_action(n *parser.Call_actionContext) interface{} { if n == nil { - return nil + return todo("VisitCall_action", n) } if n.LPAREN() != nil && n.RPAREN() != nil { funcCall := &ast.FuncCall{ @@ -569,14 +614,22 @@ func (c *cc) convertCall_actionContext(n *parser.Call_actionContext) ast.Node { } if n.Bind_parameter() != nil { - funcCall.Funcname.Items = append(funcCall.Funcname.Items, c.convert(n.Bind_parameter())) + bindPar, ok := n.Bind_parameter().Accept(c).(ast.Node) + if !ok { + return todo("VisitCall_action", n.Bind_parameter()) + } + funcCall.Funcname.Items = append(funcCall.Funcname.Items, bindPar) } else if n.EMPTY_ACTION() != nil { funcCall.Funcname.Items = append(funcCall.Funcname.Items, &ast.String{Str: "EMPTY_ACTION"}) } if n.Expr_list() != nil { for _, expr := range n.Expr_list().AllExpr() { - funcCall.Args.Items = append(funcCall.Args.Items, c.convert(expr)) + exprNode, ok := expr.Accept(c).(ast.Node) + if !ok { + return todo("VisitCall_action", expr) + } + funcCall.Args.Items = append(funcCall.Args.Items, exprNode) } } @@ -584,29 +637,33 @@ func (c *cc) convertCall_actionContext(n *parser.Call_actionContext) ast.Node { Args: &ast.List{Items: []ast.Node{funcCall}}, } } - return todo("convertCall_actionContext", n) + return todo("VisitCall_action", n) } -func (c *cc) convertInline_actionContext(n *parser.Inline_actionContext) ast.Node { +func (c *cc) VisitInline_action(n *parser.Inline_actionContext) interface{} { if n == nil { - return nil + return todo("VisitInline_action", n) } if n.BEGIN() != nil && n.END() != nil && n.DO() != nil { args := &ast.List{} if defineBody := n.Define_action_or_subquery_body(); defineBody != nil { cores := defineBody.AllSql_stmt_core() for _, stmtCore := range cores { - if converted := c.convert(stmtCore); converted != nil { - args.Items = append(args.Items, converted) + if converted := stmtCore.Accept(c); converted != nil { + var convertedNode, ok = converted.(ast.Node) + if !ok { + return todo("VisitInline_action", stmtCore) + } + args.Items = append(args.Items, convertedNode) } } } return &ast.DoStmt{Args: args} } - return todo("convertInline_actionContext", n) + return todo("VisitInline_action", n) } -func (c *cc) convertDrop_table_stmtContext(n *parser.Drop_table_stmtContext) ast.Node { +func (c *cc) VisitDrop_table_stmt(n *parser.Drop_table_stmtContext) interface{} { if n.DROP() != nil && (n.TABLESTORE() != nil || (n.EXTERNAL() != nil && n.TABLE() != nil) || n.TABLE() != nil) { name := parseTableName(n.Simple_table_ref().Simple_table_ref_core()) stmt := &ast.DropTableStmt{ @@ -615,10 +672,10 @@ func (c *cc) convertDrop_table_stmtContext(n *parser.Drop_table_stmtContext) ast } return stmt } - return todo("convertDrop_Table_stmtContxt", n) + return todo("VisitDrop_table_stmt", n) } -func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { +func (c *cc) VisitDelete_stmt(n *parser.Delete_stmtContext) interface{} { batch := n.BATCH() != nil tableName := identifier(n.Simple_table_ref().Simple_table_ref_core().GetText()) @@ -626,7 +683,11 @@ func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { var where ast.Node if n.WHERE() != nil && n.Expr() != nil { - where = c.convert(n.Expr()) + whereNode, ok := n.Expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitDelete_stmt", n.Expr()) + } + where = whereNode } var cols *ast.List var source ast.Node @@ -649,17 +710,37 @@ func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { switch { case valSource.Values_stmt() != nil: stmt := emptySelectStmt() - stmt.ValuesLists = c.convert(valSource.Values_stmt()).(*ast.List) + temp, ok := valSource.Values_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitDelete_stmt", valSource.Values_stmt()) + } + list, ok := temp.(*ast.List) + if !ok { + return todo("VisitDelete_stmt", valSource.Values_stmt()) + } + stmt.ValuesLists = list source = stmt case valSource.Select_stmt() != nil: - source = c.convert(valSource.Select_stmt()) + temp, ok := valSource.Select_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitDelete_stmt", valSource.Select_stmt()) + } + source = temp } } } returning := &ast.List{} if ret := n.Returning_columns_list(); ret != nil { - returning = c.convert(ret).(*ast.List) + temp, ok := ret.Accept(c).(ast.Node) + if !ok { + return todo("VisitDelete_stmt", n.Returning_columns_list()) + } + returningNode, ok := temp.(*ast.List) + if !ok { + return todo("VisitDelete_stmt", n.Returning_columns_list()) + } + returning = returningNode } stmts := &ast.DeleteStmt{ @@ -674,7 +755,7 @@ func (c *cc) convertDelete_stmtContext(n *parser.Delete_stmtContext) ast.Node { return stmts } -func (c *cc) convertPragma_stmtContext(n *parser.Pragma_stmtContext) ast.Node { +func (c *cc) VisitPragma_stmt(n *parser.Pragma_stmtContext) interface{} { if n.PRAGMA() != nil && n.An_id() != nil { prefix := "" if p := n.Opt_id_prefix_or_type(); p != nil { @@ -696,22 +777,30 @@ func (c *cc) convertPragma_stmtContext(n *parser.Pragma_stmtContext) ast.Node { if n.EQUALS() != nil { stmt.Equals = true if val := n.Pragma_value(0); val != nil { - stmt.Values = &ast.List{Items: []ast.Node{c.convert(val)}} + valNode, ok := val.Accept(c).(ast.Node) + if !ok { + return todo("VisitPragma_stmt", n.Pragma_value(0)) + } + stmt.Values = &ast.List{Items: []ast.Node{valNode}} } } else if lp := n.LPAREN(); lp != nil { values := []ast.Node{} for _, v := range n.AllPragma_value() { - values = append(values, c.convert(v)) + valNode, ok := v.Accept(c).(ast.Node) + if !ok { + return todo("VisitPragma_stmt", v) + } + values = append(values, valNode) } stmt.Values = &ast.List{Items: values} } return stmt } - return todo("convertPragma_stmtContext", n) + return todo("VisitPragma_stmt", n) } -func (c *cc) convertPragma_valueContext(n *parser.Pragma_valueContext) ast.Node { +func (c *cc) VisitPragma_value(n *parser.Pragma_valueContext) interface{} { switch { case n.Signed_number() != nil: if n.Signed_number().Integer() != nil { @@ -742,16 +831,20 @@ func (c *cc) convertPragma_valueContext(n *parser.Pragma_valueContext) ast.Node } return &ast.A_Const{Val: &ast.Boolean{Boolval: i}, Location: c.pos(n.GetStart())} case n.Bind_parameter() != nil: - bindPar := c.convert(n.Bind_parameter()) - return bindPar + bindPar := n.Bind_parameter().Accept(c) + var bindParNode, ok = bindPar.(ast.Node) + if !ok { + return todo("VisitPragma_value", n.Bind_parameter()) + } + return bindParNode } - return todo("convertPragma_valueContext", n) + return todo("VisitPragma_value", n) } -func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { - if n.UPDATE() == nil { - return nil +func (c *cc) VisitUpdate_stmt(n *parser.Update_stmtContext) interface{} { + if n == nil || n.UPDATE() == nil { + return todo("VisitUpdate_stmt", n) } batch := n.BATCH() != nil @@ -772,7 +865,10 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { for _, clause := range nSet.Set_clause_list().AllSet_clause() { targetCtx := clause.Set_target() columnName := identifier(targetCtx.Column_name().GetText()) - expr := c.convert(clause.Expr()) + expr, ok := clause.Expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitUpdate_stmt", clause.Expr()) + } resTarget := &ast.ResTarget{ Name: &columnName, Val: expr, @@ -798,7 +894,11 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { Args: &ast.List{}, } for _, expr := range exprList.AllExpr() { - rowExpr.Args.Items = append(rowExpr.Args.Items, c.convert(expr)) + exprNode, ok := expr.Accept(c).(ast.Node) + if !ok { + return todo("VisitUpdate_stmt", expr) + } + rowExpr.Args.Items = append(rowExpr.Args.Items, exprNode) } } @@ -817,7 +917,11 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { } if n.WHERE() != nil && n.Expr() != nil { - where = c.convert(n.Expr()) + whereNode, ok := n.Expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitUpdate_stmt", n.Expr()) + } + where = whereNode } } else if n.ON() != nil && n.Into_values_source() != nil { @@ -841,17 +945,37 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { switch { case valSource.Values_stmt() != nil: stmt := emptySelectStmt() - stmt.ValuesLists = c.convert(valSource.Values_stmt()).(*ast.List) + temp, ok := valSource.Values_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitUpdate_stmt", valSource.Values_stmt()) + } + list, ok := temp.(*ast.List) + if !ok { + return todo("VisitUpdate_stmt", valSource.Values_stmt()) + } + stmt.ValuesLists = list source = stmt case valSource.Select_stmt() != nil: - source = c.convert(valSource.Select_stmt()) + temp, ok := valSource.Select_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitUpdate_stmt", valSource.Select_stmt()) + } + source = temp } } } returning := &ast.List{} if ret := n.Returning_columns_list(); ret != nil { - returning = c.convert(ret).(*ast.List) + temp, ok := ret.Accept(c).(ast.Node) + if !ok { + return todo("VisitDelete_stmt", n.Returning_columns_list()) + } + returningNode, ok := temp.(*ast.List) + if !ok { + return todo("VisitDelete_stmt", n.Returning_columns_list()) + } + returning = returningNode } stmts := &ast.UpdateStmt{ @@ -869,7 +993,7 @@ func (c *cc) convertUpdate_stmtContext(n *parser.Update_stmtContext) ast.Node { return stmts } -func (c *cc) convertInto_table_stmtContext(n *parser.Into_table_stmtContext) ast.Node { +func (c *cc) VisitInto_table_stmt(n *parser.Into_table_stmtContext) interface{} { tableName := identifier(n.Into_simple_table_ref().Simple_table_ref().Simple_table_ref_core().GetText()) rel := &ast.RangeVar{ Relname: &tableName, @@ -911,17 +1035,37 @@ func (c *cc) convertInto_table_stmtContext(n *parser.Into_table_stmtContext) ast switch { case valSource.Values_stmt() != nil: stmt := emptySelectStmt() - stmt.ValuesLists = c.convert(valSource.Values_stmt()).(*ast.List) + temp, ok := valSource.Values_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitInto_table_stmt", valSource.Values_stmt()) + } + stmtNode, ok := temp.(*ast.List) + if !ok { + return todo("VisitInto_table_stmt", valSource.Values_stmt()) + } + stmt.ValuesLists = stmtNode source = stmt case valSource.Select_stmt() != nil: - source = c.convert(valSource.Select_stmt()) + sourceNode, ok := valSource.Select_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitInto_table_stmt", valSource.Select_stmt()) + } + source = sourceNode } } } returning := &ast.List{} if ret := n.Returning_columns_list(); ret != nil { - returning = c.convert(ret).(*ast.List) + temp, ok := ret.Accept(c).(ast.Node) + if !ok { + return todo("VisitInto_table_stmt", n.Returning_columns_list()) + } + returningNode, ok := temp.(*ast.List) + if !ok { + return todo("VisitInto_table_stmt", n.Returning_columns_list()) + } + returning = returningNode } stmts := &ast.InsertStmt{ @@ -935,7 +1079,7 @@ func (c *cc) convertInto_table_stmtContext(n *parser.Into_table_stmtContext) ast return stmts } -func (c *cc) convertValues_stmtContext(n *parser.Values_stmtContext) ast.Node { +func (c *cc) VisitValues_stmt(n *parser.Values_stmtContext) interface{} { mainList := &ast.List{} for _, rowCtx := range n.Values_source_row_list().AllValues_source_row() { @@ -943,8 +1087,12 @@ func (c *cc) convertValues_stmtContext(n *parser.Values_stmtContext) ast.Node { exprListCtx := rowCtx.Expr_list().(*parser.Expr_listContext) for _, exprCtx := range exprListCtx.AllExpr() { - if converted := c.convert(exprCtx); converted != nil { - rowList.Items = append(rowList.Items, converted) + if converted := exprCtx.Accept(c); converted != nil { + var convertedNode, ok = converted.(ast.Node) + if !ok { + return todo("VisitValues_stmt", exprCtx) + } + rowList.Items = append(rowList.Items, convertedNode) } } @@ -955,7 +1103,7 @@ func (c *cc) convertValues_stmtContext(n *parser.Values_stmtContext) ast.Node { return mainList } -func (c *cc) convertReturning_columns_listContext(n *parser.Returning_columns_listContext) ast.Node { +func (c *cc) VisitReturning_columns_list(n *parser.Returning_columns_listContext) interface{} { list := &ast.List{Items: []ast.Node{}} if n.ASTERISK() != nil { @@ -988,30 +1136,36 @@ func (c *cc) convertReturning_columns_listContext(n *parser.Returning_columns_li return list } -func (c *cc) convertSelectStmtContext(n *parser.Select_stmtContext) ast.Node { +func (c *cc) VisitSelect_stmt(n *parser.Select_stmtContext) interface{} { if len(n.AllSelect_kind_parenthesis()) == 0 { - return todo("convertSelectStmtContext", n) + return todo("VisitSelect_stmt", n) } skp := n.Select_kind_parenthesis(0) if skp == nil { - return todo("convertSelectStmtContext", skp) + return todo("VisitSelect_stmt", skp) } - stmt := c.convertSelectKindParenthesis(skp) - left, ok := stmt.(*ast.SelectStmt) + temp, ok := skp.Accept(c).(ast.Node) + if !ok { + return todo("VisitSelect_kind_parenthesis", skp) + } + left, ok := temp.(*ast.SelectStmt) if left == nil || !ok { - return todo("convertSelectKindParenthesis", skp) + return todo("VisitSelect_kind_parenthesis", skp) } kinds := n.AllSelect_kind_parenthesis() ops := n.AllSelect_op() for i := 1; i < len(kinds); i++ { - stmt := c.convertSelectKindParenthesis(kinds[i]) - right, ok := stmt.(*ast.SelectStmt) + temp, ok := kinds[i].Accept(c).(ast.Node) + if !ok { + return todo("VisitSelect_kind_parenthesis", kinds[i]) + } + right, ok := temp.(*ast.SelectStmt) if right == nil || !ok { - return todo("convertSelectKindParenthesis", kinds[i]) + return todo("VisitSelect_kind_parenthesis", kinds[i]) } var op ast.SetOperation @@ -1041,21 +1195,25 @@ func (c *cc) convertSelectStmtContext(n *parser.Select_stmtContext) ast.Node { return left } -func (c *cc) convertSelectKindParenthesis(n parser.ISelect_kind_parenthesisContext) ast.Node { +func (c *cc) VisitSelect_kind_parenthesis(n *parser.Select_kind_parenthesisContext) interface{} { if n == nil || n.Select_kind_partial() == nil { - return todo("convertSelectKindParenthesis", n) + return todo("VisitSelect_kind_parenthesis", n) } partial := n.Select_kind_partial() sk := partial.Select_kind() if sk == nil { - return todo("convertSelectKind", sk) + return todo("VisitSelect_kind_parenthesis", sk) } var base ast.Node switch { case sk.Select_core() != nil: - base = c.convertSelectCoreContext(sk.Select_core()) + baseNode, ok := sk.Select_core().Accept(c).(ast.Node) + if !ok { + return todo("VisitSelect_kind_parenthesis", sk.Select_core()) + } + base = baseNode case sk.Process_core() != nil: log.Fatalf("PROCESS is not supported in YDB engine") case sk.Reduce_core() != nil: @@ -1063,7 +1221,7 @@ func (c *cc) convertSelectKindParenthesis(n parser.ISelect_kind_parenthesisConte } stmt, ok := base.(*ast.SelectStmt) if !ok || stmt == nil { - return todo("convertSelectKindParenthesis", sk.Select_core()) + return todo("VisitSelect_kind_parenthesis", sk.Select_core()) } // TODO: handle INTO RESULT clause @@ -1071,11 +1229,19 @@ func (c *cc) convertSelectKindParenthesis(n parser.ISelect_kind_parenthesisConte if partial.LIMIT() != nil { exprs := partial.AllExpr() if len(exprs) >= 1 { - stmt.LimitCount = c.convert(exprs[0]) + temp, ok := exprs[0].Accept(c).(ast.Node) + if !ok { + return todo("VisitSelect_kind_parenthesis", exprs[0]) + } + stmt.LimitCount = temp } if partial.OFFSET() != nil { if len(exprs) >= 2 { - stmt.LimitOffset = c.convert(exprs[1]) + temp, ok := exprs[1].Accept(c).(ast.Node) + if !ok { + return todo("VisitSelect_kind_parenthesis", exprs[1]) + } + stmt.LimitOffset = temp } } } @@ -1083,7 +1249,7 @@ func (c *cc) convertSelectKindParenthesis(n parser.ISelect_kind_parenthesisConte return stmt } -func (c *cc) convertSelectCoreContext(n parser.ISelect_coreContext) ast.Node { +func (c *cc) VisitSelect_core(n *parser.Select_coreContext) interface{} { stmt := emptySelectStmt() if n.Opt_set_quantifier() != nil { oq := n.Opt_set_quantifier() @@ -1095,14 +1261,11 @@ func (c *cc) convertSelectCoreContext(n parser.ISelect_coreContext) ast.Node { if len(resultCols) > 0 { var items []ast.Node for _, rc := range resultCols { - resCol, ok := rc.(*parser.Result_columnContext) + convNode, ok := rc.Accept(c).(ast.Node) if !ok { - continue - } - convNode := c.convertResultColumn(resCol) - if convNode != nil { - items = append(items, convNode) + return todo("VisitSelect_core", rc) } + items = append(items, convNode) } stmt.TargetList = &ast.List{ Items: items, @@ -1118,15 +1281,11 @@ func (c *cc) convertSelectCoreContext(n parser.ISelect_coreContext) ast.Node { if len(jsList) > 0 { var fromItems []ast.Node for _, js := range jsList { - jsCon, ok := js.(*parser.Join_sourceContext) + joinNode, ok := js.Accept(c).(ast.Node) if !ok { - continue - } - - joinNode := c.convertJoinSource(jsCon) - if joinNode != nil { - fromItems = append(fromItems, joinNode) + return todo("VisitSelect_core", js) } + fromItems = append(fromItems, joinNode) } stmt.FromClause = &ast.List{ Items: fromItems, @@ -1136,13 +1295,21 @@ func (c *cc) convertSelectCoreContext(n parser.ISelect_coreContext) ast.Node { exprIdx := 0 if n.WHERE() != nil { if whereCtx := n.Expr(exprIdx); whereCtx != nil { - stmt.WhereClause = c.convert(whereCtx) + where, ok := whereCtx.Accept(c).(ast.Node) + if !ok { + return todo("VisitSelect_core", whereCtx) + } + stmt.WhereClause = where } exprIdx++ } if n.HAVING() != nil { if havingCtx := n.Expr(exprIdx); havingCtx != nil { - stmt.HavingClause = c.convert(havingCtx) + having, ok := havingCtx.Accept(c).(ast.Node) + if !ok || having == nil { + return todo("VisitSelect_core", havingCtx) + } + stmt.HavingClause = having } exprIdx++ } @@ -1151,7 +1318,11 @@ func (c *cc) convertSelectCoreContext(n parser.ISelect_coreContext) ast.Node { if gel := gbc.Grouping_element_list(); gel != nil { var groups []ast.Node for _, ne := range gel.AllGrouping_element() { - groups = append(groups, c.convert(ne)) + groupBy, ok := ne.Accept(c).(ast.Node) + if !ok { + return todo("VisitSelect_core", ne) + } + groups = append(groups, groupBy) } if len(groups) > 0 { stmt.GroupClause = &ast.List{Items: groups} @@ -1165,15 +1336,14 @@ func (c *cc) convertSelectCoreContext(n parser.ISelect_coreContext) ast.Node { if sl := ob.Sort_specification_list(); sl != nil { var orderItems []ast.Node for _, sp := range sl.AllSort_specification() { - ss, ok := sp.(*parser.Sort_specificationContext) - if !ok || ss == nil { - continue + expr, ok := sp.Expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitSelect_core", sp.Expr()) } - expr := c.convert(ss.Expr()) dir := ast.SortByDirDefault - if ss.ASC() != nil { + if sp.ASC() != nil { dir = ast.SortByDirAsc - } else if ss.DESC() != nil { + } else if sp.DESC() != nil { dir = ast.SortByDirDesc } orderItems = append(orderItems, &ast.SortBy{ @@ -1181,7 +1351,7 @@ func (c *cc) convertSelectCoreContext(n parser.ISelect_coreContext) ast.Node { SortbyDir: dir, SortbyNulls: ast.SortByNullsUndefined, UseOp: &ast.List{}, - Location: c.pos(ss.GetStart()), + Location: c.pos(sp.GetStart()), }) } if len(orderItems) > 0 { @@ -1193,77 +1363,109 @@ func (c *cc) convertSelectCoreContext(n parser.ISelect_coreContext) ast.Node { return stmt } -func (c *cc) convertGrouping_elementContext(n parser.IGrouping_elementContext) ast.Node { +func (c *cc) VisitGrouping_element(n *parser.Grouping_elementContext) interface{} { if n == nil { - return todo("convertGrouping_elementContext", n) + return todo("VisitGrouping_element", n) } if ogs := n.Ordinary_grouping_set(); ogs != nil { - return c.convert(ogs) + groupingSet, ok := ogs.Accept(c).(ast.Node) + if !ok { + return todo("VisitGrouping_element", ogs) + } + return groupingSet } if rl := n.Rollup_list(); rl != nil { - return c.convert(rl) + rollupList, ok := rl.Accept(c).(ast.Node) + if !ok { + return todo("VisitGrouping_element", rl) + } + return rollupList } if cl := n.Cube_list(); cl != nil { - return c.convert(cl) + cubeList, ok := cl.Accept(c).(ast.Node) + if !ok { + return todo("VisitGrouping_element", cl) + } + return cubeList } if gss := n.Grouping_sets_specification(); gss != nil { - return c.convert(gss) + groupingSets, ok := gss.Accept(c).(ast.Node) + if !ok { + return todo("VisitGrouping_element", gss) + } + return groupingSets } - return todo("convertGrouping_elementContext", n) + return todo("VisitGrouping_element", n) } -func (c *cc) convertOrdinary_grouping_setContext(n *parser.Ordinary_grouping_setContext) ast.Node { +func (c *cc) VisitOrdinary_grouping_set(n *parser.Ordinary_grouping_setContext) interface{} { if n == nil || n.Named_expr() == nil { - return todo("convertOrdinary_grouping_setContext", n) + return todo("VisitOrdinary_grouping_set", n) } - return c.convert(n.Named_expr()) + namedExpr, ok := n.Named_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitOrdinary_grouping_set", n.Named_expr()) + } + return namedExpr } -func (c *cc) convertRollup_listContext(n *parser.Rollup_listContext) ast.Node { +func (c *cc) VisitRollup_list(n *parser.Rollup_listContext) interface{} { if n == nil || n.ROLLUP() == nil || n.LPAREN() == nil || n.RPAREN() == nil { - return todo("convertRollup_listContext", n) + return todo("VisitRollup_list", n) } var items []ast.Node if list := n.Ordinary_grouping_set_list(); list != nil { for _, ogs := range list.AllOrdinary_grouping_set() { - items = append(items, c.convert(ogs)) + og, ok := ogs.Accept(c).(ast.Node) + if !ok { + return todo("VisitRollup_list", ogs) + } + items = append(items, og) } } return &ast.GroupingSet{Kind: 1, Content: &ast.List{Items: items}} } -func (c *cc) convertCube_listContext(n *parser.Cube_listContext) ast.Node { +func (c *cc) VisitCube_list(n *parser.Cube_listContext) interface{} { if n == nil || n.CUBE() == nil || n.LPAREN() == nil || n.RPAREN() == nil { - return todo("convertCube_listContext", n) + return todo("VisitCube_list", n) } var items []ast.Node if list := n.Ordinary_grouping_set_list(); list != nil { for _, ogs := range list.AllOrdinary_grouping_set() { - items = append(items, c.convert(ogs)) + og, ok := ogs.Accept(c).(ast.Node) + if !ok { + return todo("VisitCube_list", ogs) + } + items = append(items, og) } } return &ast.GroupingSet{Kind: 2, Content: &ast.List{Items: items}} } -func (c *cc) convertGrouping_sets_specificationContext(n *parser.Grouping_sets_specificationContext) ast.Node { +func (c *cc) VisitGrouping_sets_specification(n *parser.Grouping_sets_specificationContext) interface{} { if n == nil || n.GROUPING() == nil || n.SETS() == nil || n.LPAREN() == nil || n.RPAREN() == nil { - return todo("convertGrouping_sets_specificationContext", n) + return todo("VisitGrouping_sets_specification", n) } var items []ast.Node if gel := n.Grouping_element_list(); gel != nil { for _, ge := range gel.AllGrouping_element() { - items = append(items, c.convert(ge)) + g, ok := ge.Accept(c).(ast.Node) + if !ok { + return todo("VisitGrouping_sets_specification", ge) + } + items = append(items, g) } } return &ast.GroupingSet{Kind: 3, Content: &ast.List{Items: items}} } -func (c *cc) convertResultColumn(n *parser.Result_columnContext) ast.Node { +func (c *cc) VisitResult_column(n *parser.Result_columnContext) interface{} { // todo: support opt_id_prefix target := &ast.ResTarget{ Location: c.pos(n.GetStart()), @@ -1274,11 +1476,15 @@ func (c *cc) convertResultColumn(n *parser.Result_columnContext) ast.Node { case n.ASTERISK() != nil: val = c.convertWildCardField(n) case iexpr != nil: - val = c.convert(iexpr) + temp, ok := iexpr.Accept(c).(ast.Node) + if !ok { + return todo("VisitResult_column", iexpr) + } + val = temp } if val == nil { - return nil + return todo("VisitResult_column", n) } switch { case n.AS() != nil && n.An_id_or_type() != nil: @@ -1291,30 +1497,27 @@ func (c *cc) convertResultColumn(n *parser.Result_columnContext) ast.Node { return target } -func (c *cc) convertJoinSource(n *parser.Join_sourceContext) ast.Node { - if n == nil { - return nil +func (c *cc) VisitJoin_source(n *parser.Join_sourceContext) interface{} { + if n == nil || len(n.AllFlatten_source()) == 0 { + return todo("VisitJoin_source", n) } fsList := n.AllFlatten_source() - if len(fsList) == 0 { - return nil - } joinOps := n.AllJoin_op() joinConstraints := n.AllJoin_constraint() // todo: add ANY support - leftNode := c.convertFlattenSource(fsList[0]) - if leftNode == nil { - return nil + leftNode, ok := fsList[0].Accept(c).(ast.Node) + if !ok { + return todo("VisitJoin_source", fsList[0]) } for i, jopCtx := range joinOps { if i+1 >= len(fsList) { break } - rightNode := c.convertFlattenSource(fsList[i+1]) - if rightNode == nil { - return leftNode + rightNode, ok := fsList[i+1].Accept(c).(ast.Node) + if !ok { + return todo("VisitJoin_source", fsList[i+1]) } jexpr := &ast.JoinExpr{ Larg: leftNode, @@ -1343,7 +1546,11 @@ func (c *cc) convertJoinSource(n *parser.Join_sourceContext) ast.Node { switch { case jc.ON() != nil: if exprCtx := jc.Expr(); exprCtx != nil { - jexpr.Quals = c.convert(exprCtx) + expr, ok := exprCtx.Accept(c).(ast.Node) + if !ok { + return todo("VisitJoin_source", exprCtx) + } + jexpr.Quals = expr } case jc.USING() != nil: if pureListCtx := jc.Pure_column_or_named_list(); pureListCtx != nil { @@ -1353,12 +1560,17 @@ func (c *cc) convertJoinSource(n *parser.Join_sourceContext) ast.Node { if anID := pureCtx.An_id(); anID != nil { using.Items = append(using.Items, NewIdentifier(parseAnId(anID))) } else if bp := pureCtx.Bind_parameter(); bp != nil { - bindPar := c.convert(bp) + bindPar, ok := bp.Accept(c).(ast.Node) + if !ok { + return todo("VisitJoin_source", bp) + } using.Items = append(using.Items, bindPar) } } jexpr.UsingClause = &using } + default: + return todo("VisitJoin_source", jc) } } } @@ -1367,31 +1579,25 @@ func (c *cc) convertJoinSource(n *parser.Join_sourceContext) ast.Node { return leftNode } -func (c *cc) convertFlattenSource(n parser.IFlatten_sourceContext) ast.Node { - if n == nil { - return nil - } - nss := n.Named_single_source() - if nss == nil { - return nil +func (c *cc) VisitFlatten_source(n *parser.Flatten_sourceContext) interface{} { + if n == nil || n.Named_single_source() == nil { + return todo("VisitFlatten_source", n) } - namedSingleSource, ok := nss.(*parser.Named_single_sourceContext) + namedSingleSource, ok := n.Named_single_source().Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitFlatten_source", n.Named_single_source()) } - return c.convertNamedSingleSource(namedSingleSource) + return namedSingleSource } -func (c *cc) convertNamedSingleSource(n *parser.Named_single_sourceContext) ast.Node { - ss := n.Single_source() - if ss == nil { - return nil +func (c *cc) VisitNamed_single_source(n *parser.Named_single_sourceContext) interface{} { + if n == nil || n.Single_source() == nil { + return todo("VisitNamed_single_source", n) } - SingleSource, ok := ss.(*parser.Single_sourceContext) + base, ok := n.Single_source().Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitNamed_single_source", n.Single_source()) } - base := c.convertSingleSource(SingleSource) if n.AS() != nil && n.An_id() != nil { aliasText := parseAnId(n.An_id()) @@ -1407,7 +1613,11 @@ func (c *cc) convertNamedSingleSource(n *parser.Named_single_sourceContext) ast. return base } -func (c *cc) convertSingleSource(n *parser.Single_sourceContext) ast.Node { +func (c *cc) VisitSingle_source(n *parser.Single_sourceContext) interface{} { + if n == nil { + return todo("VisitSingle_source", n) + } + if n.Table_ref() != nil { tableName := n.Table_ref().GetText() // !! debug !! return &ast.RangeVar{ @@ -1417,7 +1627,10 @@ func (c *cc) convertSingleSource(n *parser.Single_sourceContext) ast.Node { } if n.Select_stmt() != nil { - subquery := c.convert(n.Select_stmt()) + subquery, ok := n.Select_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitSingle_source", n.Select_stmt()) + } return &ast.RangeSubselect{ Subquery: subquery, } @@ -1425,35 +1638,30 @@ func (c *cc) convertSingleSource(n *parser.Single_sourceContext) ast.Node { } // todo: Values stmt - return nil + return todo("VisitSingle_source", n) } -func (c *cc) convertBindParameter(n *parser.Bind_parameterContext) ast.Node { - // !!debug later!! - if n.DOLLAR() != nil { - if n.TRUE() != nil { - return &ast.A_Const{Val: &ast.Boolean{Boolval: true}, Location: c.pos(n.GetStart())} - } - if n.FALSE() != nil { - return &ast.A_Const{Val: &ast.Boolean{Boolval: false}, Location: c.pos(n.GetStart())} - } +func (c *cc) VisitBind_parameter(n *parser.Bind_parameterContext) interface{} { + if n == nil || n.DOLLAR() == nil { + return todo("VisitBind_parameter", n) + } - if an := n.An_id_or_type(); an != nil { - idText := parseAnIdOrType(an) - return &ast.A_Expr{ - Name: &ast.List{Items: []ast.Node{&ast.String{Str: "@"}}}, - Rexpr: &ast.String{Str: idText}, - Location: c.pos(n.GetStart()), - } - } - c.paramCount++ - return &ast.ParamRef{ - Number: c.paramCount, + if n.TRUE() != nil { + return &ast.A_Const{Val: &ast.Boolean{Boolval: true}, Location: c.pos(n.GetStart())} + } + if n.FALSE() != nil { + return &ast.A_Const{Val: &ast.Boolean{Boolval: false}, Location: c.pos(n.GetStart())} + } + + if an := n.An_id_or_type(); an != nil { + idText := parseAnIdOrType(an) + return &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: "@"}}}, + Rexpr: &ast.String{Str: idText}, Location: c.pos(n.GetStart()), - Dollar: true, } } - return &ast.TODO{} + return todo("VisitBind_parameter", n) } func (c *cc) convertWildCardField(n *parser.Result_columnContext) *ast.ColumnRef { @@ -1472,129 +1680,154 @@ func (c *cc) convertWildCardField(n *parser.Result_columnContext) *ast.ColumnRef } } -func (c *cc) convertOptIdPrefix(ctx parser.IOpt_id_prefixContext) string { - if ctx == nil { +func (c *cc) convertOptIdPrefix(n parser.IOpt_id_prefixContext) string { + if n == nil { return "" } - if ctx.An_id() != nil { - return ctx.An_id().GetText() + if n.An_id() != nil { + return n.An_id().GetText() } return "" } -func (c *cc) convertCreate_table_stmtContext(n *parser.Create_table_stmtContext) ast.Node { +func (c *cc) VisitCreate_table_stmt(n *parser.Create_table_stmtContext) interface{} { stmt := &ast.CreateTableStmt{ Name: parseTableName(n.Simple_table_ref().Simple_table_ref_core()), IfNotExists: n.EXISTS() != nil, } - for _, idef := range n.AllCreate_table_entry() { - if def, ok := idef.(*parser.Create_table_entryContext); ok { + for _, def := range n.AllCreate_table_entry() { + switch { + case def.Column_schema() != nil: + temp, ok := def.Column_schema().Accept(c).(ast.Node) + if !ok { + return todo("VisitCreate_table_stmt", def.Column_schema()) + } + colCtx, ok := temp.(*ast.ColumnDef) + if !ok { + return todo("VisitCreate_table_stmt", def.Column_schema()) + } + stmt.Cols = append(stmt.Cols, colCtx) + case def.Table_constraint() != nil: + conCtx := def.Table_constraint() switch { - case def.Column_schema() != nil: - if colCtx, ok := def.Column_schema().(*parser.Column_schemaContext); ok { - colDef := c.convertColumnSchema(colCtx) - if colDef != nil { - stmt.Cols = append(stmt.Cols, colDef) - } - } - case def.Table_constraint() != nil: - if conCtx, ok := def.Table_constraint().(*parser.Table_constraintContext); ok { - switch { - case conCtx.PRIMARY() != nil && conCtx.KEY() != nil: - for _, cname := range conCtx.AllAn_id() { - for _, col := range stmt.Cols { - if col.Colname == parseAnId(cname) { - col.IsNotNull = true - } - } + case conCtx.PRIMARY() != nil && conCtx.KEY() != nil: + for _, cname := range conCtx.AllAn_id() { + for _, col := range stmt.Cols { + if col.Colname == parseAnId(cname) { + col.IsNotNull = true } - case conCtx.PARTITION() != nil && conCtx.BY() != nil: - _ = conCtx - // todo: partition by constraint - case conCtx.ORDER() != nil && conCtx.BY() != nil: - _ = conCtx - // todo: order by constraint } } - - case def.Table_index() != nil: - if indCtx, ok := def.Table_index().(*parser.Table_indexContext); ok { - _ = indCtx - // todo - } - case def.Family_entry() != nil: - if famCtx, ok := def.Family_entry().(*parser.Family_entryContext); ok { - _ = famCtx - // todo - } - case def.Changefeed() != nil: // таблица ориентированная - if cgfCtx, ok := def.Changefeed().(*parser.ChangefeedContext); ok { - _ = cgfCtx - // todo - } + case conCtx.PARTITION() != nil && conCtx.BY() != nil: + return todo("VisitCreate_table_stmt", conCtx) + case conCtx.ORDER() != nil && conCtx.BY() != nil: + return todo("VisitCreate_table_stmt", conCtx) } + + case def.Table_index() != nil: + return todo("VisitCreate_table_stmt", def.Table_index()) + case def.Family_entry() != nil: + return todo("VisitCreate_table_stmt", def.Family_entry()) + case def.Changefeed() != nil: // table-oriented + return todo("VisitCreate_table_stmt", def.Changefeed()) } } return stmt } -func (c *cc) convertColumnSchema(n *parser.Column_schemaContext) *ast.ColumnDef { - +func (c *cc) VisitColumn_schema(n *parser.Column_schemaContext) interface{} { + if n == nil { + return todo("VisitColumn_schema", n) + } col := &ast.ColumnDef{} if anId := n.An_id_schema(); anId != nil { col.Colname = identifier(parseAnIdSchema(anId)) } if tnb := n.Type_name_or_bind(); tnb != nil { - col.TypeName = c.convertTypeNameOrBind(tnb) + temp, ok := tnb.Accept(c).(ast.Node) + if !ok { + return todo("VisitColumn_schema", tnb) + } + typeName, ok := temp.(*ast.TypeName) + if !ok { + return todo("VisitColumn_schema", tnb) + } + col.TypeName = typeName } if colCons := n.Opt_column_constraints(); colCons != nil { col.IsNotNull = colCons.NOT() != nil && colCons.NULL() != nil - //todo: cover exprs if needed + + if colCons.DEFAULT() != nil && colCons.Expr() != nil { + defaultExpr, ok := colCons.Expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitColumn_schema", colCons.Expr()) + } + col.RawDefault = defaultExpr + } } // todo: family return col } -func (c *cc) convertTypeNameOrBind(n parser.IType_name_or_bindContext) *ast.TypeName { +func (c *cc) VisitType_name_or_bind(n *parser.Type_name_or_bindContext) interface{} { + if n == nil { + return todo("VisitType_name_or_bind", n) + } + if t := n.Type_name(); t != nil { - return c.convertTypeName(t) + temp, ok := t.Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_or_bind", t) + } + typeName, ok := temp.(*ast.TypeName) + if !ok { + return todo("VisitType_name_or_bind", t) + } + return typeName } else if b := n.Bind_parameter(); b != nil { return &ast.TypeName{Name: "BIND:" + identifier(parseAnIdOrType(b.An_id_or_type()))} } - return nil + return todo("VisitType_name_or_bind", n) } -func (c *cc) convertTypeName(n parser.IType_nameContext) *ast.TypeName { +func (c *cc) VisitType_name(n *parser.Type_nameContext) interface{} { if n == nil { - return nil + return todo("VisitType_name", n) } if composite := n.Type_name_composite(); composite != nil { - if node := c.convertTypeNameComposite(composite); node != nil { - if typeName, ok := node.(*ast.TypeName); ok { - return typeName - } + typeName, ok := composite.Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_or_bind", composite) } + return typeName } if decimal := n.Type_name_decimal(); decimal != nil { if integerOrBinds := decimal.AllInteger_or_bind(); len(integerOrBinds) >= 2 { + first, ok := integerOrBinds[0].Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name", decimal.Integer_or_bind(0)) + } + second, ok := integerOrBinds[1].Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name", decimal.Integer_or_bind(1)) + } return &ast.TypeName{ Name: "decimal", TypeOid: 0, Names: &ast.List{ Items: []ast.Node{ - c.convertIntegerOrBind(integerOrBinds[0]), - c.convertIntegerOrBind(integerOrBinds[1]), + first, + second, }, }, } } } - // Handle simple types if simple := n.Type_name_simple(); simple != nil { return &ast.TypeName{ Name: simple.GetText(), @@ -1602,41 +1835,49 @@ func (c *cc) convertTypeName(n parser.IType_nameContext) *ast.TypeName { } } - return nil + return todo("VisitType_name", n) } -func (c *cc) convertIntegerOrBind(n parser.IInteger_or_bindContext) ast.Node { +func (c *cc) VisitInteger_or_bind(n *parser.Integer_or_bindContext) interface{} { if n == nil { - return nil + return todo("VisitInteger_or_bind", n) } if integer := n.Integer(); integer != nil { val, err := parseIntegerValue(integer.GetText()) if err != nil { - return &ast.TODO{} + return todo("VisitInteger_or_bind", n.Integer()) } return &ast.Integer{Ival: val} } if bind := n.Bind_parameter(); bind != nil { - return c.convertBindParameter(bind.(*parser.Bind_parameterContext)) + temp, ok := bind.Accept(c).(ast.Node) + if !ok { + return todo("VisitInteger_or_bind", bind) + } + return temp } - return nil + return todo("VisitInteger_or_bind", n) } -func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast.Node { +func (c *cc) VisitType_name_composite(n *parser.Type_name_compositeContext) interface{} { if n == nil { - return nil + return todo("VisitType_name_composite", n) } if opt := n.Type_name_optional(); opt != nil { if typeName := opt.Type_name_or_bind(); typeName != nil { + tn, ok := typeName.Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_composite", typeName) + } return &ast.TypeName{ Name: "Optional", TypeOid: 0, Names: &ast.List{ - Items: []ast.Node{c.convertTypeNameOrBind(typeName)}, + Items: []ast.Node{tn}, }, } } @@ -1646,7 +1887,11 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast. if typeNames := tuple.AllType_name_or_bind(); len(typeNames) > 0 { var items []ast.Node for _, tn := range typeNames { - items = append(items, c.convertTypeNameOrBind(tn)) + tnNode, ok := tn.Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_composite", tn) + } + items = append(items, tnNode) } return &ast.TypeName{ Name: "Tuple", @@ -1688,11 +1933,15 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast. if list := n.Type_name_list(); list != nil { if typeName := list.Type_name_or_bind(); typeName != nil { + tn, ok := typeName.Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_composite", typeName) + } return &ast.TypeName{ Name: "List", TypeOid: 0, Names: &ast.List{ - Items: []ast.Node{c.convertTypeNameOrBind(typeName)}, + Items: []ast.Node{tn}, }, } } @@ -1700,37 +1949,41 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast. if stream := n.Type_name_stream(); stream != nil { if typeName := stream.Type_name_or_bind(); typeName != nil { + tn, ok := typeName.Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_composite", typeName) + } return &ast.TypeName{ Name: "Stream", TypeOid: 0, Names: &ast.List{ - Items: []ast.Node{c.convertTypeNameOrBind(typeName)}, + Items: []ast.Node{tn}, }, } } } if flow := n.Type_name_flow(); flow != nil { - if typeName := flow.Type_name_or_bind(); typeName != nil { - return &ast.TypeName{ - Name: "Flow", - TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{c.convertTypeNameOrBind(typeName)}, - }, - } - } + return todo("VisitType_name_composite", flow) } if dict := n.Type_name_dict(); dict != nil { if typeNames := dict.AllType_name_or_bind(); len(typeNames) >= 2 { + first, ok := typeNames[0].Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_composite", typeNames[0]) + } + second, ok := typeNames[1].Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_composite", typeNames[1]) + } return &ast.TypeName{ Name: "Dict", TypeOid: 0, Names: &ast.List{ Items: []ast.Node{ - c.convertTypeNameOrBind(typeNames[0]), - c.convertTypeNameOrBind(typeNames[1]), + first, + second, }, }, } @@ -1739,259 +1992,234 @@ func (c *cc) convertTypeNameComposite(n parser.IType_name_compositeContext) ast. if set := n.Type_name_set(); set != nil { if typeName := set.Type_name_or_bind(); typeName != nil { + tn, ok := typeName.Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_composite", typeName) + } return &ast.TypeName{ Name: "Set", TypeOid: 0, Names: &ast.List{ - Items: []ast.Node{c.convertTypeNameOrBind(typeName)}, + Items: []ast.Node{tn}, }, } } } - if enum := n.Type_name_enum(); enum != nil { - if typeTags := enum.AllType_name_tag(); len(typeTags) > 0 { - var items []ast.Node - for range typeTags { // todo: Handle enum tags - items = append(items, &ast.TODO{}) - } - return &ast.TypeName{ - Name: "Enum", - TypeOid: 0, - Names: &ast.List{Items: items}, - } - } + if enum := n.Type_name_enum(); enum != nil { // todo: handle enum + todo("VisitType_name_composite", enum) } - if resource := n.Type_name_resource(); resource != nil { - if typeTag := resource.Type_name_tag(); typeTag != nil { - // TODO: Handle resource tag - return &ast.TypeName{ - Name: "Resource", - TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{&ast.TODO{}}, - }, - } - } + if resource := n.Type_name_resource(); resource != nil { // todo: handle resource + todo("VisitType_name_composite", resource) } - if tagged := n.Type_name_tagged(); tagged != nil { - if typeName := tagged.Type_name_or_bind(); typeName != nil { - if typeTag := tagged.Type_name_tag(); typeTag != nil { - // TODO: Handle tagged type and tag - return &ast.TypeName{ - Name: "Tagged", - TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{ - c.convertTypeNameOrBind(typeName), - &ast.TODO{}, - }, - }, - } - } - } + if tagged := n.Type_name_tagged(); tagged != nil { // todo: handle tagged + todo("VisitType_name_composite", tagged) } - if callable := n.Type_name_callable(); callable != nil { - // TODO: Handle callable argument list and return type - return &ast.TypeName{ - Name: "Callable", - TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{&ast.TODO{}}, - }, - } + if callable := n.Type_name_callable(); callable != nil { // todo: handle callable + todo("VisitType_name_composite", callable) } - return nil + return todo("VisitType_name_composite", n) } -func (c *cc) convertSqlStmtCore(n parser.ISql_stmt_coreContext) ast.Node { +func (c *cc) VisitSql_stmt_core(n *parser.Sql_stmt_coreContext) interface{} { if n == nil { - return nil + return todo("VisitSql_stmt_core", n) } if stmt := n.Pragma_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Select_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Named_nodes_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_table_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) + } + if stmt := n.Named_nodes_stmt(); stmt != nil { + return stmt.Accept(c) + } + if stmt := n.Create_table_stmt(); stmt != nil { + return stmt.Accept(c) } if stmt := n.Drop_table_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Use_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Into_table_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Commit_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Update_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Delete_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Rollback_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Declare_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Import_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Export_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_table_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_external_table_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Do_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Define_action_or_subquery_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.If_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.For_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Values_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_user_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_user_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_group_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_group_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Drop_role_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_object_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_object_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Drop_object_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_external_data_source_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_external_data_source_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Drop_external_data_source_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_replication_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Drop_replication_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_topic_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_topic_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Drop_topic_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Grant_permissions_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Revoke_permissions_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_table_store_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Upsert_object_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_view_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Drop_view_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_replication_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_resource_pool_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_resource_pool_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Drop_resource_pool_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_backup_collection_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_backup_collection_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Drop_backup_collection_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Analyze_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Create_resource_pool_classifier_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_resource_pool_classifier_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Drop_resource_pool_classifier_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Backup_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Restore_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } if stmt := n.Alter_sequence_stmt(); stmt != nil { - return c.convert(stmt) + return stmt.Accept(c) } - return nil + return todo("VisitSql_stmt_core", n) } -func (c *cc) convertNamed_exprContext(n *parser.Named_exprContext) ast.Node { +func (c *cc) VisitNamed_expr(n *parser.Named_exprContext) interface{} { if n == nil || n.Expr() == nil { - return todo("convertNamed_exprContext", n) + return todo("VisitNamed_expr", n) } - expr := c.convert(n.Expr()) + + expr, ok := n.Expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitNamed_expr", n) + } + if n.AS() != nil && n.An_id_or_type() != nil { name := parseAnIdOrType(n.An_id_or_type()) return &ast.ResTarget{ @@ -2003,32 +2231,32 @@ func (c *cc) convertNamed_exprContext(n *parser.Named_exprContext) ast.Node { return expr } -func (c *cc) convertExpr(n *parser.ExprContext) ast.Node { +func (c *cc) VisitExpr(n *parser.ExprContext) interface{} { if n == nil { - return nil + return todo("VisitExpr", n) } if tn := n.Type_name_composite(); tn != nil { - return c.convertTypeNameComposite(tn) + return tn.Accept(c) } orSubs := n.AllOr_subexpr() if len(orSubs) == 0 { - return nil + return todo("VisitExpr", n) } - orSub, ok := orSubs[0].(*parser.Or_subexprContext) + left, ok := n.Or_subexpr(0).Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitExpr", n) } - left := c.convertOrSubExpr(orSub) for i := 1; i < len(orSubs); i++ { - orSub, ok = orSubs[i].(*parser.Or_subexprContext) + + right, ok := orSubs[i].Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitExpr", n) } - right := c.convertOrSubExpr(orSub) + left = &ast.BoolExpr{ Boolop: ast.BoolExprTypeOr, Args: &ast.List{Items: []ast.Node{left, right}}, @@ -2038,26 +2266,23 @@ func (c *cc) convertExpr(n *parser.ExprContext) ast.Node { return left } -func (c *cc) convertOrSubExpr(n *parser.Or_subexprContext) ast.Node { - if n == nil { - return nil +func (c *cc) VisitOr_subexpr(n *parser.Or_subexprContext) interface{} { + if n == nil || len(n.AllAnd_subexpr()) == 0 { + return todo("VisitOr_subexpr", n) } - andSubs := n.AllAnd_subexpr() - if len(andSubs) == 0 { - return nil - } - andSub, ok := andSubs[0].(*parser.And_subexprContext) + + left, ok := n.And_subexpr(0).Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitOr_subexpr", n) } - left := c.convertAndSubexpr(andSub) - for i := 1; i < len(andSubs); i++ { - andSub, ok = andSubs[i].(*parser.And_subexprContext) + for i := 1; i < len(n.AllAnd_subexpr()); i++ { + + right, ok := n.And_subexpr(i).Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitOr_subexpr", n) } - right := c.convertAndSubexpr(andSub) + left = &ast.BoolExpr{ Boolop: ast.BoolExprTypeAnd, Args: &ast.List{Items: []ast.Node{left, right}}, @@ -2067,28 +2292,23 @@ func (c *cc) convertOrSubExpr(n *parser.Or_subexprContext) ast.Node { return left } -func (c *cc) convertAndSubexpr(n *parser.And_subexprContext) ast.Node { - if n == nil { - return nil - } - - xors := n.AllXor_subexpr() - if len(xors) == 0 { - return nil +func (c *cc) VisitAnd_subexpr(n *parser.And_subexprContext) interface{} { + if n == nil || len(n.AllXor_subexpr()) == 0 { + return todo("VisitAnd_subexpr", n) } - xor, ok := xors[0].(*parser.Xor_subexprContext) + left, ok := n.Xor_subexpr(0).Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitAnd_subexpr", n) } - left := c.convertXorSubexpr(xor) - for i := 1; i < len(xors); i++ { - xor, ok = xors[i].(*parser.Xor_subexprContext) + for i := 1; i < len(n.AllXor_subexpr()); i++ { + + right, ok := n.Xor_subexpr(i).Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitAnd_subexpr", n) } - right := c.convertXorSubexpr(xor) + left = &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: "XOR"}}}, Lexpr: left, @@ -2099,40 +2319,53 @@ func (c *cc) convertAndSubexpr(n *parser.And_subexprContext) ast.Node { return left } -func (c *cc) convertXorSubexpr(n *parser.Xor_subexprContext) ast.Node { - if n == nil { - return nil - } - es := n.Eq_subexpr() - if es == nil { - return nil +func (c *cc) VisitXor_subexpr(n *parser.Xor_subexprContext) interface{} { + if n == nil || n.Eq_subexpr() == nil { + return todo("VisitXor_subexpr", n) } - subExpr, ok := es.(*parser.Eq_subexprContext) + + base, ok := n.Eq_subexpr().Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitXor_subexpr", n) } - base := c.convertEqSubexpr(subExpr) - if cond := n.Cond_expr(); cond != nil { - condCtx, ok := cond.(*parser.Cond_exprContext) - if !ok { - return base - } + + if condCtx := n.Cond_expr(); condCtx != nil { switch { case condCtx.IN() != nil: if inExpr := condCtx.In_expr(); inExpr != nil { - return &ast.A_Expr{ - Name: &ast.List{Items: []ast.Node{&ast.String{Str: "IN"}}}, - Lexpr: base, - Rexpr: c.convert(inExpr), + temp, ok := inExpr.Accept(c).(ast.Node) + if !ok { + return todo("VisitXor_subexpr", inExpr) + } + list, ok := temp.(*ast.List) + if !ok { + return todo("VisitXor_subexpr", inExpr) + } + return &ast.In{ + Expr: base, + List: list.Items, + Not: condCtx.NOT() != nil, + Location: c.pos(n.GetStart()), } } case condCtx.BETWEEN() != nil: if eqSubs := condCtx.AllEq_subexpr(); len(eqSubs) >= 2 { + + first, ok := eqSubs[0].Accept(c).(ast.Node) + if !ok { + return todo("VisitXor_subexpr", n) + } + + second, ok := eqSubs[1].Accept(c).(ast.Node) + if !ok { + return todo("VisitXor_subexpr", n) + } + return &ast.BetweenExpr{ Expr: base, - Left: c.convert(eqSubs[0]), - Right: c.convert(eqSubs[1]), + Left: first, + Right: second, Not: condCtx.NOT() != nil, Location: c.pos(n.GetStart()), } @@ -2155,7 +2388,7 @@ func (c *cc) convertXorSubexpr(n *parser.Xor_subexprContext) ast.Node { Nulltesttype: 1, // IS NULL Location: c.pos(n.GetStart()), } - case condCtx.IS() != nil && condCtx.NOT() != nil && condCtx.NULL() != nil: + case condCtx.NOT() != nil && condCtx.NULL() != nil: return &ast.NullTest{ Arg: base, Nulltesttype: 2, // IS NOT NULL @@ -2165,10 +2398,16 @@ func (c *cc) convertXorSubexpr(n *parser.Xor_subexprContext) ast.Node { // debug!!! matchOp := condCtx.Match_op().GetText() if eqSubs := condCtx.AllEq_subexpr(); len(eqSubs) >= 1 { + + xpr, ok := eqSubs[0].Accept(c).(ast.Node) + if !ok { + return todo("VisitXor_subexpr", n) + } + expr := &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: matchOp}}}, Lexpr: base, - Rexpr: c.convert(eqSubs[0]), + Rexpr: xpr, } if condCtx.ESCAPE() != nil && len(eqSubs) >= 2 { //nolint // todo: Add ESCAPE support @@ -2177,25 +2416,43 @@ func (c *cc) convertXorSubexpr(n *parser.Xor_subexprContext) ast.Node { } case len(condCtx.AllEQUALS()) > 0 || len(condCtx.AllEQUALS2()) > 0 || len(condCtx.AllNOT_EQUALS()) > 0 || len(condCtx.AllNOT_EQUALS2()) > 0: - // debug!!! - var op string - switch { - case len(condCtx.AllEQUALS()) > 0: - op = "=" - case len(condCtx.AllEQUALS2()) > 0: - op = "==" - case len(condCtx.AllNOT_EQUALS()) > 0: - op = "!=" - case len(condCtx.AllNOT_EQUALS2()) > 0: - op = "<>" - } - if eqSubs := condCtx.AllEq_subexpr(); len(eqSubs) >= 1 { - return &ast.A_Expr{ - Name: &ast.List{Items: []ast.Node{&ast.String{Str: op}}}, - Lexpr: base, - Rexpr: c.convert(eqSubs[0]), + eqSubs := condCtx.AllEq_subexpr() + if len(eqSubs) >= 1 { + left := base + + ops := c.collectEqualityOps(condCtx) + + for i, eqSub := range eqSubs { + right, ok := eqSub.Accept(c).(ast.Node) + if !ok { + return todo("VisitXor_subexpr", condCtx) + } + + var op string + if i < len(ops) { + op = ops[i].GetText() + } else { + if len(condCtx.AllEQUALS()) > 0 { + op = "=" + } else if len(condCtx.AllEQUALS2()) > 0 { + op = "==" + } else if len(condCtx.AllNOT_EQUALS()) > 0 { + op = "!=" + } else if len(condCtx.AllNOT_EQUALS2()) > 0 { + op = "<>" + } + } + + left = &ast.A_Expr{ + Name: &ast.List{Items: []ast.Node{&ast.String{Str: op}}}, + Lexpr: left, + Rexpr: right, + Location: c.pos(condCtx.GetStart()), + } } + return left } + return todo("VisitXor_subexpr", condCtx) case len(condCtx.AllDistinct_from_op()) > 0: // debug!!! distinctOps := condCtx.AllDistinct_from_op() @@ -2206,10 +2463,16 @@ func (c *cc) convertXorSubexpr(n *parser.Xor_subexprContext) ast.Node { if not { op = "IS NOT DISTINCT FROM" } + + xpr, ok := eqSubs[0].Accept(c).(ast.Node) + if !ok { + return todo("VisitXor_subexpr", n) + } + return &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: op}}}, Lexpr: base, - Rexpr: c.convert(eqSubs[0]), + Rexpr: xpr, } } } @@ -2218,26 +2481,24 @@ func (c *cc) convertXorSubexpr(n *parser.Xor_subexprContext) ast.Node { return base } -func (c *cc) convertEqSubexpr(n *parser.Eq_subexprContext) ast.Node { - if n == nil { - return nil - } - neqList := n.AllNeq_subexpr() - if len(neqList) == 0 { - return nil +func (c *cc) VisitEq_subexpr(n *parser.Eq_subexprContext) interface{} { + if n == nil || len(n.AllNeq_subexpr()) == 0 { + return todo("VisitEq_subexpr", n) } - neq, ok := neqList[0].(*parser.Neq_subexprContext) + + left, ok := n.Neq_subexpr(0).Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitEq_subexpr", n) } - left := c.convertNeqSubexpr(neq) + ops := c.collectComparisonOps(n) - for i := 1; i < len(neqList); i++ { - neq, ok = neqList[i].(*parser.Neq_subexprContext) + for i := 1; i < len(n.AllNeq_subexpr()); i++ { + + right, ok := n.Neq_subexpr(i).Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitEq_subexpr", n) } - right := c.convertNeqSubexpr(neq) + opText := ops[i-1].GetText() left = &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, @@ -2249,40 +2510,22 @@ func (c *cc) convertEqSubexpr(n *parser.Eq_subexprContext) ast.Node { return left } -func (c *cc) collectComparisonOps(n parser.IEq_subexprContext) []antlr.TerminalNode { - var ops []antlr.TerminalNode - for _, child := range n.GetChildren() { - if tn, ok := child.(antlr.TerminalNode); ok { - switch tn.GetText() { - case "<", "<=", ">", ">=": - ops = append(ops, tn) - } - } +func (c *cc) VisitNeq_subexpr(n *parser.Neq_subexprContext) interface{} { + if n == nil || len(n.AllBit_subexpr()) == 0 { + return todo("VisitNeq_subexpr", n) } - return ops -} -func (c *cc) convertNeqSubexpr(n *parser.Neq_subexprContext) ast.Node { - if n == nil { - return nil - } - bitList := n.AllBit_subexpr() - if len(bitList) == 0 { - return nil - } - - bl, ok := bitList[0].(*parser.Bit_subexprContext) + left, ok := n.Bit_subexpr(0).Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitNeq_subexpr", n) } - left := c.convertBitSubexpr(bl) + ops := c.collectBitwiseOps(n) - for i := 1; i < len(bitList); i++ { - bl, ok = bitList[i].(*parser.Bit_subexprContext) + for i := 1; i < len(n.AllBit_subexpr()); i++ { + right, ok := n.Bit_subexpr(i).Accept(c).(ast.Node) if !ok { - return nil + return todo("VisitNeq_subexpr", n) } - right := c.convertBitSubexpr(bl) opText := ops[i-1].GetText() left = &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, @@ -2293,13 +2536,12 @@ func (c *cc) convertNeqSubexpr(n *parser.Neq_subexprContext) ast.Node { } if n.Double_question() != nil { - nextCtx := n.Neq_subexpr() - if nextCtx != nil { - neq, ok2 := nextCtx.(*parser.Neq_subexprContext) + if nextCtx := n.Neq_subexpr(); nextCtx != nil { + right, ok2 := nextCtx.Accept(c).(ast.Node) if !ok2 { - return nil + return todo("VisitNeq_subexpr", n) } - right := c.convertNeqSubexpr(neq) + left = &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: "??"}}}, Lexpr: left, @@ -2326,28 +2568,24 @@ func (c *cc) convertNeqSubexpr(n *parser.Neq_subexprContext) ast.Node { return left } -func (c *cc) collectBitwiseOps(ctx parser.INeq_subexprContext) []antlr.TerminalNode { - var ops []antlr.TerminalNode - children := ctx.GetChildren() - for _, child := range children { - if tn, ok := child.(antlr.TerminalNode); ok { - txt := tn.GetText() - switch txt { - case "<<", ">>", "<<|", ">>|", "&", "|", "^": - ops = append(ops, tn) - } - } +func (c *cc) VisitBit_subexpr(n *parser.Bit_subexprContext) interface{} { + if n == nil || len(n.AllAdd_subexpr()) == 0 { + return todo("VisitBit_subexpr", n) } - return ops -} -func (c *cc) convertBitSubexpr(n *parser.Bit_subexprContext) ast.Node { - addList := n.AllAdd_subexpr() - left := c.convertAddSubexpr(addList[0].(*parser.Add_subexprContext)) + left, ok := n.Add_subexpr(0).Accept(c).(ast.Node) + if !ok { + return todo("VisitBit_subexpr", n) + } ops := c.collectBitOps(n) - for i := 1; i < len(addList); i++ { - right := c.convertAddSubexpr(addList[i].(*parser.Add_subexprContext)) + for i := 1; i < len(n.AllAdd_subexpr()); i++ { + + right, ok := n.Add_subexpr(i).Accept(c).(ast.Node) + if !ok { + return todo("VisitBit_subexpr", n) + } + opText := ops[i-1].GetText() left = &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, @@ -2359,28 +2597,24 @@ func (c *cc) convertBitSubexpr(n *parser.Bit_subexprContext) ast.Node { return left } -func (c *cc) collectBitOps(ctx parser.IBit_subexprContext) []antlr.TerminalNode { - var ops []antlr.TerminalNode - children := ctx.GetChildren() - for _, child := range children { - if tn, ok := child.(antlr.TerminalNode); ok { - txt := tn.GetText() - switch txt { - case "+", "-": - ops = append(ops, tn) - } - } +func (c *cc) VisitAdd_subexpr(n *parser.Add_subexprContext) interface{} { + if n == nil || len(n.AllMul_subexpr()) == 0 { + return todo("VisitAdd_subexpr", n) } - return ops -} -func (c *cc) convertAddSubexpr(n *parser.Add_subexprContext) ast.Node { - mulList := n.AllMul_subexpr() - left := c.convertMulSubexpr(mulList[0].(*parser.Mul_subexprContext)) + left, ok := n.Mul_subexpr(0).Accept(c).(ast.Node) + if !ok { + return todo("VisitAdd_subexpr", n) + } ops := c.collectAddOps(n) - for i := 1; i < len(mulList); i++ { - right := c.convertMulSubexpr(mulList[i].(*parser.Mul_subexprContext)) + for i := 1; i < len(n.AllMul_subexpr()); i++ { + + right, ok := n.Mul_subexpr(i).Accept(c).(ast.Node) + if !ok { + return todo("VisitAdd_subexpr", n) + } + opText := ops[i-1].GetText() left = &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: opText}}}, @@ -2392,25 +2626,23 @@ func (c *cc) convertAddSubexpr(n *parser.Add_subexprContext) ast.Node { return left } -func (c *cc) collectAddOps(ctx parser.IAdd_subexprContext) []antlr.TerminalNode { - var ops []antlr.TerminalNode - for _, child := range ctx.GetChildren() { - if tn, ok := child.(antlr.TerminalNode); ok { - switch tn.GetText() { - case "*", "/", "%": - ops = append(ops, tn) - } - } +func (c *cc) VisitMul_subexpr(n *parser.Mul_subexprContext) interface{} { + if n == nil || len(n.AllCon_subexpr()) == 0 { + return todo("VisitMul_subexpr", n) } - return ops -} -func (c *cc) convertMulSubexpr(n *parser.Mul_subexprContext) ast.Node { - conList := n.AllCon_subexpr() - left := c.convertConSubexpr(conList[0].(*parser.Con_subexprContext)) + left, ok := n.Con_subexpr(0).Accept(c).(ast.Node) + if !ok { + return todo("VisitMul_subexpr", n) + } + + for i := 1; i < len(n.AllCon_subexpr()); i++ { + + right, ok := n.Con_subexpr(i).Accept(c).(ast.Node) + if !ok { + return todo("VisitMul_subexpr", n) + } - for i := 1; i < len(conList); i++ { - right := c.convertConSubexpr(conList[i].(*parser.Con_subexprContext)) left = &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: "||"}}}, Lexpr: left, @@ -2421,42 +2653,76 @@ func (c *cc) convertMulSubexpr(n *parser.Mul_subexprContext) ast.Node { return left } -func (c *cc) convertConSubexpr(n *parser.Con_subexprContext) ast.Node { +func (c *cc) VisitCon_subexpr(n *parser.Con_subexprContext) interface{} { + if n == nil || (n.Unary_op() == nil && n.Unary_subexpr() == nil) { + return todo("VisitCon_subexpr", n) + } + if opCtx := n.Unary_op(); opCtx != nil { op := opCtx.GetText() - operand := c.convertUnarySubexpr(n.Unary_subexpr().(*parser.Unary_subexprContext)) + operand, ok := n.Unary_subexpr().Accept(c).(ast.Node) + if !ok { + return todo("VisitCon_subexpr", opCtx) + } return &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: op}}}, Rexpr: operand, Location: c.pos(n.GetStart()), } } - return c.convertUnarySubexpr(n.Unary_subexpr().(*parser.Unary_subexprContext)) + + operand, ok := n.Unary_subexpr().Accept(c).(ast.Node) + if !ok { + return todo("VisitCon_subexpr", n.Unary_subexpr()) + } + return operand + } -func (c *cc) convertUnarySubexpr(n *parser.Unary_subexprContext) ast.Node { +func (c *cc) VisitUnary_subexpr(n *parser.Unary_subexprContext) interface{} { + if n == nil || (n.Unary_casual_subexpr() == nil && n.Json_api_expr() == nil) { + return todo("VisitUnary_subexpr", n) + } + if casual := n.Unary_casual_subexpr(); casual != nil { - return c.convertUnaryCasualSubexpr(casual.(*parser.Unary_casual_subexprContext)) + expr, ok := casual.Accept(c).(ast.Node) + if !ok { + return todo("VisitUnary_subexpr", casual) + } + return expr } if jsonExpr := n.Json_api_expr(); jsonExpr != nil { - return c.convertJsonApiExpr(jsonExpr.(*parser.Json_api_exprContext)) + expr, ok := jsonExpr.Accept(c).(ast.Node) + if !ok { + return todo("VisitUnary_subexpr", jsonExpr) + } + return expr } - return nil + + return todo("VisitUnary_subexpr", n) } -func (c *cc) convertJsonApiExpr(n *parser.Json_api_exprContext) ast.Node { - return todo("Json_api_exprContext", n) +func (c *cc) VisitJson_api_expr(n *parser.Json_api_exprContext) interface{} { + return todo("VisitJson_api_expr", n) } -func (c *cc) convertUnaryCasualSubexpr(n *parser.Unary_casual_subexprContext) ast.Node { +func (c *cc) VisitUnary_casual_subexpr(n *parser.Unary_casual_subexprContext) interface{} { var current ast.Node switch { case n.Id_expr() != nil: - current = c.convertIdExpr(n.Id_expr().(*parser.Id_exprContext)) + expr, ok := n.Id_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitUnary_casual_subexpr", n.Id_expr()) + } + current = expr case n.Atom_expr() != nil: - current = c.convertAtomExpr(n.Atom_expr().(*parser.Atom_exprContext)) + expr, ok := n.Atom_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitUnary_casual_subexpr", n.Atom_expr()) + } + current = expr default: - return todo("Unary_casual_subexprContext", n) + return todo("VisitUnary_casual_subexpr", n) } if suffix := n.Unary_subexpr_suffix(); suffix != nil { @@ -2478,17 +2744,24 @@ func (c *cc) processSuffixChain(base ast.Node, suffix *parser.Unary_subexpr_suff case antlr.TerminalNode: if elem.GetText() == "." { current = c.handleDotSuffix(current, suffix, &i) + } else { + return todo("Unary_subexpr_suffixContext", suffix) } + default: + return todo("Unary_subexpr_suffixContext", suffix) } } return current } func (c *cc) handleKeySuffix(base ast.Node, keyCtx *parser.Key_exprContext) ast.Node { - keyNode := c.convertKey_exprContext(keyCtx) + keyNode, ok := keyCtx.Accept(c).(ast.Node) + if !ok { + return todo("VisitKey_expr", keyCtx) + } ind, ok := keyNode.(*ast.A_Indirection) if !ok { - return todo("Key_exprContext", keyCtx) + return todo("VisitKey_expr", keyCtx) } if indirection, ok := base.(*ast.A_Indirection); ok { @@ -2505,9 +2778,13 @@ func (c *cc) handleKeySuffix(base ast.Node, keyCtx *parser.Key_exprContext) ast. } func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprContext, idx int) ast.Node { - funcCall, ok := c.convertInvoke_exprContext(invokeCtx).(*ast.FuncCall) + temp, ok := invokeCtx.Accept(c).(ast.Node) if !ok { - return todo("Invoke_exprContext", invokeCtx) + return todo("VisitInvoke_expr", invokeCtx) + } + funcCall, ok := temp.(*ast.FuncCall) + if !ok { + return todo("VisitInvoke_expr", invokeCtx) } if idx == 0 { @@ -2535,7 +2812,7 @@ func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprCont return funcCall } default: - return todo("Invoke_exprContext", invokeCtx) + return todo("VisitInvoke_expr", invokeCtx) } } @@ -2562,14 +2839,18 @@ func (c *cc) handleDotSuffix(base ast.Node, suffix *parser.Unary_subexpr_suffixC var field ast.Node switch v := next.(type) { case *parser.Bind_parameterContext: - field = c.convertBindParameter(v) + temp, ok := v.Accept(c).(ast.Node) + if !ok { + return todo("VisitBind_parameter", v) + } + field = temp case *parser.An_id_or_typeContext: field = &ast.String{Str: parseAnIdOrType(v)} case antlr.TerminalNode: if val, err := parseIntegerValue(v.GetText()); err == nil { field = &ast.A_Const{Val: &ast.Integer{Ival: val}} } else { - return &ast.TODO{} + return todo("Unary_subexpr_suffixContext", suffix) } } @@ -2586,16 +2867,19 @@ func (c *cc) handleDotSuffix(base ast.Node, suffix *parser.Unary_subexpr_suffixC } } -func (c *cc) convertKey_exprContext(n *parser.Key_exprContext) ast.Node { +func (c *cc) VisitKey_expr(n *parser.Key_exprContext) interface{} { if n.LBRACE_SQUARE() == nil || n.RBRACE_SQUARE() == nil || n.Expr() == nil { - return todo("Key_exprContext", n) + return todo("VisitKey_expr", n) } stmt := &ast.A_Indirection{ Indirection: &ast.List{}, } - expr := c.convert(n.Expr()) + expr, ok := n.Expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitKey_expr", n.Expr()) + } stmt.Indirection.Items = append(stmt.Indirection.Items, &ast.A_Indices{ Uidx: expr, @@ -2604,9 +2888,9 @@ func (c *cc) convertKey_exprContext(n *parser.Key_exprContext) ast.Node { return stmt } -func (c *cc) convertInvoke_exprContext(n *parser.Invoke_exprContext) ast.Node { +func (c *cc) VisitInvoke_expr(n *parser.Invoke_exprContext) interface{} { if n.LPAREN() == nil || n.RPAREN() == nil { - return todo("Invoke_exprContext", n) + return todo("VisitInvoke_expr", n) } distinct := false @@ -2625,7 +2909,10 @@ func (c *cc) convertInvoke_exprContext(n *parser.Invoke_exprContext) ast.Node { if nList := n.Named_expr_list(); nList != nil { for _, namedExpr := range nList.AllNamed_expr() { name := parseAnIdOrType(namedExpr.An_id_or_type()) - expr := c.convert(namedExpr.Expr()) + expr, ok := namedExpr.Expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitInvoke_expr", namedExpr.Expr()) + } var res ast.Node if rt, ok := expr.(*ast.ResTarget); ok { @@ -2652,7 +2939,10 @@ func (c *cc) convertInvoke_exprContext(n *parser.Invoke_exprContext) ast.Node { return stmt } -func (c *cc) convertIdExpr(n *parser.Id_exprContext) ast.Node { +func (c *cc) VisitId_expr(n *parser.Id_exprContext) interface{} { + if n == nil { + return todo("VisitId_expr", n) + } if id := n.Identifier(); id != nil { return &ast.ColumnRef{ Fields: &ast.List{ @@ -2663,25 +2953,43 @@ func (c *cc) convertIdExpr(n *parser.Id_exprContext) ast.Node { Location: c.pos(id.GetStart()), } } - return &ast.TODO{} + return todo("VisitId_expr", n) } -func (c *cc) convertAtomExpr(n *parser.Atom_exprContext) ast.Node { +func (c *cc) VisitAtom_expr(n *parser.Atom_exprContext) interface{} { + if n == nil { + return todo("VisitAtom_expr", n) + } + switch { - case n.An_id_or_type() != nil && n.NAMESPACE() != nil: - return NewIdentifier(parseAnIdOrType(n.An_id_or_type()) + "::" + parseIdOrType(n.Id_or_type())) case n.An_id_or_type() != nil: + if n.NAMESPACE() != nil { + return NewIdentifier(parseAnIdOrType(n.An_id_or_type()) + "::" + parseIdOrType(n.Id_or_type())) + } return NewIdentifier(parseAnIdOrType(n.An_id_or_type())) case n.Literal_value() != nil: - return c.convertLiteralValue(n.Literal_value().(*parser.Literal_valueContext)) + expr, ok := n.Literal_value().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Literal_value()) + } + return expr case n.Bind_parameter() != nil: - return c.convertBindParameter(n.Bind_parameter().(*parser.Bind_parameterContext)) + expr, ok := n.Bind_parameter().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Bind_parameter()) + } + return expr + // TODO: check other cases default: - return &ast.TODO{} + return todo("VisitAtom_expr", n) } } -func (c *cc) convertLiteralValue(n *parser.Literal_valueContext) ast.Node { +func (c *cc) VisitLiteral_value(n *parser.Literal_valueContext) interface{} { + if n == nil { + return todo("VisitLiteral_value", n) + } + switch { case n.Integer() != nil: text := n.Integer().GetText() @@ -2690,7 +2998,7 @@ func (c *cc) convertLiteralValue(n *parser.Literal_valueContext) ast.Node { if debug.Active { log.Printf("Failed to parse integer value '%s': %v", text, err) } - return &ast.TODO{} + return todo("VisitLiteral_value", n.Integer()) } return &ast.A_Const{Val: &ast.Integer{Ival: val}, Location: c.pos(n.GetStart())} @@ -2716,22 +3024,16 @@ func (c *cc) convertLiteralValue(n *parser.Literal_valueContext) ast.Node { return &ast.Null{} case n.CURRENT_TIME() != nil: - if debug.Active { - log.Printf("TODO: Implement CURRENT_TIME") - } - return &ast.TODO{} + log.Fatalf("CURRENT_TIME is not supported yet") + return todo("VisitLiteral_value", n) case n.CURRENT_DATE() != nil: - if debug.Active { - log.Printf("TODO: Implement CURRENT_DATE") - } - return &ast.TODO{} + log.Fatalf("CURRENT_DATE is not supported yet") + return todo("VisitLiteral_value", n) case n.CURRENT_TIMESTAMP() != nil: - if debug.Active { - log.Printf("TODO: Implement CURRENT_TIMESTAMP") - } - return &ast.TODO{} + log.Fatalf("CURRENT_TIMESTAMP is not supported yet") + return todo("VisitLiteral_value", n) case n.BLOB() != nil: blobText := n.BLOB().GetText() @@ -2744,205 +3046,36 @@ func (c *cc) convertLiteralValue(n *parser.Literal_valueContext) ast.Node { return &ast.TODO{} default: - if debug.Active { - log.Printf("Unknown literal value type: %T", n) - } - return &ast.TODO{} + return todo("VisitLiteral_value", n) } } -func (c *cc) convertSqlStmt(n *parser.Sql_stmtContext) ast.Node { - if n == nil { - return nil - } - // todo: handle explain - if core := n.Sql_stmt_core(); core != nil { - return c.convert(core) +func (c *cc) VisitSql_stmt(n *parser.Sql_stmtContext) interface{} { + if n == nil || n.Sql_stmt_core() == nil { + return todo("VisitSql_stmt", n) } - return nil -} - -func (c *cc) convert(node node) ast.Node { - switch n := node.(type) { - case *parser.Sql_stmtContext: - return c.convertSqlStmt(n) - - case *parser.Sql_stmt_coreContext: - return c.convertSqlStmtCore(n) - - case *parser.Create_table_stmtContext: - return c.convertCreate_table_stmtContext(n) - - case *parser.Select_stmtContext: - return c.convertSelectStmtContext(n) - - case *parser.Result_columnContext: - return c.convertResultColumn(n) - - case *parser.Join_sourceContext: - return c.convertJoinSource(n) - - case *parser.Flatten_sourceContext: - return c.convertFlattenSource(n) - - case *parser.Named_single_sourceContext: - return c.convertNamedSingleSource(n) - - case *parser.Single_sourceContext: - return c.convertSingleSource(n) - - case *parser.Bind_parameterContext: - return c.convertBindParameter(n) - - case *parser.ExprContext: - return c.convertExpr(n) - - case *parser.Or_subexprContext: - return c.convertOrSubExpr(n) - - case *parser.And_subexprContext: - return c.convertAndSubexpr(n) - - case *parser.Xor_subexprContext: - return c.convertXorSubexpr(n) - - case *parser.Eq_subexprContext: - return c.convertEqSubexpr(n) - - case *parser.Neq_subexprContext: - return c.convertNeqSubexpr(n) - - case *parser.Bit_subexprContext: - return c.convertBitSubexpr(n) - - case *parser.Add_subexprContext: - return c.convertAddSubexpr(n) - - case *parser.Mul_subexprContext: - return c.convertMulSubexpr(n) - - case *parser.Con_subexprContext: - return c.convertConSubexpr(n) - - case *parser.Unary_subexprContext: - return c.convertUnarySubexpr(n) - - case *parser.Unary_casual_subexprContext: - return c.convertUnaryCasualSubexpr(n) - - case *parser.Id_exprContext: - return c.convertIdExpr(n) - - case *parser.Atom_exprContext: - return c.convertAtomExpr(n) - - case *parser.Literal_valueContext: - return c.convertLiteralValue(n) - - case *parser.Json_api_exprContext: - return c.convertJsonApiExpr(n) - - case *parser.Type_name_compositeContext: - return c.convertTypeNameComposite(n) - - case *parser.Type_nameContext: - return c.convertTypeName(n) - - case *parser.Integer_or_bindContext: - return c.convertIntegerOrBind(n) - - case *parser.Type_name_or_bindContext: - return c.convertTypeNameOrBind(n) - - case *parser.Into_table_stmtContext: - return c.convertInto_table_stmtContext(n) - - case *parser.Values_stmtContext: - return c.convertValues_stmtContext(n) - - case *parser.Returning_columns_listContext: - return c.convertReturning_columns_listContext(n) - - case *parser.Delete_stmtContext: - return c.convertDelete_stmtContext(n) - - case *parser.Update_stmtContext: - return c.convertUpdate_stmtContext(n) - - case *parser.Alter_table_stmtContext: - return c.convertAlter_table_stmtContext(n) - - case *parser.Do_stmtContext: - return c.convertDo_stmtContext(n) - - case *parser.Drop_table_stmtContext: - return c.convertDrop_table_stmtContext(n) - - case *parser.Commit_stmtContext: - return c.convertCommit_stmtContext(n) - - case *parser.Rollback_stmtContext: - return c.convertRollback_stmtContext(n) - - case *parser.Pragma_valueContext: - return c.convertPragma_valueContext(n) - - case *parser.Pragma_stmtContext: - return c.convertPragma_stmtContext(n) - - case *parser.Use_stmtContext: - return c.convertUse_stmtContext(n) - - case *parser.Cluster_exprContext: - return c.convertCluster_exprContext(n) - - case *parser.Create_user_stmtContext: - return c.convertCreate_user_stmtContext(n) - - case *parser.Role_nameContext: - return c.convertRole_nameContext(n) - - case *parser.User_optionContext: - return c.convertUser_optionContext(n) - - case *parser.Create_group_stmtContext: - return c.convertCreate_group_stmtContext(n) - - case *parser.Alter_user_stmtContext: - return c.convertAlter_user_stmtContext(n) - - case *parser.Alter_group_stmtContext: - return c.convertAlter_group_stmtContext(n) - - case *parser.Drop_role_stmtContext: - return c.convertDrop_role_stmtContext(n) - - case *parser.Grouping_elementContext: - return c.convertGrouping_elementContext(n) - - case *parser.Ordinary_grouping_setContext: - return c.convertOrdinary_grouping_setContext(n) - - case *parser.Rollup_listContext: - return c.convertRollup_listContext(n) - - case *parser.Cube_listContext: - return c.convertCube_listContext(n) - - case *parser.Grouping_sets_specificationContext: - return c.convertGrouping_sets_specificationContext(n) - - case *parser.Named_exprContext: - return c.convertNamed_exprContext(n) + expr, ok := n.Sql_stmt_core().Accept(c).(ast.Node) + if !ok { + return todo("VisitSql_stmt", n.Sql_stmt_core()) + } - case *parser.Call_actionContext: - return c.convertCall_actionContext(n) + if n.EXPLAIN() != nil { + options := &ast.List{Items: []ast.Node{}} - case *parser.Inline_actionContext: - return c.convertInline_actionContext(n) + if n.QUERY() != nil && n.PLAN() != nil { + queryPlan := "QUERY PLAN" + options.Items = append(options.Items, &ast.DefElem{ + Defname: &queryPlan, + Arg: &ast.TODO{}, + }) + } - default: - return todo("convert(case=default)", n) + return &ast.ExplainStmt{ + Query: expr, + Options: options, + } } + + return expr } diff --git a/internal/engine/ydb/parse.go b/internal/engine/ydb/parse.go index 1c263924a5..8fbdd81ebb 100755 --- a/internal/engine/ydb/parse.go +++ b/internal/engine/ydb/parse.go @@ -64,7 +64,10 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { loc := 0 for _, stmt := range stmtListCtx.AllSql_stmt() { converter := &cc{content: string(blob)} - out := converter.convert(stmt) + out, ok := stmt.Accept(converter).(ast.Node) + if !ok { + return nil, fmt.Errorf("expected ast.Node; got %T", out) + } if _, ok := out.(*ast.TODO); ok { loc = byteOffset(content, stmt.GetStop().GetStop() + 2) continue diff --git a/internal/engine/ydb/utils.go b/internal/engine/ydb/utils.go index f2023e8ba9..8f118df09b 100755 --- a/internal/engine/ydb/utils.go +++ b/internal/engine/ydb/utils.go @@ -156,7 +156,13 @@ func parseIntegerValue(text string) (int64, error) { } func (c *cc) extractRoleSpec(n parser.IRole_nameContext, roletype ast.RoleSpecType) (*ast.RoleSpec, bool, ast.Node) { - roleNode := c.convert(n) + if n == nil { + return nil, false, nil + } + roleNode, ok := n.Accept(c).(ast.Node) + if !ok { + return nil, false, nil + } roleSpec := &ast.RoleSpec{ Roletype: roletype, @@ -219,3 +225,73 @@ func emptySelectStmt() *ast.SelectStmt { LockingClause: &ast.List{}, } } + +func (c *cc) collectComparisonOps(n parser.IEq_subexprContext) []antlr.TerminalNode { + var ops []antlr.TerminalNode + for _, child := range n.GetChildren() { + if tn, ok := child.(antlr.TerminalNode); ok { + switch tn.GetText() { + case "<", "<=", ">", ">=": + ops = append(ops, tn) + } + } + } + return ops +} + +func (c *cc) collectBitwiseOps(ctx parser.INeq_subexprContext) []antlr.TerminalNode { + var ops []antlr.TerminalNode + children := ctx.GetChildren() + for _, child := range children { + if tn, ok := child.(antlr.TerminalNode); ok { + txt := tn.GetText() + switch txt { + case "<<", ">>", "<<|", ">>|", "&", "|", "^": + ops = append(ops, tn) + } + } + } + return ops +} + +func (c *cc) collectBitOps(ctx parser.IBit_subexprContext) []antlr.TerminalNode { + var ops []antlr.TerminalNode + children := ctx.GetChildren() + for _, child := range children { + if tn, ok := child.(antlr.TerminalNode); ok { + txt := tn.GetText() + switch txt { + case "+", "-": + ops = append(ops, tn) + } + } + } + return ops +} + +func (c *cc) collectAddOps(ctx parser.IAdd_subexprContext) []antlr.TerminalNode { + var ops []antlr.TerminalNode + for _, child := range ctx.GetChildren() { + if tn, ok := child.(antlr.TerminalNode); ok { + switch tn.GetText() { + case "*", "/", "%": + ops = append(ops, tn) + } + } + } + return ops +} + +func (c *cc) collectEqualityOps(ctx parser.ICond_exprContext) []antlr.TerminalNode { + var ops []antlr.TerminalNode + children := ctx.GetChildren() + for _, child := range children { + if tn, ok := child.(antlr.TerminalNode); ok { + switch tn.GetText() { + case "=", "==", "!=", "<>": + ops = append(ops, tn) + } + } + } + return ops +} From a680b1b919b5e85d57d7dccabbb13bff8b90cf7c Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov <150552906+1NepuNep1@users.noreply.github.com> Date: Fri, 26 Sep 2025 20:01:12 +0300 Subject: [PATCH 16/22] Massive Optional + Functions update (#13) * Massive Functions update * Fixed ydb_type nullable problem and added new funcs to ydb catalog * Update internal/engine/ydb/convert.go * Removed comment from query.go to extractBaseType method --- internal/codegen/golang/query.go | 4 +- internal/codegen/golang/ydb_type.go | 23 +- internal/engine/ydb/convert.go | 165 ++++- internal/engine/ydb/lib/aggregate.go | 533 ++++++++------- internal/engine/ydb/lib/basic.go | 832 ++++++++++++++++++----- internal/engine/ydb/lib/cpp.go | 27 + internal/engine/ydb/lib/cpp/datetime.go | 695 +++++++++++++++++++ internal/engine/ydb/lib/cpp/digest.go | 171 +++++ internal/engine/ydb/lib/cpp/hyperscan.go | 105 +++ internal/engine/ydb/lib/cpp/ip.go | 140 ++++ internal/engine/ydb/lib/cpp/math.go | 439 ++++++++++++ internal/engine/ydb/lib/cpp/pcre.go | 105 +++ internal/engine/ydb/lib/cpp/pire.go | 85 +++ internal/engine/ydb/lib/cpp/re2.go | 319 +++++++++ internal/engine/ydb/lib/cpp/string.go | 152 +++++ internal/engine/ydb/lib/cpp/unicode.go | 532 +++++++++++++++ internal/engine/ydb/lib/cpp/url.go | 413 +++++++++++ internal/engine/ydb/lib/cpp/yson.go | 632 +++++++++++++++++ internal/engine/ydb/lib/window.go | 163 +++++ internal/engine/ydb/stdlib.go | 6 +- internal/sql/ast/recursive_func_call.go | 33 - internal/sql/astutils/rewrite.go | 8 - internal/sql/astutils/walk.go | 20 - 23 files changed, 5114 insertions(+), 488 deletions(-) create mode 100644 internal/engine/ydb/lib/cpp.go create mode 100644 internal/engine/ydb/lib/cpp/datetime.go create mode 100644 internal/engine/ydb/lib/cpp/digest.go create mode 100644 internal/engine/ydb/lib/cpp/hyperscan.go create mode 100644 internal/engine/ydb/lib/cpp/ip.go create mode 100644 internal/engine/ydb/lib/cpp/math.go create mode 100644 internal/engine/ydb/lib/cpp/pcre.go create mode 100644 internal/engine/ydb/lib/cpp/pire.go create mode 100644 internal/engine/ydb/lib/cpp/re2.go create mode 100644 internal/engine/ydb/lib/cpp/string.go create mode 100644 internal/engine/ydb/lib/cpp/unicode.go create mode 100644 internal/engine/ydb/lib/cpp/url.go create mode 100644 internal/engine/ydb/lib/cpp/yson.go create mode 100644 internal/engine/ydb/lib/window.go delete mode 100644 internal/sql/ast/recursive_func_call.go diff --git a/internal/codegen/golang/query.go b/internal/codegen/golang/query.go index 7cda1b7c2b..52be2ecceb 100644 --- a/internal/codegen/golang/query.go +++ b/internal/codegen/golang/query.go @@ -297,7 +297,9 @@ func (v QueryValue) YDBParamMapEntries() string { // ydbBuilderMethodForColumnType maps a YDB column data type to a ParamsBuilder method name. func ydbBuilderMethodForColumnType(dbType string) string { - switch strings.ToLower(dbType) { + baseType := extractBaseType(strings.ToLower(dbType)) + + switch baseType { case "bool": return "Bool" case "uint64": diff --git a/internal/codegen/golang/ydb_type.go b/internal/codegen/golang/ydb_type.go index 0ef665aee1..0a4db80a3b 100644 --- a/internal/codegen/golang/ydb_type.go +++ b/internal/codegen/golang/ydb_type.go @@ -12,9 +12,11 @@ import ( func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string { columnType := strings.ToLower(sdk.DataType(col.Type)) - notNull := col.NotNull || col.IsArray + notNull := (col.NotNull || col.IsArray) && !isNullableType(columnType) emitPointersForNull := options.EmitPointersForNullTypes + columnType = extractBaseType(columnType) + // https://ydb.tech/docs/ru/yql/reference/types/ // ydb-go-sdk doesn't support sql.Null* yet switch columnType { @@ -49,7 +51,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } // return "sql.NullInt16" return "*int16" - case "int", "int32": //ydb doesn't have int type, but we need it to support untyped constants + case "int", "int32": //ydb doesn't have int type, but we need it to support untyped constants if notNull { return "int32" } @@ -159,7 +161,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col return "*string" } return "*string" - + case "date", "date32", "datetime", "timestamp", "tzdate", "tztimestamp", "tzdatetime": if notNull { return "time.Time" @@ -185,3 +187,18 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } } + +// This function extracts the base type from optional types +func extractBaseType(typeStr string) string { + if strings.HasPrefix(typeStr, "optional<") && strings.HasSuffix(typeStr, ">") { + return strings.TrimSuffix(strings.TrimPrefix(typeStr, "optional<"), ">") + } + if strings.HasSuffix(typeStr, "?") { + return strings.TrimSuffix(typeStr, "?") + } + return typeStr +} + +func isNullableType(typeStr string) bool { + return strings.HasPrefix(typeStr, "optional<") && strings.HasSuffix(typeStr, ">") || strings.HasSuffix(typeStr, "?") +} diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index 8b67191ce6..0fa339fa56 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -1,6 +1,7 @@ package ydb import ( + "fmt" "log" "strconv" "strings" @@ -1787,7 +1788,15 @@ func (c *cc) VisitType_name_or_bind(n *parser.Type_name_or_bindContext) interfac } return typeName } else if b := n.Bind_parameter(); b != nil { - return &ast.TypeName{Name: "BIND:" + identifier(parseAnIdOrType(b.An_id_or_type()))} + param, ok := b.Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_or_bind", b) + } + return &ast.TypeName{ + Names: &ast.List{ + Items: []ast.Node{param}, + }, + } } return todo("VisitType_name_or_bind", n) } @@ -1797,6 +1806,8 @@ func (c *cc) VisitType_name(n *parser.Type_nameContext) interface{} { return todo("VisitType_name", n) } + questionCount := len(n.AllQUESTION()) + if composite := n.Type_name_composite(); composite != nil { typeName, ok := composite.Accept(c).(ast.Node) if !ok { @@ -1815,8 +1826,12 @@ func (c *cc) VisitType_name(n *parser.Type_nameContext) interface{} { if !ok { return todo("VisitType_name", decimal.Integer_or_bind(1)) } + name := "decimal" + if questionCount > 0 { + name = name + "?" + } return &ast.TypeName{ - Name: "decimal", + Name: name, TypeOid: 0, Names: &ast.List{ Items: []ast.Node{ @@ -1829,12 +1844,17 @@ func (c *cc) VisitType_name(n *parser.Type_nameContext) interface{} { } if simple := n.Type_name_simple(); simple != nil { + name := simple.GetText() + if questionCount > 0 { + name = name + "?" + } return &ast.TypeName{ - Name: simple.GetText(), + Name: name, TypeOid: 0, } } + // todo: handle multiple ? suffixes return todo("VisitType_name", n) } @@ -1868,19 +1888,7 @@ func (c *cc) VisitType_name_composite(n *parser.Type_name_compositeContext) inte } if opt := n.Type_name_optional(); opt != nil { - if typeName := opt.Type_name_or_bind(); typeName != nil { - tn, ok := typeName.Accept(c).(ast.Node) - if !ok { - return todo("VisitType_name_composite", typeName) - } - return &ast.TypeName{ - Name: "Optional", - TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{tn}, - }, - } - } + return opt.Accept(c) } if tuple := n.Type_name_tuple(); tuple != nil { @@ -2025,6 +2033,27 @@ func (c *cc) VisitType_name_composite(n *parser.Type_name_compositeContext) inte return todo("VisitType_name_composite", n) } +func (c *cc) VisitType_name_optional(n *parser.Type_name_optionalContext) interface{} { + if n == nil || n.Type_name_or_bind() == nil { + return todo("VisitType_name_optional", n) + } + + tn, ok := n.Type_name_or_bind().Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_optional", n.Type_name_or_bind()) + } + innerTypeName, ok := tn.(*ast.TypeName) + if !ok { + return todo("VisitType_name_optional", n.Type_name_or_bind()) + } + name := fmt.Sprintf("Optional<%s>", innerTypeName.Name) + return &ast.TypeName{ + Name: name, + TypeOid: 0, + Names: &ast.List{}, + } +} + func (c *cc) VisitSql_stmt_core(n *parser.Sql_stmt_coreContext) interface{} { if n == nil { return todo("VisitSql_stmt_core", n) @@ -2799,13 +2828,28 @@ func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprCont } funcName := strings.Join(nameParts, ".") - if funcName == "coalesce" { + if funcName == "coalesce" || funcName == "nvl" { return &ast.CoalesceExpr{ Args: funcCall.Args, Location: baseNode.Location, } } + if funcName == "greatest" || funcName == "max_of" { + return &ast.MinMaxExpr{ + Op: ast.MinMaxOp(1), + Args: funcCall.Args, + Location: baseNode.Location, + } + } + if funcName == "least" || funcName == "min_of" { + return &ast.MinMaxExpr{ + Op: ast.MinMaxOp(2), + Args: funcCall.Args, + Location: baseNode.Location, + } + } + funcCall.Func = &ast.FuncName{Name: funcName} funcCall.Funcname.Items = append(funcCall.Funcname.Items, &ast.String{Str: funcName}) @@ -2816,15 +2860,12 @@ func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprCont } } - stmt := &ast.RecursiveFuncCall{ - Func: base, - Funcname: funcCall.Funcname, - AggStar: funcCall.AggStar, - Location: funcCall.Location, - Args: funcCall.Args, - AggDistinct: funcCall.AggDistinct, + stmt := &ast.FuncExpr{ + Xpr: base, + Args: funcCall.Args, + Location: funcCall.Location, } - stmt.Funcname.Items = append(stmt.Funcname.Items, base) + return stmt } @@ -2943,16 +2984,42 @@ func (c *cc) VisitId_expr(n *parser.Id_exprContext) interface{} { if n == nil { return todo("VisitId_expr", n) } + + ref := &ast.ColumnRef{ + Fields: &ast.List{}, + Location: c.pos(n.GetStart()), + } + if id := n.Identifier(); id != nil { - return &ast.ColumnRef{ - Fields: &ast.List{ - Items: []ast.Node{ - NewIdentifier(id.GetText()), - }, - }, - Location: c.pos(id.GetStart()), - } + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(id.GetText())) + return ref + } + + if keyword := n.Keyword_compat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_alter_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_in_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_window_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_hint_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref } + return todo("VisitId_expr", n) } @@ -2979,12 +3046,44 @@ func (c *cc) VisitAtom_expr(n *parser.Atom_exprContext) interface{} { return todo("VisitAtom_expr", n.Bind_parameter()) } return expr + case n.Cast_expr() != nil: + expr, ok := n.Cast_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Cast_expr()) + } + return expr // TODO: check other cases default: return todo("VisitAtom_expr", n) } } +func (c *cc) VisitCast_expr(n *parser.Cast_exprContext) interface{} { + if n == nil || n.CAST() == nil || n.Expr() == nil || n.AS() == nil || n.Type_name_or_bind() == nil { + return todo("VisitCast_expr", n) + } + + expr, ok := n.Expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitCast_expr", n.Expr()) + } + + temp, ok := n.Type_name_or_bind().Accept(c).(ast.Node) + if !ok { + return todo("VisitCast_expr", n.Type_name_or_bind()) + } + typeName, ok := temp.(*ast.TypeName) + if !ok { + return todo("VisitCast_expr", n.Type_name_or_bind()) + } + + return &ast.TypeCast{ + Arg: expr, + TypeName: typeName, + Location: c.pos(n.GetStart()), + } +} + func (c *cc) VisitLiteral_value(n *parser.Literal_valueContext) interface{} { if n == nil { return todo("VisitLiteral_value", n) diff --git a/internal/engine/ydb/lib/aggregate.go b/internal/engine/ydb/lib/aggregate.go index dfb3924e90..7c5d795eca 100644 --- a/internal/engine/ydb/lib/aggregate.go +++ b/internal/engine/ydb/lib/aggregate.go @@ -8,323 +8,400 @@ import ( func AggregateFunctions() []*catalog.Function { var funcs []*catalog.Function - // COUNT(*) - funcs = append(funcs, &catalog.Function{ - Name: "COUNT", - Args: []*catalog.Argument{}, - ReturnType: &ast.TypeName{Name: "Uint64"}, - }) + funcs = append(funcs, countFuncs()...) + funcs = append(funcs, minMaxFuncs()...) + funcs = append(funcs, sumFuncs()...) + funcs = append(funcs, avgFuncs()...) + funcs = append(funcs, countIfFuncs()...) + funcs = append(funcs, sumIfFuncs()...) + funcs = append(funcs, avgIfFuncs()...) + funcs = append(funcs, someFuncs()...) + funcs = append(funcs, countDistinctEstimateHLLFuncs()...) + funcs = append(funcs, maxByMinByFuncs()...) + funcs = append(funcs, stddevVarianceFuncs()...) + funcs = append(funcs, correlationCovarianceFuncs()...) + funcs = append(funcs, percentileMedianFuncs()...) + funcs = append(funcs, boolAndOrXorFuncs()...) + funcs = append(funcs, bitAndOrXorFuncs()...) - // COUNT(T) и COUNT(T?) - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ - Name: "COUNT", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - }, - ReturnType: &ast.TypeName{Name: "Uint64"}, - }) - funcs = append(funcs, &catalog.Function{ + // TODO: Aggregate_List, Top, Bottom, Top_By, Bottom_By, TopFreq, Mode, + // Histogram LinearHistogram, LogarithmicHistogram, LogHistogram, CDF, + // SessionStart, AGGREGATE_BY, MULTI_AGGREGATE_BY + + return funcs +} + +func countFuncs() []*catalog.Function { + return []*catalog.Function{ + { Name: "COUNT", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}, Mode: ast.FuncParamVariadic}, + {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, - }) + }, } +} - // MIN и MAX - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ +func minMaxFuncs() []*catalog.Function { + return []*catalog.Function{ + { Name: "MIN", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: true, - }) - funcs = append(funcs, &catalog.Function{ + ReturnType: &ast.TypeName{Name: "any"}, + }, + { Name: "MAX", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: true, - }) + ReturnType: &ast.TypeName{Name: "any"}, + }, } +} - // SUM для unsigned типов - for _, typ := range unsignedTypes { - funcs = append(funcs, &catalog.Function{ +func sumFuncs() []*catalog.Function { + return []*catalog.Function{ + { Name: "SUM", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnType: &ast.TypeName{Name: "any"}, ReturnTypeNullable: true, - }) + }, } +} - // SUM для signed типов - for _, typ := range signedTypes { - funcs = append(funcs, &catalog.Function{ - Name: "SUM", +func avgFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "AVG", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnType: &ast.TypeName{Name: "any"}, ReturnTypeNullable: true, - }) + }, } +} - // SUM для float/double - for _, typ := range []string{"float", "double"} { - funcs = append(funcs, &catalog.Function{ - Name: "SUM", +func countIfFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "COUNT_IF", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Bool"}}, }, - ReturnType: &ast.TypeName{Name: typ}, + ReturnType: &ast.TypeName{Name: "Uint64"}, ReturnTypeNullable: true, - }) + }, } +} - // AVG для целочисленных типов - for _, typ := range append(unsignedTypes, signedTypes...) { - funcs = append(funcs, &catalog.Function{ - Name: "AVG", +func sumIfFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "SUM_IF", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, }, - ReturnType: &ast.TypeName{Name: "Double"}, + ReturnType: &ast.TypeName{Name: "any"}, ReturnTypeNullable: true, - }) + }, } +} - // AVG для float/double - for _, typ := range []string{"float", "double"} { - funcs = append(funcs, &catalog.Function{ - Name: "AVG", +func avgIfFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "AVG_IF", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, }, - ReturnType: &ast.TypeName{Name: typ}, + ReturnType: &ast.TypeName{Name: "any"}, ReturnTypeNullable: true, - }) + }, } +} - // COUNT_IF - funcs = append(funcs, &catalog.Function{ - Name: "COUNT_IF", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "Bool"}}, - }, - ReturnType: &ast.TypeName{Name: "Uint64"}, - ReturnTypeNullable: true, - }) +func someFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "SOME", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} - // SUM_IF для unsigned - for _, typ := range unsignedTypes { - funcs = append(funcs, &catalog.Function{ - Name: "SUM_IF", +func countDistinctEstimateHLLFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "CountDistinctEstimate", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, ReturnTypeNullable: true, - }) - } - - // SUM_IF для signed - for _, typ := range signedTypes { - funcs = append(funcs, &catalog.Function{ - Name: "SUM_IF", + }, + { + Name: "HyperLogLog", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnType: &ast.TypeName{Name: "Uint64"}, ReturnTypeNullable: true, - }) + }, + { + Name: "HLL", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, } +} - // SUM_IF для float/double - for _, typ := range []string{"float", "double"} { - funcs = append(funcs, &catalog.Function{ - Name: "SUM_IF", +func maxByMinByFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "MAX_BY", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: typ}, + ReturnType: &ast.TypeName{Name: "any"}, ReturnTypeNullable: true, - }) + }, + { + Name: "MIN_BY", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, } + // todo: min/max_by with third argument returning list +} - // AVG_IF для целочисленных - for _, typ := range append(unsignedTypes, signedTypes...) { - funcs = append(funcs, &catalog.Function{ - Name: "AVG_IF", +func stddevVarianceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "STDDEV", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) - } - - // AVG_IF для float/double - for _, typ := range []string{"float", "double"} { - funcs = append(funcs, &catalog.Function{ - Name: "AVG_IF", + }, + { + Name: "STDDEV_POPULATION", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: typ}, + ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) - } - - // SOME - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ - Name: "SOME", + }, + { + Name: "POPULATION_STDDEV", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: typ}, + ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) - } - - // AGGREGATE_LIST и AGGREGATE_LIST_DISTINCT - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ - Name: "AGGREGATE_LIST", + }, + { + Name: "STDDEV_SAMPLE", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: "List<" + typ + ">"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "AGGREGATE_LIST_DISTINCT", + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "STDDEVSAMP", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: "List<" + typ + ">"}, - }) - } - - // BOOL_AND, BOOL_OR, BOOL_XOR - boolAggrs := []string{"BOOL_AND", "BOOL_OR", "BOOL_XOR"} - for _, name := range boolAggrs { - funcs = append(funcs, &catalog.Function{ - Name: name, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "VARIANCE", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) - } - - // BIT_AND, BIT_OR, BIT_XOR - bitAggrs := []string{"BIT_AND", "BIT_OR", "BIT_XOR"} - for _, typ := range append(unsignedTypes, signedTypes...) { - for _, name := range bitAggrs { - funcs = append(funcs, &catalog.Function{ - Name: name, - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: true, - }) - } - } - - // STDDEV и VARIANCE - stdDevVariants := []struct { - name string - returnType string - }{ - {"STDDEV", "Double"}, - {"VARIANCE", "Double"}, - {"STDDEV_SAMPLE", "Double"}, - {"VARIANCE_SAMPLE", "Double"}, - {"STDDEV_POPULATION", "Double"}, - {"VARIANCE_POPULATION", "Double"}, - } - for _, variant := range stdDevVariants { - funcs = append(funcs, &catalog.Function{ - Name: variant.name, + }, + { + Name: "VARIANCE_POPULATION", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, - ReturnType: &ast.TypeName{Name: variant.returnType}, + ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) + }, + { + Name: "POPULATION_VARIANCE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "VARPOP", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "VARIANCE_SAMPLE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, } +} - // CORRELATION и COVARIANCE - corrCovar := []string{"CORRELATION", "COVARIANCE", "COVARIANCE_SAMPLE", "COVARIANCE_POPULATION"} - for _, name := range corrCovar { - funcs = append(funcs, &catalog.Function{ - Name: name, +func correlationCovarianceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "CORRELATION", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "COVARIANCE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "COVARIANCE_SAMPLE", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, ReturnTypeNullable: true, - }) + }, + { + Name: "COVARIANCE_POPULATION", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, } +} - // HISTOGRAM - funcs = append(funcs, &catalog.Function{ - Name: "HISTOGRAM", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "Double"}}, - }, - ReturnType: &ast.TypeName{Name: "HistogramStruct"}, - ReturnTypeNullable: true, - }) - - // TOP и BOTTOM - topBottom := []string{"TOP", "BOTTOM"} - for _, name := range topBottom { - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ - Name: name, - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Uint32"}}, - }, - ReturnType: &ast.TypeName{Name: "List<" + typ + ">"}, - }) - } +func percentileMedianFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "PERCENTILE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "MEDIAN", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "MEDIAN", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, } +} - // MAX_BY и MIN_BY - minMaxBy := []string{"MAX_BY", "MIN_BY"} - for _, name := range minMaxBy { - for _, typ := range types { - funcs = append(funcs, &catalog.Function{ - Name: name, - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "any"}}, - }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: true, - }) - } +func boolAndOrXorFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "BOOL_AND", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + { + Name: "BOOL_OR", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + { + Name: "BOOL_XOR", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, } +} - // ... (добавьте другие агрегатные функции по аналогии) - - return funcs +func bitAndOrXorFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "BIT_AND", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "BIT_OR", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "BIT_XOR", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } } diff --git a/internal/engine/ydb/lib/basic.go b/internal/engine/ydb/lib/basic.go index 08c0011787..d5cbfda950 100644 --- a/internal/engine/ydb/lib/basic.go +++ b/internal/engine/ydb/lib/basic.go @@ -5,199 +5,709 @@ import ( "github.com/sqlc-dev/sqlc/internal/sql/catalog" ) -var types = []string{ - "bool", - "int8", "int16", "int32", "int64", - "uint8", "uint16", "uint32", "uint64", - "float", "double", - "string", "utf8", - "any", -} - -var ( - unsignedTypes = []string{"uint8", "uint16", "uint32", "uint64"} - signedTypes = []string{"int8", "int16", "int32", "int64"} - numericTypes = append(append(unsignedTypes, signedTypes...), "float", "double") -) - func BasicFunctions() []*catalog.Function { var funcs []*catalog.Function - for _, typ := range types { - // COALESCE, NVL - funcs = append(funcs, &catalog.Function{ - Name: "COALESCE", + funcs = append(funcs, lengthFuncs()...) + funcs = append(funcs, substringFuncs()...) + funcs = append(funcs, findFuncs()...) + funcs = append(funcs, rfindFuncs()...) + funcs = append(funcs, startsWithFuncs()...) + funcs = append(funcs, endsWithFuncs()...) + funcs = append(funcs, ifFuncs()...) + funcs = append(funcs, nanvlFuncs()...) + funcs = append(funcs, randomFuncs()...) + funcs = append(funcs, currentUtcFuncs()...) + funcs = append(funcs, currentTzFuncs()...) + funcs = append(funcs, addTimezoneFuncs()...) + funcs = append(funcs, removeTimezoneFuncs()...) + funcs = append(funcs, versionFuncs()...) + funcs = append(funcs, ensureFuncs()...) + funcs = append(funcs, assumeStrictFuncs()...) + funcs = append(funcs, likelyFuncs()...) + funcs = append(funcs, evaluateFuncs()...) + funcs = append(funcs, simpleTypesLiteralsFuncs()...) + funcs = append(funcs, toFromBytesFuncs()...) + funcs = append(funcs, byteAtFuncs()...) + funcs = append(funcs, testClearSetFlipBitFuncs()...) + funcs = append(funcs, absFuncs()...) + funcs = append(funcs, justUnwrapNothingFuncs()...) + funcs = append(funcs, pickleUnpickleFuncs()...) + + // todo: implement functions: + // Udf, AsTuple, AsStruct, AsList, AsDict, AsSet, AsListStrict, AsDictStrict, AsSetStrict, + // Variant, AsVariant, Visit, VisitOrDefault, VariantItem, Way, DynamicVariant, + // Enum, AsEnum, AsTagged, Untag, TableRow, Callable, + // StaticMap, StaticZip, StaticFold, StaticFold1, + // AggregationFactory, AggregateTransformInput, AggregateTransformOutput, AggregateFlatten + + return funcs +} + +func lengthFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "LENGTH", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "LEN", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + } +} + +func substringFuncs() []*catalog.Function { + funcs := []*catalog.Function{ + { + Name: "Substring", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Substring", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } + return funcs +} + +func findFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Find", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Find", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + } +} + +func rfindFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "RFind", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "RFind", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + } +} + +func startsWithFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "StartsWith", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func endsWithFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "EndsWith", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func ifFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "IF", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: false, + }, + } +} + +func nanvlFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "NANVL", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func randomFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Random", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "RandomNumber", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "RandomUuid", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "Uuid"}, + }, + } +} + +func currentUtcFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "CurrentUtcDate", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, { - Type: &ast.TypeName{Name: typ}, + Type: &ast.TypeName{Name: "any"}, Mode: ast.FuncParamVariadic, }, }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: false, - }) - funcs = append(funcs, &catalog.Function{ - Name: "NVL", + ReturnType: &ast.TypeName{Name: "Date"}, + }, + { + Name: "CurrentUtcDatetime", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, { - Type: &ast.TypeName{Name: typ}, + Type: &ast.TypeName{Name: "any"}, Mode: ast.FuncParamVariadic, }, }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: false, - }) + ReturnType: &ast.TypeName{Name: "Datetime"}, + }, + { + Name: "CurrentUtcTimestamp", + Args: []*catalog.Argument{ + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + } +} - // IF(Bool, T, T) -> T - funcs = append(funcs, &catalog.Function{ - Name: "IF", +func currentTzFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "CurrentTzDate", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "TzDate"}, + }, + { + Name: "CurrentTzDatetime", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "TzDatetime"}, + }, + { + Name: "CurrentTzTimestamp", Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, + }, + ReturnType: &ast.TypeName{Name: "TzTimestamp"}, + }, + } +} + +func addTimezoneFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "AddTimezone", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func removeTimezoneFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "RemoveTimezone", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func versionFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Version", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func ensureFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ensure", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "Bool"}}, - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "String"}}, }, - ReturnType: &ast.TypeName{Name: typ}, - ReturnTypeNullable: false, - }) + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "EnsureType", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "EnsureConvertibleTo", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} - // LENGTH, LEN - funcs = append(funcs, &catalog.Function{ - Name: "LENGTH", +func assumeStrictFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "AssumeStrict", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: "Uint32"}, - ReturnTypeNullable: true, - }) - funcs = append(funcs, &catalog.Function{ - Name: "LEN", + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func likelyFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Likely", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, }, - ReturnType: &ast.TypeName{Name: "Uint32"}, - ReturnTypeNullable: true, - }) + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} - // StartsWith, EndsWith - funcs = append(funcs, &catalog.Function{ - Name: "StartsWith", +func evaluateFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "EvaluateExpr", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "EvaluateAtom", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func simpleTypesLiteralsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Bool", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "EndsWith", + }, + { + Name: "Uint8", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "Int32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Int32"}, + }, + { + Name: "Uint32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Int64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + }, + { + Name: "Uint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Float", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Float"}, + }, + { + Name: "Double", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Decimal", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, // precision + {Type: &ast.TypeName{Name: "Uint8"}}, // scale + }, + ReturnType: &ast.TypeName{Name: "Decimal"}, + }, + { + Name: "String", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Utf8", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Yson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Yson"}, + }, + { + Name: "Json", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + }, + { + Name: "Date", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Date"}, + }, + { + Name: "Datetime", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Datetime"}, + }, + { + Name: "Timestamp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + { + Name: "Interval", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "TzDate", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "TzDate"}, + }, + { + Name: "TzDatetime", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "TzDatetime"}, + }, + { + Name: "TzTimestamp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "TzTimestamp"}, + }, + { + Name: "Uuid", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uuid"}, + }, + } +} + +func toFromBytesFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "ToBytes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "FromBytes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func byteAtFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "ByteAt", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + } +} + +func testClearSetFlipBitFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "TestBit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, - }) - - // ABS(T) -> T - } - - // SUBSTRING - funcs = append(funcs, &catalog.Function{ - Name: "Substring", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "String"}}, - }, - ReturnType: &ast.TypeName{Name: "String"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "Substring", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "String"}}, - {Type: &ast.TypeName{Name: "Uint32"}}, - }, - ReturnType: &ast.TypeName{Name: "String"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "Substring", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "String"}}, - {Type: &ast.TypeName{Name: "Uint32"}}, - {Type: &ast.TypeName{Name: "Uint32"}}, - }, - ReturnType: &ast.TypeName{Name: "String"}, - }) - - // FIND / RFIND - for _, name := range []string{"FIND", "RFIND"} { - for _, typ := range []string{"String", "Utf8"} { - funcs = append(funcs, &catalog.Function{ - Name: name, - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, - }, - ReturnType: &ast.TypeName{Name: "Uint32"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: name, - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: typ}}, - {Type: &ast.TypeName{Name: "Uint32"}}, - }, - ReturnType: &ast.TypeName{Name: "Uint32"}, - }) - } + }, + { + Name: "ClearBit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "SetBit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "FlipBit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, } +} - for _, typ := range numericTypes { - funcs = append(funcs, &catalog.Function{ +func absFuncs() []*catalog.Function { + return []*catalog.Function{ + { Name: "Abs", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: typ}}, - }, - ReturnType: &ast.TypeName{Name: typ}, - }) - } - - // NANVL - funcs = append(funcs, &catalog.Function{ - Name: "NANVL", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "Float"}}, - {Type: &ast.TypeName{Name: "Float"}}, - }, - ReturnType: &ast.TypeName{Name: "Float"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "NANVL", - Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "Double"}}, - {Type: &ast.TypeName{Name: "Double"}}, - }, - ReturnType: &ast.TypeName{Name: "Double"}, - }) - - // Random* - funcs = append(funcs, &catalog.Function{ - Name: "Random", - Args: []*catalog.Argument{}, - ReturnType: &ast.TypeName{Name: "Double"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "RandomNumber", - Args: []*catalog.Argument{}, - ReturnType: &ast.TypeName{Name: "Uint64"}, - }) - funcs = append(funcs, &catalog.Function{ - Name: "RandomUuid", - Args: []*catalog.Argument{}, - ReturnType: &ast.TypeName{Name: "Uuid"}, - }) - - // todo: add all remain functions + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} - return funcs +func justUnwrapNothingFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Just", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Unwrap", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unwrap", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Nothing", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func pickleUnpickleFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pickle", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "StablePickle", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Unpickle", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } } diff --git a/internal/engine/ydb/lib/cpp.go b/internal/engine/ydb/lib/cpp.go new file mode 100644 index 0000000000..9f076aba98 --- /dev/null +++ b/internal/engine/ydb/lib/cpp.go @@ -0,0 +1,27 @@ +package lib + +import ( + "github.com/sqlc-dev/sqlc/internal/engine/ydb/lib/cpp" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func CppFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, cpp.DateTimeFunctions()...) + funcs = append(funcs, cpp.DigestFunctions()...) + funcs = append(funcs, cpp.HyperscanFunctions()...) + funcs = append(funcs, cpp.IpFunctions()...) + funcs = append(funcs, cpp.MathFunctions()...) + funcs = append(funcs, cpp.PcreFunctions()...) + funcs = append(funcs, cpp.PireFunctions()...) + funcs = append(funcs, cpp.Re2Functions()...) + funcs = append(funcs, cpp.StringFunctions()...) + funcs = append(funcs, cpp.UnicodeFunctions()...) + funcs = append(funcs, cpp.UrlFunctions()...) + funcs = append(funcs, cpp.YsonFunctions()...) + + // TODO: Histogram library, KNN library, PostgeSQL library + + return funcs +} diff --git a/internal/engine/ydb/lib/cpp/datetime.go b/internal/engine/ydb/lib/cpp/datetime.go new file mode 100644 index 0000000000..ca6f6bc6b6 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/datetime.go @@ -0,0 +1,695 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func DateTimeFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, dateTimeMakeFuncs()...) + funcs = append(funcs, dateTimeGetFuncs()...) + funcs = append(funcs, dateTimeUpdateFuncs()...) + funcs = append(funcs, dateTimeFromFuncs()...) + funcs = append(funcs, dateTimeToFuncs()...) + funcs = append(funcs, dateTimeIntervalFuncs()...) + funcs = append(funcs, dateTimeStartEndFuncs()...) + funcs = append(funcs, dateTimeFormatFuncs()...) + funcs = append(funcs, dateTimeParseFuncs()...) + + return funcs +} + +func dateTimeMakeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::MakeDate", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Date"}, + }, + { + Name: "DateTime::MakeDate32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Date32"}, + }, + { + Name: "DateTime::MakeTzDate32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "TzDate32"}, + }, + { + Name: "DateTime::MakeDatetime", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Datetime"}, + }, + { + Name: "DateTime::MakeTzDatetime", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "TzDatetime"}, + }, + { + Name: "DateTime::MakeDatetime64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Datetime64"}, + }, + { + Name: "DateTime::MakeTzDatetime64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "TzDatetime64"}, + }, + { + Name: "DateTime::MakeTimestamp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + { + Name: "DateTime::MakeTzTimestamp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "TzTimestamp"}, + }, + { + Name: "DateTime::MakeTimestamp64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp64"}, + }, + { + Name: "DateTime::MakeTzTimestamp64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "TzTimestamp64"}, + }, + } +} + +func dateTimeGetFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::GetYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint16"}, + }, + { + Name: "DateTime::GetYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Int32"}, + }, + { + Name: "DateTime::GetDayOfYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint16"}, + }, + { + Name: "DateTime::GetMonth", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetMonthName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "DateTime::GetWeekOfYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetWeekOfYearIso8601", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetDayOfMonth", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetDayOfWeek", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetDayOfWeekName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "DateTime::GetHour", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetMinute", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetSecond", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint8"}, + }, + { + Name: "DateTime::GetMillisecondOfSecond", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "DateTime::GetMicrosecondOfSecond", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "DateTime::GetTimezoneId", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint16"}, + }, + { + Name: "DateTime::GetTimezoneName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func dateTimeUpdateFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::Update", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func dateTimeFromFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::FromSeconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + { + Name: "DateTime::FromSeconds64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp64"}, + }, + { + Name: "DateTime::FromMilliseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + { + Name: "DateTime::FromMilliseconds64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp64"}, + }, + { + Name: "DateTime::FromMicroseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp"}, + }, + { + Name: "DateTime::FromMicroseconds64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Timestamp64"}, + }, + } +} + +func dateTimeToFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::ToSeconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToMilliseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToMicroseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func dateTimeIntervalFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::ToDays", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToHours", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToMinutes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToSeconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToMilliseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ToMicroseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::IntervalFromDays", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromDays", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + { + Name: "DateTime::IntervalFromHours", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromHours", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + { + Name: "DateTime::IntervalFromMinutes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromMinutes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + { + Name: "DateTime::IntervalFromSeconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromSeconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + { + Name: "DateTime::IntervalFromMilliseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromMilliseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + { + Name: "DateTime::IntervalFromMicroseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval"}, + }, + { + Name: "DateTime::Interval64FromMicroseconds", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Interval64"}, + }, + } +} + +func dateTimeStartEndFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::StartOfYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOfYear", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::StartOfQuarter", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOfQuarter", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::StartOfMonth", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOfMonth", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::StartOfWeek", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOfWeek", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::StartOfDay", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOfDay", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::StartOf", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::EndOf", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func dateTimeFormatFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::Format", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func dateTimeParseFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "DateTime::Parse", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::Parse64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "DateTime::ParseRfc822", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::ParseIso8601", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::ParseHttp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "DateTime::ParseX509", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/digest.go b/internal/engine/ydb/lib/cpp/digest.go new file mode 100644 index 0000000000..dccdb8509b --- /dev/null +++ b/internal/engine/ydb/lib/cpp/digest.go @@ -0,0 +1,171 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func DigestFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, digestCrcFuncs()...) + funcs = append(funcs, digestFnvFuncs()...) + funcs = append(funcs, digestMurmurFuncs()...) + funcs = append(funcs, digestCityFuncs()...) + + return funcs +} + +func digestCrcFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Digest::Crc32c", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::Crc64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::Crc64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func digestFnvFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Digest::Fnv32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::Fnv32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::Fnv64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::Fnv64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func digestMurmurFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Digest::MurMurHash", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::MurMurHash", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::MurMurHash32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::MurMurHash32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::MurMurHash2A", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::MurMurHash2A", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::MurMurHash2A32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + { + Name: "Digest::MurMurHash2A32", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint32"}, + }, + } +} + +func digestCityFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Digest::CityHash", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::CityHash", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Digest::CityHash128", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/hyperscan.go b/internal/engine/ydb/lib/cpp/hyperscan.go new file mode 100644 index 0000000000..be3aa968e2 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/hyperscan.go @@ -0,0 +1,105 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func HyperscanFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, hyperscanGrepFuncs()...) + funcs = append(funcs, hyperscanMatchFuncs()...) + funcs = append(funcs, hyperscanBacktrackingFuncs()...) + funcs = append(funcs, hyperscanMultiFuncs()...) + funcs = append(funcs, hyperscanCaptureFuncs()...) + funcs = append(funcs, hyperscanReplaceFuncs()...) + + return funcs +} + +func hyperscanGrepFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::Grep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func hyperscanMatchFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::Match", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func hyperscanBacktrackingFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::BacktrackingGrep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Hyperscan::BacktrackingMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func hyperscanMultiFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::MultiGrep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Hyperscan::MultiMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func hyperscanCaptureFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::Capture", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func hyperscanReplaceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Hyperscan::Replace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/ip.go b/internal/engine/ydb/lib/cpp/ip.go new file mode 100644 index 0000000000..a644da910c --- /dev/null +++ b/internal/engine/ydb/lib/cpp/ip.go @@ -0,0 +1,140 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func IpFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, ipFromStringFuncs()...) + funcs = append(funcs, ipToStringFuncs()...) + funcs = append(funcs, ipCheckFuncs()...) + funcs = append(funcs, ipConvertFuncs()...) + funcs = append(funcs, ipSubnetFuncs()...) + funcs = append(funcs, ipMatchFuncs()...) + + return funcs +} + +func ipFromStringFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::FromString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Ip::SubnetFromString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func ipToStringFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::ToString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Ip::ToString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func ipCheckFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::IsIPv4", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Ip::IsIPv6", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Ip::IsEmbeddedIPv4", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func ipConvertFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::ConvertToIPv6", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func ipSubnetFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::GetSubnet", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Ip::GetSubnet", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Ip::GetSubnetByMask", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func ipMatchFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Ip::SubnetMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/math.go b/internal/engine/ydb/lib/cpp/math.go new file mode 100644 index 0000000000..288464ad0d --- /dev/null +++ b/internal/engine/ydb/lib/cpp/math.go @@ -0,0 +1,439 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func MathFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, mathConstantsFuncs()...) + funcs = append(funcs, mathCheckFuncs()...) + funcs = append(funcs, mathUnaryFuncs()...) + funcs = append(funcs, mathBinaryFuncs()...) + funcs = append(funcs, mathLdexpFuncs()...) + funcs = append(funcs, mathRoundFuncs()...) + funcs = append(funcs, mathFuzzyEqualsFuncs()...) + funcs = append(funcs, mathModRemFuncs()...) + funcs = append(funcs, mathRoundingModeFuncs()...) + funcs = append(funcs, mathNearbyIntFuncs()...) + + return funcs +} + +func mathConstantsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Pi", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::E", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Eps", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func mathCheckFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::IsInf", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Math::IsNaN", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Math::IsFinite", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func mathUnaryFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Abs", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Acos", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Asin", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Asinh", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Atan", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Cbrt", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Ceil", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Cos", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Cosh", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Erf", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::ErfInv", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::ErfcInv", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Exp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Exp2", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Fabs", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Floor", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Lgamma", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Rint", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Sigmoid", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Sin", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Sinh", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Sqrt", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Tan", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Tanh", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Tgamma", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Trunc", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Log", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Log2", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Log10", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func mathBinaryFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Atan2", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Fmod", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Hypot", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Pow", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Remainder", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func mathLdexpFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Ldexp", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func mathRoundFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Round", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + { + Name: "Math::Round", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Int32"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func mathFuzzyEqualsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::FuzzyEquals", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Math::FuzzyEquals", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "Double"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func mathModRemFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::Mod", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + { + Name: "Math::Rem", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Int64"}}, + {Type: &ast.TypeName{Name: "Int64"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + } +} + +func mathRoundingModeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::RoundDownward", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Math::RoundToNearest", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Math::RoundTowardZero", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Math::RoundUpward", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func mathNearbyIntFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Math::NearbyInt", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Double"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/pcre.go b/internal/engine/ydb/lib/cpp/pcre.go new file mode 100644 index 0000000000..4b313ff80f --- /dev/null +++ b/internal/engine/ydb/lib/cpp/pcre.go @@ -0,0 +1,105 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func PcreFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, pcreGrepFuncs()...) + funcs = append(funcs, pcreMatchFuncs()...) + funcs = append(funcs, pcreBacktrackingFuncs()...) + funcs = append(funcs, pcreMultiFuncs()...) + funcs = append(funcs, pcreCaptureFuncs()...) + funcs = append(funcs, pcreReplaceFuncs()...) + + return funcs +} + +func pcreGrepFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::Grep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pcreMatchFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::Match", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pcreBacktrackingFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::BacktrackingGrep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Pcre::BacktrackingMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pcreMultiFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::MultiGrep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Pcre::MultiMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pcreCaptureFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::Capture", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pcreReplaceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pcre::Replace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/pire.go b/internal/engine/ydb/lib/cpp/pire.go new file mode 100644 index 0000000000..ae7eece256 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/pire.go @@ -0,0 +1,85 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func PireFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, pireGrepFuncs()...) + funcs = append(funcs, pireMatchFuncs()...) + funcs = append(funcs, pireMultiFuncs()...) + funcs = append(funcs, pireCaptureFuncs()...) + funcs = append(funcs, pireReplaceFuncs()...) + + return funcs +} + +func pireGrepFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pire::Grep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pireMatchFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pire::Match", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pireMultiFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pire::MultiGrep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Pire::MultiMatch", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pireCaptureFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pire::Capture", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func pireReplaceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Pire::Replace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/re2.go b/internal/engine/ydb/lib/cpp/re2.go new file mode 100644 index 0000000000..667c0f57e0 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/re2.go @@ -0,0 +1,319 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func Re2Functions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, re2GrepFuncs()...) + funcs = append(funcs, re2MatchFuncs()...) + funcs = append(funcs, re2CaptureFuncs()...) + funcs = append(funcs, re2FindAndConsumeFuncs()...) + funcs = append(funcs, re2ReplaceFuncs()...) + funcs = append(funcs, re2CountFuncs()...) + funcs = append(funcs, re2OptionsFuncs()...) + + return funcs +} + +func re2GrepFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Grep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Grep", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2MatchFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Match", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Match", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2CaptureFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Capture", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Capture", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2FindAndConsumeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::FindAndConsume", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::FindAndConsume", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2ReplaceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Replace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Replace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2CountFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Count", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Count", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func re2OptionsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Re2::Options", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Re2::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/string.go b/internal/engine/ydb/lib/cpp/string.go new file mode 100644 index 0000000000..291dd10eec --- /dev/null +++ b/internal/engine/ydb/lib/cpp/string.go @@ -0,0 +1,152 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func StringFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, stringBase32Funcs()...) + funcs = append(funcs, stringBase64Funcs()...) + funcs = append(funcs, stringEscapeFuncs()...) + funcs = append(funcs, stringHexFuncs()...) + funcs = append(funcs, stringHtmlFuncs()...) + funcs = append(funcs, stringCgiFuncs()...) + + return funcs +} + +func stringBase32Funcs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::Base32Encode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::Base32Decode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "String::Base32StrictDecode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func stringBase64Funcs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::Base64Encode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::Base64Decode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "String::Base64StrictDecode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func stringEscapeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::EscapeC", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::UnescapeC", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func stringHexFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::HexEncode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::HexDecode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func stringHtmlFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::EncodeHtml", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::DecodeHtml", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func stringCgiFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "String::CgiEscape", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "String::CgiUnescape", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/unicode.go b/internal/engine/ydb/lib/cpp/unicode.go new file mode 100644 index 0000000000..e8c967020d --- /dev/null +++ b/internal/engine/ydb/lib/cpp/unicode.go @@ -0,0 +1,532 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func UnicodeFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, unicodeCheckFuncs()...) + funcs = append(funcs, unicodeLengthFuncs()...) + funcs = append(funcs, unicodeFindFuncs()...) + funcs = append(funcs, unicodeSubstringFuncs()...) + funcs = append(funcs, unicodeNormalizeFuncs()...) + funcs = append(funcs, unicodeTranslitFuncs()...) + funcs = append(funcs, unicodeLevensteinFuncs()...) + funcs = append(funcs, unicodeFoldFuncs()...) + funcs = append(funcs, unicodeReplaceFuncs()...) + funcs = append(funcs, unicodeRemoveFuncs()...) + funcs = append(funcs, unicodeCodePointFuncs()...) + funcs = append(funcs, unicodeReverseFuncs()...) + funcs = append(funcs, unicodeCaseFuncs()...) + funcs = append(funcs, unicodeSplitJoinFuncs()...) + funcs = append(funcs, unicodeToUint64Funcs()...) + funcs = append(funcs, unicodeStripFuncs()...) + funcs = append(funcs, unicodeIsFuncs()...) + funcs = append(funcs, unicodeIsUnicodeSetFuncs()...) + + return funcs +} + +func unicodeCheckFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::IsUtf", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func unicodeLengthFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::GetLength", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func unicodeFindFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Find", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Unicode::Find", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Unicode::RFind", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Unicode::RFind", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + } +} + +func unicodeSubstringFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Substring", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeNormalizeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Normalize", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::NormalizeNFD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::NormalizeNFC", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::NormalizeNFKD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::NormalizeNFKC", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeTranslitFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Translit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Translit", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeLevensteinFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::LevensteinDistance", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func unicodeFoldFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::Fold", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeReplaceFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::ReplaceAll", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::ReplaceFirst", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::ReplaceLast", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeRemoveFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::RemoveAll", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::RemoveFirst", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::RemoveLast", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeCodePointFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::ToCodePointList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unicode::FromCodePointList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeReverseFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Reverse", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeCaseFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::ToLower", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::ToUpper", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + { + Name: "Unicode::ToTitle", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeSplitJoinFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::SplitToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unicode::SplitToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unicode::SplitToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unicode::SplitToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Unicode::JoinFromList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeToUint64Funcs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::ToUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Unicode::ToUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Uint16"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Unicode::TryToUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Unicode::TryToUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Uint16"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + } +} + +func unicodeStripFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::Strip", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Utf8"}, + }, + } +} + +func unicodeIsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::IsAscii", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsSpace", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsUpper", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsLower", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsAlpha", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsAlnum", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Unicode::IsHex", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func unicodeIsUnicodeSetFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Unicode::IsUnicodeSet", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Utf8"}}, + {Type: &ast.TypeName{Name: "Utf8"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/url.go b/internal/engine/ydb/lib/cpp/url.go new file mode 100644 index 0000000000..151115a8f0 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/url.go @@ -0,0 +1,413 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func UrlFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, urlNormalizeFuncs()...) + funcs = append(funcs, urlEncodeDecodeFuncs()...) + funcs = append(funcs, urlParseFuncs()...) + funcs = append(funcs, urlGetFuncs()...) + funcs = append(funcs, urlDomainFuncs()...) + funcs = append(funcs, urlCutFuncs()...) + funcs = append(funcs, urlPunycodeFuncs()...) + funcs = append(funcs, urlQueryStringFuncs()...) + + return funcs +} + +func urlNormalizeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::Normalize", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::NormalizeWithDefaultHttpScheme", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func urlEncodeDecodeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::Encode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::Decode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func urlParseFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::Parse", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func urlGetFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::GetScheme", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::GetHost", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetHostPort", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetSchemeHost", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetSchemeHostPort", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetPort", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetTail", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetPath", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetFragment", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetCGIParam", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::GetDomain", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Uint8"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + } +} + +func urlDomainFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::GetTLD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::IsKnownTLD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Url::IsWellKnownTLD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Url::GetDomainLevel", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "Url::GetSignificantDomain", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::GetSignificantDomain", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::GetOwner", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func urlCutFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::CutScheme", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::CutWWW", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::CutWWW2", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::CutQueryStringAndFragment", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} + +func urlPunycodeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Url::HostNameToPunycode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::ForceHostNameToPunycode", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::PunycodeToHostName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Url::ForcePunycodeToHostName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::CanBePunycodeHostName", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func urlQueryStringFuncs() []*catalog.Function { + // fixme: rewrite with containers if possible + return []*catalog.Function{ + { + Name: "Url::QueryStringToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::QueryStringToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Url::BuildQueryString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + { + Name: "Url::BuildQueryString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/yson.go b/internal/engine/ydb/lib/cpp/yson.go new file mode 100644 index 0000000000..78332e0f29 --- /dev/null +++ b/internal/engine/ydb/lib/cpp/yson.go @@ -0,0 +1,632 @@ +package cpp + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func YsonFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, ysonParseFuncs()...) + funcs = append(funcs, ysonFromFuncs()...) + funcs = append(funcs, ysonWithAttributesFuncs()...) + funcs = append(funcs, ysonEqualsFuncs()...) + funcs = append(funcs, ysonGetHashFuncs()...) + funcs = append(funcs, ysonIsFuncs()...) + funcs = append(funcs, ysonGetLengthFuncs()...) + funcs = append(funcs, ysonConvertToFuncs()...) + funcs = append(funcs, ysonConvertToListFuncs()...) + funcs = append(funcs, ysonConvertToDictFuncs()...) + funcs = append(funcs, ysonContainsFuncs()...) + funcs = append(funcs, ysonLookupFuncs()...) + funcs = append(funcs, ysonYPathFuncs()...) + funcs = append(funcs, ysonAttributesFuncs()...) + funcs = append(funcs, ysonSerializeFuncs()...) + funcs = append(funcs, ysonOptionsFuncs()...) + + return funcs +} + +func ysonParseFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Parse", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Yson"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ParseJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Json"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ParseJsonDecodeUtf8", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Json"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::Parse", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ParseJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ParseJsonDecodeUtf8", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonFromFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::From", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func ysonWithAttributesFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::WithAttributes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonEqualsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Equals", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func ysonGetHashFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::GetHash", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func ysonIsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::IsEntity", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsDouble", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsInt64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsBool", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + { + Name: "Yson::IsDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + }, + } +} + +func ysonGetLengthFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::GetLength", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonConvertToFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::ConvertTo", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToBool", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ConvertToInt64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ConvertToUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ConvertToDouble", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ConvertToString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::ConvertToList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func ysonConvertToListFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::ConvertToBoolList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToInt64List", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToUint64List", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToDoubleList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToStringList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func ysonConvertToDictFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::ConvertToDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToBoolDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToInt64Dict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToUint64Dict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToDoubleDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::ConvertToStringDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func ysonContainsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Contains", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonLookupFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Lookup", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupBool", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupInt64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupDouble", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::LookupList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonYPathFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::YPath", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathBool", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Bool"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathInt64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Int64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathUint64", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathDouble", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathString", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "String"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathDict", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::YPathList", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "String"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonAttributesFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Attributes", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} + +func ysonSerializeFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Serialize", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Yson"}, + }, + { + Name: "Yson::SerializeText", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Yson"}, + }, + { + Name: "Yson::SerializePretty", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Yson"}, + }, + { + Name: "Yson::SerializeJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::SerializeJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::SerializeJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::SerializeJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + ReturnTypeNullable: true, + }, + { + Name: "Yson::SerializeJson", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "Json"}, + ReturnTypeNullable: true, + }, + } +} + +func ysonOptionsFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "Yson::Options", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + { + Name: "Yson::Options", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Bool"}}, + {Type: &ast.TypeName{Name: "Bool"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/lib/window.go b/internal/engine/ydb/lib/window.go new file mode 100644 index 0000000000..7c339217ad --- /dev/null +++ b/internal/engine/ydb/lib/window.go @@ -0,0 +1,163 @@ +package lib + +import ( + "github.com/sqlc-dev/sqlc/internal/sql/ast" + "github.com/sqlc-dev/sqlc/internal/sql/catalog" +) + +func WindowFunctions() []*catalog.Function { + var funcs []*catalog.Function + + funcs = append(funcs, rowNumberFuncs()...) + funcs = append(funcs, lagLeadFuncs()...) + funcs = append(funcs, firstLastValueFuncs()...) + funcs = append(funcs, nthValueFuncs()...) + funcs = append(funcs, rankFuncs()...) + funcs = append(funcs, ntileFuncs()...) + funcs = append(funcs, cumeDistFuncs()...) + funcs = append(funcs, sessionStartFuncs()...) + + return funcs +} + +func rowNumberFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "ROW_NUMBER", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func lagLeadFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "LAG", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "LAG", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "LEAD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "LEAD", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "Uint32"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func firstLastValueFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "FIRST_VALUE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + { + Name: "LAST_VALUE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func nthValueFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "NTH_VALUE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "any"}, + ReturnTypeNullable: true, + }, + } +} + +func rankFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "RANK", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "DENSE_RANK", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + { + Name: "PERCENT_RANK", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func ntileFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "NTILE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "Uint64"}}, + }, + ReturnType: &ast.TypeName{Name: "Uint64"}, + }, + } +} + +func cumeDistFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "CUME_DIST", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "Double"}, + }, + } +} + +func sessionStartFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "SESSION_START", + Args: []*catalog.Argument{}, + ReturnType: &ast.TypeName{Name: "any"}, + }, + } +} diff --git a/internal/engine/ydb/stdlib.go b/internal/engine/ydb/stdlib.go index 21dc21242b..69ef6b223e 100644 --- a/internal/engine/ydb/stdlib.go +++ b/internal/engine/ydb/stdlib.go @@ -8,11 +8,15 @@ import ( func defaultSchema(name string) *catalog.Schema { s := &catalog.Schema{ Name: name, - Funcs: make([]*catalog.Function, 0, 128), + Funcs: []*catalog.Function{}, } s.Funcs = append(s.Funcs, lib.BasicFunctions()...) s.Funcs = append(s.Funcs, lib.AggregateFunctions()...) + s.Funcs = append(s.Funcs, lib.WindowFunctions()...) + s.Funcs = append(s.Funcs, lib.CppFunctions()...) + + // TODO: add container functions if return s } diff --git a/internal/sql/ast/recursive_func_call.go b/internal/sql/ast/recursive_func_call.go deleted file mode 100644 index 1c7c0a8125..0000000000 --- a/internal/sql/ast/recursive_func_call.go +++ /dev/null @@ -1,33 +0,0 @@ -package ast - -type RecursiveFuncCall struct { - Func Node - Funcname *List - Args *List - AggOrder *List - AggFilter Node - AggWithinGroup bool - AggStar bool - AggDistinct bool - FuncVariadic bool - Over *WindowDef - Location int -} - -func (n *RecursiveFuncCall) Pos() int { - return n.Location -} - -func (n *RecursiveFuncCall) Format(buf *TrackedBuffer) { - if n == nil { - return - } - buf.astFormat(n.Func) - buf.WriteString("(") - if n.AggStar { - buf.WriteString("*") - } else { - buf.astFormat(n.Args) - } - buf.WriteString(")") -} diff --git a/internal/sql/astutils/rewrite.go b/internal/sql/astutils/rewrite.go index bcc7c17e40..372d0ee7a2 100644 --- a/internal/sql/astutils/rewrite.go +++ b/internal/sql/astutils/rewrite.go @@ -1013,14 +1013,6 @@ func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast. a.apply(n, "Roles", nil, n.Roles) a.apply(n, "Newrole", nil, n.Newrole) - case *ast.RecursiveFuncCall: - a.apply(n, "Func", nil, n.Func) - a.apply(n, "Funcname", nil, n.Funcname) - a.apply(n, "Args", nil, n.Args) - a.apply(n, "AggOrder", nil, n.AggOrder) - a.apply(n, "AggFilter", nil, n.AggFilter) - a.apply(n, "Over", nil, n.Over) - case *ast.RefreshMatViewStmt: a.apply(n, "Relation", nil, n.Relation) diff --git a/internal/sql/astutils/walk.go b/internal/sql/astutils/walk.go index dfc313fda1..e7b78d126b 100644 --- a/internal/sql/astutils/walk.go +++ b/internal/sql/astutils/walk.go @@ -1734,26 +1734,6 @@ func Walk(f Visitor, node ast.Node) { Walk(f, n.Newrole) } - case *ast.RecursiveFuncCall: - if n.Func != nil { - Walk(f, n.Func) - } - if n.Funcname != nil { - Walk(f, n.Funcname) - } - if n.Args != nil { - Walk(f, n.Args) - } - if n.AggOrder != nil { - Walk(f, n.AggOrder) - } - if n.AggFilter != nil { - Walk(f, n.AggFilter) - } - if n.Over != nil { - Walk(f, n.Over) - } - case *ast.RefreshMatViewStmt: if n.Relation != nil { Walk(f, n.Relation) From a69429ce0005ffb7ee1298b732409727325138cf Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov <150552906+1NepuNep1@users.noreply.github.com> Date: Wed, 8 Oct 2025 17:36:16 +0300 Subject: [PATCH 17/22] Added simple types in param builder and ydbType (#14) --- internal/codegen/golang/query.go | 10 +++++++--- internal/codegen/golang/ydb_type.go | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/internal/codegen/golang/query.go b/internal/codegen/golang/query.go index 52be2ecceb..1ca3e1615e 100644 --- a/internal/codegen/golang/query.go +++ b/internal/codegen/golang/query.go @@ -304,15 +304,15 @@ func ydbBuilderMethodForColumnType(dbType string) string { return "Bool" case "uint64": return "Uint64" - case "int64": + case "int64", "bigserial", "serial8": return "Int64" case "uint32": return "Uint32" - case "int32": + case "int32", "serial", "serial4": return "Int32" case "uint16": return "Uint16" - case "int16": + case "int16", "smallserial","serial2": return "Int16" case "uint8": return "Uint8" @@ -342,6 +342,10 @@ func ydbBuilderMethodForColumnType(dbType string) string { return "TzDatetime" case "tztimestamp": return "TzTimestamp" + case "uuid": + return "UUID" + case "yson": + return "YSON" //TODO: support other types default: diff --git a/internal/codegen/golang/ydb_type.go b/internal/codegen/golang/ydb_type.go index 0a4db80a3b..3a01cc8de7 100644 --- a/internal/codegen/golang/ydb_type.go +++ b/internal/codegen/golang/ydb_type.go @@ -171,6 +171,24 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } return "*time.Time" + case "uuid": + if notNull { + return "uuid.UUID" + } + if emitPointersForNull { + return "*uuid.UUID" + } + return "*uuid.UUID" + + case "yson": + if notNull { + return "[]byte" + } + if emitPointersForNull { + return "*[]byte" + } + return "*[]byte" + case "null": // return "sql.Null" return "interface{}" From 816eda801855b270d5b6b0e58e25d50c6a97219d Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov <150552906+1NepuNep1@users.noreply.github.com> Date: Thu, 9 Oct 2025 16:28:52 +0300 Subject: [PATCH 18/22] Ydb-go-sdk codegen: Containers support in ydb.ParamsBuilder() (#15) * Added Arrays support + rewrites some internal logic to handle sqlc.arg/narg/slice in ydb * Supported containertype named parameters * Rewrited params to handle compex types and comment if type is interface{} --- examples/authors/ydb/query.sql.go | 34 +- internal/codegen/golang/query.go | 187 +++++-- .../templates/ydb-go-sdk/queryCode.tmpl | 70 ++- internal/codegen/golang/ydb_type.go | 3 +- internal/engine/ydb/convert.go | 489 +++++++++++++----- internal/sql/rewrite/parameters.go | 4 +- 6 files changed, 568 insertions(+), 219 deletions(-) diff --git a/examples/authors/ydb/query.sql.go b/examples/authors/ydb/query.sql.go index e9b6b332a4..6d3c6743a9 100644 --- a/examples/authors/ydb/query.sql.go +++ b/examples/authors/ydb/query.sql.go @@ -24,16 +24,12 @@ type CreateOrUpdateAuthorParams struct { } func (q *Queries) CreateOrUpdateAuthor(ctx context.Context, arg CreateOrUpdateAuthorParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$p0").Uint64(arg.P0) + parameters = parameters.Param("$p1").Text(arg.P1) + parameters = parameters.Param("$p2").BeginOptional().Text(arg.P2).EndOptional() err := q.db.Exec(ctx, createOrUpdateAuthor, - append(opts, - query.WithParameters( - ydb.ParamsBuilder(). - Param("$p0").Uint64(arg.P0). - Param("$p1").Text(arg.P1). - Param("$p2").BeginOptional().Text(arg.P2).EndOptional(). - Build(), - ), - )..., + append(opts, query.WithParameters(parameters.Build()))..., ) if err != nil { return xerrors.WithStackTrace(err) @@ -46,14 +42,10 @@ DELETE FROM authors WHERE id = $p0 ` func (q *Queries) DeleteAuthor(ctx context.Context, p0 uint64, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$p0").Uint64(p0) err := q.db.Exec(ctx, deleteAuthor, - append(opts, - query.WithParameters( - ydb.ParamsBuilder(). - Param("$p0").Uint64(p0). - Build(), - ), - )..., + append(opts, query.WithParameters(parameters.Build()))..., ) if err != nil { return xerrors.WithStackTrace(err) @@ -79,14 +71,10 @@ WHERE id = $p0 LIMIT 1 ` func (q *Queries) GetAuthor(ctx context.Context, p0 uint64, opts ...query.ExecuteOption) (Author, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$p0").Uint64(p0) row, err := q.db.QueryRow(ctx, getAuthor, - append(opts, - query.WithParameters( - ydb.ParamsBuilder(). - Param("$p0").Uint64(p0). - Build(), - ), - )..., + append(opts, query.WithParameters(parameters.Build()))..., ) var i Author if err != nil { diff --git a/internal/codegen/golang/query.go b/internal/codegen/golang/query.go index 1ca3e1615e..3e789f4c60 100644 --- a/internal/codegen/golang/query.go +++ b/internal/codegen/golang/query.go @@ -128,6 +128,27 @@ func (v QueryValue) UniqueFields() []Field { return fields } +// YDBUniqueFieldsWithComments returns unique fields for YDB struct generation with comments for interface{} fields +func (v QueryValue) YDBUniqueFieldsWithComments() []Field { + seen := map[string]struct{}{} + fields := make([]Field, 0, len(v.Struct.Fields)) + + for _, field := range v.Struct.Fields { + if _, found := seen[field.Name]; found { + continue + } + seen[field.Name] = struct{}{} + + if strings.HasSuffix(field.Type, "interface{}") { + field.Comment = "// sqlc couldn't resolve type, pass via params" + } + + fields = append(fields, field) + } + + return fields +} + func (v QueryValue) Params() string { if v.isEmpty() { return "" @@ -198,7 +219,7 @@ func (v QueryValue) HasSqlcSlices() bool { func (v QueryValue) Scan() string { var out []string if v.Struct == nil { - if strings.HasPrefix(v.Typ, "[]") && v.Typ != "[]byte" && !v.SQLDriver.IsPGX() { + if strings.HasPrefix(v.Typ, "[]") && v.Typ != "[]byte" && !v.SQLDriver.IsPGX() && !v.SQLDriver.IsYDBGoSDK() { out = append(out, "pq.Array(&"+v.Name+")") } else { out = append(out, "&"+v.Name) @@ -209,7 +230,7 @@ func (v QueryValue) Scan() string { // append any embedded fields if len(f.EmbedFields) > 0 { for _, embed := range f.EmbedFields { - if strings.HasPrefix(embed.Type, "[]") && embed.Type != "[]byte" && !v.SQLDriver.IsPGX() { + if strings.HasPrefix(embed.Type, "[]") && embed.Type != "[]byte" && !v.SQLDriver.IsPGX() && !v.SQLDriver.IsYDBGoSDK() { out = append(out, "pq.Array(&"+v.Name+"."+f.Name+"."+embed.Name+")") } else { out = append(out, "&"+v.Name+"."+f.Name+"."+embed.Name) @@ -218,7 +239,7 @@ func (v QueryValue) Scan() string { continue } - if strings.HasPrefix(f.Type, "[]") && f.Type != "[]byte" && !v.SQLDriver.IsPGX() { + if strings.HasPrefix(f.Type, "[]") && f.Type != "[]byte" && !v.SQLDriver.IsPGX() && !v.SQLDriver.IsYDBGoSDK() { out = append(out, "pq.Array(&"+v.Name+"."+f.Name+")") } else { out = append(out, "&"+v.Name+"."+f.Name) @@ -269,32 +290,6 @@ func addDollarPrefix(name string) string { return "$" + name } -// YDBParamMapEntries returns entries for a map[string]any literal for YDB parameters. -func (v QueryValue) YDBParamMapEntries() string { - if v.isEmpty() { - return "" - } - - var parts []string - for _, field := range v.getParameterFields() { - if field.Column != nil && field.Column.IsNamedParam { - name := field.Column.GetName() - if name != "" { - key := fmt.Sprintf("%q", addDollarPrefix(name)) - variable := v.VariableForField(field) - parts = append(parts, key+": "+escape(variable)) - } - } - } - - if len(parts) == 0 { - return "" - } - - parts = append(parts, "") - return "\n" + strings.Join(parts, ",\n") -} - // ydbBuilderMethodForColumnType maps a YDB column data type to a ParamsBuilder method name. func ydbBuilderMethodForColumnType(dbType string) string { baseType := extractBaseType(strings.ToLower(dbType)) @@ -353,52 +348,89 @@ func ydbBuilderMethodForColumnType(dbType string) string { } } -// YDBParamsBuilder emits Go code that constructs YDB params using ParamsBuilder. -func (v QueryValue) YDBParamsBuilder() string { +// ydbIterateNamedParams iterates over named parameters and calls the provided function for each one. +// The function receives the field and method name, and should return true to continue iteration. +func (v QueryValue) ydbIterateNamedParams(fn func(field Field, method string) bool) bool { if v.isEmpty() { - return "" + return false } - var lines []string - for _, field := range v.getParameterFields() { - if field.Column != nil && field.Column.IsNamedParam { + if field.Column != nil { name := field.Column.GetName() if name == "" { continue } - paramName := fmt.Sprintf("%q", addDollarPrefix(name)) - variable := escape(v.VariableForField(field)) var method string if field.Column != nil && field.Column.Type != nil { method = ydbBuilderMethodForColumnType(sdk.DataType(field.Column.Type)) } - goType := field.Type - isPtr := strings.HasPrefix(goType, "*") - if isPtr { - goType = strings.TrimPrefix(goType, "*") + if !fn(field, method) { + return false } + } + } + return true +} - if method == "" { - panic(fmt.Sprintf("unknown YDB column type for param %s (goType=%s)", name, goType)) - } +// YDBHasComplexContainers returns true if there are complex container types that sqlc cannot handle automatically. +func (v QueryValue) YDBHasComplexContainers() bool { + hasComplex := false + v.ydbIterateNamedParams(func(field Field, method string) bool { + if method == "" { + hasComplex = true + return false + } + return true + }) + return hasComplex +} - if isPtr { - lines = append(lines, fmt.Sprintf("\t\t\tParam(%s).BeginOptional().%s(%s).EndOptional().", paramName, method, variable)) - } else { - lines = append(lines, fmt.Sprintf("\t\t\tParam(%s).%s(%s).", paramName, method, variable)) - } +// YDBParamsBuilder emits Go code that constructs YDB params using ParamsBuilder. +func (v QueryValue) YDBParamsBuilder() string { + var lines []string + + v.ydbIterateNamedParams(func(field Field, method string) bool { + if method == "" { + return true } - } - if len(lines) == 0 { - return "" - } + name := field.Column.GetName() + paramName := fmt.Sprintf("%q", addDollarPrefix(name)) + variable := escape(v.VariableForField(field)) + + goType := field.Type + isPtr := strings.HasPrefix(goType, "*") + isArray := field.Column.IsArray || field.Column.IsSqlcSlice + + if isArray { + lines = append(lines, fmt.Sprintf("\tvar list = parameters.Param(%s).BeginList()", paramName)) + lines = append(lines, fmt.Sprintf("\tfor _, param := range %s {", variable)) + lines = append(lines, fmt.Sprintf("\t\tlist = list.Add().%s(param)", method)) + lines = append(lines, "\t}") + lines = append(lines, "\tparameters = list.EndList()") + } else if isPtr { + lines = append(lines, fmt.Sprintf("\tparameters = parameters.Param(%s).BeginOptional().%s(%s).EndOptional()", paramName, method, variable)) + } else { + lines = append(lines, fmt.Sprintf("\tparameters = parameters.Param(%s).%s(%s)", paramName, method, variable)) + } + + return true + }) params := strings.Join(lines, "\n") - return fmt.Sprintf("\nquery.WithParameters(\n\t\tydb.ParamsBuilder().\n%s\n\t\t\tBuild(),\n\t\t),\n", params) + return fmt.Sprintf("\tparameters := ydb.ParamsBuilder()\n%s", params) +} + +func (v QueryValue) YDBHasParams() bool { + hasParams := false + v.ydbIterateNamedParams(func(field Field, method string) bool { + hasParams = true + return false + }) + return hasParams } func (v QueryValue) getParameterFields() []Field { @@ -415,6 +447,53 @@ func (v QueryValue) getParameterFields() []Field { return v.Struct.Fields } +// YDBPair returns the argument name and type for YDB query methods, filtering out interface{} parameters +// that are handled by manualParams instead. +func (v QueryValue) YDBPair() string { + if v.isEmpty() { + return "" + } + + var out []string + for _, arg := range v.YDBPairs() { + out = append(out, arg.Name+" "+arg.Type) + } + return strings.Join(out, ",") +} + +// YDBPairs returns the argument name and type for YDB query methods, filtering out interface{} parameters +// that are handled by manualParams instead. +func (v QueryValue) YDBPairs() []Argument { + if v.isEmpty() { + return nil + } + + if !v.EmitStruct() && v.IsStruct() { + var out []Argument + for _, f := range v.Struct.Fields { + if strings.HasSuffix(f.Type, "interface{}") { + continue + } + out = append(out, Argument{ + Name: escape(toLowerCase(f.Name)), + Type: f.Type, + }) + } + return out + } + + if strings.HasSuffix(v.Typ, "interface{}") { + return nil + } + + return []Argument{ + { + Name: escape(v.Name), + Type: v.DefineType(), + }, + } +} + // A struct used to generate methods and fields on the Queries struct type Query struct { Cmd string diff --git a/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl b/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl index c56fc953f8..9c60ded05f 100644 --- a/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl +++ b/internal/codegen/golang/templates/ydb-go-sdk/queryCode.tmpl @@ -6,8 +6,8 @@ const {{.ConstantName}} = {{$.Q}}-- name: {{.MethodName}} {{.Cmd}} {{$.Q}} {{if .Arg.EmitStruct}} -type {{.Arg.Type}} struct { {{- range .Arg.UniqueFields}} - {{.Name}} {{.Type}} {{if .Tag}}{{$.Q}}{{.Tag}}{{$.Q}}{{end}} +type {{.Arg.Type}} struct { {{- range .Arg.YDBUniqueFieldsWithComments}} + {{.Name}} {{.Type}} {{if .Tag}}{{$.Q}}{{.Tag}}{{$.Q}}{{end}}{{if .Comment}} {{.Comment}}{{end}} {{- end}} } {{end}} @@ -22,13 +22,27 @@ type {{.Ret.Type}} struct { {{- range .Ret.Struct.Fields}} {{if eq .Cmd ":one"}} {{range .Comments}}//{{.}} {{end -}} -func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ({{.Ret.DefineType}}, error) { +{{if .Arg.YDBHasComplexContainers}} +func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if .Arg.YDBPair}}{{.Arg.YDBPair}}, {{end}}params ydb.Params, opts ...query.ExecuteOption) ({{.Ret.DefineType}}, error) { +{{else}} +func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if .Arg.YDBPair}}{{.Arg.YDBPair}}, {{end}}opts ...query.ExecuteOption) ({{.Ret.DefineType}}, error) { +{{end -}} {{- $dbArg := "q.db" }}{{- if $.EmitMethodsWithDBArgument }}{{- $dbArg = "db" }}{{- end -}} - {{- if .Arg.IsEmpty }} + {{- if .Arg.IsEmpty -}} row, err := {{$dbArg}}.QueryRow(ctx, {{.ConstantName}}, opts...) - {{- else }} + {{- else -}} + {{- .Arg.YDBParamsBuilder}} + {{- if .Arg.YDBHasComplexContainers }} + for name, value := range params.Range() { + parameters = parameters.Param(name).Any(value) + } + {{- end }} row, err := {{$dbArg}}.QueryRow(ctx, {{.ConstantName}}, - append(opts, {{.Arg.YDBParamsBuilder}})..., + {{- if .Arg.YDBHasParams }} + append(opts, query.WithParameters(parameters.Build()))..., + {{- else }} + opts..., + {{- end }} ) {{- end }} {{- if or (ne .Arg.Pair .Ret.Pair) (ne .Arg.DefineType .Ret.DefineType) }} @@ -58,13 +72,27 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBA {{if eq .Cmd ":many"}} {{range .Comments}}//{{.}} {{end -}} -func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) { +{{if .Arg.YDBHasComplexContainers}} +func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if .Arg.YDBPair}}{{.Arg.YDBPair}}, {{end}}params ydb.Params, opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) { +{{else}} +func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if .Arg.YDBPair}}{{.Arg.YDBPair}}, {{end}}opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) { +{{end}} {{- $dbArg := "q.db" }}{{- if $.EmitMethodsWithDBArgument }}{{- $dbArg = "db" }}{{- end -}} - {{- if .Arg.IsEmpty }} + {{- if .Arg.IsEmpty -}} result, err := {{$dbArg}}.QueryResultSet(ctx, {{.ConstantName}}, opts...) - {{- else }} + {{- else -}} + {{- .Arg.YDBParamsBuilder}} + {{- if .Arg.YDBHasComplexContainers }} + for name, value := range params.Range() { + parameters = parameters.Param(name).Any(value) + } + {{- end }} result, err := {{$dbArg}}.QueryResultSet(ctx, {{.ConstantName}}, - append(opts, {{.Arg.YDBParamsBuilder}})..., + {{- if .Arg.YDBHasParams }} + append(opts, query.WithParameters(parameters.Build()))..., + {{- else }} + opts..., + {{- end }} ) {{- end }} if err != nil { @@ -111,13 +139,27 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBA {{if eq .Cmd ":exec"}} {{range .Comments}}//{{.}} {{end -}} -func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) error { +{{if .Arg.YDBHasComplexContainers}} +func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if .Arg.YDBPair}}{{.Arg.YDBPair}}, {{end}}params ydb.Params, opts ...query.ExecuteOption) error { +{{else}} +func (q *Queries) {{.MethodName}}(ctx context.Context, {{if $.EmitMethodsWithDBArgument}}db DBTX, {{end}}{{if .Arg.YDBPair}}{{.Arg.YDBPair}}, {{end}}opts ...query.ExecuteOption) error { +{{end -}} {{- $dbArg := "q.db" }}{{- if $.EmitMethodsWithDBArgument }}{{- $dbArg = "db" }}{{- end -}} - {{- if .Arg.IsEmpty }} + {{- if .Arg.IsEmpty -}} err := {{$dbArg}}.Exec(ctx, {{.ConstantName}}, opts...) - {{- else }} + {{- else -}} + {{- .Arg.YDBParamsBuilder}} + {{- if .Arg.YDBHasComplexContainers }} + for name, value := range params.Range() { + parameters = parameters.Param(name).Any(value) + } + {{- end }} err := {{$dbArg}}.Exec(ctx, {{.ConstantName}}, - append(opts, {{.Arg.YDBParamsBuilder}})..., + {{- if .Arg.YDBHasParams }} + append(opts, query.WithParameters(parameters.Build()))..., + {{- else }} + opts..., + {{- end }} ) {{- end }} if err != nil { diff --git a/internal/codegen/golang/ydb_type.go b/internal/codegen/golang/ydb_type.go index 3a01cc8de7..ada576795d 100644 --- a/internal/codegen/golang/ydb_type.go +++ b/internal/codegen/golang/ydb_type.go @@ -12,7 +12,8 @@ import ( func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Column) string { columnType := strings.ToLower(sdk.DataType(col.Type)) - notNull := (col.NotNull || col.IsArray) && !isNullableType(columnType) + isArray := col.IsArray || col.IsSqlcSlice + notNull := (col.NotNull || isArray) && (!isNullableType(columnType) || isArray) emitPointersForNull := options.EmitPointersForNullTypes columnType = extractBaseType(columnType) diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index 0fa339fa56..fb818a5d5b 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -1754,6 +1754,11 @@ func (c *cc) VisitColumn_schema(n *parser.Column_schemaContext) interface{} { if !ok { return todo("VisitColumn_schema", tnb) } + if typeName.ArrayBounds != nil && len(typeName.ArrayBounds.Items) > 0 { + col.IsArray = true + col.ArrayDims = len(typeName.ArrayBounds.Items) + typeName.ArrayBounds = nil + } col.TypeName = typeName } if colCons := n.Opt_column_constraints(); colCons != nil { @@ -1792,6 +1797,7 @@ func (c *cc) VisitType_name_or_bind(n *parser.Type_name_or_bindContext) interfac if !ok { return todo("VisitType_name_or_bind", b) } + // FIXME: this is not working right now for type definitions return &ast.TypeName{ Names: &ast.List{ Items: []ast.Node{param}, @@ -1892,81 +1898,36 @@ func (c *cc) VisitType_name_composite(n *parser.Type_name_compositeContext) inte } if tuple := n.Type_name_tuple(); tuple != nil { - if typeNames := tuple.AllType_name_or_bind(); len(typeNames) > 0 { - var items []ast.Node - for _, tn := range typeNames { - tnNode, ok := tn.Accept(c).(ast.Node) - if !ok { - return todo("VisitType_name_composite", tn) - } - items = append(items, tnNode) - } - return &ast.TypeName{ - Name: "Tuple", - TypeOid: 0, - Names: &ast.List{Items: items}, - } - } + return tuple.Accept(c) } if struct_ := n.Type_name_struct(); struct_ != nil { if structArgs := struct_.AllStruct_arg(); len(structArgs) > 0 { - var items []ast.Node - for range structArgs { - // TODO: Handle struct field names and types - items = append(items, &ast.TODO{}) - } return &ast.TypeName{ - Name: "Struct", + Name: "any", TypeOid: 0, - Names: &ast.List{Items: items}, } } } if variant := n.Type_name_variant(); variant != nil { if variantArgs := variant.AllVariant_arg(); len(variantArgs) > 0 { - var items []ast.Node - for range variantArgs { - // TODO: Handle variant arguments - items = append(items, &ast.TODO{}) - } return &ast.TypeName{ - Name: "Variant", + Name: "any", TypeOid: 0, - Names: &ast.List{Items: items}, } } } if list := n.Type_name_list(); list != nil { - if typeName := list.Type_name_or_bind(); typeName != nil { - tn, ok := typeName.Accept(c).(ast.Node) - if !ok { - return todo("VisitType_name_composite", typeName) - } - return &ast.TypeName{ - Name: "List", - TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{tn}, - }, - } - } + return list.Accept(c) } if stream := n.Type_name_stream(); stream != nil { - if typeName := stream.Type_name_or_bind(); typeName != nil { - tn, ok := typeName.Accept(c).(ast.Node) - if !ok { - return todo("VisitType_name_composite", typeName) - } + if stream.Type_name_or_bind() != nil { return &ast.TypeName{ - Name: "Stream", + Name: "any", TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{tn}, - }, } } } @@ -1976,40 +1937,19 @@ func (c *cc) VisitType_name_composite(n *parser.Type_name_compositeContext) inte } if dict := n.Type_name_dict(); dict != nil { - if typeNames := dict.AllType_name_or_bind(); len(typeNames) >= 2 { - first, ok := typeNames[0].Accept(c).(ast.Node) - if !ok { - return todo("VisitType_name_composite", typeNames[0]) - } - second, ok := typeNames[1].Accept(c).(ast.Node) - if !ok { - return todo("VisitType_name_composite", typeNames[1]) - } + if dict.AllType_name_or_bind() != nil { return &ast.TypeName{ - Name: "Dict", + Name: "any", TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{ - first, - second, - }, - }, } } } if set := n.Type_name_set(); set != nil { - if typeName := set.Type_name_or_bind(); typeName != nil { - tn, ok := typeName.Accept(c).(ast.Node) - if !ok { - return todo("VisitType_name_composite", typeName) - } + if set.Type_name_or_bind() != nil { return &ast.TypeName{ - Name: "Set", + Name: "any", TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{tn}, - }, } } } @@ -2050,10 +1990,76 @@ func (c *cc) VisitType_name_optional(n *parser.Type_name_optionalContext) interf return &ast.TypeName{ Name: name, TypeOid: 0, - Names: &ast.List{}, } } +func (c *cc) VisitType_name_list(n *parser.Type_name_listContext) interface{} { + if n == nil || n.Type_name_or_bind() == nil { + return todo("VisitType_name_list", n) + } + + tn, ok := n.Type_name_or_bind().Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_list", n.Type_name_or_bind()) + } + innerTypeName, ok := tn.(*ast.TypeName) + if !ok { + return todo("VisitType_name_list", n.Type_name_or_bind()) + } + + if innerTypeName.ArrayBounds != nil { + return &ast.TypeName{ + Name: "any", + TypeOid: 0, + } + } + + return &ast.TypeName{ + Name: innerTypeName.Name, + TypeOid: 0, + ArrayBounds: &ast.List{ + Items: []ast.Node{&ast.TODO{}}, + }, + } +} + +func (c *cc) VisitType_name_tuple(n *parser.Type_name_tupleContext) interface{} { + if n == nil || len(n.AllType_name_or_bind()) == 0 { + return todo("VisitType_name_tuple", n) + } + + var items []ast.Node + for _, tn := range n.AllType_name_or_bind() { + tnNode, ok := tn.Accept(c).(ast.Node) + if !ok { + return todo("VisitType_name_tuple", tn) + } + items = append(items, tnNode) + } + + var typeName string + for _, node := range items { + switch innerTypeName := node.(type) { + case *ast.TypeName: + if typeName == "" { + typeName = innerTypeName.Name + } else if typeName != innerTypeName.Name { + typeName = "any" + break + } + default: + typeName = "any" + } + } + + return &ast.TypeName{ + Name: typeName, + TypeOid: 0, + ArrayBounds: &ast.List{Items: []ast.Node{&ast.TODO{}}}, + Location: c.pos(n.GetStart()), + } + +} func (c *cc) VisitSql_stmt_core(n *parser.Sql_stmt_coreContext) interface{} { if n == nil { return todo("VisitSql_stmt_core", n) @@ -2359,21 +2365,16 @@ func (c *cc) VisitXor_subexpr(n *parser.Xor_subexprContext) interface{} { } if condCtx := n.Cond_expr(); condCtx != nil { - switch { case condCtx.IN() != nil: if inExpr := condCtx.In_expr(); inExpr != nil { - temp, ok := inExpr.Accept(c).(ast.Node) - if !ok { - return todo("VisitXor_subexpr", inExpr) - } - list, ok := temp.(*ast.List) + node, ok := inExpr.Accept(c).(ast.Node) if !ok { return todo("VisitXor_subexpr", inExpr) } return &ast.In{ Expr: base, - List: list.Items, + List: []ast.Node{node}, Not: condCtx.NOT() != nil, Location: c.pos(n.GetStart()), } @@ -2708,6 +2709,145 @@ func (c *cc) VisitCon_subexpr(n *parser.Con_subexprContext) interface{} { } +func (c *cc) VisitIn_expr(n *parser.In_exprContext) interface{} { + if n == nil || n.In_unary_subexpr() == nil { + return todo("VisitIn_expr", n) + } + return n.In_unary_subexpr().Accept(c) +} + +func (c *cc) VisitIn_unary_subexpr(n *parser.In_unary_subexprContext) interface{} { + if n == nil || (n.In_unary_casual_subexpr() == nil && n.Json_api_expr() == nil) { + return todo("VisitIn_unary_subexpr", n) + } + if unary := n.In_unary_casual_subexpr(); unary != nil { + expr, ok := unary.Accept(c).(ast.Node) + if !ok { + return todo("VisitIn_unary_subexpr", unary) + } + return expr + } + jsonExpr, ok := n.Json_api_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitIn_unary_subexpr", n.Json_api_expr()) + } + return jsonExpr +} + +func (c *cc) VisitIn_unary_casual_subexpr(n *parser.In_unary_casual_subexprContext) interface{} { + var current ast.Node + switch { + case n.Id_expr_in() != nil: + expr, ok := n.Id_expr_in().Accept(c).(ast.Node) + if !ok { + return todo("VisitIn_unary_casual_subexpr", n.Id_expr_in()) + } + current = expr + case n.In_atom_expr() != nil: + expr, ok := n.In_atom_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitIn_unary_casual_subexpr", n.In_atom_expr()) + } + current = expr + default: + return todo("VisitIn_unary_casual_subexpr", n) + } + + if suffix := n.Unary_subexpr_suffix(); suffix != nil { + current = c.processSuffixChain(current, suffix.(*parser.Unary_subexpr_suffixContext)) + } + + return current +} + +func (c *cc) VisitId_expr_in(n *parser.Id_expr_inContext) interface{} { + if n == nil { + return todo("VisitId_expr", n) + } + + ref := &ast.ColumnRef{ + Fields: &ast.List{}, + Location: c.pos(n.GetStart()), + } + + if id := n.Identifier(); id != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(id.GetText())) + return ref + } + + if keyword := n.Keyword_compat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_alter_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_window_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + if keyword := n.Keyword_hint_uncompat(); keyword != nil { + ref.Fields.Items = append(ref.Fields.Items, NewIdentifier(keyword.GetText())) + return ref + } + + return todo("VisitId_expr_in", n) +} + +func (c *cc) VisitIn_atom_expr(n *parser.In_atom_exprContext) interface{} { + if n == nil { + return todo("VisitAtom_expr", n) + } + + switch { + case n.An_id_or_type() != nil: + if n.NAMESPACE() != nil { + return NewIdentifier(parseAnIdOrType(n.An_id_or_type()) + "::" + parseIdOrType(n.Id_or_type())) + } + return NewIdentifier(parseAnIdOrType(n.An_id_or_type())) + case n.Literal_value() != nil: + expr, ok := n.Literal_value().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Literal_value()) + } + return expr + case n.Bind_parameter() != nil: + expr, ok := n.Bind_parameter().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Bind_parameter()) + } + return expr + case n.Cast_expr() != nil: + expr, ok := n.Cast_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Cast_expr()) + } + return expr + + case n.LPAREN() != nil && n.Select_stmt() != nil && n.RPAREN() != nil: + selectStmt, ok := n.Select_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Select_stmt()) + } + return selectStmt + + case n.List_literal() != nil: + list, ok := n.List_literal().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.List_literal()) + } + return list + + // TODO: check other cases + default: + return todo("VisitAtom_expr", n) + } +} + func (c *cc) VisitUnary_subexpr(n *parser.Unary_subexprContext) interface{} { if n == nil || (n.Unary_casual_subexpr() == nil && n.Json_api_expr() == nil) { return todo("VisitUnary_subexpr", n) @@ -2769,7 +2909,7 @@ func (c *cc) processSuffixChain(base ast.Node, suffix *parser.Unary_subexpr_suff case *parser.Key_exprContext: current = c.handleKeySuffix(current, elem) case *parser.Invoke_exprContext: - current = c.handleInvokeSuffix(current, elem, i) + current = c.handleInvokeSuffix(current, elem) case antlr.TerminalNode: if elem.GetText() == "." { current = c.handleDotSuffix(current, suffix, &i) @@ -2806,7 +2946,7 @@ func (c *cc) handleKeySuffix(base ast.Node, keyCtx *parser.Key_exprContext) ast. } } -func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprContext, idx int) ast.Node { +func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprContext) ast.Node { temp, ok := invokeCtx.Accept(c).(ast.Node) if !ok { return todo("VisitInvoke_expr", invokeCtx) @@ -2816,48 +2956,50 @@ func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprCont return todo("VisitInvoke_expr", invokeCtx) } - if idx == 0 { - switch baseNode := base.(type) { - case *ast.ColumnRef: - if len(baseNode.Fields.Items) > 0 { - var nameParts []string - for _, item := range baseNode.Fields.Items { - if s, ok := item.(*ast.String); ok { - nameParts = append(nameParts, s.Str) - } + switch baseNode := base.(type) { + case *ast.ColumnRef: + if len(baseNode.Fields.Items) > 0 { + var nameParts []string + for _, item := range baseNode.Fields.Items { + if s, ok := item.(*ast.String); ok { + nameParts = append(nameParts, s.Str) } - funcName := strings.Join(nameParts, ".") + } + funcCall.Func = &ast.FuncName{} + if len(nameParts) == 2 { + funcCall.Func.Schema = nameParts[0] + funcCall.Func.Name = nameParts[1] + } else { + funcCall.Func.Name = strings.Join(nameParts, ".") + } - if funcName == "coalesce" || funcName == "nvl" { - return &ast.CoalesceExpr{ - Args: funcCall.Args, - Location: baseNode.Location, - } + if funcCall.Func.Name == "coalesce" || funcCall.Func.Name == "nvl" { + return &ast.CoalesceExpr{ + Args: funcCall.Args, + Location: baseNode.Location, } + } - if funcName == "greatest" || funcName == "max_of" { - return &ast.MinMaxExpr{ - Op: ast.MinMaxOp(1), - Args: funcCall.Args, - Location: baseNode.Location, - } + if funcCall.Func.Name == "greatest" || funcCall.Func.Name == "max_of" { + return &ast.MinMaxExpr{ + Op: ast.MinMaxOp(1), + Args: funcCall.Args, + Location: baseNode.Location, } - if funcName == "least" || funcName == "min_of" { - return &ast.MinMaxExpr{ - Op: ast.MinMaxOp(2), - Args: funcCall.Args, - Location: baseNode.Location, - } + } + if funcCall.Func.Name == "least" || funcCall.Func.Name == "min_of" { + return &ast.MinMaxExpr{ + Op: ast.MinMaxOp(2), + Args: funcCall.Args, + Location: baseNode.Location, } - - funcCall.Func = &ast.FuncName{Name: funcName} - funcCall.Funcname.Items = append(funcCall.Funcname.Items, &ast.String{Str: funcName}) - - return funcCall } - default: - return todo("VisitInvoke_expr", invokeCtx) + funcCall.Funcname.Items = append(funcCall.Funcname.Items, &ast.String{Str: funcCall.Func.Name}) + funcCall.Location = baseNode.Location + return funcCall } + default: + return todo("VisitInvoke_expr", invokeCtx) } stmt := &ast.FuncExpr{ @@ -3029,29 +3171,65 @@ func (c *cc) VisitAtom_expr(n *parser.Atom_exprContext) interface{} { } switch { - case n.An_id_or_type() != nil: - if n.NAMESPACE() != nil { - return NewIdentifier(parseAnIdOrType(n.An_id_or_type()) + "::" + parseIdOrType(n.Id_or_type())) - } - return NewIdentifier(parseAnIdOrType(n.An_id_or_type())) case n.Literal_value() != nil: expr, ok := n.Literal_value().Accept(c).(ast.Node) if !ok { return todo("VisitAtom_expr", n.Literal_value()) } return expr + case n.Bind_parameter() != nil: expr, ok := n.Bind_parameter().Accept(c).(ast.Node) if !ok { return todo("VisitAtom_expr", n.Bind_parameter()) } return expr + + case n.Lambda() != nil: + expr, ok := n.Lambda().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Lambda()) + } + return expr + case n.Cast_expr() != nil: expr, ok := n.Cast_expr().Accept(c).(ast.Node) if !ok { return todo("VisitAtom_expr", n.Cast_expr()) } return expr + + case n.Exists_expr() != nil: + return todo("VisitAtom_expr", n.Exists_expr()) + + case n.Case_expr() != nil: + return todo("VisitAtom_expr", n.Case_expr()) + + case n.An_id_or_type() != nil: + if n.NAMESPACE() != nil { + return NewIdentifier(parseAnIdOrType(n.An_id_or_type()) + "::" + parseIdOrType(n.Id_or_type())) + } + return NewIdentifier(parseAnIdOrType(n.An_id_or_type())) + + case n.Value_constructor() != nil: + return todo("VisitAtom_expr", n.Value_constructor()) + + case n.Bitcast_expr() != nil: + return todo("VisitAtom_expr", n.Bitcast_expr()) + + case n.List_literal() != nil: + list, ok := n.List_literal().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.List_literal()) + } + return list + + case n.Dict_literal() != nil: + return todo("VisitAtom_expr", n.Dict_literal()) + + case n.Struct_literal() != nil: + return todo("VisitAtom_expr", n.Struct_literal()) + // TODO: check other cases default: return todo("VisitAtom_expr", n) @@ -3067,7 +3245,7 @@ func (c *cc) VisitCast_expr(n *parser.Cast_exprContext) interface{} { if !ok { return todo("VisitCast_expr", n.Expr()) } - + temp, ok := n.Type_name_or_bind().Accept(c).(ast.Node) if !ok { return todo("VisitCast_expr", n.Type_name_or_bind()) @@ -3084,6 +3262,27 @@ func (c *cc) VisitCast_expr(n *parser.Cast_exprContext) interface{} { } } +func (c *cc) VisitList_literal(n *parser.List_literalContext) interface{} { + if n == nil || n.LBRACE_SQUARE() == nil || n.RBRACE_SQUARE() == nil || n.Expr_list() == nil { + return todo("VisitList_literal", n) + } + + array := &ast.A_ArrayExpr{ + Elements: &ast.List{}, + Location: c.pos(n.GetStart()), + } + + for _, item := range n.Expr_list().AllExpr() { + expr, ok := item.Accept(c).(ast.Node) + if !ok { + return todo("VisitList_literal", item) + } + array.Elements.Items = append(array.Elements.Items, expr) + } + + return array +} + func (c *cc) VisitLiteral_value(n *parser.Literal_valueContext) interface{} { if n == nil { return todo("VisitLiteral_value", n) @@ -3149,6 +3348,44 @@ func (c *cc) VisitLiteral_value(n *parser.Literal_valueContext) interface{} { } } +func (c *cc) VisitLambda(n *parser.LambdaContext) interface{} { + if n == nil || n.Smart_parenthesis() == nil { + return todo("VisitLambda", n) + } + + if n.ARROW() != nil { + log.Panicln("Lambda stmts are not supported in SQLC") + return todo("VisitLambda", n) + } + + lambdaBody, ok := n.Smart_parenthesis().Accept(c).(ast.Node) + if !ok { + return todo("VisitLambda", n.Smart_parenthesis()) + } + + return lambdaBody +} + +func (c *cc) VisitSmart_parenthesis(n *parser.Smart_parenthesisContext) interface{} { + if n == nil || n.Named_expr_list() == nil || n.LPAREN() == nil || n.RPAREN() == nil { + return todo("VisitSmart_parenthesis", n) + } + + var args ast.List + for _, namedExpr := range n.Named_expr_list().AllNamed_expr() { + expr, ok := namedExpr.Accept(c).(ast.Node) + if !ok { + return todo("VisitSmart_parenthesis", namedExpr) + } + args.Items = append(args.Items, expr) + } + + return &ast.A_ArrayExpr{ + Elements: &args, + Location: c.pos(n.GetStart()), + } +} + func (c *cc) VisitSql_stmt(n *parser.Sql_stmtContext) interface{} { if n == nil || n.Sql_stmt_core() == nil { return todo("VisitSql_stmt", n) diff --git a/internal/sql/rewrite/parameters.go b/internal/sql/rewrite/parameters.go index 9146d17e08..5f213ae6c4 100644 --- a/internal/sql/rewrite/parameters.go +++ b/internal/sql/rewrite/parameters.go @@ -102,7 +102,9 @@ func NamedParameters(engine config.Engine, raw *ast.RawStmt, numbs map[int]bool, }) var replace string - if engine == config.EngineMySQL || engine == config.EngineSQLite || !dollar { + if engine == config.EngineYDB { + replace = fmt.Sprintf("$%s", param.Name()) + } else if engine == config.EngineMySQL || engine == config.EngineSQLite || !dollar { if param.IsSqlcSlice() { // This sequence is also replicated in internal/codegen/golang.Field // since it's needed during template generation for replacement From 2eaa5d08dc6744940bc02f3b93c6dde8e2220e6b Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov <150552906+1NepuNep1@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:18:52 +0300 Subject: [PATCH 19/22] Tests: Added a lot of ydb e2e tests + some engine and types fixes * Fixed range result.Rows(ctx) issue (go<1.23) * Rewrited strings to BYTES ([]byte) * Fixed count(*) issue * Fixed datatype test * fixed uuid issue * rewrited ydb-go-sdk codegen to ranges back (+ upped testada go.mod version to 1.23) * rewrited parseStringLiteral func to be more understandable * resolved limit issue * Rewrited slices logic not replace them --- internal/codegen/golang/gen.go | 7 + internal/codegen/golang/imports.go | 9 +- internal/codegen/golang/opts/options.go | 6 + internal/codegen/golang/query.go | 30 +- .../golang/templates/stdlib/queryCode.tmpl | 2 +- .../templates/ydb-go-sdk/interfaceCode.tmpl | 20 +- internal/codegen/golang/ydb_type.go | 52 +- internal/compiler/resolve.go | 17 +- .../testdata/alias/ydb/stdlib/go/db.go | 31 + .../testdata/alias/ydb/stdlib/go/models.go | 9 + .../testdata/alias/ydb/stdlib/go/query.sql.go | 22 + .../testdata/alias/ydb/stdlib/query.sql | 6 + .../testdata/alias/ydb/stdlib/schema.sql | 1 + .../testdata/alias/ydb/stdlib/sqlc.json | 12 + .../testdata/alias/ydb/ydb-go-sdk/go/db.go | 26 + .../alias/ydb/ydb-go-sdk/go/models.go | 9 + .../alias/ydb/ydb-go-sdk/go/query.sql.go | 36 + .../testdata/alias/ydb/ydb-go-sdk/query.sql | 6 + .../testdata/alias/ydb/ydb-go-sdk/schema.sql | 4 + .../testdata/alias/ydb/ydb-go-sdk/sqlc.json | 16 + .../testdata/array_in/ydb/stdlib/go/db.go | 31 + .../testdata/array_in/ydb/stdlib/go/models.go | 9 + .../array_in/ydb/stdlib/go/query.sql.go | 44 + .../testdata/array_in/ydb/stdlib/query.sql | 4 + .../testdata/array_in/ydb/stdlib/schema.sql | 1 + .../testdata/array_in/ydb/stdlib/sqlc.json | 12 + .../testdata/array_in/ydb/ydb-go-sdk/go/db.go | 26 + .../array_in/ydb/ydb-go-sdk/go/models.go | 9 + .../array_in/ydb/ydb-go-sdk/go/query.sql.go | 52 ++ .../array_in/ydb/ydb-go-sdk/query.sql | 4 + .../array_in/ydb/ydb-go-sdk/schema.sql | 1 + .../array_in/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/array_text/ydb-go-sdk/go/db.go | 26 + .../array_text/ydb-go-sdk/go/models.go | 9 + .../array_text/ydb-go-sdk/go/query.sql.go | 30 + .../testdata/array_text/ydb-go-sdk/query.sql | 2 + .../testdata/array_text/ydb-go-sdk/schema.sql | 1 + .../testdata/array_text/ydb-go-sdk/sqlc.json | 14 + .../testdata/between_args/ydb/go/db.go | 31 + .../testdata/between_args/ydb/go/models.go | 11 + .../testdata/between_args/ydb/go/query.sql.go | 146 +++ .../testdata/between_args/ydb/query.sql | 19 + .../testdata/between_args/ydb/schema.sql | 6 + .../testdata/between_args/ydb/sqlc.json | 12 + .../endtoend/testdata/builtins/ydb/go/db.go | 31 + .../testdata/builtins/ydb/go/models.go | 12 + .../testdata/builtins/ydb/go/query.sql.go | 873 ++++++++++++++++++ .../endtoend/testdata/builtins/ydb/query.sql | 163 ++++ .../endtoend/testdata/builtins/ydb/schema.sql | 7 + .../endtoend/testdata/builtins/ydb/sqlc.json | 12 + .../testdata/case_named_params/ydb/go/db.go | 31 + .../case_named_params/ydb/go/models.go | 13 + .../case_named_params/ydb/go/query.sql.go | 36 + .../testdata/case_named_params/ydb/query.sql | 6 + .../testdata/case_named_params/ydb/schema.sql | 10 + .../testdata/case_named_params/ydb/sqlc.json | 12 + .../testdata/case_sensitive/ydb/go/db.go | 31 + .../testdata/case_sensitive/ydb/go/models.go | 10 + .../case_sensitive/ydb/go/query.sql.go | 28 + .../testdata/case_sensitive/ydb/query.sql | 10 + .../testdata/case_sensitive/ydb/schema.sql | 9 + .../testdata/case_sensitive/ydb/sqlc.json | 16 + .../testdata/case_stmt_bool/ydb/go/db.go | 31 + .../testdata/case_stmt_bool/ydb/go/models.go | 9 + .../case_stmt_bool/ydb/go/query.sql.go | 41 + .../testdata/case_stmt_bool/ydb/query.sql | 10 + .../testdata/case_stmt_bool/ydb/schema.sql | 5 + .../testdata/case_stmt_bool/ydb/sqlc.json | 16 + .../endtoend/testdata/case_text/ydb/go/db.go | 31 + .../testdata/case_text/ydb/go/models.go | 9 + .../testdata/case_text/ydb/go/query.sql.go | 41 + .../endtoend/testdata/case_text/ydb/query.sql | 10 + .../testdata/case_text/ydb/schema.sql | 5 + .../endtoend/testdata/case_text/ydb/sqlc.json | 16 + .../testdata/case_value_param/ydb/go/db.go | 31 + .../case_value_param/ydb/go/models.go | 10 + .../case_value_param/ydb/go/query.sql.go | 20 + .../testdata/case_value_param/ydb/query.sql | 6 + .../testdata/case_value_param/ydb/schema.sql | 8 + .../testdata/case_value_param/ydb/sqlc.json | 16 + .../cast_coalesce/ydb/stdlib/go/db.go | 31 + .../cast_coalesce/ydb/stdlib/go/models.go | 9 + .../cast_coalesce/ydb/stdlib/go/query.sql.go | 38 + .../cast_coalesce/ydb/stdlib/query.sql | 6 + .../cast_coalesce/ydb/stdlib/schema.sql | 4 + .../cast_coalesce/ydb/stdlib/sqlc.json | 15 + .../cast_coalesce/ydb/ydb-go-sdk/go/db.go | 26 + .../cast_coalesce/ydb/ydb-go-sdk/go/models.go | 9 + .../ydb/ydb-go-sdk/go/query.sql.go | 40 + .../cast_coalesce/ydb/ydb-go-sdk/query.sql | 6 + .../cast_coalesce/ydb/ydb-go-sdk/schema.sql | 4 + .../cast_coalesce/ydb/ydb-go-sdk/sqlc.json | 16 + .../testdata/cast_null/ydb/stdlib/go/db.go | 31 + .../cast_null/ydb/stdlib/go/models.go | 9 + .../cast_null/ydb/stdlib/go/query.sql.go | 55 ++ .../testdata/cast_null/ydb/stdlib/query.sql | 11 + .../testdata/cast_null/ydb/stdlib/schema.sql | 4 + .../testdata/cast_null/ydb/stdlib/sqlc.json | 15 + .../cast_null/ydb/ydb-go-sdk/go/db.go | 26 + .../cast_null/ydb/ydb-go-sdk/go/models.go | 9 + .../cast_null/ydb/ydb-go-sdk/go/query.sql.go | 57 ++ .../cast_null/ydb/ydb-go-sdk/query.sql | 11 + .../cast_null/ydb/ydb-go-sdk/schema.sql | 4 + .../cast_null/ydb/ydb-go-sdk/sqlc.json | 16 + .../endtoend/testdata/cast_param/ydb/go/db.go | 31 + .../testdata/cast_param/ydb/go/models.go | 10 + .../testdata/cast_param/ydb/go/query.sql.go | 39 + .../testdata/cast_param/ydb/query.sql | 7 + .../testdata/cast_param/ydb/schema.sql | 8 + .../testdata/cast_param/ydb/sqlc.json | 15 + .../testdata/coalesce/ydb/stdlib/go/db.go | 31 + .../testdata/coalesce/ydb/stdlib/go/models.go | 12 + .../coalesce/ydb/stdlib/go/query.sql.go | 200 ++++ .../testdata/coalesce/ydb/stdlib/query.sql | 23 + .../testdata/coalesce/ydb/stdlib/schema.sql | 7 + .../testdata/coalesce/ydb/stdlib/sqlc.json | 12 + .../testdata/coalesce/ydb/ydb-go-sdk/go/db.go | 26 + .../coalesce/ydb/ydb-go-sdk/go/models.go | 12 + .../coalesce/ydb/ydb-go-sdk/go/query.sql.go | 197 ++++ .../coalesce/ydb/ydb-go-sdk/query.sql | 23 + .../coalesce/ydb/ydb-go-sdk/schema.sql | 7 + .../coalesce/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/coalesce_as/ydb/stdlib/go/db.go | 31 + .../coalesce_as/ydb/stdlib/go/models.go | 10 + .../coalesce_as/ydb/stdlib/go/query.sql.go | 44 + .../testdata/coalesce_as/ydb/stdlib/query.sql | 4 + .../coalesce_as/ydb/stdlib/schema.sql | 5 + .../testdata/coalesce_as/ydb/stdlib/sqlc.json | 12 + .../coalesce_as/ydb/ydb-go-sdk/go/db.go | 26 + .../coalesce_as/ydb/ydb-go-sdk/go/models.go | 10 + .../ydb/ydb-go-sdk/go/query.sql.go | 46 + .../coalesce_as/ydb/ydb-go-sdk/query.sql | 4 + .../coalesce_as/ydb/ydb-go-sdk/schema.sql | 5 + .../coalesce_as/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/coalesce_join/ydb/go/db.go | 31 + .../testdata/coalesce_join/ydb/go/models.go | 13 + .../coalesce_join/ydb/go/query.sql.go | 44 + .../testdata/coalesce_join/ydb/query.sql | 4 + .../testdata/coalesce_join/ydb/schema.sql | 2 + .../testdata/coalesce_join/ydb/sqlc.json | 12 + .../testdata/coalesce_params/ydb/go/db.go | 31 + .../testdata/coalesce_params/ydb/go/models.go | 42 + .../coalesce_params/ydb/go/query.sql.go | 36 + .../testdata/coalesce_params/ydb/query.sql | 11 + .../testdata/coalesce_params/ydb/schema.sql | 35 + .../testdata/coalesce_params/ydb/sqlc.json | 12 + .../testdata/column_alias/ydb/go/db.go | 31 + .../testdata/column_alias/ydb/go/models.go | 18 + .../testdata/column_alias/ydb/go/query.sql.go | 74 ++ .../testdata/column_alias/ydb/query.sql | 16 + .../testdata/column_alias/ydb/schema.sql | 9 + .../testdata/column_alias/ydb/sqlc.json | 12 + .../testdata/column_as/ydb/stdlib/go/db.go | 31 + .../column_as/ydb/stdlib/go/models.go | 5 + .../column_as/ydb/stdlib/go/query.sql.go | 42 + .../testdata/column_as/ydb/stdlib/query.sql | 5 + .../testdata/column_as/ydb/stdlib/schema.sql | 1 + .../testdata/column_as/ydb/stdlib/sqlc.json | 12 + .../column_as/ydb/ydb-go-sdk/go/db.go | 26 + .../column_as/ydb/ydb-go-sdk/go/models.go | 5 + .../column_as/ydb/ydb-go-sdk/go/query.sql.go | 57 ++ .../column_as/ydb/ydb-go-sdk/query.sql | 5 + .../column_as/ydb/ydb-go-sdk/schema.sql | 0 .../column_as/ydb/ydb-go-sdk/sqlc.json | 13 + .../comment_syntax/ydb/stdlib/go/db.go | 31 + .../comment_syntax/ydb/stdlib/go/models.go | 9 + .../comment_syntax/ydb/stdlib/go/query.sql.go | 32 + .../comment_syntax/ydb/stdlib/query.sql | 5 + .../comment_syntax/ydb/stdlib/schema.sql | 3 + .../comment_syntax/ydb/stdlib/sqlc.json | 14 + .../comment_syntax/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 9 + .../ydb/ydb-go-sdk/go/query.sql.go | 47 + .../comment_syntax/ydb/ydb-go-sdk/query.sql | 7 + .../comment_syntax/ydb/ydb-go-sdk/schema.sql | 3 + .../comment_syntax/ydb/ydb-go-sdk/sqlc.json | 15 + .../testdata/comparisons/ydb/stdlib/go/db.go | 31 + .../comparisons/ydb/stdlib/go/models.go | 9 + .../comparisons/ydb/stdlib/go/query.sql.go | 199 ++++ .../testdata/comparisons/ydb/stdlib/query.sql | 22 + .../comparisons/ydb/stdlib/schema.sql | 6 + .../testdata/comparisons/ydb/stdlib/sqlc.json | 14 + .../comparisons/ydb/ydb-go-sdk/go/db.go | 26 + .../comparisons/ydb/ydb-go-sdk/go/models.go | 9 + .../ydb/ydb-go-sdk/go/query.sql.go | 195 ++++ .../comparisons/ydb/ydb-go-sdk/query.sql | 22 + .../comparisons/ydb/ydb-go-sdk/schema.sql | 6 + .../comparisons/ydb/ydb-go-sdk/sqlc.json | 15 + .../testdata/count_star/ydb/stdlib/go/db.go | 31 + .../count_star/ydb/stdlib/go/models.go | 9 + .../count_star/ydb/stdlib/go/query.sql.go | 32 + .../testdata/count_star/ydb/stdlib/query.sql | 7 + .../testdata/count_star/ydb/stdlib/schema.sql | 3 + .../testdata/count_star/ydb/stdlib/sqlc.json | 14 + .../count_star/ydb/ydb-go-sdk/go/db.go | 26 + .../count_star/ydb/ydb-go-sdk/go/models.go | 9 + .../count_star/ydb/ydb-go-sdk/go/query.sql.go | 47 + .../count_star/ydb/ydb-go-sdk/query.sql | 7 + .../count_star/ydb/ydb-go-sdk/schema.sql | 3 + .../count_star/ydb/ydb-go-sdk/sqlc.json | 15 + .../testdata/create_view/ydb/go/db.go | 31 + .../testdata/create_view/ydb/go/models.go | 19 + .../testdata/create_view/ydb/go/query.sql.go | 64 ++ .../testdata/create_view/ydb/query.sql | 5 + .../testdata/create_view/ydb/schema.sql | 15 + .../testdata/create_view/ydb/sqlc.json | 12 + .../testdata/datatype/ydb/ydb-go-sdk/go/db.go | 26 + .../datatype/ydb/ydb-go-sdk/go/models.go | 132 +++ .../datatype/ydb/ydb-go-sdk/go/query.sql.go | 30 + .../datatype/ydb/ydb-go-sdk/sql/boolean.sql | 14 + .../datatype/ydb/ydb-go-sdk/sql/character.sql | 17 + .../datatype/ydb/ydb-go-sdk/sql/datetime.sql | 36 + .../datatype/ydb/ydb-go-sdk/sql/json.sql | 18 + .../datatype/ydb/ydb-go-sdk/sql/numeric.sql | 57 ++ .../datatype/ydb/ydb-go-sdk/sql/query.sql | 3 + .../datatype/ydb/ydb-go-sdk/sql/uuid.sql | 14 + .../datatype/ydb/ydb-go-sdk/sqlc.json | 13 + .../ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 12 + .../ydb/stdlib/go/query.sql.go | 19 + .../ydb/stdlib/query.sql | 2 + .../ydb/stdlib/schema.sql | 8 + .../ydb/stdlib/sqlc.json | 12 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 12 + .../ydb/ydb-go-sdk/go/query.sql.go | 25 + .../ydb/ydb-go-sdk/query.sql | 2 + .../ydb/ydb-go-sdk/schema.sql | 8 + .../ydb/ydb-go-sdk/sqlc.json | 13 + .../ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 13 + .../ydb/stdlib/go/query.sql.go | 19 + .../ydb/stdlib/query.sql | 2 + .../ydb/stdlib/schema.sql | 8 + .../ydb/stdlib/sqlc.json | 12 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 13 + .../ydb/ydb-go-sdk/go/query.sql.go | 25 + .../ydb/ydb-go-sdk/query.sql | 2 + .../ydb/ydb-go-sdk/schema.sql | 8 + .../ydb/ydb-go-sdk/sqlc.json | 13 + .../ydb/go/db.go | 31 + .../ydb/go/models.go | 10 + .../ydb/go/query.sql.go | 19 + .../ydb/query.sql | 2 + .../ydb/schema.sql | 8 + .../ydb/sqlc.json | 12 + .../ddl_alter_table_drop_column/ydb/go/db.go | 31 + .../ydb/go/models.go | 9 + .../ydb/go/query.sql.go | 19 + .../ddl_alter_table_drop_column/ydb/query.sql | 2 + .../ydb/schema.sql | 7 + .../ddl_alter_table_drop_column/ydb/sqlc.json | 12 + .../ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 9 + .../ydb/stdlib/go/query.sql.go | 37 + .../ydb/stdlib/query.sql | 2 + .../ydb/stdlib/schema.sql | 6 + .../ydb/stdlib/sqlc.json | 12 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 9 + .../ydb/ydb-go-sdk/go/query.sql.go | 39 + .../ydb/ydb-go-sdk/query.sql | 2 + .../ydb/ydb-go-sdk/schema.sql | 6 + .../ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/ddl_create_table/ydb/go/db.go | 31 + .../ddl_create_table/ydb/go/models.go | 9 + .../ddl_create_table/ydb/go/query.sql.go | 19 + .../testdata/ddl_create_table/ydb/query.sql | 2 + .../testdata/ddl_create_table/ydb/schema.sql | 4 + .../testdata/ddl_create_table/ydb/sqlc.json | 12 + .../ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 10 + .../ydb/stdlib/go/query.sql.go | 19 + .../ydb/stdlib/query.sql | 2 + .../ydb/stdlib/schema.sql | 8 + .../ydb/stdlib/sqlc.json | 12 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 10 + .../ydb/ydb-go-sdk/go/query.sql.go | 25 + .../ydb/ydb-go-sdk/query.sql | 2 + .../ydb/ydb-go-sdk/schema.sql | 8 + .../ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/ddl_drop_table/ydb/go/db.go | 31 + .../testdata/ddl_drop_table/ydb/go/models.go | 5 + .../ddl_drop_table/ydb/go/query.sql.go | 19 + .../ddl_drop_table/ydb/stdlib/go/db.go | 31 + .../ddl_drop_table/ydb/stdlib/go/models.go | 5 + .../ddl_drop_table/ydb/stdlib/go/query.sql.go | 19 + .../ddl_drop_table/ydb/stdlib/query.sql | 2 + .../ddl_drop_table/ydb/stdlib/schema.sql | 17 + .../ddl_drop_table/ydb/stdlib/sqlc.json | 12 + .../ddl_drop_table/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 5 + .../ydb/ydb-go-sdk/go/query.sql.go | 25 + .../ddl_drop_table/ydb/ydb-go-sdk/query.sql | 2 + .../ddl_drop_table/ydb/ydb-go-sdk/schema.sql | 17 + .../ddl_drop_table/ydb/ydb-go-sdk/sqlc.json | 13 + .../ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 5 + .../ydb/stdlib/go/query.sql.go | 19 + .../ydb/stdlib/query.sql | 2 + .../ydb/stdlib/schema.sql | 6 + .../ydb/stdlib/sqlc.json | 12 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 5 + .../ydb/ydb-go-sdk/go/query.sql.go | 25 + .../ydb/ydb-go-sdk/query.sql | 2 + .../ydb/ydb-go-sdk/schema.sql | 6 + .../ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/delete_from/ydb/stdlib/go/db.go | 31 + .../delete_from/ydb/stdlib/go/models.go | 9 + .../delete_from/ydb/stdlib/go/query.sql.go | 19 + .../testdata/delete_from/ydb/stdlib/query.sql | 2 + .../delete_from/ydb/stdlib/schema.sql | 4 + .../testdata/delete_from/ydb/stdlib/sqlc.json | 12 + .../delete_from/ydb/ydb-go-sdk/go/db.go | 26 + .../delete_from/ydb/ydb-go-sdk/go/models.go | 9 + .../ydb/ydb-go-sdk/go/query.sql.go | 30 + .../delete_from/ydb/ydb-go-sdk/query.sql | 2 + .../delete_from/ydb/ydb-go-sdk/schema.sql | 4 + .../delete_from/ydb/ydb-go-sdk/sqlc.json | 13 + .../emit_db_and_json_tags/ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 12 + .../ydb/stdlib/go/query.sql.go | 42 + .../ydb/stdlib/query.sql | 2 + .../ydb/stdlib/schema.sql | 7 + .../ydb/stdlib/sqlc.json | 14 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 12 + .../ydb/ydb-go-sdk/go/query.sql.go | 44 + .../ydb/ydb-go-sdk/query.sql | 2 + .../ydb/ydb-go-sdk/schema.sql | 7 + .../ydb/ydb-go-sdk/sqlc.json | 15 + .../testdata/emit_db_tags/ydb/stdlib/go/db.go | 31 + .../emit_db_tags/ydb/stdlib/go/models.go | 12 + .../emit_db_tags/ydb/stdlib/go/query.sql.go | 42 + .../emit_db_tags/ydb/stdlib/query.sql | 2 + .../emit_db_tags/ydb/stdlib/schema.sql | 7 + .../emit_db_tags/ydb/stdlib/sqlc.json | 13 + .../emit_db_tags/ydb/ydb-go-sdk/go/db.go | 26 + .../emit_db_tags/ydb/ydb-go-sdk/go/models.go | 12 + .../ydb/ydb-go-sdk/go/query.sql.go | 44 + .../emit_db_tags/ydb/ydb-go-sdk/query.sql | 2 + .../emit_db_tags/ydb/ydb-go-sdk/schema.sql | 7 + .../emit_db_tags/ydb/ydb-go-sdk/sqlc.json | 14 + .../testdata/emit_empty_slices/ydb/go/db.go | 31 + .../emit_empty_slices/ydb/go/models.go | 9 + .../emit_empty_slices/ydb/go/query.sql.go | 37 + .../testdata/emit_empty_slices/ydb/query.sql | 2 + .../testdata/emit_empty_slices/ydb/schema.sql | 4 + .../testdata/emit_empty_slices/ydb/sqlc.json | 13 + .../emit_exported_queries/ydb/go/db.go | 31 + .../emit_exported_queries/ydb/go/models.go | 9 + .../emit_exported_queries/ydb/go/query.sql.go | 24 + .../emit_exported_queries/ydb/query.sql | 2 + .../emit_exported_queries/ydb/schema.sql | 4 + .../emit_exported_queries/ydb/sqlc.json | 13 + .../ydb/go/db.go | 24 + .../ydb/go/models.go | 12 + .../ydb/go/query.sql.go | 42 + .../ydb/stdlib/go/db.go | 24 + .../ydb/stdlib/go/models.go | 12 + .../ydb/stdlib/go/query.sql.go | 42 + .../ydb/stdlib/query.sql | 2 + .../ydb/stdlib/schema.sql | 7 + .../ydb/stdlib/sqlc.json | 13 + .../ydb/ydb-go-sdk/go/db.go | 25 + .../ydb/ydb-go-sdk/go/models.go | 12 + .../ydb/ydb-go-sdk/go/query.sql.go | 44 + .../ydb/ydb-go-sdk/query.sql | 2 + .../ydb/ydb-go-sdk/schema.sql | 7 + .../ydb/ydb-go-sdk/sqlc.json | 14 + .../ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 43 + .../ydb/stdlib/go/query.sql.go | 21 + .../ydb/stdlib/query.sql | 2 + .../ydb/stdlib/schema.sql | 36 + .../ydb/stdlib/sqlc.json | 13 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 43 + .../ydb/ydb-go-sdk/go/query.sql.go | 30 + .../ydb/ydb-go-sdk/query.sql | 2 + .../ydb/ydb-go-sdk/schema.sql | 36 + .../ydb/ydb-go-sdk/sqlc.json | 14 + .../ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 10 + .../ydb/stdlib/go/querier.go | 17 + .../ydb/stdlib/go/query.sql.go | 80 ++ .../ydb/stdlib/query.sql | 8 + .../ydb/stdlib/schema.sql | 5 + .../ydb/stdlib/sqlc.json | 15 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 10 + .../ydb/ydb-go-sdk/go/querier.go | 19 + .../ydb/ydb-go-sdk/go/query.sql.go | 97 ++ .../ydb/ydb-go-sdk/query.sql | 8 + .../ydb/ydb-go-sdk/schema.sql | 5 + .../ydb/ydb-go-sdk/sqlc.json | 16 + .../exec_create_table/ydb/stdlib/go/db.go | 31 + .../exec_create_table/ydb/stdlib/go/models.go | 5 + .../ydb/stdlib/go/query.sql.go | 19 + .../exec_create_table/ydb/stdlib/query.sql | 2 + .../exec_create_table/ydb/stdlib/schema.sql | 0 .../exec_create_table/ydb/stdlib/sqlc.json | 17 + .../exec_create_table/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 5 + .../ydb/ydb-go-sdk/go/query.sql.go | 25 + .../ydb/ydb-go-sdk/query.sql | 2 + .../ydb/ydb-go-sdk/schema.sql | 0 .../ydb/ydb-go-sdk/sqlc.json | 17 + .../testdata/exec_imports/ydb/stdlib/go/db.go | 31 + .../exec_imports/ydb/stdlib/go/models.go | 10 + .../exec_imports/ydb/stdlib/go/querier.go | 16 + .../exec_imports/ydb/stdlib/go/query.sql.go | 30 + .../exec_imports/ydb/stdlib/query.sql | 7 + .../exec_imports/ydb/stdlib/schema.sql | 5 + .../exec_imports/ydb/stdlib/sqlc.json | 13 + .../exec_imports/ydb/ydb-go-sdk/go/db.go | 26 + .../exec_imports/ydb/ydb-go-sdk/go/models.go | 10 + .../exec_imports/ydb/ydb-go-sdk/go/querier.go | 18 + .../ydb/ydb-go-sdk/go/query.sql.go | 39 + .../exec_imports/ydb/ydb-go-sdk/query.sql | 7 + .../exec_imports/ydb/ydb-go-sdk/schema.sql | 5 + .../exec_imports/ydb/ydb-go-sdk/sqlc.json | 14 + .../func_call_cast/ydb/stdlib/go/db.go | 31 + .../func_call_cast/ydb/stdlib/go/models.go | 5 + .../func_call_cast/ydb/stdlib/go/query.sql.go | 21 + .../func_call_cast/ydb/stdlib/query.sql | 2 + .../func_call_cast/ydb/stdlib/schema.sql | 0 .../func_call_cast/ydb/stdlib/sqlc.json | 12 + .../func_call_cast/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 5 + .../ydb/ydb-go-sdk/go/query.sql.go | 30 + .../func_call_cast/ydb/ydb-go-sdk/query.sql | 2 + .../func_call_cast/ydb/ydb-go-sdk/schema.sql | 0 .../func_call_cast/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/func_match_types/ydb/go/db.go | 31 + .../func_match_types/ydb/go/models.go | 12 + .../func_match_types/ydb/go/query.sql.go | 45 + .../testdata/func_match_types/ydb/query.sql | 6 + .../testdata/func_match_types/ydb/schema.sql | 7 + .../testdata/func_match_types/ydb/sqlc.json | 14 + .../testdata/func_return_table/ydb/go/db.go | 31 + .../func_return_table/ydb/go/models.go | 11 + .../func_return_table/ydb/go/query.sql.go | 26 + .../testdata/func_return_table/ydb/query.sql | 4 + .../testdata/func_return_table/ydb/schema.sql | 8 + .../testdata/func_return_table/ydb/sqlc.json | 14 + internal/endtoend/testdata/go.mod | 20 +- internal/endtoend/testdata/go.sum | 195 +++- .../endtoend/testdata/having/ydb/go/db.go | 31 + .../endtoend/testdata/having/ydb/go/models.go | 10 + .../testdata/having/ydb/go/query.sql.go | 40 + .../endtoend/testdata/having/ydb/query.sql | 5 + .../endtoend/testdata/having/ydb/schema.sql | 7 + .../endtoend/testdata/having/ydb/sqlc.json | 14 + .../identical_tables/ydb/stdlib/go/db.go | 31 + .../identical_tables/ydb/stdlib/go/models.go | 13 + .../ydb/stdlib/go/query.sql.go | 37 + .../identical_tables/ydb/stdlib/query.sql | 4 + .../identical_tables/ydb/stdlib/schema.sql | 11 + .../identical_tables/ydb/stdlib/sqlc.json | 14 + .../identical_tables/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 13 + .../ydb/ydb-go-sdk/go/query.sql.go | 39 + .../identical_tables/ydb/ydb-go-sdk/query.sql | 4 + .../ydb/ydb-go-sdk/schema.sql | 11 + .../identical_tables/ydb/ydb-go-sdk/sqlc.json | 15 + .../endtoend/testdata/in_union/ydb/go/db.go | 31 + .../testdata/in_union/ydb/go/models.go | 21 + .../testdata/in_union/ydb/go/query.sql.go | 38 + .../endtoend/testdata/in_union/ydb/query.sql | 5 + .../endtoend/testdata/in_union/ydb/schema.sql | 20 + .../endtoend/testdata/in_union/ydb/sqlc.json | 14 + .../endtoend/testdata/inflection/ydb/go/db.go | 31 + .../testdata/inflection/ydb/go/models.go | 25 + .../testdata/inflection/ydb/go/query.sql.go | 145 +++ .../testdata/inflection/ydb/query.sql | 14 + .../testdata/inflection/ydb/schema.sql | 5 + .../testdata/inflection/ydb/sqlc.json | 12 + .../ydb/go/db.go | 26 + .../ydb/go/models.go | 20 + .../ydb/go/query.sql.go | 77 ++ .../ydb/query.sql | 8 + .../ydb/schema.sql | 3 + .../ydb/sqlc.json | 21 + .../insert_select/ydb/stdlib/go/db.go | 31 + .../insert_select/ydb/stdlib/go/models.go | 15 + .../insert_select/ydb/stdlib/go/query.sql.go | 26 + .../insert_select/ydb/stdlib/query.sql | 4 + .../insert_select/ydb/stdlib/schema.sql | 11 + .../insert_select/ydb/stdlib/sqlc.json | 12 + .../insert_select/ydb/ydb-go-sdk/go/db.go | 26 + .../insert_select/ydb/ydb-go-sdk/go/models.go | 15 + .../ydb/ydb-go-sdk/go/query.sql.go | 38 + .../insert_select/ydb/ydb-go-sdk/query.sql | 4 + .../insert_select/ydb/ydb-go-sdk/schema.sql | 11 + .../insert_select/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/insert_select_case/ydb/go/db.go | 31 + .../insert_select_case/ydb/go/models.go | 10 + .../insert_select_case/ydb/go/query.sql.go | 26 + .../testdata/insert_select_case/ydb/query.sql | 4 + .../insert_select_case/ydb/schema.sql | 5 + .../testdata/insert_select_case/ydb/sqlc.json | 12 + .../testdata/insert_select_param/ydb/go/db.go | 31 + .../insert_select_param/ydb/go/models.go | 11 + .../insert_select_param/ydb/go/query.sql.go | 27 + .../insert_select_param/ydb/query.sql | 5 + .../insert_select_param/ydb/schema.sql | 6 + .../insert_select_param/ydb/sqlc.json | 12 + .../insert_values/ydb/stdlib/go/db.go | 31 + .../insert_values/ydb/stdlib/go/models.go | 10 + .../insert_values/ydb/stdlib/go/query.sql.go | 45 + .../insert_values/ydb/stdlib/query.sql | 5 + .../insert_values/ydb/stdlib/schema.sql | 1 + .../insert_values/ydb/stdlib/sqlc.json | 12 + .../insert_values/ydb/ydb-go-sdk/go/db.go | 26 + .../insert_values/ydb/ydb-go-sdk/go/models.go | 10 + .../ydb/ydb-go-sdk/go/query.sql.go | 62 ++ .../insert_values/ydb/ydb-go-sdk/query.sql | 5 + .../insert_values/ydb/ydb-go-sdk/schema.sql | 1 + .../insert_values/ydb/ydb-go-sdk/sqlc.json | 13 + .../insert_values_public/ydb/go/db.go | 31 + .../insert_values_public/ydb/go/models.go | 10 + .../insert_values_public/ydb/go/query.sql.go | 24 + .../insert_values_public/ydb/query.sql | 2 + .../insert_values_public/ydb/schema.sql | 1 + .../insert_values_public/ydb/sqlc.json | 12 + .../endtoend/testdata/interval/ydb/go/db.go | 31 + .../testdata/interval/ydb/go/models.go | 14 + .../testdata/interval/ydb/go/query.sql.go | 37 + .../endtoend/testdata/interval/ydb/query.sql | 2 + .../endtoend/testdata/interval/ydb/schema.sql | 1 + .../endtoend/testdata/interval/ydb/sqlc.json | 12 + .../testdata/join_alias/ydb/stdlib/go/db.go | 31 + .../join_alias/ydb/stdlib/go/models.go | 14 + .../join_alias/ydb/stdlib/go/query.sql.go | 81 ++ .../testdata/join_alias/ydb/stdlib/query.sql | 11 + .../testdata/join_alias/ydb/stdlib/schema.sql | 3 + .../testdata/join_alias/ydb/stdlib/sqlc.json | 12 + .../join_alias/ydb/ydb-go-sdk/go/db.go | 26 + .../join_alias/ydb/ydb-go-sdk/go/models.go | 14 + .../join_alias/ydb/ydb-go-sdk/go/query.sql.go | 91 ++ .../join_alias/ydb/ydb-go-sdk/query.sql | 11 + .../join_alias/ydb/ydb-go-sdk/schema.sql | 3 + .../join_alias/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/join_clauses_order/ydb/go/db.go | 31 + .../join_clauses_order/ydb/go/models.go | 34 + .../join_clauses_order/ydb/go/query.sql.go | 174 ++++ .../testdata/join_clauses_order/ydb/query.sql | 27 + .../join_clauses_order/ydb/schema.sql | 33 + .../testdata/join_clauses_order/ydb/sqlc.json | 12 + .../testdata/join_from/ydb/stdlib/go/db.go | 31 + .../join_from/ydb/stdlib/go/models.go | 13 + .../join_from/ydb/stdlib/go/query.sql.go | 37 + .../testdata/join_from/ydb/stdlib/query.sql | 2 + .../testdata/join_from/ydb/stdlib/schema.sql | 2 + .../testdata/join_from/ydb/stdlib/sqlc.json | 12 + .../join_from/ydb/ydb-go-sdk/go/db.go | 26 + .../join_from/ydb/ydb-go-sdk/go/models.go | 13 + .../join_from/ydb/ydb-go-sdk/go/query.sql.go | 44 + .../join_from/ydb/ydb-go-sdk/query.sql | 2 + .../join_from/ydb/ydb-go-sdk/schema.sql | 2 + .../join_from/ydb/ydb-go-sdk/sqlc.json | 13 + .../endtoend/testdata/join_full/ydb/go/db.go | 31 + .../testdata/join_full/ydb/go/models.go | 14 + .../testdata/join_full/ydb/go/query.sql.go | 46 + .../endtoend/testdata/join_full/ydb/query.sql | 5 + .../testdata/join_full/ydb/schema.sql | 12 + .../endtoend/testdata/join_full/ydb/sqlc.json | 14 + .../testdata/join_group_by_alias/ydb/go/db.go | 31 + .../join_group_by_alias/ydb/go/models.go | 9 + .../join_group_by_alias/ydb/go/query.sql.go | 39 + .../join_group_by_alias/ydb/query.sql | 4 + .../join_group_by_alias/ydb/schema.sql | 1 + .../join_group_by_alias/ydb/sqlc.json | 12 + .../endtoend/testdata/join_inner/ydb/go/db.go | 31 + .../testdata/join_inner/ydb/go/models.go | 14 + .../testdata/join_inner/ydb/go/query.sql.go | 70 ++ .../testdata/join_inner/ydb/query.sql | 15 + .../testdata/join_inner/ydb/schema.sql | 14 + .../testdata/join_inner/ydb/sqlc.json | 16 + .../endtoend/testdata/join_left/ydb/go/db.go | 31 + .../testdata/join_left/ydb/go/models.go | 59 ++ .../testdata/join_left/ydb/go/query.sql.go | 409 ++++++++ .../endtoend/testdata/join_left/ydb/query.sql | 43 + .../testdata/join_left/ydb/schema.sql | 60 ++ .../endtoend/testdata/join_left/ydb/sqlc.json | 16 + .../join_left_same_table/ydb/go/db.go | 31 + .../join_left_same_table/ydb/go/models.go | 11 + .../join_left_same_table/ydb/go/query.sql.go | 55 ++ .../join_left_same_table/ydb/query.sql | 8 + .../join_left_same_table/ydb/schema.sql | 6 + .../join_left_same_table/ydb/sqlc.json | 12 + .../join_left_table_alias/ydb/go/db.go | 31 + .../join_left_table_alias/ydb/go/models.go | 14 + .../join_left_table_alias/ydb/go/query.sql.go | 46 + .../join_left_table_alias/ydb/query.sql | 9 + .../join_left_table_alias/ydb/schema.sql | 10 + .../join_left_table_alias/ydb/sqlc.json | 12 + .../testdata/join_order_by/ydb/go/db.go | 31 + .../testdata/join_order_by/ydb/go/models.go | 11 + .../join_order_by/ydb/go/query.sql.go | 23 + .../testdata/join_order_by/ydb/query.sql | 4 + .../testdata/join_order_by/ydb/schema.sql | 6 + .../testdata/join_order_by/ydb/sqlc.json | 12 + .../testdata/join_order_by_alias/ydb/go/db.go | 31 + .../join_order_by_alias/ydb/go/models.go | 9 + .../join_order_by_alias/ydb/go/query.sql.go | 39 + .../join_order_by_alias/ydb/query.sql | 4 + .../join_order_by_alias/ydb/schema.sql | 1 + .../join_order_by_alias/ydb/sqlc.json | 12 + .../endtoend/testdata/join_right/ydb/go/db.go | 31 + .../testdata/join_right/ydb/go/models.go | 14 + .../testdata/join_right/ydb/go/query.sql.go | 46 + .../testdata/join_right/ydb/query.sql | 7 + .../testdata/join_right/ydb/schema.sql | 12 + .../testdata/join_right/ydb/sqlc.json | 14 + .../join_table_name/ydb/stdlib/go/db.go | 31 + .../join_table_name/ydb/stdlib/go/models.go | 14 + .../ydb/stdlib/go/query.sql.go | 29 + .../join_table_name/ydb/stdlib/query.sql | 5 + .../join_table_name/ydb/stdlib/schema.sql | 2 + .../join_table_name/ydb/stdlib/sqlc.json | 12 + .../join_table_name/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 14 + .../ydb/ydb-go-sdk/go/query.sql.go | 44 + .../join_table_name/ydb/ydb-go-sdk/query.sql | 5 + .../join_table_name/ydb/ydb-go-sdk/schema.sql | 2 + .../join_table_name/ydb/ydb-go-sdk/sqlc.json | 13 + .../join_two_tables/ydb/stdlib/go/db.go | 31 + .../join_two_tables/ydb/stdlib/go/models.go | 18 + .../ydb/stdlib/go/query.sql.go | 40 + .../join_two_tables/ydb/stdlib/query.sql | 5 + .../join_two_tables/ydb/stdlib/schema.sql | 3 + .../join_two_tables/ydb/stdlib/sqlc.json | 12 + .../join_two_tables/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 18 + .../ydb/ydb-go-sdk/go/query.sql.go | 42 + .../join_two_tables/ydb/ydb-go-sdk/query.sql | 5 + .../join_two_tables/ydb/ydb-go-sdk/schema.sql | 3 + .../join_two_tables/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/join_update/ydb/go/db.go | 31 + .../testdata/join_update/ydb/go/models.go | 20 + .../testdata/join_update/ydb/go/query.sql.go | 23 + .../testdata/join_update/ydb/query.sql | 6 + .../testdata/join_update/ydb/schema.sql | 17 + .../testdata/join_update/ydb/sqlc.json | 12 + .../endtoend/testdata/join_using/ydb/go/db.go | 31 + .../testdata/join_using/ydb/go/models.go | 13 + .../testdata/join_using/ydb/go/query.sql.go | 42 + .../testdata/join_using/ydb/query.sql | 2 + .../testdata/join_using/ydb/schema.sql | 10 + .../testdata/join_using/ydb/sqlc.json | 13 + .../join_where_clause/ydb/stdlib/go/db.go | 31 + .../join_where_clause/ydb/stdlib/go/models.go | 14 + .../ydb/stdlib/go/query.sql.go | 110 +++ .../join_where_clause/ydb/stdlib/query.sql | 17 + .../join_where_clause/ydb/stdlib/schema.sql | 2 + .../join_where_clause/ydb/stdlib/sqlc.json | 12 + .../join_where_clause/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 14 + .../ydb/ydb-go-sdk/go/query.sql.go | 125 +++ .../ydb/ydb-go-sdk/query.sql | 17 + .../ydb/ydb-go-sdk/schema.sql | 2 + .../ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/json/ydb/stdlib/go/db.go | 31 + .../testdata/json/ydb/stdlib/go/models.go | 12 + .../testdata/json/ydb/stdlib/go/query.sql.go | 19 + .../testdata/json/ydb/stdlib/query.sql | 2 + .../testdata/json/ydb/stdlib/schema.sql | 7 + .../testdata/json/ydb/stdlib/sqlc.json | 12 + .../testdata/json/ydb/ydb-go-sdk/go/db.go | 26 + .../testdata/json/ydb/ydb-go-sdk/go/models.go | 12 + .../json/ydb/ydb-go-sdk/go/query.sql.go | 25 + .../testdata/json/ydb/ydb-go-sdk/query.sql | 2 + .../testdata/json/ydb/ydb-go-sdk/schema.sql | 7 + .../testdata/json/ydb/ydb-go-sdk/sqlc.json | 13 + internal/endtoend/testdata/limit/ydb/go/db.go | 31 + .../endtoend/testdata/limit/ydb/go/models.go | 9 + .../testdata/limit/ydb/go/query.sql.go | 37 + .../endtoend/testdata/limit/ydb/query.sql | 2 + .../endtoend/testdata/limit/ydb/schema.sql | 1 + .../endtoend/testdata/limit/ydb/sqlc.json | 12 + internal/endtoend/testdata/lower/ydb/go/db.go | 31 + .../endtoend/testdata/lower/ydb/go/models.go | 10 + .../testdata/lower/ydb/go/query.sql.go | 42 + .../endtoend/testdata/lower/ydb/query.sql | 2 + .../endtoend/testdata/lower/ydb/schema.sql | 1 + .../endtoend/testdata/lower/ydb/sqlc.json | 12 + .../lower_switched_order/ydb/go/db.go | 31 + .../lower_switched_order/ydb/go/models.go | 10 + .../lower_switched_order/ydb/go/query.sql.go | 42 + .../lower_switched_order/ydb/query.sql | 2 + .../lower_switched_order/ydb/schema.sql | 1 + .../lower_switched_order/ydb/sqlc.json | 12 + .../mathmatical_operator/ydb/go/db.go | 31 + .../mathmatical_operator/ydb/go/models.go | 9 + .../mathmatical_operator/ydb/go/query.sql.go | 42 + .../mathmatical_operator/ydb/query.sql | 2 + .../mathmatical_operator/ydb/schema.sql | 1 + .../mathmatical_operator/ydb/sqlc.json | 12 + .../testdata/min_max_date/ydb/go/db.go | 31 + .../testdata/min_max_date/ydb/go/models.go | 14 + .../testdata/min_max_date/ydb/go/query.sql.go | 32 + .../testdata/min_max_date/ydb/query.sql | 7 + .../testdata/min_max_date/ydb/schema.sql | 6 + .../testdata/min_max_date/ydb/sqlc.json | 13 + .../testdata/mix_param_types/ydb/go/db.go | 31 + .../testdata/mix_param_types/ydb/go/models.go | 11 + .../mix_param_types/ydb/go/test.sql.go | 60 ++ .../testdata/mix_param_types/ydb/schema.sql | 7 + .../testdata/mix_param_types/ydb/sqlc.json | 13 + .../testdata/mix_param_types/ydb/test.sql | 9 + .../testdata/named_param/ydb/go/db.go | 31 + .../testdata/named_param/ydb/go/models.go | 10 + .../testdata/named_param/ydb/go/query.sql.go | 128 +++ .../testdata/named_param/ydb/query.sql | 23 + .../testdata/named_param/ydb/schema.sql | 4 + .../testdata/named_param/ydb/sqlc.json | 15 + .../testdata/nested_select/ydb/go/db.go | 31 + .../testdata/nested_select/ydb/go/models.go | 11 + .../nested_select/ydb/go/query.sql.go | 39 + .../testdata/nested_select/ydb/query.sql | 11 + .../testdata/nested_select/ydb/schema.sql | 7 + .../testdata/nested_select/ydb/sqlc.json | 13 + .../on_duplicate_key_update/ydb/go/db.go | 31 + .../on_duplicate_key_update/ydb/go/models.go | 11 + .../ydb/go/query.sql.go | 40 + .../on_duplicate_key_update/ydb/query.sql | 8 + .../on_duplicate_key_update/ydb/schema.sql | 7 + .../on_duplicate_key_update/ydb/sqlc.json | 13 + .../testdata/order_by_binds/ydb/go/db.go | 31 + .../testdata/order_by_binds/ydb/go/models.go | 11 + .../order_by_binds/ydb/go/query.sql.go | 101 ++ .../testdata/order_by_binds/ydb/query.sql | 14 + .../testdata/order_by_binds/ydb/schema.sql | 7 + .../testdata/order_by_binds/ydb/sqlc.json | 13 + .../testdata/order_by_union/ydb/go/db.go | 31 + .../testdata/order_by_union/ydb/go/models.go | 15 + .../order_by_union/ydb/go/query.sql.go | 40 + .../testdata/order_by_union/ydb/query.sql | 6 + .../testdata/order_by_union/ydb/schema.sql | 12 + .../testdata/order_by_union/ydb/sqlc.json | 13 + .../output_file_names/ydb/go/db_gen.go | 31 + .../output_file_names/ydb/go/models_gen.go | 9 + .../output_file_names/ydb/go/querier_gen.go | 15 + .../output_file_names/ydb/go/query.sql.go | 37 + .../testdata/output_file_names/ydb/query.sql | 2 + .../testdata/output_file_names/ydb/schema.sql | 1 + .../testdata/output_file_names/ydb/sqlc.json | 18 + .../testdata/output_files_suffix/ydb/go/db.go | 31 + .../output_files_suffix/ydb/go/models.go | 9 + .../ydb/go/query.sql_gen.go | 37 + .../output_files_suffix/ydb/query.sql | 3 + .../output_files_suffix/ydb/schema.sql | 2 + .../output_files_suffix/ydb/sqlc.json | 14 + .../endtoend/testdata/overrides/ydb/go/db.go | 31 + .../testdata/overrides/ydb/go/models.go | 15 + .../testdata/overrides/ydb/go/query.sql.go | 21 + .../endtoend/testdata/overrides/ydb/query.sql | 3 + .../testdata/overrides/ydb/schema.sql | 7 + .../endtoend/testdata/overrides/ydb/sqlc.json | 19 + .../ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 11 + .../ydb/stdlib/go/query.sql.go | 21 + .../ydb/stdlib/query.sql | 2 + .../ydb/stdlib/schema.sql | 6 + .../ydb/stdlib/sqlc.json | 28 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 11 + .../ydb/ydb-go-sdk/go/query.sql.go | 30 + .../ydb/ydb-go-sdk/query.sql | 2 + .../ydb/ydb-go-sdk/schema.sql | 6 + .../ydb/ydb-go-sdk/sqlc.json | 29 + .../overrides_go_types/ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 22 + .../ydb/stdlib/go/query.sql.go | 46 + .../overrides_go_types/ydb/stdlib/query.sql | 3 + .../overrides_go_types/ydb/stdlib/schema.sql | 10 + .../overrides_go_types/ydb/stdlib/sqlc.json | 63 ++ .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 22 + .../ydb/ydb-go-sdk/go/query.sql.go | 52 ++ .../ydb/ydb-go-sdk/query.sql | 3 + .../ydb/ydb-go-sdk/schema.sql | 10 + .../ydb/ydb-go-sdk/sqlc.json | 57 ++ .../overrides_pointers/ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 18 + .../ydb/stdlib/go/query.sql.go | 21 + .../overrides_pointers/ydb/stdlib/query.sql | 3 + .../overrides_pointers/ydb/stdlib/schema.sql | 9 + .../overrides_pointers/ydb/stdlib/sqlc.json | 24 + .../testdata/params_duplicate/ydb/go/db.go | 26 + .../params_duplicate/ydb/go/models.go | 11 + .../params_duplicate/ydb/go/query.sql.go | 109 +++ .../testdata/params_duplicate/ydb/query.sql | 13 + .../testdata/params_duplicate/ydb/schema.sql | 6 + .../testdata/params_duplicate/ydb/sqlc.json | 13 + .../testdata/params_go_keywords/ydb/go/db.go | 31 + .../params_go_keywords/ydb/go/models.go | 34 + .../params_go_keywords/ydb/go/query.sql.go | 530 +++++++++++ .../testdata/params_go_keywords/ydb/query.sql | 155 ++++ .../params_go_keywords/ydb/schema.sql | 32 + .../testdata/params_go_keywords/ydb/sqlc.json | 15 + .../params_in_nested_func/ydb/db/db.go | 31 + .../params_in_nested_func/ydb/db/models.go | 15 + .../params_in_nested_func/ydb/db/query.sql.go | 54 ++ .../params_in_nested_func/ydb/query.sql | 10 + .../params_in_nested_func/ydb/schema.sql | 11 + .../params_in_nested_func/ydb/sqlc.yaml | 9 + .../params_location/ydb/stdlib/go/db.go | 31 + .../params_location/ydb/stdlib/go/models.go | 23 + .../ydb/stdlib/go/query.sql.go | 258 ++++++ .../params_location/ydb/stdlib/query.sql | 45 + .../params_location/ydb/stdlib/schema.sql | 28 + .../params_location/ydb/stdlib/sqlc.json | 25 + .../params_location/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 23 + .../ydb/ydb-go-sdk/go/query.sql.go | 299 ++++++ .../params_location/ydb/ydb-go-sdk/query.sql | 46 + .../params_location/ydb/ydb-go-sdk/schema.sql | 28 + .../params_location/ydb/ydb-go-sdk/sqlc.json | 26 + .../ydb/go/db.go | 31 + .../ydb/go/models.go | 10 + .../ydb/go/query.sql.go | 64 ++ .../ydb/query.sql | 5 + .../ydb/schema.sql | 5 + .../ydb/sqlc.json | 12 + .../testdata/params_two/ydb/stdlib/go/db.go | 31 + .../params_two/ydb/stdlib/go/models.go | 10 + .../params_two/ydb/stdlib/go/query.sql.go | 43 + .../testdata/params_two/ydb/stdlib/query.sql | 3 + .../testdata/params_two/ydb/stdlib/schema.sql | 5 + .../testdata/params_two/ydb/stdlib/sqlc.json | 12 + .../params_two/ydb/ydb-go-sdk/go/db.go | 26 + .../params_two/ydb/ydb-go-sdk/go/models.go | 10 + .../params_two/ydb/ydb-go-sdk/go/query.sql.go | 51 + .../params_two/ydb/ydb-go-sdk/query.sql | 3 + .../params_two/ydb/ydb-go-sdk/schema.sql | 5 + .../params_two/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/pattern_matching/ydb/go/db.go | 31 + .../pattern_matching/ydb/go/models.go | 9 + .../pattern_matching/ydb/go/query.sql.go | 37 + .../testdata/pattern_matching/ydb/query.sql | 2 + .../testdata/pattern_matching/ydb/schema.sql | 4 + .../testdata/pattern_matching/ydb/sqlc.json | 12 + .../ydb/go/db.go | 31 + .../ydb/go/models.go | 17 + .../ydb/go/querier.go | 17 + .../ydb/go/query.sql.go | 32 + .../ydb/query.sql | 8 + .../ydb/schema.sql | 8 + .../ydb/sqlc.json | 14 + .../query_parameter_limit_to_two/ydb/go/db.go | 31 + .../ydb/go/models.go | 18 + .../ydb/go/query.sql.go | 149 +++ .../ydb/query.sql | 34 + .../ydb/schema.sql | 15 + .../ydb/sqlc.json | 13 + .../ydb/go/db.go | 31 + .../ydb/go/models.go | 12 + .../ydb/go/querier.go | 18 + .../ydb/go/query.sql.go | 106 +++ .../ydb/query.sql | 19 + .../ydb/schema.sql | 8 + .../ydb/sqlc.json | 14 + .../testdata/returning/ydb/stdlib/go/db.go | 31 + .../returning/ydb/stdlib/go/models.go | 10 + .../returning/ydb/stdlib/go/query.sql.go | 96 ++ .../testdata/returning/ydb/stdlib/query.sql | 27 + .../testdata/returning/ydb/stdlib/schema.sql | 5 + .../testdata/returning/ydb/stdlib/sqlc.json | 12 + .../returning/ydb/ydb-go-sdk/go/db.go | 26 + .../returning/ydb/ydb-go-sdk/go/models.go | 10 + .../returning/ydb/ydb-go-sdk/go/query.sql.go | 162 ++++ .../returning/ydb/ydb-go-sdk/query.sql | 27 + .../returning/ydb/ydb-go-sdk/schema.sql | 5 + .../returning/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/select_column_cast/ydb/go/db.go | 31 + .../select_column_cast/ydb/go/models.go | 9 + .../select_column_cast/ydb/go/query.sql.go | 37 + .../testdata/select_column_cast/ydb/query.sql | 2 + .../select_column_cast/ydb/schema.sql | 4 + .../testdata/select_column_cast/ydb/sqlc.json | 12 + .../select_distinct/ydb/stdlib/go/db.go | 31 + .../select_distinct/ydb/stdlib/go/models.go | 10 + .../ydb/stdlib/go/query.sql.go | 38 + .../select_distinct/ydb/stdlib/query.sql | 3 + .../select_distinct/ydb/stdlib/schema.sql | 1 + .../select_distinct/ydb/stdlib/sqlc.json | 12 + .../select_distinct/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 10 + .../ydb/ydb-go-sdk/go/query.sql.go | 40 + .../select_distinct/ydb/ydb-go-sdk/query.sql | 3 + .../select_distinct/ydb/ydb-go-sdk/schema.sql | 1 + .../select_distinct/ydb/ydb-go-sdk/sqlc.json | 13 + .../select_exists/ydb/stdlib/go/db.go | 31 + .../select_exists/ydb/stdlib/go/models.go | 9 + .../select_exists/ydb/stdlib/go/query.sql.go | 29 + .../select_exists/ydb/stdlib/query.sql | 10 + .../select_exists/ydb/stdlib/schema.sql | 1 + .../select_exists/ydb/stdlib/sqlc.json | 12 + .../select_exists/ydb/ydb-go-sdk/go/db.go | 26 + .../select_exists/ydb/ydb-go-sdk/go/models.go | 9 + .../ydb/ydb-go-sdk/go/query.sql.go | 43 + .../select_exists/ydb/ydb-go-sdk/query.sql | 10 + .../select_exists/ydb/ydb-go-sdk/schema.sql | 1 + .../select_exists/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/select_in_and/ydb/go/db.go | 31 + .../testdata/select_in_and/ydb/go/models.go | 24 + .../select_in_and/ydb/go/query.sql.go | 44 + .../testdata/select_in_and/ydb/query.sql | 21 + .../testdata/select_in_and/ydb/schema.sql | 25 + .../testdata/select_in_and/ydb/sqlc.json | 15 + .../testdata/select_limit/ydb/stdlib/go/db.go | 31 + .../select_limit/ydb/stdlib/go/models.go | 9 + .../select_limit/ydb/stdlib/go/query.sql.go | 71 ++ .../select_limit/ydb/stdlib/query.sql | 8 + .../select_limit/ydb/stdlib/schema.sql | 2 + .../select_limit/ydb/stdlib/sqlc.json | 13 + .../select_limit/ydb/ydb-go-sdk/go/db.go | 26 + .../select_limit/ydb/ydb-go-sdk/go/models.go | 9 + .../ydb/ydb-go-sdk/go/query.sql.go | 82 ++ .../select_limit/ydb/ydb-go-sdk/query.sql | 8 + .../select_limit/ydb/ydb-go-sdk/schema.sql | 2 + .../select_limit/ydb/ydb-go-sdk/sqlc.json | 14 + .../testdata/select_nested_count/ydb/go/db.go | 31 + .../select_nested_count/ydb/go/models.go | 17 + .../select_nested_count/ydb/go/query.sql.go | 56 ++ .../select_nested_count/ydb/query.sql | 9 + .../select_nested_count/ydb/schema.sql | 16 + .../select_nested_count/ydb/sqlc.json | 15 + .../select_not_exists/ydb-go-sdk/go/db.go | 26 + .../select_not_exists/ydb-go-sdk/go/models.go | 9 + .../ydb-go-sdk/go/query.sql.go | 43 + .../select_not_exists/ydb-go-sdk/query.sql | 10 + .../select_not_exists/ydb-go-sdk/schema.sql | 1 + .../select_not_exists/ydb-go-sdk/sqlc.json | 15 + .../testdata/select_star/ydb/stdlib/go/db.go | 31 + .../select_star/ydb/stdlib/go/models.go | 12 + .../select_star/ydb/stdlib/go/query.sql.go | 69 ++ .../testdata/select_star/ydb/stdlib/query.sql | 5 + .../select_star/ydb/stdlib/schema.sql | 7 + .../testdata/select_star/ydb/stdlib/sqlc.json | 12 + .../select_star/ydb/ydb-go-sdk/go/db.go | 26 + .../select_star/ydb/ydb-go-sdk/go/models.go | 12 + .../ydb/ydb-go-sdk/go/query.sql.go | 70 ++ .../select_star/ydb/ydb-go-sdk/query.sql | 5 + .../select_star/ydb/ydb-go-sdk/schema.sql | 7 + .../select_star/ydb/ydb-go-sdk/sqlc.json | 13 + .../select_text_array/ydb-go-sdk/go/db.go | 26 + .../select_text_array/ydb-go-sdk/go/models.go | 9 + .../ydb-go-sdk/go/query.sql.go | 48 + .../select_text_array/ydb-go-sdk/query.sql | 2 + .../select_text_array/ydb-go-sdk/schema.sql | 1 + .../select_text_array/ydb-go-sdk/sqlc.json | 13 + .../testdata/select_union/ydb/stdlib/go/db.go | 31 + .../select_union/ydb/stdlib/go/models.go | 15 + .../select_union/ydb/stdlib/go/query.sql.go | 132 +++ .../select_union/ydb/stdlib/query.sql | 23 + .../select_union/ydb/stdlib/schema.sql | 5 + .../select_union/ydb/stdlib/sqlc.json | 15 + .../select_union/ydb/ydb-go-sdk/go/db.go | 26 + .../select_union/ydb/ydb-go-sdk/go/models.go | 15 + .../ydb/ydb-go-sdk/go/query.sql.go | 137 +++ .../select_union/ydb/ydb-go-sdk/query.sql | 23 + .../select_union/ydb/ydb-go-sdk/schema.sql | 5 + .../select_union/ydb/ydb-go-sdk/sqlc.json | 16 + .../single_param_conflict/ydb/go/db.go | 31 + .../single_param_conflict/ydb/go/models.go | 19 + .../single_param_conflict/ydb/go/query.sql.go | 67 ++ .../single_param_conflict/ydb/query.sql | 25 + .../single_param_conflict/ydb/schema.sql | 13 + .../single_param_conflict/ydb/sqlc.json | 12 + .../endtoend/testdata/sqlc_arg/ydb/query.sql | 6 + .../testdata/sqlc_arg/ydb/stdlib/go/db.go | 31 + .../testdata/sqlc_arg/ydb/stdlib/go/models.go | 9 + .../sqlc_arg/ydb/stdlib/go/query.sql.go | 64 ++ .../testdata/sqlc_arg/ydb/stdlib/query.sql | 5 + .../testdata/sqlc_arg/ydb/stdlib/schema.sql | 4 + .../testdata/sqlc_arg/ydb/stdlib/sqlc.json | 12 + .../testdata/sqlc_arg/ydb/ydb-go-sdk/go/db.go | 26 + .../sqlc_arg/ydb/ydb-go-sdk/go/models.go | 9 + .../sqlc_arg/ydb/ydb-go-sdk/go/query.sql.go | 74 ++ .../sqlc_arg/ydb/ydb-go-sdk/query.sql | 5 + .../sqlc_arg/ydb/ydb-go-sdk/schema.sql | 4 + .../sqlc_arg/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/sqlc_embed/ydb/stdlib/go/db.go | 31 + .../sqlc_embed/ydb/stdlib/go/models.go | 17 + .../sqlc_embed/ydb/stdlib/go/query.sql.go | 149 +++ .../testdata/sqlc_embed/ydb/stdlib/query.sql | 18 + .../testdata/sqlc_embed/ydb/stdlib/schema.sql | 13 + .../testdata/sqlc_embed/ydb/stdlib/sqlc.json | 12 + .../sqlc_embed/ydb/ydb-go-sdk/go/db.go | 26 + .../sqlc_embed/ydb/ydb-go-sdk/go/models.go | 17 + .../sqlc_embed/ydb/ydb-go-sdk/go/query.sql.go | 181 ++++ .../sqlc_embed/ydb/ydb-go-sdk/query.sql | 18 + .../sqlc_embed/ydb/ydb-go-sdk/schema.sql | 13 + .../sqlc_embed/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/sqlc_narg/ydb/stdlib/go/db.go | 31 + .../sqlc_narg/ydb/stdlib/go/models.go | 10 + .../sqlc_narg/ydb/stdlib/go/query.sql.go | 118 +++ .../testdata/sqlc_narg/ydb/stdlib/query.sql | 11 + .../testdata/sqlc_narg/ydb/stdlib/schema.sql | 5 + .../testdata/sqlc_narg/ydb/stdlib/sqlc.json | 12 + .../sqlc_narg/ydb/ydb-go-sdk/go/db.go | 26 + .../sqlc_narg/ydb/ydb-go-sdk/go/models.go | 10 + .../sqlc_narg/ydb/ydb-go-sdk/go/query.sql.go | 134 +++ .../sqlc_narg/ydb/ydb-go-sdk/query.sql | 11 + .../sqlc_narg/ydb/ydb-go-sdk/schema.sql | 5 + .../sqlc_narg/ydb/ydb-go-sdk/sqlc.json | 13 + .../testdata/sqlc_slice/ydb/stdlib/go/db.go | 31 + .../sqlc_slice/ydb/stdlib/go/models.go | 11 + .../sqlc_slice/ydb/stdlib/go/query.sql.go | 177 ++++ .../testdata/sqlc_slice/ydb/stdlib/query.sql | 25 + .../testdata/sqlc_slice/ydb/stdlib/schema.sql | 1 + .../testdata/sqlc_slice/ydb/stdlib/sqlc.json | 12 + .../sqlc_slice/ydb/ydb-go-sdk/go/db.go | 26 + .../sqlc_slice/ydb/ydb-go-sdk/go/models.go | 11 + .../sqlc_slice/ydb/ydb-go-sdk/go/query.sql.go | 230 +++++ .../sqlc_slice/ydb/ydb-go-sdk/query.sql | 25 + .../sqlc_slice/ydb/ydb-go-sdk/schema.sql | 1 + .../sqlc_slice/ydb/ydb-go-sdk/sqlc.json | 13 + .../star_expansion/ydb/stdlib/go/db.go | 31 + .../star_expansion/ydb/stdlib/go/models.go | 10 + .../star_expansion/ydb/stdlib/go/query.sql.go | 80 ++ .../star_expansion/ydb/stdlib/query.sql | 5 + .../star_expansion/ydb/stdlib/schema.sql | 5 + .../star_expansion/ydb/stdlib/sqlc.json | 12 + .../star_expansion/ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 10 + .../ydb/ydb-go-sdk/go/query.sql.go | 81 ++ .../star_expansion/ydb/ydb-go-sdk/query.sql | 5 + .../star_expansion/ydb/ydb-go-sdk/schema.sql | 5 + .../star_expansion/ydb/ydb-go-sdk/sqlc.json | 13 + .../star_expansion_join/ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 15 + .../ydb/stdlib/go/query.sql.go | 49 + .../star_expansion_join/ydb/stdlib/query.sql | 3 + .../star_expansion_join/ydb/stdlib/schema.sql | 12 + .../star_expansion_join/ydb/stdlib/sqlc.json | 13 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 15 + .../ydb/ydb-go-sdk/go/query.sql.go | 51 + .../ydb/ydb-go-sdk/query.sql | 3 + .../ydb/ydb-go-sdk/schema.sql | 12 + .../ydb/ydb-go-sdk/sqlc.json | 14 + .../ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 10 + .../ydb/stdlib/go/query.sql.go | 37 + .../ydb/stdlib/query.sql | 3 + .../ydb/stdlib/schema.sql | 6 + .../ydb/stdlib/sqlc.json | 13 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 10 + .../ydb/ydb-go-sdk/go/query.sql.go | 39 + .../ydb/ydb-go-sdk/query.sql | 3 + .../ydb/ydb-go-sdk/schema.sql | 6 + .../ydb/ydb-go-sdk/sqlc.json | 14 + .../testdata/types_uuid/ydb/stdlib/go/db.go | 31 + .../types_uuid/ydb/stdlib/go/models.go | 15 + .../types_uuid/ydb/stdlib/go/query.sql.go | 50 + .../testdata/types_uuid/ydb/stdlib/query.sql | 6 + .../testdata/types_uuid/ydb/stdlib/schema.sql | 7 + .../testdata/types_uuid/ydb/stdlib/sqlc.json | 13 + .../types_uuid/ydb/ydb-go-sdk/go/db.go | 26 + .../types_uuid/ydb/ydb-go-sdk/go/models.go | 15 + .../types_uuid/ydb/ydb-go-sdk/go/query.sql.go | 62 ++ .../types_uuid/ydb/ydb-go-sdk/query.sql | 6 + .../types_uuid/ydb/ydb-go-sdk/schema.sql | 7 + .../types_uuid/ydb/ydb-go-sdk/sqlc.json | 14 + .../testdata/update_set/ydb/stdlib/go/db.go | 31 + .../update_set/ydb/stdlib/go/models.go | 10 + .../update_set/ydb/stdlib/go/query.sql.go | 24 + .../testdata/update_set/ydb/stdlib/query.sql | 2 + .../testdata/update_set/ydb/stdlib/schema.sql | 5 + .../testdata/update_set/ydb/stdlib/sqlc.json | 12 + .../update_set/ydb/ydb-go-sdk/go/db.go | 26 + .../update_set/ydb/ydb-go-sdk/go/models.go | 10 + .../update_set/ydb/ydb-go-sdk/go/query.sql.go | 36 + .../update_set/ydb/ydb-go-sdk/query.sql | 2 + .../update_set/ydb/ydb-go-sdk/schema.sql | 5 + .../update_set/ydb/ydb-go-sdk/sqlc.json | 13 + .../update_set_multiple/ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 10 + .../ydb/stdlib/go/query.sql.go | 24 + .../update_set_multiple/ydb/stdlib/query.sql | 3 + .../update_set_multiple/ydb/stdlib/schema.sql | 6 + .../update_set_multiple/ydb/stdlib/sqlc.json | 13 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 10 + .../ydb/ydb-go-sdk/go/query.sql.go | 36 + .../ydb/ydb-go-sdk/query.sql | 3 + .../ydb/ydb-go-sdk/schema.sql | 6 + .../ydb/ydb-go-sdk/sqlc.json | 14 + .../endtoend/testdata/upsert/ydb/go/db.go | 26 + .../endtoend/testdata/upsert/ydb/go/models.go | 14 + .../testdata/upsert/ydb/go/query.sql.go | 52 ++ .../endtoend/testdata/upsert/ydb/query.sql | 13 + .../endtoend/testdata/upsert/ydb/schema.sql | 14 + .../endtoend/testdata/upsert/ydb/sqlc.json | 16 + .../ydb/stdlib/go/db.go | 31 + .../ydb/stdlib/go/models.go | 35 + .../ydb/stdlib/go/query.sql.go | 103 +++ .../ydb/stdlib/query.sql | 15 + .../ydb/stdlib/schema.sql | 28 + .../ydb/stdlib/sqlc.json | 13 + .../ydb/ydb-go-sdk/go/db.go | 26 + .../ydb/ydb-go-sdk/go/models.go | 35 + .../ydb/ydb-go-sdk/go/query.sql.go | 103 +++ .../ydb/ydb-go-sdk/query.sql | 15 + .../ydb/ydb-go-sdk/schema.sql | 28 + .../ydb/ydb-go-sdk/sqlc.json | 14 + .../ydb/catalog_tests/create_table_test.go | 8 +- .../engine/ydb/catalog_tests/delete_test.go | 12 +- .../engine/ydb/catalog_tests/insert_test.go | 42 +- .../engine/ydb/catalog_tests/select_test.go | 11 +- .../engine/ydb/catalog_tests/update_test.go | 22 +- internal/engine/ydb/convert.go | 763 +++++++++++++-- internal/engine/ydb/lib/aggregate.go | 5 +- internal/engine/ydb/lib/basic.go | 12 + internal/engine/ydb/lib/cpp/datetime.go | 171 ++-- internal/engine/ydb/lib/cpp/digest.go | 36 +- internal/engine/ydb/lib/cpp/hyperscan.go | 16 +- internal/engine/ydb/lib/cpp/ip.go | 24 +- internal/engine/ydb/lib/cpp/math.go | 104 +-- internal/engine/ydb/lib/cpp/pcre.go | 16 +- internal/engine/ydb/lib/cpp/pire.go | 12 +- internal/engine/ydb/lib/cpp/re2.go | 52 +- internal/engine/ydb/lib/cpp/string.go | 28 +- internal/engine/ydb/lib/cpp/unicode.go | 102 +- internal/engine/ydb/lib/cpp/url.go | 88 +- internal/engine/ydb/lib/cpp/yson.go | 132 +-- internal/engine/ydb/parse.go | 10 +- internal/engine/ydb/stdlib.go | 1 - internal/engine/ydb/utils.go | 47 + 1138 files changed, 27691 insertions(+), 548 deletions(-) create mode 100644 internal/endtoend/testdata/alias/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/alias/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/alias/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/alias/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/alias/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/alias/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/alias/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/alias/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/alias/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/array_in/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/array_in/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/array_in/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/array_in/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/array_in/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/array_in/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/array_text/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/array_text/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/array_text/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/array_text/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/array_text/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/array_text/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/between_args/ydb/go/db.go create mode 100644 internal/endtoend/testdata/between_args/ydb/go/models.go create mode 100644 internal/endtoend/testdata/between_args/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/between_args/ydb/query.sql create mode 100644 internal/endtoend/testdata/between_args/ydb/schema.sql create mode 100644 internal/endtoend/testdata/between_args/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/builtins/ydb/go/db.go create mode 100644 internal/endtoend/testdata/builtins/ydb/go/models.go create mode 100644 internal/endtoend/testdata/builtins/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/builtins/ydb/query.sql create mode 100644 internal/endtoend/testdata/builtins/ydb/schema.sql create mode 100644 internal/endtoend/testdata/builtins/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/case_named_params/ydb/go/db.go create mode 100644 internal/endtoend/testdata/case_named_params/ydb/go/models.go create mode 100644 internal/endtoend/testdata/case_named_params/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/case_named_params/ydb/query.sql create mode 100644 internal/endtoend/testdata/case_named_params/ydb/schema.sql create mode 100644 internal/endtoend/testdata/case_named_params/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/case_sensitive/ydb/go/db.go create mode 100644 internal/endtoend/testdata/case_sensitive/ydb/go/models.go create mode 100644 internal/endtoend/testdata/case_sensitive/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/case_sensitive/ydb/query.sql create mode 100644 internal/endtoend/testdata/case_sensitive/ydb/schema.sql create mode 100644 internal/endtoend/testdata/case_sensitive/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/case_stmt_bool/ydb/go/db.go create mode 100644 internal/endtoend/testdata/case_stmt_bool/ydb/go/models.go create mode 100644 internal/endtoend/testdata/case_stmt_bool/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/case_stmt_bool/ydb/query.sql create mode 100644 internal/endtoend/testdata/case_stmt_bool/ydb/schema.sql create mode 100644 internal/endtoend/testdata/case_stmt_bool/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/case_text/ydb/go/db.go create mode 100644 internal/endtoend/testdata/case_text/ydb/go/models.go create mode 100644 internal/endtoend/testdata/case_text/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/case_text/ydb/query.sql create mode 100644 internal/endtoend/testdata/case_text/ydb/schema.sql create mode 100644 internal/endtoend/testdata/case_text/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/case_value_param/ydb/go/db.go create mode 100644 internal/endtoend/testdata/case_value_param/ydb/go/models.go create mode 100644 internal/endtoend/testdata/case_value_param/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/case_value_param/ydb/query.sql create mode 100644 internal/endtoend/testdata/case_value_param/ydb/schema.sql create mode 100644 internal/endtoend/testdata/case_value_param/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/cast_null/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/cast_null/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/cast_null/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/cast_null/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/cast_null/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/cast_null/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/cast_param/ydb/go/db.go create mode 100644 internal/endtoend/testdata/cast_param/ydb/go/models.go create mode 100644 internal/endtoend/testdata/cast_param/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/cast_param/ydb/query.sql create mode 100644 internal/endtoend/testdata/cast_param/ydb/schema.sql create mode 100644 internal/endtoend/testdata/cast_param/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/coalesce/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/coalesce/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/coalesce/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/coalesce/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/coalesce/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/coalesce/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/coalesce_join/ydb/go/db.go create mode 100644 internal/endtoend/testdata/coalesce_join/ydb/go/models.go create mode 100644 internal/endtoend/testdata/coalesce_join/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/coalesce_join/ydb/query.sql create mode 100644 internal/endtoend/testdata/coalesce_join/ydb/schema.sql create mode 100644 internal/endtoend/testdata/coalesce_join/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/coalesce_params/ydb/go/db.go create mode 100644 internal/endtoend/testdata/coalesce_params/ydb/go/models.go create mode 100644 internal/endtoend/testdata/coalesce_params/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/coalesce_params/ydb/query.sql create mode 100644 internal/endtoend/testdata/coalesce_params/ydb/schema.sql create mode 100644 internal/endtoend/testdata/coalesce_params/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/column_alias/ydb/go/db.go create mode 100644 internal/endtoend/testdata/column_alias/ydb/go/models.go create mode 100644 internal/endtoend/testdata/column_alias/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/column_alias/ydb/query.sql create mode 100644 internal/endtoend/testdata/column_alias/ydb/schema.sql create mode 100644 internal/endtoend/testdata/column_alias/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/column_as/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/column_as/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/column_as/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/column_as/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/column_as/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/column_as/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/comparisons/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/comparisons/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/comparisons/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/comparisons/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/comparisons/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/comparisons/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/count_star/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/count_star/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/count_star/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/count_star/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/count_star/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/count_star/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/create_view/ydb/go/db.go create mode 100644 internal/endtoend/testdata/create_view/ydb/go/models.go create mode 100644 internal/endtoend/testdata/create_view/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/create_view/ydb/query.sql create mode 100644 internal/endtoend/testdata/create_view/ydb/schema.sql create mode 100644 internal/endtoend/testdata/create_view/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/boolean.sql create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/character.sql create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/datetime.sql create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/json.sql create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/numeric.sql create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/query.sql create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/uuid.sql create mode 100644 internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/db.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/models.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/query.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/schema.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/db.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/models.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/query.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/schema.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_create_table/ydb/go/db.go create mode 100644 internal/endtoend/testdata/ddl_create_table/ydb/go/models.go create mode 100644 internal/endtoend/testdata/ddl_create_table/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_create_table/ydb/query.sql create mode 100644 internal/endtoend/testdata/ddl_create_table/ydb/schema.sql create mode 100644 internal/endtoend/testdata/ddl_create_table/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/go/db.go create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/go/models.go create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/delete_from/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/delete_from/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/delete_from/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/delete_from/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/delete_from/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/delete_from/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/emit_empty_slices/ydb/go/db.go create mode 100644 internal/endtoend/testdata/emit_empty_slices/ydb/go/models.go create mode 100644 internal/endtoend/testdata/emit_empty_slices/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_empty_slices/ydb/query.sql create mode 100644 internal/endtoend/testdata/emit_empty_slices/ydb/schema.sql create mode 100644 internal/endtoend/testdata/emit_empty_slices/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/emit_exported_queries/ydb/go/db.go create mode 100644 internal/endtoend/testdata/emit_exported_queries/ydb/go/models.go create mode 100644 internal/endtoend/testdata/emit_exported_queries/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_exported_queries/ydb/query.sql create mode 100644 internal/endtoend/testdata/emit_exported_queries/ydb/schema.sql create mode 100644 internal/endtoend/testdata/emit_exported_queries/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/db.go create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/models.go create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/querier.go create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/querier.go create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/exec_imports/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/exec_imports/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/exec_imports/ydb/stdlib/go/querier.go create mode 100644 internal/endtoend/testdata/exec_imports/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/exec_imports/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/exec_imports/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/exec_imports/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/querier.go create mode 100644 internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/func_match_types/ydb/go/db.go create mode 100644 internal/endtoend/testdata/func_match_types/ydb/go/models.go create mode 100644 internal/endtoend/testdata/func_match_types/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/func_match_types/ydb/query.sql create mode 100644 internal/endtoend/testdata/func_match_types/ydb/schema.sql create mode 100644 internal/endtoend/testdata/func_match_types/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/func_return_table/ydb/go/db.go create mode 100644 internal/endtoend/testdata/func_return_table/ydb/go/models.go create mode 100644 internal/endtoend/testdata/func_return_table/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/func_return_table/ydb/query.sql create mode 100644 internal/endtoend/testdata/func_return_table/ydb/schema.sql create mode 100644 internal/endtoend/testdata/func_return_table/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/having/ydb/go/db.go create mode 100644 internal/endtoend/testdata/having/ydb/go/models.go create mode 100644 internal/endtoend/testdata/having/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/having/ydb/query.sql create mode 100644 internal/endtoend/testdata/having/ydb/schema.sql create mode 100644 internal/endtoend/testdata/having/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/identical_tables/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/identical_tables/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/identical_tables/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/identical_tables/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/identical_tables/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/identical_tables/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/in_union/ydb/go/db.go create mode 100644 internal/endtoend/testdata/in_union/ydb/go/models.go create mode 100644 internal/endtoend/testdata/in_union/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/in_union/ydb/query.sql create mode 100644 internal/endtoend/testdata/in_union/ydb/schema.sql create mode 100644 internal/endtoend/testdata/in_union/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/inflection/ydb/go/db.go create mode 100644 internal/endtoend/testdata/inflection/ydb/go/models.go create mode 100644 internal/endtoend/testdata/inflection/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/inflection/ydb/query.sql create mode 100644 internal/endtoend/testdata/inflection/ydb/schema.sql create mode 100644 internal/endtoend/testdata/inflection/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/db.go create mode 100644 internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/models.go create mode 100644 internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/inflection_exclude_table_names/ydb/query.sql create mode 100644 internal/endtoend/testdata/inflection_exclude_table_names/ydb/schema.sql create mode 100644 internal/endtoend/testdata/inflection_exclude_table_names/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/insert_select/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/insert_select/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/insert_select/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/insert_select/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/insert_select/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/insert_select/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/insert_select_case/ydb/go/db.go create mode 100644 internal/endtoend/testdata/insert_select_case/ydb/go/models.go create mode 100644 internal/endtoend/testdata/insert_select_case/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/insert_select_case/ydb/query.sql create mode 100644 internal/endtoend/testdata/insert_select_case/ydb/schema.sql create mode 100644 internal/endtoend/testdata/insert_select_case/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/insert_select_param/ydb/go/db.go create mode 100644 internal/endtoend/testdata/insert_select_param/ydb/go/models.go create mode 100644 internal/endtoend/testdata/insert_select_param/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/insert_select_param/ydb/query.sql create mode 100644 internal/endtoend/testdata/insert_select_param/ydb/schema.sql create mode 100644 internal/endtoend/testdata/insert_select_param/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/insert_values/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/insert_values/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/insert_values/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/insert_values/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/insert_values/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/insert_values/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/insert_values_public/ydb/go/db.go create mode 100644 internal/endtoend/testdata/insert_values_public/ydb/go/models.go create mode 100644 internal/endtoend/testdata/insert_values_public/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/insert_values_public/ydb/query.sql create mode 100644 internal/endtoend/testdata/insert_values_public/ydb/schema.sql create mode 100644 internal/endtoend/testdata/insert_values_public/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/interval/ydb/go/db.go create mode 100644 internal/endtoend/testdata/interval/ydb/go/models.go create mode 100644 internal/endtoend/testdata/interval/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/interval/ydb/query.sql create mode 100644 internal/endtoend/testdata/interval/ydb/schema.sql create mode 100644 internal/endtoend/testdata/interval/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_alias/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/join_alias/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/join_alias/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_alias/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/join_alias/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/join_alias/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/join_clauses_order/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_clauses_order/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_clauses_order/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_clauses_order/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_clauses_order/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_clauses_order/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_from/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/join_from/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/join_from/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_from/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/join_from/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/join_from/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/join_full/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_full/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_full/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_full/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_full/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_full/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_group_by_alias/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_group_by_alias/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_group_by_alias/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_group_by_alias/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_group_by_alias/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_group_by_alias/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_inner/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_inner/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_inner/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_inner/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_inner/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_inner/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_left/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_left/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_left/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_left/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_left/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_left/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_left_same_table/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_left_same_table/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_left_same_table/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_left_same_table/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_left_same_table/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_left_same_table/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_left_table_alias/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_left_table_alias/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_left_table_alias/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_left_table_alias/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_left_table_alias/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_left_table_alias/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_order_by/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_order_by/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_order_by/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_order_by/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_order_by/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_order_by/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_order_by_alias/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_order_by_alias/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_order_by_alias/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_order_by_alias/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_order_by_alias/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_order_by_alias/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_right/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_right/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_right/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_right/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_right/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_right/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_table_name/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/join_table_name/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/join_table_name/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_table_name/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/join_table_name/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/join_table_name/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/join_update/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_update/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_update/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_update/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_update/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_update/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_using/ydb/go/db.go create mode 100644 internal/endtoend/testdata/join_using/ydb/go/models.go create mode 100644 internal/endtoend/testdata/join_using/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_using/ydb/query.sql create mode 100644 internal/endtoend/testdata/join_using/ydb/schema.sql create mode 100644 internal/endtoend/testdata/join_using/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/json/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/json/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/json/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/json/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/json/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/json/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/json/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/json/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/json/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/limit/ydb/go/db.go create mode 100644 internal/endtoend/testdata/limit/ydb/go/models.go create mode 100644 internal/endtoend/testdata/limit/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/limit/ydb/query.sql create mode 100644 internal/endtoend/testdata/limit/ydb/schema.sql create mode 100644 internal/endtoend/testdata/limit/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/lower/ydb/go/db.go create mode 100644 internal/endtoend/testdata/lower/ydb/go/models.go create mode 100644 internal/endtoend/testdata/lower/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/lower/ydb/query.sql create mode 100644 internal/endtoend/testdata/lower/ydb/schema.sql create mode 100644 internal/endtoend/testdata/lower/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/lower_switched_order/ydb/go/db.go create mode 100644 internal/endtoend/testdata/lower_switched_order/ydb/go/models.go create mode 100644 internal/endtoend/testdata/lower_switched_order/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/lower_switched_order/ydb/query.sql create mode 100644 internal/endtoend/testdata/lower_switched_order/ydb/schema.sql create mode 100644 internal/endtoend/testdata/lower_switched_order/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/mathmatical_operator/ydb/go/db.go create mode 100644 internal/endtoend/testdata/mathmatical_operator/ydb/go/models.go create mode 100644 internal/endtoend/testdata/mathmatical_operator/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/mathmatical_operator/ydb/query.sql create mode 100644 internal/endtoend/testdata/mathmatical_operator/ydb/schema.sql create mode 100644 internal/endtoend/testdata/mathmatical_operator/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/min_max_date/ydb/go/db.go create mode 100644 internal/endtoend/testdata/min_max_date/ydb/go/models.go create mode 100644 internal/endtoend/testdata/min_max_date/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/min_max_date/ydb/query.sql create mode 100644 internal/endtoend/testdata/min_max_date/ydb/schema.sql create mode 100644 internal/endtoend/testdata/min_max_date/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/mix_param_types/ydb/go/db.go create mode 100644 internal/endtoend/testdata/mix_param_types/ydb/go/models.go create mode 100644 internal/endtoend/testdata/mix_param_types/ydb/go/test.sql.go create mode 100644 internal/endtoend/testdata/mix_param_types/ydb/schema.sql create mode 100644 internal/endtoend/testdata/mix_param_types/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/mix_param_types/ydb/test.sql create mode 100644 internal/endtoend/testdata/named_param/ydb/go/db.go create mode 100644 internal/endtoend/testdata/named_param/ydb/go/models.go create mode 100644 internal/endtoend/testdata/named_param/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/named_param/ydb/query.sql create mode 100644 internal/endtoend/testdata/named_param/ydb/schema.sql create mode 100644 internal/endtoend/testdata/named_param/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/nested_select/ydb/go/db.go create mode 100644 internal/endtoend/testdata/nested_select/ydb/go/models.go create mode 100644 internal/endtoend/testdata/nested_select/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/nested_select/ydb/query.sql create mode 100644 internal/endtoend/testdata/nested_select/ydb/schema.sql create mode 100644 internal/endtoend/testdata/nested_select/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/on_duplicate_key_update/ydb/go/db.go create mode 100644 internal/endtoend/testdata/on_duplicate_key_update/ydb/go/models.go create mode 100644 internal/endtoend/testdata/on_duplicate_key_update/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/on_duplicate_key_update/ydb/query.sql create mode 100644 internal/endtoend/testdata/on_duplicate_key_update/ydb/schema.sql create mode 100644 internal/endtoend/testdata/on_duplicate_key_update/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/order_by_binds/ydb/go/db.go create mode 100644 internal/endtoend/testdata/order_by_binds/ydb/go/models.go create mode 100644 internal/endtoend/testdata/order_by_binds/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/order_by_binds/ydb/query.sql create mode 100644 internal/endtoend/testdata/order_by_binds/ydb/schema.sql create mode 100644 internal/endtoend/testdata/order_by_binds/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/order_by_union/ydb/go/db.go create mode 100644 internal/endtoend/testdata/order_by_union/ydb/go/models.go create mode 100644 internal/endtoend/testdata/order_by_union/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/order_by_union/ydb/query.sql create mode 100644 internal/endtoend/testdata/order_by_union/ydb/schema.sql create mode 100644 internal/endtoend/testdata/order_by_union/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/output_file_names/ydb/go/db_gen.go create mode 100644 internal/endtoend/testdata/output_file_names/ydb/go/models_gen.go create mode 100644 internal/endtoend/testdata/output_file_names/ydb/go/querier_gen.go create mode 100644 internal/endtoend/testdata/output_file_names/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/output_file_names/ydb/query.sql create mode 100644 internal/endtoend/testdata/output_file_names/ydb/schema.sql create mode 100644 internal/endtoend/testdata/output_file_names/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/output_files_suffix/ydb/go/db.go create mode 100644 internal/endtoend/testdata/output_files_suffix/ydb/go/models.go create mode 100644 internal/endtoend/testdata/output_files_suffix/ydb/go/query.sql_gen.go create mode 100644 internal/endtoend/testdata/output_files_suffix/ydb/query.sql create mode 100644 internal/endtoend/testdata/output_files_suffix/ydb/schema.sql create mode 100644 internal/endtoend/testdata/output_files_suffix/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/overrides/ydb/go/db.go create mode 100644 internal/endtoend/testdata/overrides/ydb/go/models.go create mode 100644 internal/endtoend/testdata/overrides/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/overrides/ydb/query.sql create mode 100644 internal/endtoend/testdata/overrides/ydb/schema.sql create mode 100644 internal/endtoend/testdata/overrides/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/overrides_pointers/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/overrides_pointers/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/overrides_pointers/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/params_duplicate/ydb/go/db.go create mode 100644 internal/endtoend/testdata/params_duplicate/ydb/go/models.go create mode 100644 internal/endtoend/testdata/params_duplicate/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/params_duplicate/ydb/query.sql create mode 100644 internal/endtoend/testdata/params_duplicate/ydb/schema.sql create mode 100644 internal/endtoend/testdata/params_duplicate/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/params_go_keywords/ydb/go/db.go create mode 100644 internal/endtoend/testdata/params_go_keywords/ydb/go/models.go create mode 100644 internal/endtoend/testdata/params_go_keywords/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/params_go_keywords/ydb/query.sql create mode 100644 internal/endtoend/testdata/params_go_keywords/ydb/schema.sql create mode 100644 internal/endtoend/testdata/params_go_keywords/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/params_in_nested_func/ydb/db/db.go create mode 100644 internal/endtoend/testdata/params_in_nested_func/ydb/db/models.go create mode 100644 internal/endtoend/testdata/params_in_nested_func/ydb/db/query.sql.go create mode 100644 internal/endtoend/testdata/params_in_nested_func/ydb/query.sql create mode 100644 internal/endtoend/testdata/params_in_nested_func/ydb/schema.sql create mode 100644 internal/endtoend/testdata/params_in_nested_func/ydb/sqlc.yaml create mode 100644 internal/endtoend/testdata/params_location/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/params_location/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/params_location/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/params_location/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/params_location/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/params_location/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/db.go create mode 100644 internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/models.go create mode 100644 internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/query.sql create mode 100644 internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/schema.sql create mode 100644 internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/params_two/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/params_two/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/params_two/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/params_two/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/params_two/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/params_two/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/pattern_matching/ydb/go/db.go create mode 100644 internal/endtoend/testdata/pattern_matching/ydb/go/models.go create mode 100644 internal/endtoend/testdata/pattern_matching/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/pattern_matching/ydb/query.sql create mode 100644 internal/endtoend/testdata/pattern_matching/ydb/schema.sql create mode 100644 internal/endtoend/testdata/pattern_matching/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/db.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/models.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/querier.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_param_only/ydb/query.sql create mode 100644 internal/endtoend/testdata/query_parameter_limit_param_only/ydb/schema.sql create mode 100644 internal/endtoend/testdata/query_parameter_limit_param_only/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/db.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/models.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_two/ydb/query.sql create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_two/ydb/schema.sql create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_two/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/db.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/models.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/querier.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/query.sql create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/schema.sql create mode 100644 internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/returning/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/returning/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/returning/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/returning/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/returning/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/returning/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/returning/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/returning/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/returning/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/select_column_cast/ydb/go/db.go create mode 100644 internal/endtoend/testdata/select_column_cast/ydb/go/models.go create mode 100644 internal/endtoend/testdata/select_column_cast/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_column_cast/ydb/query.sql create mode 100644 internal/endtoend/testdata/select_column_cast/ydb/schema.sql create mode 100644 internal/endtoend/testdata/select_column_cast/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/select_distinct/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/select_distinct/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/select_distinct/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_distinct/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/select_distinct/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/select_distinct/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/select_exists/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/select_exists/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/select_exists/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_exists/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/select_exists/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/select_exists/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/select_in_and/ydb/go/db.go create mode 100644 internal/endtoend/testdata/select_in_and/ydb/go/models.go create mode 100644 internal/endtoend/testdata/select_in_and/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_in_and/ydb/query.sql create mode 100644 internal/endtoend/testdata/select_in_and/ydb/schema.sql create mode 100644 internal/endtoend/testdata/select_in_and/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/select_limit/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/select_limit/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/select_limit/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_limit/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/select_limit/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/select_limit/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/select_nested_count/ydb/go/db.go create mode 100644 internal/endtoend/testdata/select_nested_count/ydb/go/models.go create mode 100644 internal/endtoend/testdata/select_nested_count/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_nested_count/ydb/query.sql create mode 100644 internal/endtoend/testdata/select_nested_count/ydb/schema.sql create mode 100644 internal/endtoend/testdata/select_nested_count/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_not_exists/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/select_not_exists/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/select_not_exists/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/select_star/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/select_star/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/select_star/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_star/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/select_star/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/select_star/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_text_array/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/select_text_array/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/select_text_array/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/select_union/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/select_union/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/select_union/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_union/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/select_union/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/select_union/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/single_param_conflict/ydb/go/db.go create mode 100644 internal/endtoend/testdata/single_param_conflict/ydb/go/models.go create mode 100644 internal/endtoend/testdata/single_param_conflict/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/single_param_conflict/ydb/query.sql create mode 100644 internal/endtoend/testdata/single_param_conflict/ydb/schema.sql create mode 100644 internal/endtoend/testdata/single_param_conflict/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/query.sql create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/star_expansion/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/star_expansion/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/star_expansion/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/star_expansion/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/star_expansion/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/star_expansion/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/types_uuid/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/types_uuid/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/types_uuid/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/types_uuid/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/types_uuid/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/types_uuid/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/update_set/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/update_set/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/update_set/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/update_set/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/update_set/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/update_set/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/sqlc.json create mode 100644 internal/endtoend/testdata/upsert/ydb/go/db.go create mode 100644 internal/endtoend/testdata/upsert/ydb/go/models.go create mode 100644 internal/endtoend/testdata/upsert/ydb/go/query.sql.go create mode 100644 internal/endtoend/testdata/upsert/ydb/query.sql create mode 100644 internal/endtoend/testdata/upsert/ydb/schema.sql create mode 100644 internal/endtoend/testdata/upsert/ydb/sqlc.json create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/db.go create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/models.go create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/query.sql.go create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/query.sql create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/schema.sql create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/sqlc.json create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/db.go create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/models.go create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/query.sql.go create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/query.sql create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/schema.sql create mode 100644 internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/sqlc.json diff --git a/internal/codegen/golang/gen.go b/internal/codegen/golang/gen.go index 4b48f34bde..28beaa5af3 100644 --- a/internal/codegen/golang/gen.go +++ b/internal/codegen/golang/gen.go @@ -42,6 +42,7 @@ type tmplCtx struct { OmitSqlcVersion bool BuildTags string WrapErrors bool + EmitSliceExpansion bool } func (t *tmplCtx) OutputQuery(sourceName string) bool { @@ -55,6 +56,10 @@ func (t *tmplCtx) codegenDbarg() string { return "" } +func (t *tmplCtx) shouldExpandSlices(q Query) bool { + return t.EmitSliceExpansion && q.Arg.HasSqlcSlices() +} + // Called as a global method since subtemplate queryCodeStdExec does not have // access to the toplevel tmplCtx func (t *tmplCtx) codegenEmitPreparedQueries() bool { @@ -181,6 +186,7 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum, EmitMethodsWithDBArgument: options.EmitMethodsWithDbArgument, EmitEnumValidMethod: options.EmitEnumValidMethod, EmitAllEnumValues: options.EmitAllEnumValues, + EmitSliceExpansion: options.Engine != "ydb", UsesCopyFrom: usesCopyFrom(queries), UsesBatch: usesBatch(queries), SQLDriver: parseDriver(options.SqlPackage), @@ -232,6 +238,7 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum, "emitPreparedQueries": tctx.codegenEmitPreparedQueries, "queryMethod": tctx.codegenQueryMethod, "queryRetval": tctx.codegenQueryRetval, + "shouldExpandSlices": tctx.shouldExpandSlices, } tmpl := template.Must( diff --git a/internal/codegen/golang/imports.go b/internal/codegen/golang/imports.go index 17e426b8f9..d1522a31ba 100644 --- a/internal/codegen/golang/imports.go +++ b/internal/codegen/golang/imports.go @@ -149,6 +149,7 @@ func (i *importer) dbImports() fileImports { var stdlibTypes = map[string]string{ "json.RawMessage": "encoding/json", "time.Time": "time", + "time.Duration": "time", "net.IP": "net", "net.HardwareAddr": "net", "netip.Addr": "net/netip", @@ -232,6 +233,10 @@ func buildImports(options *opts.Options, queries []Query, uses func(string) bool if uses("pgvector.Vector") && !overrideVector { pkg[ImportSpec{Path: "github.com/pgvector/pgvector-go"}] = struct{}{} } + _, overrideDecimal := overrideTypes["types.Decimal"] + if uses("types.Decimal") && !overrideDecimal { + pkg[ImportSpec{Path: "github.com/ydb-platform/ydb-go-sdk/v3/table/types"}] = struct{}{} + } // Custom imports for _, override := range options.Overrides { @@ -271,7 +276,7 @@ func (i *importer) interfaceImports() fileImports { }) std["context"] = struct{}{} - + sqlpkg := parseDriver(i.Options.SqlPackage) if sqlpkg.IsYDBGoSDK() { pkg[ImportSpec{Path: "github.com/ydb-platform/ydb-go-sdk/v3/query"}] = struct{}{} @@ -404,7 +409,7 @@ func (i *importer) queryImports(filename string) fileImports { } sqlpkg := parseDriver(i.Options.SqlPackage) - if sqlcSliceScan() && !sqlpkg.IsPGX() && !sqlpkg.IsYDBGoSDK() { + if sqlcSliceScan() && !sqlpkg.IsPGX() && !sqlpkg.IsYDBGoSDK() && i.Options.Engine != "ydb" { std["strings"] = struct{}{} } if sliceScan() && !sqlpkg.IsPGX() && !sqlpkg.IsYDBGoSDK() { diff --git a/internal/codegen/golang/opts/options.go b/internal/codegen/golang/opts/options.go index 0d5d51c2dd..c9f28bb1de 100644 --- a/internal/codegen/golang/opts/options.go +++ b/internal/codegen/golang/opts/options.go @@ -47,6 +47,7 @@ type Options struct { Initialisms *[]string `json:"initialisms,omitempty" yaml:"initialisms"` InitialismsMap map[string]struct{} `json:"-" yaml:"-"` + Engine string `json:"-" yaml:"-"` } type GlobalOptions struct { @@ -72,6 +73,11 @@ func Parse(req *plugin.GenerateRequest) (*Options, error) { } maps.Copy(options.Rename, global.Rename) } + + if req.Settings != nil { + options.Engine = req.Settings.Engine + } + return options, nil } diff --git a/internal/codegen/golang/query.go b/internal/codegen/golang/query.go index 3e789f4c60..c825ac3dce 100644 --- a/internal/codegen/golang/query.go +++ b/internal/codegen/golang/query.go @@ -307,7 +307,7 @@ func ydbBuilderMethodForColumnType(dbType string) string { return "Int32" case "uint16": return "Uint16" - case "int16", "smallserial","serial2": + case "int16", "smallserial", "serial2": return "Int16" case "uint8": return "Uint8" @@ -321,8 +321,10 @@ func ydbBuilderMethodForColumnType(dbType string) string { return "JSON" case "jsondocument": return "JSONDocument" - case "utf8", "text", "string": + case "utf8", "text": return "Text" + case "string": + return "Bytes" case "date": return "Date" case "date32": @@ -338,12 +340,19 @@ func ydbBuilderMethodForColumnType(dbType string) string { case "tztimestamp": return "TzTimestamp" case "uuid": - return "UUID" + return "Uuid" case "yson": return "YSON" + case "integer": // LIMIT/OFFSET parameters support + return "Uint64" + //TODO: support other types default: + // Check for decimal types + if strings.HasPrefix(baseType, "decimal") { + return "Decimal" + } return "" } } @@ -405,6 +414,21 @@ func (v QueryValue) YDBParamsBuilder() string { isPtr := strings.HasPrefix(goType, "*") isArray := field.Column.IsArray || field.Column.IsSqlcSlice + if method == "Decimal" { + if isArray { + lines = append(lines, fmt.Sprintf("\tvar list = parameters.Param(%s).BeginList()", paramName)) + lines = append(lines, fmt.Sprintf("\tfor _, param := range %s {", variable)) + lines = append(lines, "\t\tlist = list.Add().Decimal(param.Bytes, param.Precision, param.Scale)") + lines = append(lines, "\t}") + lines = append(lines, "\tparameters = list.EndList()") + } else if isPtr { + lines = append(lines, fmt.Sprintf("\tparameters = parameters.Param(%s).BeginOptional().Decimal(&%s.Bytes, %s.Precision, %s.Scale).EndOptional()", paramName, variable, variable, variable)) + } else { + lines = append(lines, fmt.Sprintf("\tparameters = parameters.Param(%s).Decimal(%s.Bytes, %s.Precision, %s.Scale)", paramName, variable, variable, variable)) + } + return true + } + if isArray { lines = append(lines, fmt.Sprintf("\tvar list = parameters.Param(%s).BeginList()", paramName)) lines = append(lines, fmt.Sprintf("\tfor _, param := range %s {", variable)) diff --git a/internal/codegen/golang/templates/stdlib/queryCode.tmpl b/internal/codegen/golang/templates/stdlib/queryCode.tmpl index 1e7f4e22a4..17e18fa86d 100644 --- a/internal/codegen/golang/templates/stdlib/queryCode.tmpl +++ b/internal/codegen/golang/templates/stdlib/queryCode.tmpl @@ -125,7 +125,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}} {{end}} {{define "queryCodeStdExec"}} - {{- if .Arg.HasSqlcSlices }} + {{- if shouldExpandSlices . }} query := {{.ConstantName}} var queryParams []interface{} {{- if .Arg.Struct }} diff --git a/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl b/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl index f9c06cc705..9ed0dd1bc3 100644 --- a/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl +++ b/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl @@ -3,17 +3,17 @@ {{- $dbtxParam := .EmitMethodsWithDBArgument -}} {{- range .GoQueries}} {{- if and (eq .Cmd ":one") ($dbtxParam) }} - {{range .Comments}}//{{.}} - {{end -}} + {{- range .Comments}}//{{.}} + {{- end}} {{.MethodName}}(ctx context.Context, db DBTX, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ({{.Ret.DefineType}}, error) {{- else if eq .Cmd ":one"}} - {{range .Comments}}//{{.}} - {{end -}} + {{- range .Comments}}//{{.}} + {{- end}} {{.MethodName}}(ctx context.Context, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ({{.Ret.DefineType}}, error) {{- end}} {{- if and (eq .Cmd ":many") ($dbtxParam) }} - {{range .Comments}}//{{.}} - {{end -}} + {{- range .Comments}}//{{.}} + {{- end}} {{.MethodName}}(ctx context.Context, db DBTX, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) {{- else if eq .Cmd ":many"}} {{range .Comments}}//{{.}} @@ -21,12 +21,12 @@ {{.MethodName}}(ctx context.Context, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) {{- end}} {{- if and (eq .Cmd ":exec") ($dbtxParam) }} - {{range .Comments}}//{{.}} - {{end -}} + {{- range .Comments}}//{{.}} + {{- end}} {{.MethodName}}(ctx context.Context, db DBTX, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) error {{- else if eq .Cmd ":exec"}} - {{range .Comments}}//{{.}} - {{end -}} + {{- range .Comments}}//{{.}} + {{- end}} {{.MethodName}}(ctx context.Context, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) error {{- end}} {{- end}} diff --git a/internal/codegen/golang/ydb_type.go b/internal/codegen/golang/ydb_type.go index ada576795d..572f79f334 100644 --- a/internal/codegen/golang/ydb_type.go +++ b/internal/codegen/golang/ydb_type.go @@ -43,7 +43,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col // // use the smallest type they have which is NullInt16 // return "sql.NullInt16" return "*int8" - case "int16": + case "int16", "smallint": if notNull { return "int16" } @@ -52,7 +52,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } // return "sql.NullInt16" return "*int16" - case "int", "int32": //ydb doesn't have int type, but we need it to support untyped constants + case "int", "int32", "integer": if notNull { return "int32" } @@ -61,7 +61,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } // return "sql.NullInt32" return "*int32" - case "int64": + case "int64", "bigint": if notNull { return "int64" } @@ -72,25 +72,37 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col return "*int64" case "uint8": + if notNull { + return "uint8" + } if emitPointersForNull { return "*uint8" } - return "uint8" + return "*uint8" case "uint16": + if notNull { + return "uint16" + } if emitPointersForNull { return "*uint16" } - return "uint16" + return "*uint16" case "uint32": + if notNull { + return "uint32" + } if emitPointersForNull { return "*uint32" } - return "uint32" + return "*uint32" case "uint64": + if notNull { + return "uint64" + } if emitPointersForNull { return "*uint64" } - return "uint64" + return "*uint64" case "float": if notNull { @@ -114,7 +126,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col return "*float64" // string types - case "string", "utf8", "text": + case "utf8", "text": if notNull { return "string" } @@ -163,7 +175,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } return "*string" - case "date", "date32", "datetime", "timestamp", "tzdate", "tztimestamp", "tzdatetime": + case "date", "date32", "datetime", "timestamp", "tzdate", "tztimestamp", "tzdatetime", "datetime64", "timestamp64", "tzdate32", "tzdatetime64", "tztimestamp64": if notNull { return "time.Time" } @@ -172,6 +184,15 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } return "*time.Time" + case "interval", "interval64": + if notNull { + return "time.Duration" + } + if emitPointersForNull { + return "*time.Duration" + } + return "*time.Duration" + case "uuid": if notNull { return "uuid.UUID" @@ -181,7 +202,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col } return "*uuid.UUID" - case "yson": + case "yson", "string": if notNull { return "[]byte" } @@ -198,6 +219,17 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col return "interface{}" default: + if strings.HasPrefix(columnType, "decimal") { + if notNull { + return "types.Decimal" + } + + if emitPointersForNull { + return "*types.Decimal" + } + return "*types.Decimal" + } + if debug.Active { log.Printf("unknown YDB type: %s\n", columnType) } diff --git a/internal/compiler/resolve.go b/internal/compiler/resolve.go index b1fbb1990e..39685d640e 100644 --- a/internal/compiler/resolve.go +++ b/internal/compiler/resolve.go @@ -5,6 +5,7 @@ import ( "log/slog" "strconv" + "github.com/sqlc-dev/sqlc/internal/config" "github.com/sqlc-dev/sqlc/internal/sql/ast" "github.com/sqlc-dev/sqlc/internal/sql/astutils" "github.com/sqlc-dev/sqlc/internal/sql/catalog" @@ -118,11 +119,17 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar, case *limitOffset: defaultP := named.NewInferredParam("offset", true) p, isNamed := params.FetchMerge(ref.ref.Number, defaultP) + + dataType := "integer" + if comp.conf.Engine == config.EngineYDB { + dataType = "uint64" + } + a = append(a, Parameter{ Number: ref.ref.Number, Column: &Column{ Name: p.Name(), - DataType: "integer", + DataType: dataType, NotNull: p.NotNull(), IsNamedParam: isNamed, }, @@ -131,11 +138,17 @@ func (comp *Compiler) resolveCatalogRefs(qc *QueryCatalog, rvs []*ast.RangeVar, case *limitCount: defaultP := named.NewInferredParam("limit", true) p, isNamed := params.FetchMerge(ref.ref.Number, defaultP) + + dataType := "integer" + if comp.conf.Engine == config.EngineYDB { + dataType = "uint64" + } + a = append(a, Parameter{ Number: ref.ref.Number, Column: &Column{ Name: p.Name(), - DataType: "integer", + DataType: dataType, NotNull: p.NotNull(), IsNamedParam: isNamed, }, diff --git a/internal/endtoend/testdata/alias/ydb/stdlib/go/db.go b/internal/endtoend/testdata/alias/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/alias/ydb/stdlib/go/models.go b/internal/endtoend/testdata/alias/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/alias/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/alias/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..b3cd2a53c8 --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/stdlib/go/query.sql.go @@ -0,0 +1,22 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const aliasBar = `-- name: AliasBar :one +SELECT id FROM bar AS b +WHERE b.id = $i +` + +func (q *Queries) AliasBar(ctx context.Context, i int32) (int32, error) { + row := q.db.QueryRowContext(ctx, aliasBar, i) + var id int32 + err := row.Scan(&id) + return id, err +} diff --git a/internal/endtoend/testdata/alias/ydb/stdlib/query.sql b/internal/endtoend/testdata/alias/ydb/stdlib/query.sql new file mode 100644 index 0000000000..e8d221cefe --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/stdlib/query.sql @@ -0,0 +1,6 @@ +-- name: AliasBar :one +SELECT * FROM bar AS b +WHERE b.id = $i; + + + diff --git a/internal/endtoend/testdata/alias/ydb/stdlib/schema.sql b/internal/endtoend/testdata/alias/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..5548b1b85f --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/stdlib/schema.sql @@ -0,0 +1 @@ +CREATE TABLE bar (id Int32 NOT NULL, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/alias/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/alias/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..a7f0d9dc2c --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,36 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const aliasBar = `-- name: AliasBar :one +SELECT id FROM bar AS b +WHERE b.id = $i +` + +func (q *Queries) AliasBar(ctx context.Context, i int32, opts ...query.ExecuteOption) (int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$i").Int32(i) + row, err := q.db.QueryRow(ctx, aliasBar, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var id int32 + if err != nil { + return id, xerrors.WithStackTrace(err) + } + err = row.Scan(&id) + if err != nil { + return id, xerrors.WithStackTrace(err) + } + return id, nil +} diff --git a/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..e8d221cefe --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,6 @@ +-- name: AliasBar :one +SELECT * FROM bar AS b +WHERE b.id = $i; + + + diff --git a/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..de98d1bdd4 --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE bar (id Int32 NOT NULL, PRIMARY KEY (id)); + + + diff --git a/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..a210888689 --- /dev/null +++ b/internal/endtoend/testdata/alias/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/array_in/ydb/stdlib/go/db.go b/internal/endtoend/testdata/array_in/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/array_in/ydb/stdlib/go/models.go b/internal/endtoend/testdata/array_in/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/array_in/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/array_in/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..d1cd71a037 --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/stdlib/go/query.sql.go @@ -0,0 +1,44 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const in = `-- name: In :many +SELECT id +FROM bar +WHERE id IN ($p1, $p2) +` + +type InParams struct { + P1 int32 + P2 int32 +} + +func (q *Queries) In(ctx context.Context, arg InParams) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, in, arg.P1, arg.P2) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var id int32 + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + 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/array_in/ydb/stdlib/query.sql b/internal/endtoend/testdata/array_in/ydb/stdlib/query.sql new file mode 100644 index 0000000000..7e2709977b --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/stdlib/query.sql @@ -0,0 +1,4 @@ +-- name: In :many +SELECT * +FROM bar +WHERE id IN ($p1, $p2); diff --git a/internal/endtoend/testdata/array_in/ydb/stdlib/schema.sql b/internal/endtoend/testdata/array_in/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..5548b1b85f --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/stdlib/schema.sql @@ -0,0 +1 @@ +CREATE TABLE bar (id Int32 NOT NULL, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/array_in/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/array_in/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..e19eb4c476 --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,52 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const in = `-- name: In :many +SELECT id +FROM bar +WHERE id IN ($p1, $p2) +` + +type InParams struct { + P1 int32 + P2 int32 +} + +func (q *Queries) In(ctx context.Context, arg InParams, opts ...query.ExecuteOption) ([]int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$p1").Int32(arg.P1) + parameters = parameters.Param("$p2").Int32(arg.P2) + result, err := q.db.QueryResultSet(ctx, in, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []int32 + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var id int32 + if err := row.Scan(&id); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, id) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..7e2709977b --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,4 @@ +-- name: In :many +SELECT * +FROM bar +WHERE id IN ($p1, $p2); diff --git a/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..5548b1b85f --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1 @@ +CREATE TABLE bar (id Int32 NOT NULL, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/array_in/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/array_text/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/array_text/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/array_text/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/array_text/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/array_text/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/array_text/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/array_text/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/array_text/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..95e88d9b87 --- /dev/null +++ b/internal/endtoend/testdata/array_text/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,30 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const textArray = `-- name: TextArray :one +SELECT ["1", "2", "3"] +` + +func (q *Queries) TextArray(ctx context.Context, opts ...query.ExecuteOption) (interface{}, error) { + row, err := q.db.QueryRow(ctx, textArray, opts...) + var column_1 interface{} + if err != nil { + return column_1, xerrors.WithStackTrace(err) + } + err = row.Scan(&column_1) + if err != nil { + return column_1, xerrors.WithStackTrace(err) + } + return column_1, nil +} diff --git a/internal/endtoend/testdata/array_text/ydb-go-sdk/query.sql b/internal/endtoend/testdata/array_text/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..4fe300c3f3 --- /dev/null +++ b/internal/endtoend/testdata/array_text/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: TextArray :one +SELECT ["1", "2", "3"]; diff --git a/internal/endtoend/testdata/array_text/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/array_text/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..a81897d939 --- /dev/null +++ b/internal/endtoend/testdata/array_text/ydb-go-sdk/schema.sql @@ -0,0 +1 @@ +CREATE TABLE bar (id Serial, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/array_text/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/array_text/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..155771a4bb --- /dev/null +++ b/internal/endtoend/testdata/array_text/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] + } + \ No newline at end of file diff --git a/internal/endtoend/testdata/between_args/ydb/go/db.go b/internal/endtoend/testdata/between_args/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/between_args/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/between_args/ydb/go/models.go b/internal/endtoend/testdata/between_args/ydb/go/models.go new file mode 100644 index 0000000000..5d811ab385 --- /dev/null +++ b/internal/endtoend/testdata/between_args/ydb/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Product struct { + ID int64 + Name string + Price int32 +} diff --git a/internal/endtoend/testdata/between_args/ydb/go/query.sql.go b/internal/endtoend/testdata/between_args/ydb/go/query.sql.go new file mode 100644 index 0000000000..4cb392f637 --- /dev/null +++ b/internal/endtoend/testdata/between_args/ydb/go/query.sql.go @@ -0,0 +1,146 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getBetweenPrices = `-- name: GetBetweenPrices :many +SELECT id, name, price +FROM products +WHERE price BETWEEN $min_price AND $max_price +` + +type GetBetweenPricesParams struct { + MinPrice int32 + MaxPrice int32 +} + +func (q *Queries) GetBetweenPrices(ctx context.Context, arg GetBetweenPricesParams) ([]Product, error) { + rows, err := q.db.QueryContext(ctx, getBetweenPrices, arg.MinPrice, arg.MaxPrice) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Product + for rows.Next() { + var i Product + if err := rows.Scan(&i.ID, &i.Name, &i.Price); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getBetweenPricesNamed = `-- name: GetBetweenPricesNamed :many +SELECT id, name, price +FROM products +WHERE price BETWEEN $min_price AND $max_price +` + +type GetBetweenPricesNamedParams struct { + MinPrice int32 + MaxPrice int32 +} + +func (q *Queries) GetBetweenPricesNamed(ctx context.Context, arg GetBetweenPricesNamedParams) ([]Product, error) { + rows, err := q.db.QueryContext(ctx, getBetweenPricesNamed, arg.MinPrice, arg.MaxPrice) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Product + for rows.Next() { + var i Product + if err := rows.Scan(&i.ID, &i.Name, &i.Price); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getBetweenPricesTable = `-- name: GetBetweenPricesTable :many +SELECT id, name, price +FROM products +WHERE products.price BETWEEN $min_price AND $max_price +` + +type GetBetweenPricesTableParams struct { + MinPrice int32 + MaxPrice int32 +} + +func (q *Queries) GetBetweenPricesTable(ctx context.Context, arg GetBetweenPricesTableParams) ([]Product, error) { + rows, err := q.db.QueryContext(ctx, getBetweenPricesTable, arg.MinPrice, arg.MaxPrice) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Product + for rows.Next() { + var i Product + if err := rows.Scan(&i.ID, &i.Name, &i.Price); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getBetweenPricesTableAlias = `-- name: GetBetweenPricesTableAlias :many +SELECT id, name, price +FROM products AS p +WHERE p.price BETWEEN $min_price AND $max_price +` + +type GetBetweenPricesTableAliasParams struct { + MinPrice int32 + MaxPrice int32 +} + +func (q *Queries) GetBetweenPricesTableAlias(ctx context.Context, arg GetBetweenPricesTableAliasParams) ([]Product, error) { + rows, err := q.db.QueryContext(ctx, getBetweenPricesTableAlias, arg.MinPrice, arg.MaxPrice) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Product + for rows.Next() { + var i Product + if err := rows.Scan(&i.ID, &i.Name, &i.Price); err != nil { + return nil, err + } + items = append(items, i) + } + 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/between_args/ydb/query.sql b/internal/endtoend/testdata/between_args/ydb/query.sql new file mode 100644 index 0000000000..a70b27aa6a --- /dev/null +++ b/internal/endtoend/testdata/between_args/ydb/query.sql @@ -0,0 +1,19 @@ +-- name: GetBetweenPrices :many +SELECT * +FROM products +WHERE price BETWEEN $min_price AND $max_price; + +-- name: GetBetweenPricesTable :many +SELECT * +FROM products +WHERE products.price BETWEEN $min_price AND $max_price; + +-- name: GetBetweenPricesTableAlias :many +SELECT * +FROM products AS p +WHERE p.price BETWEEN $min_price AND $max_price; + +-- name: GetBetweenPricesNamed :many +SELECT * +FROM products +WHERE price BETWEEN sqlc.arg(min_price) AND sqlc.arg(max_price); diff --git a/internal/endtoend/testdata/between_args/ydb/schema.sql b/internal/endtoend/testdata/between_args/ydb/schema.sql new file mode 100644 index 0000000000..1717277195 --- /dev/null +++ b/internal/endtoend/testdata/between_args/ydb/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE products ( + id BigSerial, + name Text NOT NULL, + price Int32 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/between_args/ydb/sqlc.json b/internal/endtoend/testdata/between_args/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/between_args/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/builtins/ydb/go/db.go b/internal/endtoend/testdata/builtins/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/builtins/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/builtins/ydb/go/models.go b/internal/endtoend/testdata/builtins/ydb/go/models.go new file mode 100644 index 0000000000..65ca163572 --- /dev/null +++ b/internal/endtoend/testdata/builtins/ydb/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Dummy struct { + ID int32 + S *string + N *float64 + B *bool +} diff --git a/internal/endtoend/testdata/builtins/ydb/go/query.sql.go b/internal/endtoend/testdata/builtins/ydb/go/query.sql.go new file mode 100644 index 0000000000..ccae911039 --- /dev/null +++ b/internal/endtoend/testdata/builtins/ydb/go/query.sql.go @@ -0,0 +1,873 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + "time" +) + +const fByteAt = `-- name: FByteAt :one +SELECT ByteAt("abc", 1) +` + +func (q *Queries) FByteAt(ctx context.Context) (uint8, error) { + row := q.db.QueryRowContext(ctx, fByteAt) + var byteat uint8 + err := row.Scan(&byteat) + return byteat, err +} + +const fClearBit = `-- name: FClearBit :one +SELECT ClearBit("a", 0) +` + +func (q *Queries) FClearBit(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, fClearBit) + var clearbit interface{} + err := row.Scan(&clearbit) + return clearbit, err +} + +const fCurrentUtcDate = `-- name: FCurrentUtcDate :one +SELECT CurrentUtcDate() +` + +func (q *Queries) FCurrentUtcDate(ctx context.Context) (time.Time, error) { + row := q.db.QueryRowContext(ctx, fCurrentUtcDate) + var currentutcdate time.Time + err := row.Scan(¤tutcdate) + return currentutcdate, err +} + +const fCurrentUtcDatetime = `-- name: FCurrentUtcDatetime :one +SELECT CurrentUtcDatetime() +` + +func (q *Queries) FCurrentUtcDatetime(ctx context.Context) (time.Time, error) { + row := q.db.QueryRowContext(ctx, fCurrentUtcDatetime) + var currentutcdatetime time.Time + err := row.Scan(¤tutcdatetime) + return currentutcdatetime, err +} + +const fCurrentUtcTimestamp = `-- name: FCurrentUtcTimestamp :one +SELECT CurrentUtcTimestamp() +` + +func (q *Queries) FCurrentUtcTimestamp(ctx context.Context) (time.Time, error) { + row := q.db.QueryRowContext(ctx, fCurrentUtcTimestamp) + var currentutctimestamp time.Time + err := row.Scan(¤tutctimestamp) + return currentutctimestamp, err +} + +const fDateTimeFrommilliseconds = `-- name: FDateTimeFrommilliseconds :one +SELECT DateTime::Frommilliseconds(1640995200000) +` + +func (q *Queries) FDateTimeFrommilliseconds(ctx context.Context) (time.Time, error) { + row := q.db.QueryRowContext(ctx, fDateTimeFrommilliseconds) + var datetime_frommilliseconds time.Time + err := row.Scan(&datetime_frommilliseconds) + return datetime_frommilliseconds, err +} + +const fDateTimeFromseconds = `-- name: FDateTimeFromseconds :one +SELECT DateTime::Fromseconds(1640995200) +` + +func (q *Queries) FDateTimeFromseconds(ctx context.Context) (time.Time, error) { + row := q.db.QueryRowContext(ctx, fDateTimeFromseconds) + var datetime_fromseconds time.Time + err := row.Scan(&datetime_fromseconds) + return datetime_fromseconds, err +} + +const fDateTimeGetdayofmonth = `-- name: FDateTimeGetdayofmonth :one +SELECT DateTime::Getdayofmonth(CurrentUtcDate()) +` + +func (q *Queries) FDateTimeGetdayofmonth(ctx context.Context) (uint8, error) { + row := q.db.QueryRowContext(ctx, fDateTimeGetdayofmonth) + var datetime_getdayofmonth uint8 + err := row.Scan(&datetime_getdayofmonth) + return datetime_getdayofmonth, err +} + +const fDateTimeGethour = `-- name: FDateTimeGethour :one +SELECT DateTime::Gethour(CurrentUtcDatetime()) +` + +func (q *Queries) FDateTimeGethour(ctx context.Context) (uint8, error) { + row := q.db.QueryRowContext(ctx, fDateTimeGethour) + var datetime_gethour uint8 + err := row.Scan(&datetime_gethour) + return datetime_gethour, err +} + +const fDateTimeGetminute = `-- name: FDateTimeGetminute :one +SELECT DateTime::Getminute(CurrentUtcDatetime()) +` + +func (q *Queries) FDateTimeGetminute(ctx context.Context) (uint8, error) { + row := q.db.QueryRowContext(ctx, fDateTimeGetminute) + var datetime_getminute uint8 + err := row.Scan(&datetime_getminute) + return datetime_getminute, err +} + +const fDateTimeGetmonth = `-- name: FDateTimeGetmonth :one +SELECT DateTime::Getmonth(CurrentUtcDate()) +` + +func (q *Queries) FDateTimeGetmonth(ctx context.Context) (uint8, error) { + row := q.db.QueryRowContext(ctx, fDateTimeGetmonth) + var datetime_getmonth uint8 + err := row.Scan(&datetime_getmonth) + return datetime_getmonth, err +} + +const fDateTimeGetsecond = `-- name: FDateTimeGetsecond :one +SELECT DateTime::Getsecond(CurrentUtcDatetime()) +` + +func (q *Queries) FDateTimeGetsecond(ctx context.Context) (uint8, error) { + row := q.db.QueryRowContext(ctx, fDateTimeGetsecond) + var datetime_getsecond uint8 + err := row.Scan(&datetime_getsecond) + return datetime_getsecond, err +} + +const fDateTimeGetyear = `-- name: FDateTimeGetyear :one +SELECT DateTime::Getyear(CurrentUtcDate()) +` + +// DateTime functions with concrete return types +func (q *Queries) FDateTimeGetyear(ctx context.Context) (uint16, error) { + row := q.db.QueryRowContext(ctx, fDateTimeGetyear) + var datetime_getyear uint16 + err := row.Scan(&datetime_getyear) + return datetime_getyear, err +} + +const fDateTimeIntervalfromdays = `-- name: FDateTimeIntervalfromdays :one +SELECT DateTime::Intervalfromdays(7) +` + +func (q *Queries) FDateTimeIntervalfromdays(ctx context.Context) (time.Duration, error) { + row := q.db.QueryRowContext(ctx, fDateTimeIntervalfromdays) + var datetime_intervalfromdays time.Duration + err := row.Scan(&datetime_intervalfromdays) + return datetime_intervalfromdays, err +} + +const fEndsWith = `-- name: FEndsWith :one +SELECT EndsWith("abcdef", "def") +` + +func (q *Queries) FEndsWith(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fEndsWith) + var endswith bool + err := row.Scan(&endswith) + return endswith, err +} + +const fFind2 = `-- name: FFind2 :one +SELECT Find("abcdef", "cd") +` + +func (q *Queries) FFind2(ctx context.Context) (uint32, error) { + row := q.db.QueryRowContext(ctx, fFind2) + var find uint32 + err := row.Scan(&find) + return find, err +} + +const fFind3 = `-- name: FFind3 :one +SELECT Find("abcdef", "c", 3) +` + +func (q *Queries) FFind3(ctx context.Context) (uint32, error) { + row := q.db.QueryRowContext(ctx, fFind3) + var find uint32 + err := row.Scan(&find) + return find, err +} + +const fFlipBit = `-- name: FFlipBit :one +SELECT FlipBit("a", 0) +` + +func (q *Queries) FFlipBit(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, fFlipBit) + var flipbit interface{} + err := row.Scan(&flipbit) + return flipbit, err +} + +const fIf2 = `-- name: FIf2 :one +SELECT IF(true, 1) +` + +func (q *Queries) FIf2(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, fIf2) + var if_ interface{} + err := row.Scan(&if_) + return if_, err +} + +const fIf3 = `-- name: FIf3 :one +SELECT IF(false, 1, 2) +` + +func (q *Queries) FIf3(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, fIf3) + var if_ interface{} + err := row.Scan(&if_) + return if_, err +} + +const fLen = `-- name: FLen :one +SELECT LEN("world") +` + +func (q *Queries) FLen(ctx context.Context) (uint32, error) { + row := q.db.QueryRowContext(ctx, fLen) + var len uint32 + err := row.Scan(&len) + return len, err +} + +const fLength = `-- name: FLength :one +SELECT LENGTH("hello") +` + +// Basic functions with concrete return types +func (q *Queries) FLength(ctx context.Context) (uint32, error) { + row := q.db.QueryRowContext(ctx, fLength) + var length uint32 + err := row.Scan(&length) + return length, err +} + +const fMathAbs = `-- name: FMathAbs :one +SELECT Math::Abs(-5.5) +` + +func (q *Queries) FMathAbs(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathAbs) + var math_abs float64 + err := row.Scan(&math_abs) + return math_abs, err +} + +const fMathAcos = `-- name: FMathAcos :one +SELECT Math::Acos(0.5) +` + +func (q *Queries) FMathAcos(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathAcos) + var math_acos float64 + err := row.Scan(&math_acos) + return math_acos, err +} + +const fMathAsin = `-- name: FMathAsin :one +SELECT Math::Asin(0.5) +` + +func (q *Queries) FMathAsin(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathAsin) + var math_asin float64 + err := row.Scan(&math_asin) + return math_asin, err +} + +const fMathAtan = `-- name: FMathAtan :one +SELECT Math::Atan(1.0) +` + +func (q *Queries) FMathAtan(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathAtan) + var math_atan float64 + err := row.Scan(&math_atan) + return math_atan, err +} + +const fMathAtan2 = `-- name: FMathAtan2 :one +SELECT Math::Atan2(1.0, 1.0) +` + +func (q *Queries) FMathAtan2(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathAtan2) + var math_atan2 float64 + err := row.Scan(&math_atan2) + return math_atan2, err +} + +const fMathCbrt = `-- name: FMathCbrt :one +SELECT Math::Cbrt(27.0) +` + +func (q *Queries) FMathCbrt(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathCbrt) + var math_cbrt float64 + err := row.Scan(&math_cbrt) + return math_cbrt, err +} + +const fMathCeil = `-- name: FMathCeil :one +SELECT Math::Ceil(4.2) +` + +func (q *Queries) FMathCeil(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathCeil) + var math_ceil float64 + err := row.Scan(&math_ceil) + return math_ceil, err +} + +const fMathCos = `-- name: FMathCos :one +SELECT Math::Cos(0.0) +` + +func (q *Queries) FMathCos(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathCos) + var math_cos float64 + err := row.Scan(&math_cos) + return math_cos, err +} + +const fMathE = `-- name: FMathE :one +SELECT Math::E() +` + +func (q *Queries) FMathE(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathE) + var math_e float64 + err := row.Scan(&math_e) + return math_e, err +} + +const fMathExp = `-- name: FMathExp :one +SELECT Math::Exp(1.0) +` + +func (q *Queries) FMathExp(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathExp) + var math_exp float64 + err := row.Scan(&math_exp) + return math_exp, err +} + +const fMathFloor = `-- name: FMathFloor :one +SELECT Math::Floor(4.8) +` + +func (q *Queries) FMathFloor(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathFloor) + var math_floor float64 + err := row.Scan(&math_floor) + return math_floor, err +} + +const fMathFmod = `-- name: FMathFmod :one +SELECT Math::Fmod(10.5, 3.0) +` + +func (q *Queries) FMathFmod(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathFmod) + var math_fmod float64 + err := row.Scan(&math_fmod) + return math_fmod, err +} + +const fMathFuzzyequals = `-- name: FMathFuzzyequals :one +SELECT Math::Fuzzyequals(1.0, 1.0001) +` + +func (q *Queries) FMathFuzzyequals(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fMathFuzzyequals) + var math_fuzzyequals bool + err := row.Scan(&math_fuzzyequals) + return math_fuzzyequals, err +} + +const fMathHypot = `-- name: FMathHypot :one +SELECT Math::Hypot(3.0, 4.0) +` + +func (q *Queries) FMathHypot(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathHypot) + var math_hypot float64 + err := row.Scan(&math_hypot) + return math_hypot, err +} + +const fMathIsfinite = `-- name: FMathIsfinite :one +SELECT Math::Isfinite(5.0) +` + +func (q *Queries) FMathIsfinite(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fMathIsfinite) + var math_isfinite bool + err := row.Scan(&math_isfinite) + return math_isfinite, err +} + +const fMathIsinf = `-- name: FMathIsinf :one +SELECT Math::Isinf(1.0/0.0) +` + +func (q *Queries) FMathIsinf(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fMathIsinf) + var math_isinf bool + err := row.Scan(&math_isinf) + return math_isinf, err +} + +const fMathIsnan = `-- name: FMathIsnan :one +SELECT Math::Isnan(0.0/0.0) +` + +func (q *Queries) FMathIsnan(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fMathIsnan) + var math_isnan bool + err := row.Scan(&math_isnan) + return math_isnan, err +} + +const fMathLog = `-- name: FMathLog :one +SELECT Math::Log(2.718281828) +` + +func (q *Queries) FMathLog(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathLog) + var math_log float64 + err := row.Scan(&math_log) + return math_log, err +} + +const fMathLog10 = `-- name: FMathLog10 :one +SELECT Math::Log10(100.0) +` + +func (q *Queries) FMathLog10(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathLog10) + var math_log10 float64 + err := row.Scan(&math_log10) + return math_log10, err +} + +const fMathLog2 = `-- name: FMathLog2 :one +SELECT Math::Log2(8.0) +` + +func (q *Queries) FMathLog2(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathLog2) + var math_log2 float64 + err := row.Scan(&math_log2) + return math_log2, err +} + +const fMathMod = `-- name: FMathMod :one +SELECT Math::Mod(10, 3) +` + +func (q *Queries) FMathMod(ctx context.Context) (*int64, error) { + row := q.db.QueryRowContext(ctx, fMathMod) + var math_mod *int64 + err := row.Scan(&math_mod) + return math_mod, err +} + +const fMathPi = `-- name: FMathPi :one +SELECT Math::Pi() +` + +// Math functions with concrete return types +func (q *Queries) FMathPi(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathPi) + var math_pi float64 + err := row.Scan(&math_pi) + return math_pi, err +} + +const fMathPow = `-- name: FMathPow :one +SELECT Math::Pow(2.0, 3.0) +` + +func (q *Queries) FMathPow(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathPow) + var math_pow float64 + err := row.Scan(&math_pow) + return math_pow, err +} + +const fMathRem = `-- name: FMathRem :one +SELECT Math::Rem(10, 3) +` + +func (q *Queries) FMathRem(ctx context.Context) (*int64, error) { + row := q.db.QueryRowContext(ctx, fMathRem) + var math_rem *int64 + err := row.Scan(&math_rem) + return math_rem, err +} + +const fMathRound = `-- name: FMathRound :one +SELECT Math::Round(4.6) +` + +func (q *Queries) FMathRound(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathRound) + var math_round float64 + err := row.Scan(&math_round) + return math_round, err +} + +const fMathRound2 = `-- name: FMathRound2 :one +SELECT Math::Round(4.567, 2) +` + +func (q *Queries) FMathRound2(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathRound2) + var math_round float64 + err := row.Scan(&math_round) + return math_round, err +} + +const fMathSin = `-- name: FMathSin :one +SELECT Math::Sin(0.0) +` + +func (q *Queries) FMathSin(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathSin) + var math_sin float64 + err := row.Scan(&math_sin) + return math_sin, err +} + +const fMathSqrt = `-- name: FMathSqrt :one +SELECT Math::Sqrt(16.0) +` + +func (q *Queries) FMathSqrt(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathSqrt) + var math_sqrt float64 + err := row.Scan(&math_sqrt) + return math_sqrt, err +} + +const fMathTan = `-- name: FMathTan :one +SELECT Math::Tan(0.0) +` + +func (q *Queries) FMathTan(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathTan) + var math_tan float64 + err := row.Scan(&math_tan) + return math_tan, err +} + +const fMathTrunc = `-- name: FMathTrunc :one +SELECT Math::Trunc(4.9) +` + +func (q *Queries) FMathTrunc(ctx context.Context) (float64, error) { + row := q.db.QueryRowContext(ctx, fMathTrunc) + var math_trunc float64 + err := row.Scan(&math_trunc) + return math_trunc, err +} + +const fRFind2 = `-- name: FRFind2 :one +SELECT RFind("ababa", "ba") +` + +func (q *Queries) FRFind2(ctx context.Context) (uint32, error) { + row := q.db.QueryRowContext(ctx, fRFind2) + var rfind uint32 + err := row.Scan(&rfind) + return rfind, err +} + +const fSetBit = `-- name: FSetBit :one +SELECT SetBit("a", 0) +` + +func (q *Queries) FSetBit(ctx context.Context) (interface{}, error) { + row := q.db.QueryRowContext(ctx, fSetBit) + var setbit interface{} + err := row.Scan(&setbit) + return setbit, err +} + +const fStartsWith = `-- name: FStartsWith :one +SELECT StartsWith("abcdef", "abc") +` + +func (q *Queries) FStartsWith(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fStartsWith) + var startswith bool + err := row.Scan(&startswith) + return startswith, err +} + +const fSubstring2 = `-- name: FSubstring2 :one +SELECT Substring("abcdef", 2) +` + +func (q *Queries) FSubstring2(ctx context.Context) ([]byte, error) { + row := q.db.QueryRowContext(ctx, fSubstring2) + var substring []byte + err := row.Scan(&substring) + return substring, err +} + +const fSubstring3 = `-- name: FSubstring3 :one +SELECT Substring("abcdef", 2, 3) +` + +func (q *Queries) FSubstring3(ctx context.Context) ([]byte, error) { + row := q.db.QueryRowContext(ctx, fSubstring3) + var substring []byte + err := row.Scan(&substring) + return substring, err +} + +const fTestBit = `-- name: FTestBit :one +SELECT TestBit("a", 0) +` + +func (q *Queries) FTestBit(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fTestBit) + var testbit bool + err := row.Scan(&testbit) + return testbit, err +} + +const fToBytes = `-- name: FToBytes :one +SELECT ToBytes("abc") +` + +func (q *Queries) FToBytes(ctx context.Context) ([]byte, error) { + row := q.db.QueryRowContext(ctx, fToBytes) + var tobytes []byte + err := row.Scan(&tobytes) + return tobytes, err +} + +const fUnicodeFind = `-- name: FUnicodeFind :one +SELECT Unicode::Find("hello", "ll") +` + +func (q *Queries) FUnicodeFind(ctx context.Context) (*uint64, error) { + row := q.db.QueryRowContext(ctx, fUnicodeFind) + var unicode_find *uint64 + err := row.Scan(&unicode_find) + return unicode_find, err +} + +const fUnicodeGetlength = `-- name: FUnicodeGetlength :one +SELECT Unicode::Getlength("привет") +` + +func (q *Queries) FUnicodeGetlength(ctx context.Context) (uint64, error) { + row := q.db.QueryRowContext(ctx, fUnicodeGetlength) + var unicode_getlength uint64 + err := row.Scan(&unicode_getlength) + return unicode_getlength, err +} + +const fUnicodeIsalnum = `-- name: FUnicodeIsalnum :one +SELECT Unicode::Isalnum("hello123") +` + +func (q *Queries) FUnicodeIsalnum(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fUnicodeIsalnum) + var unicode_isalnum bool + err := row.Scan(&unicode_isalnum) + return unicode_isalnum, err +} + +const fUnicodeIsalpha = `-- name: FUnicodeIsalpha :one +SELECT Unicode::Isalpha("hello") +` + +func (q *Queries) FUnicodeIsalpha(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fUnicodeIsalpha) + var unicode_isalpha bool + err := row.Scan(&unicode_isalpha) + return unicode_isalpha, err +} + +const fUnicodeIsascii = `-- name: FUnicodeIsascii :one +SELECT Unicode::Isascii("hello") +` + +func (q *Queries) FUnicodeIsascii(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fUnicodeIsascii) + var unicode_isascii bool + err := row.Scan(&unicode_isascii) + return unicode_isascii, err +} + +const fUnicodeIshex = `-- name: FUnicodeIshex :one +SELECT Unicode::Ishex("FF") +` + +func (q *Queries) FUnicodeIshex(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fUnicodeIshex) + var unicode_ishex bool + err := row.Scan(&unicode_ishex) + return unicode_ishex, err +} + +const fUnicodeIslower = `-- name: FUnicodeIslower :one +SELECT Unicode::Islower("hello") +` + +func (q *Queries) FUnicodeIslower(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fUnicodeIslower) + var unicode_islower bool + err := row.Scan(&unicode_islower) + return unicode_islower, err +} + +const fUnicodeIsspace = `-- name: FUnicodeIsspace :one +SELECT Unicode::Isspace(" ") +` + +func (q *Queries) FUnicodeIsspace(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fUnicodeIsspace) + var unicode_isspace bool + err := row.Scan(&unicode_isspace) + return unicode_isspace, err +} + +const fUnicodeIsupper = `-- name: FUnicodeIsupper :one +SELECT Unicode::Isupper("HELLO") +` + +func (q *Queries) FUnicodeIsupper(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fUnicodeIsupper) + var unicode_isupper bool + err := row.Scan(&unicode_isupper) + return unicode_isupper, err +} + +const fUnicodeIsutf = `-- name: FUnicodeIsutf :one +SELECT Unicode::Isutf("hello") +` + +// Unicode functions with concrete return types +func (q *Queries) FUnicodeIsutf(ctx context.Context) (bool, error) { + row := q.db.QueryRowContext(ctx, fUnicodeIsutf) + var unicode_isutf bool + err := row.Scan(&unicode_isutf) + return unicode_isutf, err +} + +const fUnicodeLevensteindistance = `-- name: FUnicodeLevensteindistance :one +SELECT Unicode::Levensteindistance("hello", "hallo") +` + +func (q *Queries) FUnicodeLevensteindistance(ctx context.Context) (uint64, error) { + row := q.db.QueryRowContext(ctx, fUnicodeLevensteindistance) + var unicode_levensteindistance uint64 + err := row.Scan(&unicode_levensteindistance) + return unicode_levensteindistance, err +} + +const fUnicodeNormalize = `-- name: FUnicodeNormalize :one +SELECT Unicode::Normalize("café") +` + +func (q *Queries) FUnicodeNormalize(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, fUnicodeNormalize) + var unicode_normalize string + err := row.Scan(&unicode_normalize) + return unicode_normalize, err +} + +const fUnicodeReverse = `-- name: FUnicodeReverse :one +SELECT Unicode::Reverse("hello") +` + +func (q *Queries) FUnicodeReverse(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, fUnicodeReverse) + var unicode_reverse string + err := row.Scan(&unicode_reverse) + return unicode_reverse, err +} + +const fUnicodeRfind = `-- name: FUnicodeRfind :one +SELECT Unicode::Rfind("hello", "l") +` + +func (q *Queries) FUnicodeRfind(ctx context.Context) (*uint64, error) { + row := q.db.QueryRowContext(ctx, fUnicodeRfind) + var unicode_rfind *uint64 + err := row.Scan(&unicode_rfind) + return unicode_rfind, err +} + +const fUnicodeSubstring = `-- name: FUnicodeSubstring :one +SELECT Unicode::Substring("hello", 1, 3) +` + +func (q *Queries) FUnicodeSubstring(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, fUnicodeSubstring) + var unicode_substring string + err := row.Scan(&unicode_substring) + return unicode_substring, err +} + +const fUnicodeTolower = `-- name: FUnicodeTolower :one +SELECT Unicode::Tolower("HELLO") +` + +func (q *Queries) FUnicodeTolower(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, fUnicodeTolower) + var unicode_tolower string + err := row.Scan(&unicode_tolower) + return unicode_tolower, err +} + +const fUnicodeTouint64 = `-- name: FUnicodeTouint64 :one +SELECT Unicode::Touint64("123") +` + +func (q *Queries) FUnicodeTouint64(ctx context.Context) (uint64, error) { + row := q.db.QueryRowContext(ctx, fUnicodeTouint64) + var unicode_touint64 uint64 + err := row.Scan(&unicode_touint64) + return unicode_touint64, err +} + +const fUnicodeToupper = `-- name: FUnicodeToupper :one +SELECT Unicode::Toupper("hello") +` + +func (q *Queries) FUnicodeToupper(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, fUnicodeToupper) + var unicode_toupper string + err := row.Scan(&unicode_toupper) + return unicode_toupper, err +} + +const fVersion = `-- name: FVersion :one +SELECT Version() +` + +func (q *Queries) FVersion(ctx context.Context) ([]byte, error) { + row := q.db.QueryRowContext(ctx, fVersion) + var version []byte + err := row.Scan(&version) + return version, err +} diff --git a/internal/endtoend/testdata/builtins/ydb/query.sql b/internal/endtoend/testdata/builtins/ydb/query.sql new file mode 100644 index 0000000000..afcdf1dbb1 --- /dev/null +++ b/internal/endtoend/testdata/builtins/ydb/query.sql @@ -0,0 +1,163 @@ +-- Basic functions with concrete return types +-- name: FLength :one +SELECT LENGTH("hello"); +-- name: FLen :one +SELECT LEN("world"); +-- name: FSubstring2 :one +SELECT Substring("abcdef", 2); +-- name: FSubstring3 :one +SELECT Substring("abcdef", 2, 3); +-- name: FFind2 :one +SELECT Find("abcdef", "cd"); +-- name: FFind3 :one +SELECT Find("abcdef", "c", 3); +-- name: FRFind2 :one +SELECT RFind("ababa", "ba"); +-- name: FStartsWith :one +SELECT StartsWith("abcdef", "abc"); +-- name: FEndsWith :one +SELECT EndsWith("abcdef", "def"); +-- name: FIf2 :one +SELECT IF(true, 1); +-- name: FIf3 :one +SELECT IF(false, 1, 2); +-- name: FCurrentUtcDate :one +SELECT CurrentUtcDate(); +-- name: FCurrentUtcDatetime :one +SELECT CurrentUtcDatetime(); +-- name: FCurrentUtcTimestamp :one +SELECT CurrentUtcTimestamp(); +-- name: FVersion :one +SELECT Version(); +-- name: FToBytes :one +SELECT ToBytes("abc"); +-- name: FByteAt :one +SELECT ByteAt("abc", 1); +-- name: FTestBit :one +SELECT TestBit("a", 0); +-- name: FClearBit :one +SELECT ClearBit("a", 0); +-- name: FSetBit :one +SELECT SetBit("a", 0); +-- name: FFlipBit :one +SELECT FlipBit("a", 0); + +-- Math functions with concrete return types +-- name: FMathPi :one +SELECT Math::Pi(); +-- name: FMathE :one +SELECT Math::E(); +-- name: FMathAbs :one +SELECT Math::Abs(-5.5); +-- name: FMathAcos :one +SELECT Math::Acos(0.5); +-- name: FMathAsin :one +SELECT Math::Asin(0.5); +-- name: FMathAtan :one +SELECT Math::Atan(1.0); +-- name: FMathCbrt :one +SELECT Math::Cbrt(27.0); +-- name: FMathCeil :one +SELECT Math::Ceil(4.2); +-- name: FMathCos :one +SELECT Math::Cos(0.0); +-- name: FMathExp :one +SELECT Math::Exp(1.0); +-- name: FMathFloor :one +SELECT Math::Floor(4.8); +-- name: FMathLog :one +SELECT Math::Log(2.718281828); +-- name: FMathLog2 :one +SELECT Math::Log2(8.0); +-- name: FMathLog10 :one +SELECT Math::Log10(100.0); +-- name: FMathRound :one +SELECT Math::Round(4.6); +-- name: FMathRound2 :one +SELECT Math::Round(4.567, 2); +-- name: FMathSin :one +SELECT Math::Sin(0.0); +-- name: FMathSqrt :one +SELECT Math::Sqrt(16.0); +-- name: FMathTan :one +SELECT Math::Tan(0.0); +-- name: FMathTrunc :one +SELECT Math::Trunc(4.9); +-- name: FMathAtan2 :one +SELECT Math::Atan2(1.0, 1.0); +-- name: FMathPow :one +SELECT Math::Pow(2.0, 3.0); +-- name: FMathHypot :one +SELECT Math::Hypot(3.0, 4.0); +-- name: FMathFmod :one +SELECT Math::Fmod(10.5, 3.0); +-- name: FMathIsinf :one +SELECT Math::Isinf(1.0/0.0); +-- name: FMathIsnan :one +SELECT Math::Isnan(0.0/0.0); +-- name: FMathIsfinite :one +SELECT Math::Isfinite(5.0); +-- name: FMathFuzzyequals :one +SELECT Math::Fuzzyequals(1.0, 1.0001); +-- name: FMathMod :one +SELECT Math::Mod(10, 3); +-- name: FMathRem :one +SELECT Math::Rem(10, 3); + +-- DateTime functions with concrete return types +-- name: FDateTimeGetyear :one +SELECT DateTime::Getyear(CurrentUtcDate()); +-- name: FDateTimeGetmonth :one +SELECT DateTime::Getmonth(CurrentUtcDate()); +-- name: FDateTimeGetdayofmonth :one +SELECT DateTime::Getdayofmonth(CurrentUtcDate()); +-- name: FDateTimeGethour :one +SELECT DateTime::Gethour(CurrentUtcDatetime()); +-- name: FDateTimeGetminute :one +SELECT DateTime::Getminute(CurrentUtcDatetime()); +-- name: FDateTimeGetsecond :one +SELECT DateTime::Getsecond(CurrentUtcDatetime()); +-- name: FDateTimeFromseconds :one +SELECT DateTime::Fromseconds(1640995200); +-- name: FDateTimeFrommilliseconds :one +SELECT DateTime::Frommilliseconds(1640995200000); +-- name: FDateTimeIntervalfromdays :one +SELECT DateTime::Intervalfromdays(7); + +-- Unicode functions with concrete return types +-- name: FUnicodeIsutf :one +SELECT Unicode::Isutf("hello"); +-- name: FUnicodeGetlength :one +SELECT Unicode::Getlength("привет"); +-- name: FUnicodeFind :one +SELECT Unicode::Find("hello", "ll"); +-- name: FUnicodeRfind :one +SELECT Unicode::Rfind("hello", "l"); +-- name: FUnicodeSubstring :one +SELECT Unicode::Substring("hello", 1, 3); +-- name: FUnicodeNormalize :one +SELECT Unicode::Normalize("café"); +-- name: FUnicodeTolower :one +SELECT Unicode::Tolower("HELLO"); +-- name: FUnicodeToupper :one +SELECT Unicode::Toupper("hello"); +-- name: FUnicodeReverse :one +SELECT Unicode::Reverse("hello"); +-- name: FUnicodeIsascii :one +SELECT Unicode::Isascii("hello"); +-- name: FUnicodeIsspace :one +SELECT Unicode::Isspace(" "); +-- name: FUnicodeIsupper :one +SELECT Unicode::Isupper("HELLO"); +-- name: FUnicodeIslower :one +SELECT Unicode::Islower("hello"); +-- name: FUnicodeIsalpha :one +SELECT Unicode::Isalpha("hello"); +-- name: FUnicodeIsalnum :one +SELECT Unicode::Isalnum("hello123"); +-- name: FUnicodeIshex :one +SELECT Unicode::Ishex("FF"); +-- name: FUnicodeTouint64 :one +SELECT Unicode::Touint64("123"); +-- name: FUnicodeLevensteindistance :one +SELECT Unicode::Levensteindistance("hello", "hallo"); diff --git a/internal/endtoend/testdata/builtins/ydb/schema.sql b/internal/endtoend/testdata/builtins/ydb/schema.sql new file mode 100644 index 0000000000..6babf0f48d --- /dev/null +++ b/internal/endtoend/testdata/builtins/ydb/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE dummy ( + id Int32, + s Text, + n Double, + b Bool, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/builtins/ydb/sqlc.json b/internal/endtoend/testdata/builtins/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/builtins/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/case_named_params/ydb/go/db.go b/internal/endtoend/testdata/case_named_params/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/case_named_params/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/case_named_params/ydb/go/models.go b/internal/endtoend/testdata/case_named_params/ydb/go/models.go new file mode 100644 index 0000000000..2a1484e2af --- /dev/null +++ b/internal/endtoend/testdata/case_named_params/ydb/go/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int64 + Username *string + Email *string + Name string + Bio *string +} diff --git a/internal/endtoend/testdata/case_named_params/ydb/go/query.sql.go b/internal/endtoend/testdata/case_named_params/ydb/go/query.sql.go new file mode 100644 index 0000000000..7ad6dd237f --- /dev/null +++ b/internal/endtoend/testdata/case_named_params/ydb/go/query.sql.go @@ -0,0 +1,36 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const listAuthors = `-- name: ListAuthors :one +SELECT id, username, email, name, bio +FROM authors +WHERE email = CASE WHEN Cast($email as Text?) = '' THEN NULL ELSE $email END + OR username = CASE WHEN Cast($username as Text?) = '' THEN NULL ELSE $username END +LIMIT 1 +` + +type ListAuthorsParams struct { + Email *string + Username *string +} + +func (q *Queries) ListAuthors(ctx context.Context, arg ListAuthorsParams) (Author, error) { + row := q.db.QueryRowContext(ctx, listAuthors, arg.Email, arg.Username) + var i Author + err := row.Scan( + &i.ID, + &i.Username, + &i.Email, + &i.Name, + &i.Bio, + ) + return i, err +} diff --git a/internal/endtoend/testdata/case_named_params/ydb/query.sql b/internal/endtoend/testdata/case_named_params/ydb/query.sql new file mode 100644 index 0000000000..ad0b8ebe18 --- /dev/null +++ b/internal/endtoend/testdata/case_named_params/ydb/query.sql @@ -0,0 +1,6 @@ +-- name: ListAuthors :one +SELECT * +FROM authors +WHERE email = CASE WHEN Cast($email as Text?) = '' THEN NULL ELSE $email END + OR username = CASE WHEN Cast($username as Text?) = '' THEN NULL ELSE $username END +LIMIT 1; diff --git a/internal/endtoend/testdata/case_named_params/ydb/schema.sql b/internal/endtoend/testdata/case_named_params/ydb/schema.sql new file mode 100644 index 0000000000..dd78dc389b --- /dev/null +++ b/internal/endtoend/testdata/case_named_params/ydb/schema.sql @@ -0,0 +1,10 @@ +-- https://github.com/sqlc-dev/sqlc/issues/1195 + +CREATE TABLE authors ( + id BigSerial, + username Text, + email Text, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/case_named_params/ydb/sqlc.json b/internal/endtoend/testdata/case_named_params/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/case_named_params/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/case_sensitive/ydb/go/db.go b/internal/endtoend/testdata/case_sensitive/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/case_sensitive/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/case_sensitive/ydb/go/models.go b/internal/endtoend/testdata/case_sensitive/ydb/go/models.go new file mode 100644 index 0000000000..e09185b11a --- /dev/null +++ b/internal/endtoend/testdata/case_sensitive/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Contact struct { + Pid string + Customername *string +} diff --git a/internal/endtoend/testdata/case_sensitive/ydb/go/query.sql.go b/internal/endtoend/testdata/case_sensitive/ydb/go/query.sql.go new file mode 100644 index 0000000000..53169ff143 --- /dev/null +++ b/internal/endtoend/testdata/case_sensitive/ydb/go/query.sql.go @@ -0,0 +1,28 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const insertContact = `-- name: InsertContact :exec +INSERT INTO contacts ( + pid, + CustomerName +) +VALUES ($pid, $customer_name) +` + +type InsertContactParams struct { + Pid string + CustomerName *string +} + +func (q *Queries) InsertContact(ctx context.Context, arg InsertContactParams) error { + _, err := q.db.ExecContext(ctx, insertContact, arg.Pid, arg.CustomerName) + return err +} diff --git a/internal/endtoend/testdata/case_sensitive/ydb/query.sql b/internal/endtoend/testdata/case_sensitive/ydb/query.sql new file mode 100644 index 0000000000..b0723c7f4f --- /dev/null +++ b/internal/endtoend/testdata/case_sensitive/ydb/query.sql @@ -0,0 +1,10 @@ +-- name: InsertContact :exec +INSERT INTO contacts ( + pid, + CustomerName +) +VALUES ($pid, $customer_name); + + + + diff --git a/internal/endtoend/testdata/case_sensitive/ydb/schema.sql b/internal/endtoend/testdata/case_sensitive/ydb/schema.sql new file mode 100644 index 0000000000..7e97e62564 --- /dev/null +++ b/internal/endtoend/testdata/case_sensitive/ydb/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE contacts ( + pid Text, + CustomerName Text, + PRIMARY KEY (pid) +); + + + + diff --git a/internal/endtoend/testdata/case_sensitive/ydb/sqlc.json b/internal/endtoend/testdata/case_sensitive/ydb/sqlc.json new file mode 100644 index 0000000000..e85f2a696f --- /dev/null +++ b/internal/endtoend/testdata/case_sensitive/ydb/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + + diff --git a/internal/endtoend/testdata/case_stmt_bool/ydb/go/db.go b/internal/endtoend/testdata/case_stmt_bool/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/case_stmt_bool/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/case_stmt_bool/ydb/go/models.go b/internal/endtoend/testdata/case_stmt_bool/ydb/go/models.go new file mode 100644 index 0000000000..ef6e41447e --- /dev/null +++ b/internal/endtoend/testdata/case_stmt_bool/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + ID string +} diff --git a/internal/endtoend/testdata/case_stmt_bool/ydb/go/query.sql.go b/internal/endtoend/testdata/case_stmt_bool/ydb/go/query.sql.go new file mode 100644 index 0000000000..943041661b --- /dev/null +++ b/internal/endtoend/testdata/case_stmt_bool/ydb/go/query.sql.go @@ -0,0 +1,41 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const caseStatementBoolean = `-- name: CaseStatementBoolean :many +SELECT CASE + WHEN id = $id THEN true + ELSE false +END AS is_one +FROM foo +` + +func (q *Queries) CaseStatementBoolean(ctx context.Context, id string) ([]bool, error) { + rows, err := q.db.QueryContext(ctx, caseStatementBoolean, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []bool + for rows.Next() { + var is_one bool + if err := rows.Scan(&is_one); err != nil { + return nil, err + } + items = append(items, is_one) + } + 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/case_stmt_bool/ydb/query.sql b/internal/endtoend/testdata/case_stmt_bool/ydb/query.sql new file mode 100644 index 0000000000..cb686c2288 --- /dev/null +++ b/internal/endtoend/testdata/case_stmt_bool/ydb/query.sql @@ -0,0 +1,10 @@ +-- name: CaseStatementBoolean :many +SELECT CASE + WHEN id = $id THEN true + ELSE false +END AS is_one +FROM foo; + + + + diff --git a/internal/endtoend/testdata/case_stmt_bool/ydb/schema.sql b/internal/endtoend/testdata/case_stmt_bool/ydb/schema.sql new file mode 100644 index 0000000000..1312538949 --- /dev/null +++ b/internal/endtoend/testdata/case_stmt_bool/ydb/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo (id Text NOT NULL, PRIMARY KEY (id)); + + + + diff --git a/internal/endtoend/testdata/case_stmt_bool/ydb/sqlc.json b/internal/endtoend/testdata/case_stmt_bool/ydb/sqlc.json new file mode 100644 index 0000000000..e85f2a696f --- /dev/null +++ b/internal/endtoend/testdata/case_stmt_bool/ydb/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + + diff --git a/internal/endtoend/testdata/case_text/ydb/go/db.go b/internal/endtoend/testdata/case_text/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/case_text/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/case_text/ydb/go/models.go b/internal/endtoend/testdata/case_text/ydb/go/models.go new file mode 100644 index 0000000000..ef6e41447e --- /dev/null +++ b/internal/endtoend/testdata/case_text/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + ID string +} diff --git a/internal/endtoend/testdata/case_text/ydb/go/query.sql.go b/internal/endtoend/testdata/case_text/ydb/go/query.sql.go new file mode 100644 index 0000000000..c6df7fd2ed --- /dev/null +++ b/internal/endtoend/testdata/case_text/ydb/go/query.sql.go @@ -0,0 +1,41 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const caseStatementText = `-- name: CaseStatementText :many +SELECT CASE + WHEN id = $id THEN 'foo' + ELSE 'bar' +END AS is_one +FROM foo +` + +func (q *Queries) CaseStatementText(ctx context.Context, id string) ([]string, error) { + rows, err := q.db.QueryContext(ctx, caseStatementText, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var is_one string + if err := rows.Scan(&is_one); err != nil { + return nil, err + } + items = append(items, is_one) + } + 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/case_text/ydb/query.sql b/internal/endtoend/testdata/case_text/ydb/query.sql new file mode 100644 index 0000000000..c4d69e44dd --- /dev/null +++ b/internal/endtoend/testdata/case_text/ydb/query.sql @@ -0,0 +1,10 @@ +-- name: CaseStatementText :many +SELECT CASE + WHEN id = $id THEN 'foo' + ELSE 'bar' +END AS is_one +FROM foo; + + + + diff --git a/internal/endtoend/testdata/case_text/ydb/schema.sql b/internal/endtoend/testdata/case_text/ydb/schema.sql new file mode 100644 index 0000000000..1312538949 --- /dev/null +++ b/internal/endtoend/testdata/case_text/ydb/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo (id Text NOT NULL, PRIMARY KEY (id)); + + + + diff --git a/internal/endtoend/testdata/case_text/ydb/sqlc.json b/internal/endtoend/testdata/case_text/ydb/sqlc.json new file mode 100644 index 0000000000..e85f2a696f --- /dev/null +++ b/internal/endtoend/testdata/case_text/ydb/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + + diff --git a/internal/endtoend/testdata/case_value_param/ydb/go/db.go b/internal/endtoend/testdata/case_value_param/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/case_value_param/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/case_value_param/ydb/go/models.go b/internal/endtoend/testdata/case_value_param/ydb/go/models.go new file mode 100644 index 0000000000..1dd31b55ae --- /dev/null +++ b/internal/endtoend/testdata/case_value_param/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Testing struct { + ID int32 + Value *string +} diff --git a/internal/endtoend/testdata/case_value_param/ydb/go/query.sql.go b/internal/endtoend/testdata/case_value_param/ydb/go/query.sql.go new file mode 100644 index 0000000000..7227417638 --- /dev/null +++ b/internal/endtoend/testdata/case_value_param/ydb/go/query.sql.go @@ -0,0 +1,20 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const update = `-- name: Update :exec +UPDATE testing +SET value = CASE CAST($condition AS Bool) WHEN true THEN Utf8('Hello') WHEN false THEN Utf8('Goodbye') ELSE value END +` + +func (q *Queries) Update(ctx context.Context, condition bool) error { + _, err := q.db.ExecContext(ctx, update, condition) + return err +} diff --git a/internal/endtoend/testdata/case_value_param/ydb/query.sql b/internal/endtoend/testdata/case_value_param/ydb/query.sql new file mode 100644 index 0000000000..5abb61063e --- /dev/null +++ b/internal/endtoend/testdata/case_value_param/ydb/query.sql @@ -0,0 +1,6 @@ +-- name: Update :exec +UPDATE testing +SET value = CASE CAST($condition AS Bool) WHEN true THEN Utf8('Hello') WHEN false THEN Utf8('Goodbye') ELSE value END; + + + diff --git a/internal/endtoend/testdata/case_value_param/ydb/schema.sql b/internal/endtoend/testdata/case_value_param/ydb/schema.sql new file mode 100644 index 0000000000..eaa52079a5 --- /dev/null +++ b/internal/endtoend/testdata/case_value_param/ydb/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE testing ( + id Int32, + value Text, + PRIMARY KEY (id) +); + + + diff --git a/internal/endtoend/testdata/case_value_param/ydb/sqlc.json b/internal/endtoend/testdata/case_value_param/ydb/sqlc.json new file mode 100644 index 0000000000..bb070aeeba --- /dev/null +++ b/internal/endtoend/testdata/case_value_param/ydb/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] + } + + + + diff --git a/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/db.go b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/cast_coalesce/ydb/stdlib/go/models.go b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..0cd442222e --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string +} diff --git a/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..a564e61835 --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/go/query.sql.go @@ -0,0 +1,38 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const castCoalesce = `-- name: CastCoalesce :many +SELECT COALESCE(bar, '') AS login +FROM foo +` + +func (q *Queries) CastCoalesce(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, castCoalesce) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var login string + if err := rows.Scan(&login); err != nil { + return nil, err + } + items = append(items, login) + } + 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/cast_coalesce/ydb/stdlib/query.sql b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/query.sql new file mode 100644 index 0000000000..58febc7ab3 --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/query.sql @@ -0,0 +1,6 @@ +-- name: CastCoalesce :many +SELECT COALESCE(bar, '') AS login +FROM foo; + + + diff --git a/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/schema.sql b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..6ca25109f3 --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo (bar Text, PRIMARY KEY (bar)); + + + diff --git a/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..c5959ba446 --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/stdlib/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..0cd442222e --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string +} diff --git a/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..5f1e1209a5 --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,40 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const castCoalesce = `-- name: CastCoalesce :many +SELECT COALESCE(bar, '') AS login +FROM foo +` + +func (q *Queries) CastCoalesce(ctx context.Context, opts ...query.ExecuteOption) ([]string, error) { + result, err := q.db.QueryResultSet(ctx, castCoalesce, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var login string + if err := row.Scan(&login); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, login) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..58febc7ab3 --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,6 @@ +-- name: CastCoalesce :many +SELECT COALESCE(bar, '') AS login +FROM foo; + + + diff --git a/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..6ca25109f3 --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo (bar Text, PRIMARY KEY (bar)); + + + diff --git a/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..41b4416e16 --- /dev/null +++ b/internal/endtoend/testdata/cast_coalesce/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} + + + diff --git a/internal/endtoend/testdata/cast_null/ydb/stdlib/go/db.go b/internal/endtoend/testdata/cast_null/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/cast_null/ydb/stdlib/go/models.go b/internal/endtoend/testdata/cast_null/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..0cd442222e --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string +} diff --git a/internal/endtoend/testdata/cast_null/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/cast_null/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..2711419e58 --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/stdlib/go/query.sql.go @@ -0,0 +1,55 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + "time" +) + +const listNullable = `-- name: ListNullable :many +SELECT + Cast(NULL AS Text?) AS a, + Cast(NULL AS Int32?) AS b, + Cast(NULL AS Int64?) AS c, + Cast(NULL AS DateTime?) AS d +FROM foo +` + +type ListNullableRow struct { + A *string + B *int32 + C *int64 + D *time.Time +} + +func (q *Queries) ListNullable(ctx context.Context) ([]ListNullableRow, error) { + rows, err := q.db.QueryContext(ctx, listNullable) + if err != nil { + return nil, err + } + defer rows.Close() + var items []ListNullableRow + for rows.Next() { + var i ListNullableRow + if err := rows.Scan( + &i.A, + &i.B, + &i.C, + &i.D, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/cast_null/ydb/stdlib/query.sql b/internal/endtoend/testdata/cast_null/ydb/stdlib/query.sql new file mode 100644 index 0000000000..d87e614af9 --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/stdlib/query.sql @@ -0,0 +1,11 @@ +-- name: ListNullable :many +SELECT + Cast(NULL AS Text?) AS a, + Cast(NULL AS Int32?) AS b, + Cast(NULL AS Int64?) AS c, + Cast(NULL AS DateTime?) AS d +FROM foo; + + + + diff --git a/internal/endtoend/testdata/cast_null/ydb/stdlib/schema.sql b/internal/endtoend/testdata/cast_null/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..6ca25109f3 --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/stdlib/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo (bar Text, PRIMARY KEY (bar)); + + + diff --git a/internal/endtoend/testdata/cast_null/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/cast_null/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..c5959ba446 --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/stdlib/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..0cd442222e --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string +} diff --git a/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..64f1d0f7d4 --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,57 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + "time" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const listNullable = `-- name: ListNullable :many +SELECT + Cast(NULL AS Text?) AS a, + Cast(NULL AS Int32?) AS b, + Cast(NULL AS Int64?) AS c, + Cast(NULL AS DateTime?) AS d +FROM foo +` + +type ListNullableRow struct { + A *string + B *int32 + C *int64 + D *time.Time +} + +func (q *Queries) ListNullable(ctx context.Context, opts ...query.ExecuteOption) ([]ListNullableRow, error) { + result, err := q.db.QueryResultSet(ctx, listNullable, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []ListNullableRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i ListNullableRow + if err := row.Scan( + &i.A, + &i.B, + &i.C, + &i.D, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..d87e614af9 --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,11 @@ +-- name: ListNullable :many +SELECT + Cast(NULL AS Text?) AS a, + Cast(NULL AS Int32?) AS b, + Cast(NULL AS Int64?) AS c, + Cast(NULL AS DateTime?) AS d +FROM foo; + + + + diff --git a/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..6ca25109f3 --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo (bar Text, PRIMARY KEY (bar)); + + + diff --git a/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..41b4416e16 --- /dev/null +++ b/internal/endtoend/testdata/cast_null/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} + + + diff --git a/internal/endtoend/testdata/cast_param/ydb/go/db.go b/internal/endtoend/testdata/cast_param/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/cast_param/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/cast_param/ydb/go/models.go b/internal/endtoend/testdata/cast_param/ydb/go/models.go new file mode 100644 index 0000000000..4c6487b2b1 --- /dev/null +++ b/internal/endtoend/testdata/cast_param/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type MyTable struct { + Invalid bool + Foo string +} diff --git a/internal/endtoend/testdata/cast_param/ydb/go/query.sql.go b/internal/endtoend/testdata/cast_param/ydb/go/query.sql.go new file mode 100644 index 0000000000..98e709266d --- /dev/null +++ b/internal/endtoend/testdata/cast_param/ydb/go/query.sql.go @@ -0,0 +1,39 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getData = `-- name: GetData :many +SELECT invalid, foo +FROM my_table +WHERE (CAST($allow_invalid AS Bool) OR NOT invalid) +` + +func (q *Queries) GetData(ctx context.Context, allowInvalid bool) ([]MyTable, error) { + rows, err := q.db.QueryContext(ctx, getData, allowInvalid) + if err != nil { + return nil, err + } + defer rows.Close() + var items []MyTable + for rows.Next() { + var i MyTable + if err := rows.Scan(&i.Invalid, &i.Foo); err != nil { + return nil, err + } + items = append(items, i) + } + 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/cast_param/ydb/query.sql b/internal/endtoend/testdata/cast_param/ydb/query.sql new file mode 100644 index 0000000000..0196291aaf --- /dev/null +++ b/internal/endtoend/testdata/cast_param/ydb/query.sql @@ -0,0 +1,7 @@ +-- name: GetData :many +SELECT * +FROM my_table +WHERE (CAST($allow_invalid AS Bool) OR NOT invalid); + + + diff --git a/internal/endtoend/testdata/cast_param/ydb/schema.sql b/internal/endtoend/testdata/cast_param/ydb/schema.sql new file mode 100644 index 0000000000..64a2bbae25 --- /dev/null +++ b/internal/endtoend/testdata/cast_param/ydb/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE my_table ( + invalid Bool, + foo Text, + PRIMARY KEY (invalid, foo) +); + + + diff --git a/internal/endtoend/testdata/cast_param/ydb/sqlc.json b/internal/endtoend/testdata/cast_param/ydb/sqlc.json new file mode 100644 index 0000000000..c5959ba446 --- /dev/null +++ b/internal/endtoend/testdata/cast_param/ydb/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/coalesce/ydb/stdlib/go/db.go b/internal/endtoend/testdata/coalesce/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/coalesce/ydb/stdlib/go/models.go b/internal/endtoend/testdata/coalesce/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..70e7f026cb --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/stdlib/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar *string + Bat string + Baz *int64 + Qux int64 +} diff --git a/internal/endtoend/testdata/coalesce/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/coalesce/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..20ec52d2cb --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/stdlib/go/query.sql.go @@ -0,0 +1,200 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const coalesceNumeric = `-- name: CoalesceNumeric :many +SELECT COALESCE(baz, 0) AS login +FROM foo +` + +func (q *Queries) CoalesceNumeric(ctx context.Context) ([]int64, error) { + rows, err := q.db.QueryContext(ctx, coalesceNumeric) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int64 + for rows.Next() { + var login int64 + if err := rows.Scan(&login); err != nil { + return nil, err + } + items = append(items, login) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const coalesceNumericColumns = `-- name: CoalesceNumericColumns :many +SELECT baz, qux, COALESCE(baz, qux) +FROM foo +` + +type CoalesceNumericColumnsRow struct { + Baz *int64 + Qux int64 + Baz_2 int64 +} + +func (q *Queries) CoalesceNumericColumns(ctx context.Context) ([]CoalesceNumericColumnsRow, error) { + rows, err := q.db.QueryContext(ctx, coalesceNumericColumns) + if err != nil { + return nil, err + } + defer rows.Close() + var items []CoalesceNumericColumnsRow + for rows.Next() { + var i CoalesceNumericColumnsRow + if err := rows.Scan(&i.Baz, &i.Qux, &i.Baz_2); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const coalesceNumericNull = `-- name: CoalesceNumericNull :many +SELECT baz, COALESCE(baz) +FROM foo +` + +type CoalesceNumericNullRow struct { + Baz *int64 + Baz_2 *int64 +} + +func (q *Queries) CoalesceNumericNull(ctx context.Context) ([]CoalesceNumericNullRow, error) { + rows, err := q.db.QueryContext(ctx, coalesceNumericNull) + if err != nil { + return nil, err + } + defer rows.Close() + var items []CoalesceNumericNullRow + for rows.Next() { + var i CoalesceNumericNullRow + if err := rows.Scan(&i.Baz, &i.Baz_2); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const coalesceString = `-- name: CoalesceString :many +SELECT COALESCE(bar, '') AS login +FROM foo +` + +func (q *Queries) CoalesceString(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, coalesceString) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var login string + if err := rows.Scan(&login); err != nil { + return nil, err + } + items = append(items, login) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const coalesceStringColumns = `-- name: CoalesceStringColumns :many +SELECT bar, bat, COALESCE(bar, bat) +FROM foo +` + +type CoalesceStringColumnsRow struct { + Bar *string + Bat string + Bar_2 string +} + +func (q *Queries) CoalesceStringColumns(ctx context.Context) ([]CoalesceStringColumnsRow, error) { + rows, err := q.db.QueryContext(ctx, coalesceStringColumns) + if err != nil { + return nil, err + } + defer rows.Close() + var items []CoalesceStringColumnsRow + for rows.Next() { + var i CoalesceStringColumnsRow + if err := rows.Scan(&i.Bar, &i.Bat, &i.Bar_2); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const coalesceStringNull = `-- name: CoalesceStringNull :many +SELECT bar, COALESCE(bar) +FROM foo +` + +type CoalesceStringNullRow struct { + Bar *string + Bar_2 *string +} + +func (q *Queries) CoalesceStringNull(ctx context.Context) ([]CoalesceStringNullRow, error) { + rows, err := q.db.QueryContext(ctx, coalesceStringNull) + if err != nil { + return nil, err + } + defer rows.Close() + var items []CoalesceStringNullRow + for rows.Next() { + var i CoalesceStringNullRow + if err := rows.Scan(&i.Bar, &i.Bar_2); err != nil { + return nil, err + } + items = append(items, i) + } + 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/coalesce/ydb/stdlib/query.sql b/internal/endtoend/testdata/coalesce/ydb/stdlib/query.sql new file mode 100644 index 0000000000..36933ec438 --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/stdlib/query.sql @@ -0,0 +1,23 @@ +-- name: CoalesceString :many +SELECT COALESCE(bar, '') AS login +FROM foo; + +-- name: CoalesceNumeric :many +SELECT COALESCE(baz, 0) AS login +FROM foo; + +-- name: CoalesceStringColumns :many +SELECT bar, bat, COALESCE(bar, bat) +FROM foo; + +-- name: CoalesceNumericColumns :many +SELECT baz, qux, COALESCE(baz, qux) +FROM foo; + +-- name: CoalesceStringNull :many +SELECT bar, COALESCE(bar) +FROM foo; + +-- name: CoalesceNumericNull :many +SELECT baz, COALESCE(baz) +FROM foo; diff --git a/internal/endtoend/testdata/coalesce/ydb/stdlib/schema.sql b/internal/endtoend/testdata/coalesce/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..2106ed970c --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/stdlib/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE foo ( + bar Text, + bat Text NOT NULL, + baz Int64, + qux Int64 NOT NULL, + PRIMARY KEY (bat, qux) +); diff --git a/internal/endtoend/testdata/coalesce/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/coalesce/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..70e7f026cb --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar *string + Bat string + Baz *int64 + Qux int64 +} diff --git a/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..0dd8e8c0a4 --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,197 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const coalesceNumeric = `-- name: CoalesceNumeric :many +SELECT COALESCE(baz, 0) AS login +FROM foo +` + +func (q *Queries) CoalesceNumeric(ctx context.Context, opts ...query.ExecuteOption) ([]int64, error) { + result, err := q.db.QueryResultSet(ctx, coalesceNumeric, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []int64 + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var login int64 + if err := row.Scan(&login); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, login) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const coalesceNumericColumns = `-- name: CoalesceNumericColumns :many +SELECT baz, qux, COALESCE(baz, qux) +FROM foo +` + +type CoalesceNumericColumnsRow struct { + Baz *int64 + Qux int64 + Baz_2 int64 +} + +func (q *Queries) CoalesceNumericColumns(ctx context.Context, opts ...query.ExecuteOption) ([]CoalesceNumericColumnsRow, error) { + result, err := q.db.QueryResultSet(ctx, coalesceNumericColumns, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []CoalesceNumericColumnsRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i CoalesceNumericColumnsRow + if err := row.Scan(&i.Baz, &i.Qux, &i.Baz_2); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const coalesceNumericNull = `-- name: CoalesceNumericNull :many +SELECT baz, COALESCE(baz) +FROM foo +` + +type CoalesceNumericNullRow struct { + Baz *int64 + Baz_2 *int64 +} + +func (q *Queries) CoalesceNumericNull(ctx context.Context, opts ...query.ExecuteOption) ([]CoalesceNumericNullRow, error) { + result, err := q.db.QueryResultSet(ctx, coalesceNumericNull, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []CoalesceNumericNullRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i CoalesceNumericNullRow + if err := row.Scan(&i.Baz, &i.Baz_2); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const coalesceString = `-- name: CoalesceString :many +SELECT COALESCE(bar, '') AS login +FROM foo +` + +func (q *Queries) CoalesceString(ctx context.Context, opts ...query.ExecuteOption) ([]string, error) { + result, err := q.db.QueryResultSet(ctx, coalesceString, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var login string + if err := row.Scan(&login); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, login) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const coalesceStringColumns = `-- name: CoalesceStringColumns :many +SELECT bar, bat, COALESCE(bar, bat) +FROM foo +` + +type CoalesceStringColumnsRow struct { + Bar *string + Bat string + Bar_2 string +} + +func (q *Queries) CoalesceStringColumns(ctx context.Context, opts ...query.ExecuteOption) ([]CoalesceStringColumnsRow, error) { + result, err := q.db.QueryResultSet(ctx, coalesceStringColumns, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []CoalesceStringColumnsRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i CoalesceStringColumnsRow + if err := row.Scan(&i.Bar, &i.Bat, &i.Bar_2); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const coalesceStringNull = `-- name: CoalesceStringNull :many +SELECT bar, COALESCE(bar) +FROM foo +` + +type CoalesceStringNullRow struct { + Bar *string + Bar_2 *string +} + +func (q *Queries) CoalesceStringNull(ctx context.Context, opts ...query.ExecuteOption) ([]CoalesceStringNullRow, error) { + result, err := q.db.QueryResultSet(ctx, coalesceStringNull, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []CoalesceStringNullRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i CoalesceStringNullRow + if err := row.Scan(&i.Bar, &i.Bar_2); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..36933ec438 --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,23 @@ +-- name: CoalesceString :many +SELECT COALESCE(bar, '') AS login +FROM foo; + +-- name: CoalesceNumeric :many +SELECT COALESCE(baz, 0) AS login +FROM foo; + +-- name: CoalesceStringColumns :many +SELECT bar, bat, COALESCE(bar, bat) +FROM foo; + +-- name: CoalesceNumericColumns :many +SELECT baz, qux, COALESCE(baz, qux) +FROM foo; + +-- name: CoalesceStringNull :many +SELECT bar, COALESCE(bar) +FROM foo; + +-- name: CoalesceNumericNull :many +SELECT baz, COALESCE(baz) +FROM foo; diff --git a/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..2106ed970c --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE foo ( + bar Text, + bat Text NOT NULL, + baz Int64, + qux Int64 NOT NULL, + PRIMARY KEY (bat, qux) +); diff --git a/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..02f4bf76c3 --- /dev/null +++ b/internal/endtoend/testdata/coalesce/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} diff --git a/internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/db.go b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/coalesce_as/ydb/stdlib/go/models.go b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..3590f4ba11 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string + Baz *int64 +} diff --git a/internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..e90904e340 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/go/query.sql.go @@ -0,0 +1,44 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const sumBaz = `-- name: SumBaz :many +SELECT bar, CAST(COALESCE(SUM(baz), 0) AS Int64) AS quantity +FROM foo +GROUP BY bar +` + +type SumBazRow struct { + Bar string + Quantity int64 +} + +func (q *Queries) SumBaz(ctx context.Context) ([]SumBazRow, error) { + rows, err := q.db.QueryContext(ctx, sumBaz) + if err != nil { + return nil, err + } + defer rows.Close() + var items []SumBazRow + for rows.Next() { + var i SumBazRow + if err := rows.Scan(&i.Bar, &i.Quantity); err != nil { + return nil, err + } + items = append(items, i) + } + 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/coalesce_as/ydb/stdlib/query.sql b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/query.sql new file mode 100644 index 0000000000..b5ffb750dc --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/query.sql @@ -0,0 +1,4 @@ +-- name: SumBaz :many +SELECT bar, CAST(COALESCE(SUM(baz), 0) AS Int64) AS quantity +FROM foo +GROUP BY bar; diff --git a/internal/endtoend/testdata/coalesce_as/ydb/stdlib/schema.sql b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..db0d85ccf6 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + bar Text, + baz Int64, + PRIMARY KEY (bar) +); diff --git a/internal/endtoend/testdata/coalesce_as/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..3590f4ba11 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string + Baz *int64 +} diff --git a/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..dc63f12992 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,46 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const sumBaz = `-- name: SumBaz :many +SELECT bar, CAST(COALESCE(SUM(baz), 0) AS Int64) AS quantity +FROM foo +GROUP BY bar +` + +type SumBazRow struct { + Bar string + Quantity int64 +} + +func (q *Queries) SumBaz(ctx context.Context, opts ...query.ExecuteOption) ([]SumBazRow, error) { + result, err := q.db.QueryResultSet(ctx, sumBaz, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []SumBazRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i SumBazRow + if err := row.Scan(&i.Bar, &i.Quantity); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..b5ffb750dc --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,4 @@ +-- name: SumBaz :many +SELECT bar, CAST(COALESCE(SUM(baz), 0) AS Int64) AS quantity +FROM foo +GROUP BY bar; diff --git a/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..db0d85ccf6 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + bar Text, + baz Int64, + PRIMARY KEY (bar) +); diff --git a/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..02f4bf76c3 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_as/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} diff --git a/internal/endtoend/testdata/coalesce_join/ydb/go/db.go b/internal/endtoend/testdata/coalesce_join/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_join/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/coalesce_join/ydb/go/models.go b/internal/endtoend/testdata/coalesce_join/ydb/go/models.go new file mode 100644 index 0000000000..d093635683 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_join/ydb/go/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int64 +} + +type Foo struct { + ID int64 +} diff --git a/internal/endtoend/testdata/coalesce_join/ydb/go/query.sql.go b/internal/endtoend/testdata/coalesce_join/ydb/go/query.sql.go new file mode 100644 index 0000000000..4d0489e792 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_join/ydb/go/query.sql.go @@ -0,0 +1,44 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getBar = `-- name: GetBar :many +SELECT foo.id, COALESCE(bar.id, 0) AS bar_id +FROM foo +LEFT JOIN bar ON foo.id = bar.id +` + +type GetBarRow struct { + ID int64 + BarID int64 +} + +func (q *Queries) GetBar(ctx context.Context) ([]GetBarRow, error) { + rows, err := q.db.QueryContext(ctx, getBar) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetBarRow + for rows.Next() { + var i GetBarRow + if err := rows.Scan(&i.ID, &i.BarID); err != nil { + return nil, err + } + items = append(items, i) + } + 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/coalesce_join/ydb/query.sql b/internal/endtoend/testdata/coalesce_join/ydb/query.sql new file mode 100644 index 0000000000..d91add88e6 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_join/ydb/query.sql @@ -0,0 +1,4 @@ +-- name: GetBar :many +SELECT foo.*, COALESCE(bar.id, 0) AS bar_id +FROM foo +LEFT JOIN bar ON foo.id = bar.id; diff --git a/internal/endtoend/testdata/coalesce_join/ydb/schema.sql b/internal/endtoend/testdata/coalesce_join/ydb/schema.sql new file mode 100644 index 0000000000..281133ce84 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_join/ydb/schema.sql @@ -0,0 +1,2 @@ +CREATE TABLE foo (id BigSerial, PRIMARY KEY (id)); +CREATE TABLE bar (id BigSerial, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/coalesce_join/ydb/sqlc.json b/internal/endtoend/testdata/coalesce_join/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_join/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/coalesce_params/ydb/go/db.go b/internal/endtoend/testdata/coalesce_params/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_params/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/coalesce_params/ydb/go/models.go b/internal/endtoend/testdata/coalesce_params/ydb/go/models.go new file mode 100644 index 0000000000..db72580ccd --- /dev/null +++ b/internal/endtoend/testdata/coalesce_params/ydb/go/models.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "time" +) + +type Author struct { + ID int64 + Address string + Name string + Bio string +} + +type Calendar struct { + ID *int64 + Relation *int64 + Calendarname string + Title string + Description string + Timezone string + Uniquekey string + Idkey string + Maincalendar bool + Createdate time.Time + Modifydate time.Time +} + +type Event struct { + ID *int64 + Relation *int64 + Calendarreference *int64 + Uniquekey string + Eventname string + Description string + Location string + Timezone string + Idkey *string +} diff --git a/internal/endtoend/testdata/coalesce_params/ydb/go/query.sql.go b/internal/endtoend/testdata/coalesce_params/ydb/go/query.sql.go new file mode 100644 index 0000000000..9b73c39cb2 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_params/ydb/go/query.sql.go @@ -0,0 +1,36 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const addAuthor = `-- name: AddAuthor :execlastid +INSERT INTO authors ( + address, + name, + bio +) VALUES ( + $address, + COALESCE($cal_name, ''), + COALESCE($cal_description, '') +) +` + +type AddAuthorParams struct { + Address string + CalName interface{} + CalDescription interface{} +} + +func (q *Queries) AddAuthor(ctx context.Context, arg AddAuthorParams) (int64, error) { + result, err := q.db.ExecContext(ctx, addAuthor, arg.Address, arg.CalName, arg.CalDescription) + if err != nil { + return 0, err + } + return result.LastInsertId() +} diff --git a/internal/endtoend/testdata/coalesce_params/ydb/query.sql b/internal/endtoend/testdata/coalesce_params/ydb/query.sql new file mode 100644 index 0000000000..5949b84514 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_params/ydb/query.sql @@ -0,0 +1,11 @@ + +-- name: AddAuthor :execlastid +INSERT INTO authors ( + address, + name, + bio +) VALUES ( + $address, + COALESCE($cal_name, ''), + COALESCE($cal_description, '') +); diff --git a/internal/endtoend/testdata/coalesce_params/ydb/schema.sql b/internal/endtoend/testdata/coalesce_params/ydb/schema.sql new file mode 100644 index 0000000000..4c816cb303 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_params/ydb/schema.sql @@ -0,0 +1,35 @@ +CREATE TABLE Calendar ( + Id BigSerial, + Relation BigSerial, + CalendarName Text NOT NULL, + Title Text NOT NULL, + Description Text NOT NULL, + Timezone Text NOT NULL, + UniqueKey Text NOT NULL, + IdKey Text NOT NULL, + MainCalendar Bool NOT NULL, + CreateDate DateTime NOT NULL, + ModifyDate DateTime NOT NULL, + PRIMARY KEY (Id) +); + +CREATE TABLE Event ( + Id BigSerial, + Relation BigSerial, + CalendarReference BigSerial, + UniqueKey Text NOT NULL, + EventName Text NOT NULL, + Description Text NOT NULL, + Location Text NOT NULL, + Timezone Text NOT NULL, + IdKey Text, + PRIMARY KEY (Id) +); + +CREATE TABLE authors ( + id BigSerial, + address Text NOT NULL, + name Text NOT NULL, + bio Text NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/coalesce_params/ydb/sqlc.json b/internal/endtoend/testdata/coalesce_params/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/coalesce_params/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/column_alias/ydb/go/db.go b/internal/endtoend/testdata/column_alias/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/column_alias/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/column_alias/ydb/go/models.go b/internal/endtoend/testdata/column_alias/ydb/go/models.go new file mode 100644 index 0000000000..05352919de --- /dev/null +++ b/internal/endtoend/testdata/column_alias/ydb/go/models.go @@ -0,0 +1,18 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "time" +) + +type User struct { + ID int32 + Fname string + Lname string + Email string + EncPasswd string + CreatedAt time.Time +} diff --git a/internal/endtoend/testdata/column_alias/ydb/go/query.sql.go b/internal/endtoend/testdata/column_alias/ydb/go/query.sql.go new file mode 100644 index 0000000000..847000288a --- /dev/null +++ b/internal/endtoend/testdata/column_alias/ydb/go/query.sql.go @@ -0,0 +1,74 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + "time" +) + +const getUsers = `-- name: GetUsers :many +SELECT + users.id, + users.fname, + users.lname, + users.email, + users.created_at, + CASE WHEN users.email LIKE '%' || $search_term || '%' THEN 1 ELSE 0 END AS rank_email, + CASE WHEN users.fname LIKE '%' || $search_term || '%' THEN 1 ELSE 0 END AS rank_fname, + CASE WHEN users.lname LIKE '%' || $search_term || '%' THEN 1 ELSE 0 END AS rank_lname, + CASE WHEN (users.email || users.fname || users.lname) LIKE '%' || $search_term || '%' THEN 1 ELSE 0 END AS similarity +FROM users +WHERE users.email LIKE '%' || $search_term || '%' + OR users.fname LIKE '%' || $search_term || '%' + OR users.lname LIKE '%' || $search_term || '%' +ORDER BY rank_email DESC, rank_lname DESC, rank_fname DESC, similarity DESC +` + +type GetUsersRow struct { + ID int32 + Fname string + Lname string + Email string + CreatedAt time.Time + RankEmail int32 + RankFname int32 + RankLname int32 + Similarity int32 +} + +func (q *Queries) GetUsers(ctx context.Context, searchTerm *string) ([]GetUsersRow, error) { + rows, err := q.db.QueryContext(ctx, getUsers, searchTerm) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetUsersRow + for rows.Next() { + var i GetUsersRow + if err := rows.Scan( + &i.ID, + &i.Fname, + &i.Lname, + &i.Email, + &i.CreatedAt, + &i.RankEmail, + &i.RankFname, + &i.RankLname, + &i.Similarity, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/column_alias/ydb/query.sql b/internal/endtoend/testdata/column_alias/ydb/query.sql new file mode 100644 index 0000000000..95af381b00 --- /dev/null +++ b/internal/endtoend/testdata/column_alias/ydb/query.sql @@ -0,0 +1,16 @@ +-- name: GetUsers :many +SELECT + users.id, + users.fname, + users.lname, + users.email, + users.created_at, + CASE WHEN users.email LIKE '%' || $search_term || '%' THEN 1 ELSE 0 END AS rank_email, + CASE WHEN users.fname LIKE '%' || $search_term || '%' THEN 1 ELSE 0 END AS rank_fname, + CASE WHEN users.lname LIKE '%' || $search_term || '%' THEN 1 ELSE 0 END AS rank_lname, + CASE WHEN (users.email || users.fname || users.lname) LIKE '%' || $search_term || '%' THEN 1 ELSE 0 END AS similarity +FROM users +WHERE users.email LIKE '%' || $search_term || '%' + OR users.fname LIKE '%' || $search_term || '%' + OR users.lname LIKE '%' || $search_term || '%' +ORDER BY rank_email DESC, rank_lname DESC, rank_fname DESC, similarity DESC; diff --git a/internal/endtoend/testdata/column_alias/ydb/schema.sql b/internal/endtoend/testdata/column_alias/ydb/schema.sql new file mode 100644 index 0000000000..c7d95f1474 --- /dev/null +++ b/internal/endtoend/testdata/column_alias/ydb/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE users ( + id Serial, + fname Text NOT NULL, + lname Text NOT NULL, + email Text NOT NULL, + enc_passwd Text NOT NULL, + created_at DateTime NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/column_alias/ydb/sqlc.json b/internal/endtoend/testdata/column_alias/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/column_alias/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/column_as/ydb/stdlib/go/db.go b/internal/endtoend/testdata/column_as/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/column_as/ydb/stdlib/go/models.go b/internal/endtoend/testdata/column_as/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..333ea43ea3 --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/stdlib/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest diff --git a/internal/endtoend/testdata/column_as/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/column_as/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..bb26fb91ca --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/stdlib/go/query.sql.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const withAs = `-- name: WithAs :one +SELECT 1 AS x, 2 AS y +` + +type WithAsRow struct { + X int32 + Y int32 +} + +func (q *Queries) WithAs(ctx context.Context) (WithAsRow, error) { + row := q.db.QueryRowContext(ctx, withAs) + var i WithAsRow + err := row.Scan(&i.X, &i.Y) + return i, err +} + +const withoutAs = `-- name: WithoutAs :one +SELECT 1 x, 2 y +` + +type WithoutAsRow struct { + X int32 + Y int32 +} + +func (q *Queries) WithoutAs(ctx context.Context) (WithoutAsRow, error) { + row := q.db.QueryRowContext(ctx, withoutAs) + var i WithoutAsRow + err := row.Scan(&i.X, &i.Y) + return i, err +} diff --git a/internal/endtoend/testdata/column_as/ydb/stdlib/query.sql b/internal/endtoend/testdata/column_as/ydb/stdlib/query.sql new file mode 100644 index 0000000000..c7282d88ef --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/stdlib/query.sql @@ -0,0 +1,5 @@ +-- name: WithAs :one +SELECT 1 AS x, 2 AS y; + +-- name: WithoutAs :one +SELECT 1 x, 2 y; diff --git a/internal/endtoend/testdata/column_as/ydb/stdlib/schema.sql b/internal/endtoend/testdata/column_as/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/stdlib/schema.sql @@ -0,0 +1 @@ + diff --git a/internal/endtoend/testdata/column_as/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/column_as/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..333ea43ea3 --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest diff --git a/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..6f122ea02e --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,57 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const withAs = `-- name: WithAs :one +SELECT 1 AS x, 2 AS y +` + +type WithAsRow struct { + X int32 + Y int32 +} + +func (q *Queries) WithAs(ctx context.Context, opts ...query.ExecuteOption) (WithAsRow, error) { + row, err := q.db.QueryRow(ctx, withAs, opts...) + var i WithAsRow + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.X, &i.Y) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const withoutAs = `-- name: WithoutAs :one +SELECT 1 x, 2 y +` + +type WithoutAsRow struct { + X int32 + Y int32 +} + +func (q *Queries) WithoutAs(ctx context.Context, opts ...query.ExecuteOption) (WithoutAsRow, error) { + row, err := q.db.QueryRow(ctx, withoutAs, opts...) + var i WithoutAsRow + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.X, &i.Y) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} diff --git a/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..c7282d88ef --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,5 @@ +-- name: WithAs :one +SELECT 1 AS x, 2 AS y; + +-- name: WithoutAs :one +SELECT 1 x, 2 y; diff --git a/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..02f4bf76c3 --- /dev/null +++ b/internal/endtoend/testdata/column_as/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} diff --git a/internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/db.go b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/comment_syntax/ydb/stdlib/go/models.go b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..0cd442222e --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string +} diff --git a/internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..03cb89900d --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/go/query.sql.go @@ -0,0 +1,32 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const doubleDash = `-- name: DoubleDash :one +SELECT bar FROM foo LIMIT 1 +` + +func (q *Queries) DoubleDash(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, doubleDash) + var bar string + err := row.Scan(&bar) + return bar, err +} + +const slashStar = `-- name: SlashStar :one +SELECT bar FROM foo LIMIT 1 +` + +func (q *Queries) SlashStar(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, slashStar) + var bar string + err := row.Scan(&bar) + return bar, err +} diff --git a/internal/endtoend/testdata/comment_syntax/ydb/stdlib/query.sql b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/query.sql new file mode 100644 index 0000000000..ddf6f4b70c --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/query.sql @@ -0,0 +1,5 @@ +-- name: DoubleDash :one +SELECT * FROM foo LIMIT 1; + +/* name: SlashStar :one */ +SELECT * FROM foo LIMIT 1; diff --git a/internal/endtoend/testdata/comment_syntax/ydb/stdlib/schema.sql b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..63a287e754 --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE foo (bar Utf8, PRIMARY KEY (bar)); + + diff --git a/internal/endtoend/testdata/comment_syntax/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..8dc3083c5d --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/stdlib/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..0cd442222e --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string +} diff --git a/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..0787c72f06 --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,47 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const doubleDash = `-- name: DoubleDash :one +SELECT bar FROM foo LIMIT 1 +` + +func (q *Queries) DoubleDash(ctx context.Context, opts ...query.ExecuteOption) (string, error) { + row, err := q.db.QueryRow(ctx, doubleDash, opts...) + var bar string + if err != nil { + return bar, xerrors.WithStackTrace(err) + } + err = row.Scan(&bar) + if err != nil { + return bar, xerrors.WithStackTrace(err) + } + return bar, nil +} + +const slashStar = `-- name: SlashStar :one +SELECT bar FROM foo LIMIT 1 +` + +func (q *Queries) SlashStar(ctx context.Context, opts ...query.ExecuteOption) (string, error) { + row, err := q.db.QueryRow(ctx, slashStar, opts...) + var bar string + if err != nil { + return bar, xerrors.WithStackTrace(err) + } + err = row.Scan(&bar) + if err != nil { + return bar, xerrors.WithStackTrace(err) + } + return bar, nil +} diff --git a/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..ce4eb70318 --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,7 @@ +-- name: DoubleDash :one +SELECT * FROM foo LIMIT 1; + +/* name: SlashStar :one */ +SELECT * FROM foo LIMIT 1; + + diff --git a/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..5e756dfc4f --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE foo (bar Text, PRIMARY KEY (bar)); + + diff --git a/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..2610f39f40 --- /dev/null +++ b/internal/endtoend/testdata/comment_syntax/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} + + diff --git a/internal/endtoend/testdata/comparisons/ydb/stdlib/go/db.go b/internal/endtoend/testdata/comparisons/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/comparisons/ydb/stdlib/go/models.go b/internal/endtoend/testdata/comparisons/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/comparisons/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/comparisons/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..65942b4e9b --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/stdlib/go/query.sql.go @@ -0,0 +1,199 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const alsoNotEqual = `-- name: AlsoNotEqual :many +SELECT COUNT(*) <> 0 FROM bar +` + +func (q *Queries) AlsoNotEqual(ctx context.Context) ([]bool, error) { + rows, err := q.db.QueryContext(ctx, alsoNotEqual) + if err != nil { + return nil, err + } + defer rows.Close() + var items []bool + for rows.Next() { + var column_1 bool + if err := rows.Scan(&column_1); err != nil { + return nil, err + } + items = append(items, column_1) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const equal = `-- name: Equal :many +SELECT COUNT(*) = 0 FROM bar +` + +func (q *Queries) Equal(ctx context.Context) ([]bool, error) { + rows, err := q.db.QueryContext(ctx, equal) + if err != nil { + return nil, err + } + defer rows.Close() + var items []bool + for rows.Next() { + var column_1 bool + if err := rows.Scan(&column_1); err != nil { + return nil, err + } + items = append(items, column_1) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const greaterThan = `-- name: GreaterThan :many +SELECT COUNT(*) > 0 FROM bar +` + +func (q *Queries) GreaterThan(ctx context.Context) ([]bool, error) { + rows, err := q.db.QueryContext(ctx, greaterThan) + if err != nil { + return nil, err + } + defer rows.Close() + var items []bool + for rows.Next() { + var column_1 bool + if err := rows.Scan(&column_1); err != nil { + return nil, err + } + items = append(items, column_1) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const greaterThanOrEqual = `-- name: GreaterThanOrEqual :many +SELECT COUNT(*) >= 0 FROM bar +` + +func (q *Queries) GreaterThanOrEqual(ctx context.Context) ([]bool, error) { + rows, err := q.db.QueryContext(ctx, greaterThanOrEqual) + if err != nil { + return nil, err + } + defer rows.Close() + var items []bool + for rows.Next() { + var column_1 bool + if err := rows.Scan(&column_1); err != nil { + return nil, err + } + items = append(items, column_1) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const lessThan = `-- name: LessThan :many +SELECT COUNT(*) < 0 FROM bar +` + +func (q *Queries) LessThan(ctx context.Context) ([]bool, error) { + rows, err := q.db.QueryContext(ctx, lessThan) + if err != nil { + return nil, err + } + defer rows.Close() + var items []bool + for rows.Next() { + var column_1 bool + if err := rows.Scan(&column_1); err != nil { + return nil, err + } + items = append(items, column_1) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const lessThanOrEqual = `-- name: LessThanOrEqual :many +SELECT COUNT(*) <= 0 FROM bar +` + +func (q *Queries) LessThanOrEqual(ctx context.Context) ([]bool, error) { + rows, err := q.db.QueryContext(ctx, lessThanOrEqual) + if err != nil { + return nil, err + } + defer rows.Close() + var items []bool + for rows.Next() { + var column_1 bool + if err := rows.Scan(&column_1); err != nil { + return nil, err + } + items = append(items, column_1) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const notEqual = `-- name: NotEqual :many +SELECT COUNT(*) != 0 FROM bar +` + +func (q *Queries) NotEqual(ctx context.Context) ([]bool, error) { + rows, err := q.db.QueryContext(ctx, notEqual) + if err != nil { + return nil, err + } + defer rows.Close() + var items []bool + for rows.Next() { + var column_1 bool + if err := rows.Scan(&column_1); err != nil { + return nil, err + } + items = append(items, column_1) + } + 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/comparisons/ydb/stdlib/query.sql b/internal/endtoend/testdata/comparisons/ydb/stdlib/query.sql new file mode 100644 index 0000000000..81f9fb9fa4 --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/stdlib/query.sql @@ -0,0 +1,22 @@ +-- name: GreaterThan :many +SELECT COUNT(*) > 0 FROM bar; + +-- name: LessThan :many +SELECT COUNT(*) < 0 FROM bar; + +-- name: GreaterThanOrEqual :many +SELECT COUNT(*) >= 0 FROM bar; + +-- name: LessThanOrEqual :many +SELECT COUNT(*) <= 0 FROM bar; + +-- name: NotEqual :many +SELECT COUNT(*) != 0 FROM bar; + +-- name: AlsoNotEqual :many +SELECT COUNT(*) <> 0 FROM bar; + +-- name: Equal :many +SELECT COUNT(*) = 0 FROM bar; + + diff --git a/internal/endtoend/testdata/comparisons/ydb/stdlib/schema.sql b/internal/endtoend/testdata/comparisons/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..7f6dc4d7f1 --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/stdlib/schema.sql @@ -0,0 +1,6 @@ +-- Comparison Functions and Operators +-- https://www.postgresql.org/docs/current/functions-comparison.html + +CREATE TABLE bar (id Serial NOT NULL, PRIMARY KEY (id)); + + diff --git a/internal/endtoend/testdata/comparisons/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/comparisons/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..8dc3083c5d --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/stdlib/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..7f14ed3178 --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,195 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const alsoNotEqual = `-- name: AlsoNotEqual :many +SELECT COUNT(*) <> 0 FROM bar +` + +func (q *Queries) AlsoNotEqual(ctx context.Context, opts ...query.ExecuteOption) ([]bool, error) { + result, err := q.db.QueryResultSet(ctx, alsoNotEqual, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []bool + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var column_1 bool + if err := row.Scan(&column_1); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, column_1) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const equal = `-- name: Equal :many +SELECT COUNT(*) = 0 FROM bar +` + +func (q *Queries) Equal(ctx context.Context, opts ...query.ExecuteOption) ([]bool, error) { + result, err := q.db.QueryResultSet(ctx, equal, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []bool + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var column_1 bool + if err := row.Scan(&column_1); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, column_1) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const greaterThan = `-- name: GreaterThan :many +SELECT COUNT(*) > 0 FROM bar +` + +func (q *Queries) GreaterThan(ctx context.Context, opts ...query.ExecuteOption) ([]bool, error) { + result, err := q.db.QueryResultSet(ctx, greaterThan, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []bool + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var column_1 bool + if err := row.Scan(&column_1); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, column_1) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const greaterThanOrEqual = `-- name: GreaterThanOrEqual :many +SELECT COUNT(*) >= 0 FROM bar +` + +func (q *Queries) GreaterThanOrEqual(ctx context.Context, opts ...query.ExecuteOption) ([]bool, error) { + result, err := q.db.QueryResultSet(ctx, greaterThanOrEqual, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []bool + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var column_1 bool + if err := row.Scan(&column_1); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, column_1) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const lessThan = `-- name: LessThan :many +SELECT COUNT(*) < 0 FROM bar +` + +func (q *Queries) LessThan(ctx context.Context, opts ...query.ExecuteOption) ([]bool, error) { + result, err := q.db.QueryResultSet(ctx, lessThan, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []bool + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var column_1 bool + if err := row.Scan(&column_1); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, column_1) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const lessThanOrEqual = `-- name: LessThanOrEqual :many +SELECT COUNT(*) <= 0 FROM bar +` + +func (q *Queries) LessThanOrEqual(ctx context.Context, opts ...query.ExecuteOption) ([]bool, error) { + result, err := q.db.QueryResultSet(ctx, lessThanOrEqual, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []bool + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var column_1 bool + if err := row.Scan(&column_1); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, column_1) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const notEqual = `-- name: NotEqual :many +SELECT COUNT(*) != 0 FROM bar +` + +func (q *Queries) NotEqual(ctx context.Context, opts ...query.ExecuteOption) ([]bool, error) { + result, err := q.db.QueryResultSet(ctx, notEqual, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []bool + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var column_1 bool + if err := row.Scan(&column_1); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, column_1) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..81f9fb9fa4 --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,22 @@ +-- name: GreaterThan :many +SELECT COUNT(*) > 0 FROM bar; + +-- name: LessThan :many +SELECT COUNT(*) < 0 FROM bar; + +-- name: GreaterThanOrEqual :many +SELECT COUNT(*) >= 0 FROM bar; + +-- name: LessThanOrEqual :many +SELECT COUNT(*) <= 0 FROM bar; + +-- name: NotEqual :many +SELECT COUNT(*) != 0 FROM bar; + +-- name: AlsoNotEqual :many +SELECT COUNT(*) <> 0 FROM bar; + +-- name: Equal :many +SELECT COUNT(*) = 0 FROM bar; + + diff --git a/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..7f6dc4d7f1 --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,6 @@ +-- Comparison Functions and Operators +-- https://www.postgresql.org/docs/current/functions-comparison.html + +CREATE TABLE bar (id Serial NOT NULL, PRIMARY KEY (id)); + + diff --git a/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..2610f39f40 --- /dev/null +++ b/internal/endtoend/testdata/comparisons/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} + + diff --git a/internal/endtoend/testdata/count_star/ydb/stdlib/go/db.go b/internal/endtoend/testdata/count_star/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/count_star/ydb/stdlib/go/models.go b/internal/endtoend/testdata/count_star/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/count_star/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/count_star/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..3fd0bc3d0c --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/stdlib/go/query.sql.go @@ -0,0 +1,32 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const countStarLower = `-- name: CountStarLower :one +SELECT COUNT(*) FROM bar +` + +func (q *Queries) CountStarLower(ctx context.Context) (uint64, error) { + row := q.db.QueryRowContext(ctx, countStarLower) + var count uint64 + err := row.Scan(&count) + return count, err +} + +const countStarUpper = `-- name: CountStarUpper :one +SELECT COUNT(*) FROM bar +` + +func (q *Queries) CountStarUpper(ctx context.Context) (uint64, error) { + row := q.db.QueryRowContext(ctx, countStarUpper) + var count uint64 + err := row.Scan(&count) + return count, err +} diff --git a/internal/endtoend/testdata/count_star/ydb/stdlib/query.sql b/internal/endtoend/testdata/count_star/ydb/stdlib/query.sql new file mode 100644 index 0000000000..dc30d99eb1 --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/stdlib/query.sql @@ -0,0 +1,7 @@ +-- name: CountStarLower :one +SELECT COUNT(*) FROM bar; + +-- name: CountStarUpper :one +SELECT COUNT(*) FROM bar; + + diff --git a/internal/endtoend/testdata/count_star/ydb/stdlib/schema.sql b/internal/endtoend/testdata/count_star/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..9a7f07e291 --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/stdlib/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE bar (id Serial NOT NULL, PRIMARY KEY (id)); + + diff --git a/internal/endtoend/testdata/count_star/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/count_star/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..8dc3083c5d --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/stdlib/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..a2ecb29812 --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,47 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const countStarLower = `-- name: CountStarLower :one +SELECT COUNT(*) FROM bar +` + +func (q *Queries) CountStarLower(ctx context.Context, opts ...query.ExecuteOption) (uint64, error) { + row, err := q.db.QueryRow(ctx, countStarLower, opts...) + var count uint64 + if err != nil { + return count, xerrors.WithStackTrace(err) + } + err = row.Scan(&count) + if err != nil { + return count, xerrors.WithStackTrace(err) + } + return count, nil +} + +const countStarUpper = `-- name: CountStarUpper :one +SELECT COUNT(*) FROM bar +` + +func (q *Queries) CountStarUpper(ctx context.Context, opts ...query.ExecuteOption) (uint64, error) { + row, err := q.db.QueryRow(ctx, countStarUpper, opts...) + var count uint64 + if err != nil { + return count, xerrors.WithStackTrace(err) + } + err = row.Scan(&count) + if err != nil { + return count, xerrors.WithStackTrace(err) + } + return count, nil +} diff --git a/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..dc30d99eb1 --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,7 @@ +-- name: CountStarLower :one +SELECT COUNT(*) FROM bar; + +-- name: CountStarUpper :one +SELECT COUNT(*) FROM bar; + + diff --git a/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..9a7f07e291 --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE bar (id Serial NOT NULL, PRIMARY KEY (id)); + + diff --git a/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..2610f39f40 --- /dev/null +++ b/internal/endtoend/testdata/count_star/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} + + diff --git a/internal/endtoend/testdata/create_view/ydb/go/db.go b/internal/endtoend/testdata/create_view/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/create_view/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/create_view/ydb/go/models.go b/internal/endtoend/testdata/create_view/ydb/go/models.go new file mode 100644 index 0000000000..19e2dc5b41 --- /dev/null +++ b/internal/endtoend/testdata/create_view/ydb/go/models.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type FirstView struct { + Val string +} + +type Foo struct { + Val string + Val2 *int32 +} + +type SecondView struct { + Val string + Val2 *int32 +} diff --git a/internal/endtoend/testdata/create_view/ydb/go/query.sql.go b/internal/endtoend/testdata/create_view/ydb/go/query.sql.go new file mode 100644 index 0000000000..42df7a5fc5 --- /dev/null +++ b/internal/endtoend/testdata/create_view/ydb/go/query.sql.go @@ -0,0 +1,64 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getFirst = `-- name: GetFirst :many +SELECT val FROM first_view +` + +func (q *Queries) GetFirst(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, getFirst) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var val string + if err := rows.Scan(&val); err != nil { + return nil, err + } + items = append(items, val) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getSecond = `-- name: GetSecond :many +SELECT val, val2 FROM second_view WHERE val2 = $val2 +` + +func (q *Queries) GetSecond(ctx context.Context, val2 *int32) ([]SecondView, error) { + rows, err := q.db.QueryContext(ctx, getSecond, val2) + if err != nil { + return nil, err + } + defer rows.Close() + var items []SecondView + for rows.Next() { + var i SecondView + if err := rows.Scan(&i.Val, &i.Val2); err != nil { + return nil, err + } + items = append(items, i) + } + 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/create_view/ydb/query.sql b/internal/endtoend/testdata/create_view/ydb/query.sql new file mode 100644 index 0000000000..dc2d2a4e68 --- /dev/null +++ b/internal/endtoend/testdata/create_view/ydb/query.sql @@ -0,0 +1,5 @@ +-- name: GetFirst :many +SELECT * FROM first_view; + +-- name: GetSecond :many +SELECT * FROM second_view WHERE val2 = $val2; diff --git a/internal/endtoend/testdata/create_view/ydb/schema.sql b/internal/endtoend/testdata/create_view/ydb/schema.sql new file mode 100644 index 0000000000..bfed666038 --- /dev/null +++ b/internal/endtoend/testdata/create_view/ydb/schema.sql @@ -0,0 +1,15 @@ +CREATE TABLE foo ( + val Text NOT NULL, + PRIMARY KEY (val) +); + +CREATE VIEW first_view AS SELECT * FROM foo; +CREATE VIEW third_view AS SELECT * FROM foo; + +ALTER TABLE foo ADD COLUMN val2 Int32; +-- YDB doesn't support CREATE OR REPLACE VIEW, only CREATE or DROP +-- So we need to DROP and CREATE again +DROP VIEW second_view; +CREATE VIEW second_view AS SELECT * FROM foo; + +DROP VIEW third_view; diff --git a/internal/endtoend/testdata/create_view/ydb/sqlc.json b/internal/endtoend/testdata/create_view/ydb/sqlc.json new file mode 100644 index 0000000000..d8c24916cd --- /dev/null +++ b/internal/endtoend/testdata/create_view/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..2e928799e1 --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package datatype + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..b0ba25d411 --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,132 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package datatype + +import ( + "time" + + "github.com/google/uuid" + "github.com/ydb-platform/ydb-go-sdk/v3/table/types" +) + +type DtBoolean struct { + ID int32 + A *bool +} + +type DtBooleanNotNull struct { + ID int32 + A bool +} + +type DtCharacter struct { + ID int32 + A *[]byte + B *string +} + +type DtCharacterNotNull struct { + ID int32 + A []byte + B string +} + +type DtDatetime struct { + ID int32 + A *time.Time + B *time.Time + C *time.Time + D *time.Time + E *time.Time + F *time.Time + G *time.Duration + H *time.Duration + I *time.Time + J *time.Time + K *time.Time +} + +type DtDatetimeNotNull struct { + ID int32 + A time.Time + B time.Time + C time.Time + D time.Time + E time.Time + F time.Time + G time.Duration + H time.Duration + I time.Time + J time.Time + K time.Time +} + +type DtJson struct { + ID int32 + A *string + B *string + C *[]byte +} + +type DtJsonNotNull struct { + ID int32 + A string + B string + C []byte +} + +type DtNumeric struct { + ID int32 + A *int8 + B *int16 + C *int32 + D *int64 + E *uint8 + F *uint16 + G *uint32 + H *uint64 + I *float32 + J *float64 + K *types.Decimal + L *types.Decimal + N *int16 + O *int16 + P *int32 + Q *int32 + R *int64 + S *int64 +} + +type DtNumericNotNull struct { + ID int32 + A int8 + B int16 + C int32 + D int64 + E uint8 + F uint16 + G uint32 + H uint64 + I float32 + J float64 + K types.Decimal + L types.Decimal + N int16 + O int16 + P int32 + Q int32 + R int64 + S int64 +} + +type DtUuid struct { + ID int32 + A *uuid.UUID +} + +type DtUuidNotNull struct { + ID int32 + A uuid.UUID +} diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..7024a3fff1 --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,30 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package datatype + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const test = `-- name: Test :one +SELECT 1 +` + +func (q *Queries) Test(ctx context.Context, opts ...query.ExecuteOption) (int32, error) { + row, err := q.db.QueryRow(ctx, test, opts...) + var column_1 int32 + if err != nil { + return column_1, xerrors.WithStackTrace(err) + } + err = row.Scan(&column_1) + if err != nil { + return column_1, xerrors.WithStackTrace(err) + } + return column_1, nil +} diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/boolean.sql b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/boolean.sql new file mode 100644 index 0000000000..9b08cba11d --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/boolean.sql @@ -0,0 +1,14 @@ +-- Boolean Types +-- https://ydb.tech/docs/ru/concepts/datatypes#boolean + +CREATE TABLE dt_boolean ( + id Serial, + a Bool, + PRIMARY KEY (id) +); + +CREATE TABLE dt_boolean_not_null ( + id Serial, + a Bool NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/character.sql b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/character.sql new file mode 100644 index 0000000000..ee06b4ca31 --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/character.sql @@ -0,0 +1,17 @@ +-- Character and String Types +-- https://ydb.tech/docs/ru/concepts/datatypes#string + +CREATE TABLE dt_character ( + id Serial, + a String, + b Utf8, + PRIMARY KEY (id) +); + +CREATE TABLE dt_character_not_null ( + id Serial, + a String NOT NULL, + b Utf8 NOT NULL, + PRIMARY KEY (id) +); + diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/datetime.sql b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/datetime.sql new file mode 100644 index 0000000000..be2312caea --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/datetime.sql @@ -0,0 +1,36 @@ +-- Date and Time Types +-- https://ydb.tech/docs/ru/concepts/datatypes#datetime + +CREATE TABLE dt_datetime ( + id Serial, + a Date, + b Date32, + c Datetime, + d Datetime64, + e Timestamp, + f Timestamp64, + g Interval, + h Interval64, + -- Timezone types + i TzDate32, + j TzDateTime64, + k TzTimestamp64, + PRIMARY KEY (id) +); + +CREATE TABLE dt_datetime_not_null ( + id Serial, + a Date NOT NULL, + b Date32 NOT NULL, + c Datetime NOT NULL, + d Datetime64 NOT NULL, + e Timestamp NOT NULL, + f Timestamp64 NOT NULL, + g Interval NOT NULL, + h Interval64 NOT NULL, + -- Timezone types + i TzDate32 NOT NULL, + j TzDateTime64 NOT NULL, + k TzTimestamp64 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/json.sql b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/json.sql new file mode 100644 index 0000000000..89d264a6bc --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/json.sql @@ -0,0 +1,18 @@ +-- JSON and Document Types +-- https://ydb.tech/docs/ru/concepts/datatypes#json + +CREATE TABLE dt_json ( + id Serial, + a Json, + b JsonDocument, + c Yson, + PRIMARY KEY (id) +); + +CREATE TABLE dt_json_not_null ( + id Serial, + a Json NOT NULL, + b JsonDocument NOT NULL, + c Yson NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/numeric.sql b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/numeric.sql new file mode 100644 index 0000000000..1cc688315c --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/numeric.sql @@ -0,0 +1,57 @@ +-- Numeric Types +-- https://ydb.tech/docs/ru/concepts/datatypes#numeric + +CREATE TABLE dt_numeric ( + id Serial, + -- Integer types + a Int8, + b Int16, + c Int32, + d Int64, + e Uint8, + f Uint16, + g Uint32, + h Uint64, + -- Floating point types + i Float, + j Double, + -- Decimal types + k Decimal(22, 9), + l Decimal(35, 0), + -- Serial types + n SmallSerial, + o Serial2, + p Serial, + q Serial4, + r Serial8, + s BigSerial, + PRIMARY KEY (id) +); + +CREATE TABLE dt_numeric_not_null ( + id Serial, + -- Integer types + a Int8 NOT NULL, + b Int16 NOT NULL, + c Int32 NOT NULL, + d Int64 NOT NULL, + e Uint8 NOT NULL, + f Uint16 NOT NULL, + g Uint32 NOT NULL, + h Uint64 NOT NULL, + -- Floating point types + i Float NOT NULL, + j Double NOT NULL, + -- Decimal types + k Decimal(22, 9) NOT NULL, + l Decimal(35, 0) NOT NULL, + -- Serial types + n SmallSerial NOT NULL, + o Serial2 NOT NULL, + p Serial NOT NULL, + q Serial4 NOT NULL, + r Serial8 NOT NULL, + s BigSerial NOT NULL, + PRIMARY KEY (id) +); + diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/query.sql b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/query.sql new file mode 100644 index 0000000000..56b89671a0 --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/query.sql @@ -0,0 +1,3 @@ + +-- name: Test :one +SELECT 1; diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/uuid.sql b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/uuid.sql new file mode 100644 index 0000000000..00e4faa8d2 --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sql/uuid.sql @@ -0,0 +1,14 @@ +-- UUID Types +-- https://ydb.tech/docs/ru/concepts/datatypes#uuid + +CREATE TABLE dt_uuid ( + id Serial, + a Uuid, + PRIMARY KEY (id) +); + +CREATE TABLE dt_uuid_not_null ( + id Serial, + a Uuid NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..b1c079f1a8 --- /dev/null +++ b/internal/endtoend/testdata/datatype/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "datatype", + "schema": "sql", + "queries": "sql/query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/db.go b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/ddl_alter_table_add_column/ydb/stdlib/go/models.go b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..b1240a9d27 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string + Baz *int32 + Bio *int32 + Foobar *string +} diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..3f59aec9b9 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, placeholder) + return err +} diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/query.sql b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/schema.sql b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..618375bf31 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE foo ( + bar Text NOT NULL, + PRIMARY KEY (bar) +); + +ALTER TABLE foo ADD COLUMN baz Int32; +ALTER TABLE foo ADD COLUMN bio Int32; +ALTER TABLE foo ADD COLUMN foobar Text diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..b1240a9d27 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string + Baz *int32 + Bio *int32 + Foobar *string +} diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..eb1e7ea3e2 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,25 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, placeholder, opts...) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..7781142268 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE foo ( + bar Text NOT NULL, + PRIMARY KEY (bar) +); + +ALTER TABLE foo ADD COLUMN baz Int32; +ALTER TABLE foo ADD COLUMN bio Int32; +ALTER TABLE foo ADD COLUMN foobar Text; diff --git a/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..02f4bf76c3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_add_column/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/db.go b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/ddl_alter_table_alter_type/ydb/stdlib/go/models.go b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..751b7df65d --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "time" +) + +type Foo struct { + Bar *time.Time +} diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..3f59aec9b9 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, placeholder) + return err +} diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/query.sql b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/schema.sql b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..3f8b1527c3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE foo ( + bar Text, + PRIMARY KEY (bar) +); + +-- YDB doesn't support ALTER COLUMN TYPE, so we use DROP COLUMN + ADD COLUMN +ALTER TABLE foo DROP COLUMN bar; +ALTER TABLE foo ADD COLUMN bar Timestamp; diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..751b7df65d --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "time" +) + +type Foo struct { + Bar *time.Time +} diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..eb1e7ea3e2 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,25 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, placeholder, opts...) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..3f8b1527c3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE foo ( + bar Text, + PRIMARY KEY (bar) +); + +-- YDB doesn't support ALTER COLUMN TYPE, so we use DROP COLUMN + ADD COLUMN +ALTER TABLE foo DROP COLUMN bar; +ALTER TABLE foo ADD COLUMN bar Timestamp; diff --git a/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..02f4bf76c3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_alter_type/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/db.go b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/ddl_alter_table_column_drop_not_null/ydb/go/models.go b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/models.go new file mode 100644 index 0000000000..2e5f929eef --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar *string + Baz *string +} diff --git a/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/query.sql.go b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/query.sql.go new file mode 100644 index 0000000000..3f59aec9b9 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, placeholder) + return err +} diff --git a/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/query.sql b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/schema.sql b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/schema.sql new file mode 100644 index 0000000000..1bb0ef7731 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE foo ( + bar Text NOT NULL, + baz Text NOT NULL, + PRIMARY KEY (bar) +); + +ALTER TABLE foo ALTER COLUMN bar DROP NOT NULL; +ALTER TABLE foo ALTER COLUMN baz DROP NOT NULL; diff --git a/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/sqlc.json b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_column_drop_not_null/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/db.go b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/ddl_alter_table_drop_column/ydb/go/models.go b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/models.go new file mode 100644 index 0000000000..0cd442222e --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string +} diff --git a/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/query.sql.go b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/query.sql.go new file mode 100644 index 0000000000..1b0cf67985 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const placeholder = `-- name: Placeholder :exec +SELECT bar FROM foo +` + +func (q *Queries) Placeholder(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, placeholder) + return err +} diff --git a/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/query.sql b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/query.sql new file mode 100644 index 0000000000..92dc72524c --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT * FROM foo; diff --git a/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/schema.sql b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/schema.sql new file mode 100644 index 0000000000..1b6d025936 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE foo ( + bar Text, + baz Text, + PRIMARY KEY (bar) +); + +ALTER TABLE foo DROP COLUMN baz; diff --git a/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/sqlc.json b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_drop_column/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/db.go b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/ddl_alter_table_rename/ydb/stdlib/go/models.go b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..c9b3eabe96 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Arena struct { + Name string +} diff --git a/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..0002035dff --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/go/query.sql.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const placeholder = `-- name: Placeholder :many +SELECT name FROM arenas +` + +func (q *Queries) Placeholder(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, placeholder) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + return nil, err + } + items = append(items, name) + } + 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/ddl_alter_table_rename/ydb/stdlib/query.sql b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/query.sql new file mode 100644 index 0000000000..bf777e0cb6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +/* name: Placeholder :many */ +SELECT * FROM arenas; diff --git a/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/schema.sql b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..6063ebc54d --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE venues ( + name Text, + PRIMARY KEY (name) +); + +ALTER TABLE venues RENAME TO arenas; diff --git a/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..c9b3eabe96 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Arena struct { + Name string +} diff --git a/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..bc97bc28a3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,39 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const placeholder = `-- name: Placeholder :many +SELECT name FROM arenas +` + +func (q *Queries) Placeholder(ctx context.Context, opts ...query.ExecuteOption) ([]string, error) { + result, err := q.db.QueryResultSet(ctx, placeholder, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var name string + if err := row.Scan(&name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, name) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..bf777e0cb6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +/* name: Placeholder :many */ +SELECT * FROM arenas; diff --git a/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..6063ebc54d --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE venues ( + name Text, + PRIMARY KEY (name) +); + +ALTER TABLE venues RENAME TO arenas; diff --git a/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..02f4bf76c3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_alter_table_rename/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_create_table/ydb/go/db.go b/internal/endtoend/testdata/ddl_create_table/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/ddl_create_table/ydb/go/models.go b/internal/endtoend/testdata/ddl_create_table/ydb/go/models.go new file mode 100644 index 0000000000..88bad93cfa --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Venue struct { + Name string +} diff --git a/internal/endtoend/testdata/ddl_create_table/ydb/go/query.sql.go b/internal/endtoend/testdata/ddl_create_table/ydb/go/query.sql.go new file mode 100644 index 0000000000..3f59aec9b9 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table/ydb/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, placeholder) + return err +} diff --git a/internal/endtoend/testdata/ddl_create_table/ydb/query.sql b/internal/endtoend/testdata/ddl_create_table/ydb/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_create_table/ydb/schema.sql b/internal/endtoend/testdata/ddl_create_table/ydb/schema.sql new file mode 100644 index 0000000000..f84b5e5ee9 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table/ydb/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE venues ( + name Text, + PRIMARY KEY (name) +); diff --git a/internal/endtoend/testdata/ddl_create_table/ydb/sqlc.json b/internal/endtoend/testdata/ddl_create_table/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/db.go b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/ddl_create_table_partition/ydb/stdlib/go/models.go b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..85b74b5396 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + ID string + OtherID string +} diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..3f59aec9b9 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, placeholder) + return err +} diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/query.sql b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/schema.sql b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..7d8598df14 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE foo ( + id Text NOT NULL, + other_id Text NOT NULL, + PRIMARY KEY (id) +) WITH ( + AUTO_PARTITIONING_BY_SIZE = ENABLED, + AUTO_PARTITIONING_PARTITION_SIZE_MB = 512 +); diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..85b74b5396 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + ID string + OtherID string +} diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..eb1e7ea3e2 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,25 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, placeholder, opts...) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..7d8598df14 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE foo ( + id Text NOT NULL, + other_id Text NOT NULL, + PRIMARY KEY (id) +) WITH ( + AUTO_PARTITIONING_BY_SIZE = ENABLED, + AUTO_PARTITIONING_PARTITION_SIZE_MB = 512 +); diff --git a/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..02f4bf76c3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_create_table_partition/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/go/db.go b/internal/endtoend/testdata/ddl_drop_table/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/ddl_drop_table/ydb/go/models.go b/internal/endtoend/testdata/ddl_drop_table/ydb/go/models.go new file mode 100644 index 0000000000..333ea43ea3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/go/query.sql.go b/internal/endtoend/testdata/ddl_drop_table/ydb/go/query.sql.go new file mode 100644 index 0000000000..3f59aec9b9 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, placeholder) + return err +} diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/db.go b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/ddl_drop_table/ydb/stdlib/go/models.go b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..333ea43ea3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..3f59aec9b9 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, placeholder) + return err +} diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/query.sql b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/schema.sql b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..1c2625ddf3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/schema.sql @@ -0,0 +1,17 @@ +CREATE TABLE venues ( + hi Text, + PRIMARY KEY (hi) +); +DROP TABLE venues; + +CREATE TABLE Authors ( + id Int32, + PRIMARY KEY (id) +); +DROP TABLE Authors; + +CREATE TABLE "Books" ( + id Int32, + PRIMARY KEY (id) +); +DROP TABLE "Books"; diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..333ea43ea3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..eb1e7ea3e2 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,25 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, placeholder, opts...) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..1c2625ddf3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,17 @@ +CREATE TABLE venues ( + hi Text, + PRIMARY KEY (hi) +); +DROP TABLE venues; + +CREATE TABLE Authors ( + id Int32, + PRIMARY KEY (id) +); +DROP TABLE Authors; + +CREATE TABLE "Books" ( + id Int32, + PRIMARY KEY (id) +); +DROP TABLE "Books"; diff --git a/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..02f4bf76c3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/db.go b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/ddl_drop_table_if_exists/ydb/stdlib/go/models.go b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..333ea43ea3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..3f59aec9b9 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, placeholder) + return err +} diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/query.sql b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/schema.sql b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..8bf587c771 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE venues ( + id Int32, + PRIMARY KEY (id) +); +DROP TABLE IF EXISTS venues; +DROP TABLE IF EXISTS venues; diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..333ea43ea3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..eb1e7ea3e2 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,25 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const placeholder = `-- name: Placeholder :exec +SELECT 1 +` + +func (q *Queries) Placeholder(ctx context.Context, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, placeholder, opts...) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..6520aef4b6 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: Placeholder :exec +SELECT 1; diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..8bf587c771 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE venues ( + id Int32, + PRIMARY KEY (id) +); +DROP TABLE IF EXISTS venues; +DROP TABLE IF EXISTS venues; diff --git a/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..02f4bf76c3 --- /dev/null +++ b/internal/endtoend/testdata/ddl_drop_table_if_exists/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk" + } + ] +} diff --git a/internal/endtoend/testdata/delete_from/ydb/stdlib/go/db.go b/internal/endtoend/testdata/delete_from/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/delete_from/ydb/stdlib/go/models.go b/internal/endtoend/testdata/delete_from/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..ef6e41447e --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + ID string +} diff --git a/internal/endtoend/testdata/delete_from/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/delete_from/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..2c1fd125ab --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/stdlib/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const deleteFrom = `-- name: DeleteFrom :exec +DELETE FROM foo WHERE id = $id +` + +func (q *Queries) DeleteFrom(ctx context.Context, id string) error { + _, err := q.db.ExecContext(ctx, deleteFrom, id) + return err +} diff --git a/internal/endtoend/testdata/delete_from/ydb/stdlib/query.sql b/internal/endtoend/testdata/delete_from/ydb/stdlib/query.sql new file mode 100644 index 0000000000..ecb05c7ddd --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: DeleteFrom :exec +DELETE FROM foo WHERE id = $id; diff --git a/internal/endtoend/testdata/delete_from/ydb/stdlib/schema.sql b/internal/endtoend/testdata/delete_from/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..ea2d8aa772 --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/stdlib/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo ( + id Utf8 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/delete_from/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/delete_from/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..ef6e41447e --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + ID string +} diff --git a/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..ffc914599c --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,30 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const deleteFrom = `-- name: DeleteFrom :exec +DELETE FROM foo WHERE id = $id +` + +func (q *Queries) DeleteFrom(ctx context.Context, id string, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Text(id) + err := q.db.Exec(ctx, deleteFrom, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..ecb05c7ddd --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: DeleteFrom :exec +DELETE FROM foo WHERE id = $id; diff --git a/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..ea2d8aa772 --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo ( + id Utf8 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/delete_from/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/db.go b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/emit_db_and_json_tags/ydb/stdlib/go/models.go b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..439baff3cf --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int32 `db:"id" json:"id"` + FirstName string `db:"first_name" json:"first_name"` + LastName *string `db:"last_name" json:"last_name"` + Age int32 `db:"age" json:"age"` +} diff --git a/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..5018df0e2a --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/go/query.sql.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getAll = `-- name: GetAll :many +SELECT id, first_name, last_name, age FROM users +` + +func (q *Queries) GetAll(ctx context.Context) ([]User, error) { + rows, err := q.db.QueryContext(ctx, getAll) + if err != nil { + return nil, err + } + defer rows.Close() + var items []User + for rows.Next() { + var i User + if err := rows.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/emit_db_and_json_tags/ydb/stdlib/query.sql b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/query.sql new file mode 100644 index 0000000000..237b20193b --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: GetAll :many +SELECT * FROM users; diff --git a/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/schema.sql b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..3e5d6c1619 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE users ( + id Serial, + first_name Text NOT NULL, + last_name Text, + age Int32 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..536f98a039 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/stdlib/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "emit_json_tags": true, + "emit_db_tags": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..439baff3cf --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int32 `db:"id" json:"id"` + FirstName string `db:"first_name" json:"first_name"` + LastName *string `db:"last_name" json:"last_name"` + Age int32 `db:"age" json:"age"` +} diff --git a/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..c975d37405 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,44 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const getAll = `-- name: GetAll :many +SELECT id, first_name, last_name, age FROM users +` + +func (q *Queries) GetAll(ctx context.Context, opts ...query.ExecuteOption) ([]User, error) { + result, err := q.db.QueryResultSet(ctx, getAll, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []User + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i User + if err := row.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..237b20193b --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: GetAll :many +SELECT * FROM users; diff --git a/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..3e5d6c1619 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE users ( + id Serial, + first_name Text NOT NULL, + last_name Text, + age Int32 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..27acb3fe8d --- /dev/null +++ b/internal/endtoend/testdata/emit_db_and_json_tags/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk", + "emit_json_tags": true, + "emit_db_tags": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/db.go b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/emit_db_tags/ydb/stdlib/go/models.go b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..9520de214b --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int32 `db:"id"` + FirstName string `db:"first_name"` + LastName *string `db:"last_name"` + Age int32 `db:"age"` +} diff --git a/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..5018df0e2a --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/go/query.sql.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getAll = `-- name: GetAll :many +SELECT id, first_name, last_name, age FROM users +` + +func (q *Queries) GetAll(ctx context.Context) ([]User, error) { + rows, err := q.db.QueryContext(ctx, getAll) + if err != nil { + return nil, err + } + defer rows.Close() + var items []User + for rows.Next() { + var i User + if err := rows.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/emit_db_tags/ydb/stdlib/query.sql b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/query.sql new file mode 100644 index 0000000000..237b20193b --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: GetAll :many +SELECT * FROM users; diff --git a/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/schema.sql b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..3e5d6c1619 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE users ( + id Serial, + first_name Text NOT NULL, + last_name Text, + age Int32 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..31a85fbf10 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/stdlib/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "emit_db_tags": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..9520de214b --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int32 `db:"id"` + FirstName string `db:"first_name"` + LastName *string `db:"last_name"` + Age int32 `db:"age"` +} diff --git a/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..c975d37405 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,44 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const getAll = `-- name: GetAll :many +SELECT id, first_name, last_name, age FROM users +` + +func (q *Queries) GetAll(ctx context.Context, opts ...query.ExecuteOption) ([]User, error) { + result, err := q.db.QueryResultSet(ctx, getAll, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []User + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i User + if err := row.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..237b20193b --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: GetAll :many +SELECT * FROM users; diff --git a/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..3e5d6c1619 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE users ( + id Serial, + first_name Text NOT NULL, + last_name Text, + age Int32 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..64b7dc7c26 --- /dev/null +++ b/internal/endtoend/testdata/emit_db_tags/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk", + "emit_db_tags": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_empty_slices/ydb/go/db.go b/internal/endtoend/testdata/emit_empty_slices/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/emit_empty_slices/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/emit_empty_slices/ydb/go/models.go b/internal/endtoend/testdata/emit_empty_slices/ydb/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/emit_empty_slices/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/emit_empty_slices/ydb/go/query.sql.go b/internal/endtoend/testdata/emit_empty_slices/ydb/go/query.sql.go new file mode 100644 index 0000000000..24ca1da9c1 --- /dev/null +++ b/internal/endtoend/testdata/emit_empty_slices/ydb/go/query.sql.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const listBar = `-- name: ListBar :many +SELECT id FROM bar +` + +func (q *Queries) ListBar(ctx context.Context) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, listBar) + if err != nil { + return nil, err + } + defer rows.Close() + items := []int32{} + for rows.Next() { + var id int32 + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + 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/emit_empty_slices/ydb/query.sql b/internal/endtoend/testdata/emit_empty_slices/ydb/query.sql new file mode 100644 index 0000000000..af1f130f18 --- /dev/null +++ b/internal/endtoend/testdata/emit_empty_slices/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: ListBar :many +SELECT * FROM bar; diff --git a/internal/endtoend/testdata/emit_empty_slices/ydb/schema.sql b/internal/endtoend/testdata/emit_empty_slices/ydb/schema.sql new file mode 100644 index 0000000000..6fc66ccc41 --- /dev/null +++ b/internal/endtoend/testdata/emit_empty_slices/ydb/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE bar ( + id Serial NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/emit_empty_slices/ydb/sqlc.json b/internal/endtoend/testdata/emit_empty_slices/ydb/sqlc.json new file mode 100644 index 0000000000..776fbccb73 --- /dev/null +++ b/internal/endtoend/testdata/emit_empty_slices/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "emit_empty_slices": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_exported_queries/ydb/go/db.go b/internal/endtoend/testdata/emit_exported_queries/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/emit_exported_queries/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/emit_exported_queries/ydb/go/models.go b/internal/endtoend/testdata/emit_exported_queries/ydb/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/emit_exported_queries/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/emit_exported_queries/ydb/go/query.sql.go b/internal/endtoend/testdata/emit_exported_queries/ydb/go/query.sql.go new file mode 100644 index 0000000000..33db515ec9 --- /dev/null +++ b/internal/endtoend/testdata/emit_exported_queries/ydb/go/query.sql.go @@ -0,0 +1,24 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const UpdateBarID = `-- name: UpdateBarID :exec +UPDATE bar SET id = $new_id WHERE id = $old_id +` + +type UpdateBarIDParams struct { + NewID int32 + OldID int32 +} + +func (q *Queries) UpdateBarID(ctx context.Context, arg UpdateBarIDParams) error { + _, err := q.db.ExecContext(ctx, UpdateBarID, arg.NewID, arg.OldID) + return err +} diff --git a/internal/endtoend/testdata/emit_exported_queries/ydb/query.sql b/internal/endtoend/testdata/emit_exported_queries/ydb/query.sql new file mode 100644 index 0000000000..c03af084dd --- /dev/null +++ b/internal/endtoend/testdata/emit_exported_queries/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: UpdateBarID :exec +UPDATE bar SET id = $new_id WHERE id = $old_id; diff --git a/internal/endtoend/testdata/emit_exported_queries/ydb/schema.sql b/internal/endtoend/testdata/emit_exported_queries/ydb/schema.sql new file mode 100644 index 0000000000..6fc66ccc41 --- /dev/null +++ b/internal/endtoend/testdata/emit_exported_queries/ydb/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE bar ( + id Serial NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/emit_exported_queries/ydb/sqlc.json b/internal/endtoend/testdata/emit_exported_queries/ydb/sqlc.json new file mode 100644 index 0000000000..a7644386bd --- /dev/null +++ b/internal/endtoend/testdata/emit_exported_queries/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "emit_exported_queries": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/db.go b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/db.go new file mode 100644 index 0000000000..44139faf54 --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/db.go @@ -0,0 +1,24 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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() *Queries { + return &Queries{} +} + +type Queries struct { +} diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/models.go b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/models.go new file mode 100644 index 0000000000..1957832e2a --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int32 + FirstName string + LastName *string + Age int32 +} diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/query.sql.go b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/query.sql.go new file mode 100644 index 0000000000..a710fa5c85 --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/go/query.sql.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getAll = `-- name: GetAll :many +SELECT id, first_name, last_name, age FROM users +` + +func (q *Queries) GetAll(ctx context.Context, db DBTX) ([]User, error) { + rows, err := db.QueryContext(ctx, getAll) + if err != nil { + return nil, err + } + defer rows.Close() + var items []User + for rows.Next() { + var i User + if err := rows.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/emit_methods_with_db_argument/ydb/stdlib/go/db.go b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..44139faf54 --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/db.go @@ -0,0 +1,24 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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() *Queries { + return &Queries{} +} + +type Queries struct { +} diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/models.go b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..1957832e2a --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int32 + FirstName string + LastName *string + Age int32 +} diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..a710fa5c85 --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/go/query.sql.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getAll = `-- name: GetAll :many +SELECT id, first_name, last_name, age FROM users +` + +func (q *Queries) GetAll(ctx context.Context, db DBTX) ([]User, error) { + rows, err := db.QueryContext(ctx, getAll) + if err != nil { + return nil, err + } + defer rows.Close() + var items []User + for rows.Next() { + var i User + if err := rows.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/emit_methods_with_db_argument/ydb/stdlib/query.sql b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/query.sql new file mode 100644 index 0000000000..e2f85e2a9a --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +/* name: GetAll :many */ +SELECT * FROM users; diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/schema.sql b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..4b828255d1 --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE users ( + id Int32 NOT NULL, + first_name Text NOT NULL, + last_name Text, + age Int32 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..30c728a740 --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/stdlib/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "name": "querytest", + "path": "go", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "emit_methods_with_db_argument": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..918dcde7fc --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,25 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New() *Queries { + return &Queries{} +} + +type Queries struct { +} diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..1957832e2a --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int32 + FirstName string + LastName *string + Age int32 +} diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..6a3374d949 --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,44 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const getAll = `-- name: GetAll :many +SELECT id, first_name, last_name, age FROM users +` + +func (q *Queries) GetAll(ctx context.Context, db DBTX, opts ...query.ExecuteOption) ([]User, error) { + result, err := db.QueryResultSet(ctx, getAll, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []User + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i User + if err := row.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..e2f85e2a9a --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +/* name: GetAll :many */ +SELECT * FROM users; diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..4b828255d1 --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE users ( + id Int32 NOT NULL, + first_name Text NOT NULL, + last_name Text, + age Int32 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..6928d55ae9 --- /dev/null +++ b/internal/endtoend/testdata/emit_methods_with_db_argument/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "name": "querytest", + "path": "go", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk", + "emit_methods_with_db_argument": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/db.go b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..0a639a6476 --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package datatype + +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/emit_pointers_for_null_types/ydb/stdlib/go/models.go b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..d8deaf0cd3 --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/models.go @@ -0,0 +1,43 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package datatype + +import ( + "github.com/ydb-platform/ydb-go-sdk/v3/table/types" +) + +type DtNumeric struct { + A int8 + B *int16 + C *int32 + D *int64 + E *uint8 + F *uint16 + G *uint32 + H *uint64 + I *float32 + J *float64 + K *types.Decimal + L *int16 + M *int32 + N *int64 +} + +type DtNumericNotNull struct { + A int8 + B int16 + C int32 + D int64 + E uint8 + F uint16 + G uint32 + H uint64 + I float32 + J float64 + K types.Decimal + L int16 + M int32 + N int64 +} diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..4720927d0a --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/go/query.sql.go @@ -0,0 +1,21 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package datatype + +import ( + "context" +) + +const test = `-- name: Test :one +SELECT 1 +` + +func (q *Queries) Test(ctx context.Context) (int32, error) { + row := q.db.QueryRowContext(ctx, test) + var column_1 int32 + err := row.Scan(&column_1) + return column_1, err +} diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/query.sql b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/query.sql new file mode 100644 index 0000000000..9da604b57e --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: Test :one +SELECT 1; diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/schema.sql b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..fc1760482a --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/schema.sql @@ -0,0 +1,36 @@ +-- Numeric Types for YDB +CREATE TABLE dt_numeric ( + a Int8, + b Int16, + c Int32, + d Int64, + e Uint8, + f Uint16, + g Uint32, + h Uint64, + i Float, + j Double, + k Decimal(10, 2), + l SmallSerial, + m Serial, + n BigSerial, + PRIMARY KEY (a) +); + +CREATE TABLE dt_numeric_not_null ( + a Int8 NOT NULL, + b Int16 NOT NULL, + c Int32 NOT NULL, + d Int64 NOT NULL, + e Uint8 NOT NULL, + f Uint16 NOT NULL, + g Uint32 NOT NULL, + h Uint64 NOT NULL, + i Float NOT NULL, + j Double NOT NULL, + k Decimal(10, 2) NOT NULL, + l SmallSerial NOT NULL, + m Serial NOT NULL, + n BigSerial NOT NULL, + PRIMARY KEY (a) +); diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..2544301e31 --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/stdlib/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "datatype", + "schema": "schema.sql", + "queries": "query.sql", + "emit_pointers_for_null_types": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..2e928799e1 --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package datatype + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..d8deaf0cd3 --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,43 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package datatype + +import ( + "github.com/ydb-platform/ydb-go-sdk/v3/table/types" +) + +type DtNumeric struct { + A int8 + B *int16 + C *int32 + D *int64 + E *uint8 + F *uint16 + G *uint32 + H *uint64 + I *float32 + J *float64 + K *types.Decimal + L *int16 + M *int32 + N *int64 +} + +type DtNumericNotNull struct { + A int8 + B int16 + C int32 + D int64 + E uint8 + F uint16 + G uint32 + H uint64 + I float32 + J float64 + K types.Decimal + L int16 + M int32 + N int64 +} diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..7024a3fff1 --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,30 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package datatype + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const test = `-- name: Test :one +SELECT 1 +` + +func (q *Queries) Test(ctx context.Context, opts ...query.ExecuteOption) (int32, error) { + row, err := q.db.QueryRow(ctx, test, opts...) + var column_1 int32 + if err != nil { + return column_1, xerrors.WithStackTrace(err) + } + err = row.Scan(&column_1) + if err != nil { + return column_1, xerrors.WithStackTrace(err) + } + return column_1, nil +} diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..9da604b57e --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: Test :one +SELECT 1; diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..fc1760482a --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,36 @@ +-- Numeric Types for YDB +CREATE TABLE dt_numeric ( + a Int8, + b Int16, + c Int32, + d Int64, + e Uint8, + f Uint16, + g Uint32, + h Uint64, + i Float, + j Double, + k Decimal(10, 2), + l SmallSerial, + m Serial, + n BigSerial, + PRIMARY KEY (a) +); + +CREATE TABLE dt_numeric_not_null ( + a Int8 NOT NULL, + b Int16 NOT NULL, + c Int32 NOT NULL, + d Int64 NOT NULL, + e Uint8 NOT NULL, + f Uint16 NOT NULL, + g Uint32 NOT NULL, + h Uint64 NOT NULL, + i Float NOT NULL, + j Double NOT NULL, + k Decimal(10, 2) NOT NULL, + l SmallSerial NOT NULL, + m Serial NOT NULL, + n BigSerial NOT NULL, + PRIMARY KEY (a) +); diff --git a/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..aec4f79043 --- /dev/null +++ b/internal/endtoend/testdata/emit_pointers_for_null_types/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "datatype", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk", + "emit_pointers_for_null_types": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/db.go b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/emit_result_and_params_struct_pointers/ydb/stdlib/go/models.go b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..0f9b3aeb29 --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A int32 + B *int32 +} diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/querier.go b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/querier.go new file mode 100644 index 0000000000..6224355ad4 --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/querier.go @@ -0,0 +1,17 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" +) + +type Querier interface { + GetAll(ctx context.Context) ([]*Foo, error) + GetAllAByB(ctx context.Context, b *int32) ([]int32, error) + GetOne(ctx context.Context, arg *GetOneParams) (*Foo, error) +} + +var _ Querier = (*Queries)(nil) diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..c4cdaba94a --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/go/query.sql.go @@ -0,0 +1,80 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getAll = `-- name: GetAll :many +SELECT a, b FROM foo +` + +func (q *Queries) GetAll(ctx context.Context) ([]*Foo, error) { + rows, err := q.db.QueryContext(ctx, getAll) + if err != nil { + return nil, err + } + defer rows.Close() + var items []*Foo + for rows.Next() { + var i Foo + if err := rows.Scan(&i.A, &i.B); err != nil { + return nil, err + } + items = append(items, &i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getAllAByB = `-- name: GetAllAByB :many +SELECT a FROM foo WHERE b = $b +` + +func (q *Queries) GetAllAByB(ctx context.Context, b *int32) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, getAllAByB, b) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var a int32 + if err := rows.Scan(&a); err != nil { + return nil, err + } + items = append(items, a) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getOne = `-- name: GetOne :one +SELECT a, b FROM foo WHERE a = $a AND b = $b LIMIT 1 +` + +type GetOneParams struct { + A int32 + B *int32 +} + +func (q *Queries) GetOne(ctx context.Context, arg *GetOneParams) (*Foo, error) { + row := q.db.QueryRowContext(ctx, getOne, arg.A, arg.B) + var i Foo + err := row.Scan(&i.A, &i.B) + return &i, err +} diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/query.sql b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/query.sql new file mode 100644 index 0000000000..04578be86b --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/query.sql @@ -0,0 +1,8 @@ +/* name: GetOne :one */ +SELECT * FROM foo WHERE a = $a AND b = $b LIMIT 1; + +/* name: GetAll :many */ +SELECT * FROM foo; + +/* name: GetAllAByB :many */ +SELECT a FROM foo WHERE b = $b; diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/schema.sql b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..9541c7f9a9 --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + a Int32, + b Int32, + PRIMARY KEY (a) +); diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..5b0e95bcd0 --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/stdlib/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "name": "querytest", + "path": "go", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "emit_interface": true, + "emit_result_struct_pointers": true, + "emit_params_struct_pointers": true + } + ] +} diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..0f9b3aeb29 --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A int32 + B *int32 +} diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/querier.go b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/querier.go new file mode 100644 index 0000000000..c7680cd56e --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/querier.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type Querier interface { + GetAll(ctx context.Context, opts ...query.ExecuteOption) ([]*Foo, error) + GetAllAByB(ctx context.Context, b *int32, opts ...query.ExecuteOption) ([]int32, error) + GetOne(ctx context.Context, arg *GetOneParams, opts ...query.ExecuteOption) (*Foo, error) +} + +var _ Querier = (*Queries)(nil) diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..7c5ec17d00 --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,97 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const getAll = `-- name: GetAll :many +SELECT a, b FROM foo +` + +func (q *Queries) GetAll(ctx context.Context, opts ...query.ExecuteOption) ([]*Foo, error) { + result, err := q.db.QueryResultSet(ctx, getAll, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []*Foo + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Foo + if err := row.Scan(&i.A, &i.B); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, &i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const getAllAByB = `-- name: GetAllAByB :many +SELECT a FROM foo WHERE b = $b +` + +func (q *Queries) GetAllAByB(ctx context.Context, b *int32, opts ...query.ExecuteOption) ([]int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$b").BeginOptional().Int32(b).EndOptional() + result, err := q.db.QueryResultSet(ctx, getAllAByB, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []int32 + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var a int32 + if err := row.Scan(&a); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, a) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const getOne = `-- name: GetOne :one +SELECT a, b FROM foo WHERE a = $a AND b = $b LIMIT 1 +` + +type GetOneParams struct { + A int32 + B *int32 +} + +func (q *Queries) GetOne(ctx context.Context, arg *GetOneParams, opts ...query.ExecuteOption) (*Foo, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$a").Int32(arg.A) + parameters = parameters.Param("$b").BeginOptional().Int32(arg.B).EndOptional() + row, err := q.db.QueryRow(ctx, getOne, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i Foo + if err != nil { + return &i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.A, &i.B) + if err != nil { + return &i, xerrors.WithStackTrace(err) + } + return &i, nil +} diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..04578be86b --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,8 @@ +/* name: GetOne :one */ +SELECT * FROM foo WHERE a = $a AND b = $b LIMIT 1; + +/* name: GetAll :many */ +SELECT * FROM foo; + +/* name: GetAllAByB :many */ +SELECT a FROM foo WHERE b = $b; diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..9541c7f9a9 --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + a Int32, + b Int32, + PRIMARY KEY (a) +); diff --git a/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..3851d32d76 --- /dev/null +++ b/internal/endtoend/testdata/emit_result_and_params_struct_pointers/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "name": "querytest", + "path": "go", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk", + "emit_interface": true, + "emit_result_struct_pointers": true, + "emit_params_struct_pointers": true + } + ] +} diff --git a/internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/db.go b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..cd5bbb8e08 --- /dev/null +++ b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package db + +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/exec_create_table/ydb/stdlib/go/models.go b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..32099017df --- /dev/null +++ b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package db diff --git a/internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..99717a9016 --- /dev/null +++ b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package db + +import ( + "context" +) + +const createTable = `-- name: CreateTable :exec +CREATE TABLE test (id Int32 NOT NULL) +` + +func (q *Queries) CreateTable(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, createTable) + return err +} diff --git a/internal/endtoend/testdata/exec_create_table/ydb/stdlib/query.sql b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/query.sql new file mode 100644 index 0000000000..d5bdb2a326 --- /dev/null +++ b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: CreateTable :exec +CREATE TABLE test (id Int32 NOT NULL); diff --git a/internal/endtoend/testdata/exec_create_table/ydb/stdlib/schema.sql b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/endtoend/testdata/exec_create_table/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..e0a4924d1d --- /dev/null +++ b/internal/endtoend/testdata/exec_create_table/ydb/stdlib/sqlc.json @@ -0,0 +1,17 @@ +{ + "version": "2", + "sql": [ + { + "queries": "query.sql", + "schema": "schema.sql", + "engine": "ydb", + "gen": { + "go": { + "out": "go", + "package": "db", + "sql_package": "database/sql" + } + } + } + ] +} diff --git a/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..54957882a0 --- /dev/null +++ b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package db + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..32099017df --- /dev/null +++ b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package db diff --git a/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..8eb032d217 --- /dev/null +++ b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,25 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package db + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const createTable = `-- name: CreateTable :exec +CREATE TABLE test (id Int32 NOT NULL) +` + +func (q *Queries) CreateTable(ctx context.Context, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, createTable, opts...) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..d5bdb2a326 --- /dev/null +++ b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: CreateTable :exec +CREATE TABLE test (id Int32 NOT NULL); diff --git a/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..01257035bd --- /dev/null +++ b/internal/endtoend/testdata/exec_create_table/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,17 @@ +{ + "version": "2", + "sql": [ + { + "queries": "query.sql", + "schema": "schema.sql", + "engine": "ydb", + "gen": { + "go": { + "out": "go", + "package": "db", + "sql_package": "ydb-go-sdk" + } + } + } + ] +} diff --git a/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/db.go b/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/exec_imports/ydb/stdlib/go/models.go b/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..c597b42998 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar int32 + Bars string +} diff --git a/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/querier.go b/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/querier.go new file mode 100644 index 0000000000..4ac6134bc7 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/querier.go @@ -0,0 +1,16 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" +) + +type Querier interface { + Bar(ctx context.Context) error + Bars(ctx context.Context) error +} + +var _ Querier = (*Queries)(nil) diff --git a/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..56f78eddb9 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/stdlib/go/query.sql.go @@ -0,0 +1,30 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const bar = `-- name: Bar :exec +SELECT bar +FROM foo +` + +func (q *Queries) Bar(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, bar) + return err +} + +const bars = `-- name: Bars :exec +SELECT bars +FROM foo +` + +func (q *Queries) Bars(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, bars) + return err +} diff --git a/internal/endtoend/testdata/exec_imports/ydb/stdlib/query.sql b/internal/endtoend/testdata/exec_imports/ydb/stdlib/query.sql new file mode 100644 index 0000000000..b1be28c911 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/stdlib/query.sql @@ -0,0 +1,7 @@ +-- name: Bar :exec +SELECT bar +FROM foo; + +-- name: Bars :exec +SELECT bars +FROM foo; diff --git a/internal/endtoend/testdata/exec_imports/ydb/stdlib/schema.sql b/internal/endtoend/testdata/exec_imports/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..e82c0d4637 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/stdlib/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + bar Int32, + bars json NOT NULL, + PRIMARY KEY (bar) +); diff --git a/internal/endtoend/testdata/exec_imports/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/exec_imports/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..5d726403da --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/stdlib/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "emit_interface": true + } + ] +} diff --git a/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..c597b42998 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar int32 + Bars string +} diff --git a/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/querier.go b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/querier.go new file mode 100644 index 0000000000..75f58a2ec8 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/querier.go @@ -0,0 +1,18 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type Querier interface { + Bar(ctx context.Context, opts ...query.ExecuteOption) error + Bars(ctx context.Context, opts ...query.ExecuteOption) error +} + +var _ Querier = (*Queries)(nil) diff --git a/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..05ec43ba68 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,39 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const bar = `-- name: Bar :exec +SELECT bar +FROM foo +` + +func (q *Queries) Bar(ctx context.Context, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, bar, opts...) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} + +const bars = `-- name: Bars :exec +SELECT bars +FROM foo +` + +func (q *Queries) Bars(ctx context.Context, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, bars, opts...) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..b1be28c911 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,7 @@ +-- name: Bar :exec +SELECT bar +FROM foo; + +-- name: Bars :exec +SELECT bars +FROM foo; diff --git a/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..e82c0d4637 --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + bar Int32, + bars json NOT NULL, + PRIMARY KEY (bar) +); diff --git a/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..061cb6989b --- /dev/null +++ b/internal/endtoend/testdata/exec_imports/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "emit_interface": true + } + ] +} diff --git a/internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/db.go b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/func_call_cast/ydb/stdlib/go/models.go b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..333ea43ea3 --- /dev/null +++ b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest diff --git a/internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..31538e5453 --- /dev/null +++ b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/go/query.sql.go @@ -0,0 +1,21 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const demo = `-- name: Demo :one +SELECT Cast(Length("hello") AS Int32) AS col1 +` + +func (q *Queries) Demo(ctx context.Context) (int32, error) { + row := q.db.QueryRowContext(ctx, demo) + var col1 int32 + err := row.Scan(&col1) + return col1, err +} diff --git a/internal/endtoend/testdata/func_call_cast/ydb/stdlib/query.sql b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/query.sql new file mode 100644 index 0000000000..b592d92d3c --- /dev/null +++ b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: Demo :one +SELECT Cast(Length("hello") AS Int32) AS col1; diff --git a/internal/endtoend/testdata/func_call_cast/ydb/stdlib/schema.sql b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/endtoend/testdata/func_call_cast/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/func_call_cast/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..333ea43ea3 --- /dev/null +++ b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,5 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest diff --git a/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..3c33e43990 --- /dev/null +++ b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,30 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const demo = `-- name: Demo :one +SELECT Cast(Length("hello") AS Int32) AS col1 +` + +func (q *Queries) Demo(ctx context.Context, opts ...query.ExecuteOption) (int32, error) { + row, err := q.db.QueryRow(ctx, demo, opts...) + var col1 int32 + if err != nil { + return col1, xerrors.WithStackTrace(err) + } + err = row.Scan(&col1) + if err != nil { + return col1, xerrors.WithStackTrace(err) + } + return col1, nil +} diff --git a/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..b592d92d3c --- /dev/null +++ b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: Demo :one +SELECT Cast(Length("hello") AS Int32) AS col1; diff --git a/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..e69de29bb2 diff --git a/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/func_call_cast/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/func_match_types/ydb/go/db.go b/internal/endtoend/testdata/func_match_types/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/func_match_types/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/func_match_types/ydb/go/models.go b/internal/endtoend/testdata/func_match_types/ydb/go/models.go new file mode 100644 index 0000000000..eb64577fc3 --- /dev/null +++ b/internal/endtoend/testdata/func_match_types/ydb/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Book struct { + ID int32 + Title string + Author string + Pages int32 +} diff --git a/internal/endtoend/testdata/func_match_types/ydb/go/query.sql.go b/internal/endtoend/testdata/func_match_types/ydb/go/query.sql.go new file mode 100644 index 0000000000..1d2d434c7a --- /dev/null +++ b/internal/endtoend/testdata/func_match_types/ydb/go/query.sql.go @@ -0,0 +1,45 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const authorPages = `-- name: AuthorPages :many +SELECT author, Count(title) AS num_books, CAST(Sum(pages) AS Int32) AS total_pages +FROM books +GROUP BY author +` + +type AuthorPagesRow struct { + Author string + NumBooks uint64 + TotalPages int32 +} + +func (q *Queries) AuthorPages(ctx context.Context) ([]AuthorPagesRow, error) { + rows, err := q.db.QueryContext(ctx, authorPages) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AuthorPagesRow + for rows.Next() { + var i AuthorPagesRow + if err := rows.Scan(&i.Author, &i.NumBooks, &i.TotalPages); err != nil { + return nil, err + } + items = append(items, i) + } + 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/func_match_types/ydb/query.sql b/internal/endtoend/testdata/func_match_types/ydb/query.sql new file mode 100644 index 0000000000..35833d8fc1 --- /dev/null +++ b/internal/endtoend/testdata/func_match_types/ydb/query.sql @@ -0,0 +1,6 @@ +-- name: AuthorPages :many +SELECT author, Count(title) AS num_books, CAST(Sum(pages) AS Int32) AS total_pages +FROM books +GROUP BY author; + + diff --git a/internal/endtoend/testdata/func_match_types/ydb/schema.sql b/internal/endtoend/testdata/func_match_types/ydb/schema.sql new file mode 100644 index 0000000000..c2f82c5975 --- /dev/null +++ b/internal/endtoend/testdata/func_match_types/ydb/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE books ( + id Int32, + title Text NOT NULL, + author Text NOT NULL, + pages Int32 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/func_match_types/ydb/sqlc.json b/internal/endtoend/testdata/func_match_types/ydb/sqlc.json new file mode 100644 index 0000000000..8dc3083c5d --- /dev/null +++ b/internal/endtoend/testdata/func_match_types/ydb/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/func_return_table/ydb/go/db.go b/internal/endtoend/testdata/func_return_table/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/func_return_table/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/func_return_table/ydb/go/models.go b/internal/endtoend/testdata/func_return_table/ydb/go/models.go new file mode 100644 index 0000000000..d5beec506b --- /dev/null +++ b/internal/endtoend/testdata/func_return_table/ydb/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Account struct { + ID int64 + Username string + Password string +} diff --git a/internal/endtoend/testdata/func_return_table/ydb/go/query.sql.go b/internal/endtoend/testdata/func_return_table/ydb/go/query.sql.go new file mode 100644 index 0000000000..c49e94f9dc --- /dev/null +++ b/internal/endtoend/testdata/func_return_table/ydb/go/query.sql.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const foo = `-- name: Foo :one +SELECT id, bebra FROM AS_TABLE($table) AS t(id, bebra) +` + +type FooRow struct { + ID interface{} + Bebra interface{} +} + +func (q *Queries) Foo(ctx context.Context, table interface{}) (FooRow, error) { + row := q.db.QueryRowContext(ctx, foo, table) + var i FooRow + err := row.Scan(&i.ID, &i.Bebra) + return i, err +} diff --git a/internal/endtoend/testdata/func_return_table/ydb/query.sql b/internal/endtoend/testdata/func_return_table/ydb/query.sql new file mode 100644 index 0000000000..184c63bedd --- /dev/null +++ b/internal/endtoend/testdata/func_return_table/ydb/query.sql @@ -0,0 +1,4 @@ +-- name: Foo :one +SELECT id, bebra FROM AS_TABLE($table) AS t(id, bebra); + + diff --git a/internal/endtoend/testdata/func_return_table/ydb/schema.sql b/internal/endtoend/testdata/func_return_table/ydb/schema.sql new file mode 100644 index 0000000000..4372437cd9 --- /dev/null +++ b/internal/endtoend/testdata/func_return_table/ydb/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE accounts ( + id BigSerial, + username Text NOT NULL, + password Text NOT NULL, + PRIMARY KEY (id) +); + + diff --git a/internal/endtoend/testdata/func_return_table/ydb/sqlc.json b/internal/endtoend/testdata/func_return_table/ydb/sqlc.json new file mode 100644 index 0000000000..8dc3083c5d --- /dev/null +++ b/internal/endtoend/testdata/func_return_table/ydb/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/go.mod b/internal/endtoend/testdata/go.mod index e2a7ea704b..4d94c38024 100644 --- a/internal/endtoend/testdata/go.mod +++ b/internal/endtoend/testdata/go.mod @@ -1,35 +1,45 @@ module github.com/sqlc-dev/sqlc/endtoend -go 1.18 +go 1.23.0 require ( github.com/go-sql-driver/mysql v1.7.0 github.com/gofrs/uuid v4.0.0+incompatible - github.com/google/uuid v1.3.0 + github.com/google/uuid v1.6.0 github.com/hexon/mysqltsv v0.1.0 github.com/jackc/pgconn v1.5.1-0.20200601181101-fa742c524853 github.com/jackc/pgtype v1.6.2 github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904 github.com/jackc/pgx/v5 v5.4.3 github.com/lib/pq v1.9.0 + github.com/pgvector/pgvector-go v0.1.1 github.com/sqlc-dev/pqtype v0.2.0 github.com/sqlc-dev/sqlc-testdata v1.0.0 github.com/volatiletech/null/v8 v8.1.2 + github.com/ydb-platform/ydb-go-sdk/v3 v3.117.1 gopkg.in/guregu/null.v4 v4.0.0 ) require ( github.com/friendsofgo/errors v0.9.2 // indirect + github.com/golang-jwt/jwt/v4 v4.5.2 // indirect github.com/jackc/chunkreader/v2 v2.0.1 // indirect github.com/jackc/pgio v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgproto3/v2 v2.0.1 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect - github.com/pgvector/pgvector-go v0.1.1 // indirect + github.com/jonboulle/clockwork v0.5.0 // indirect github.com/volatiletech/inflect v0.0.1 // indirect github.com/volatiletech/randomize v0.0.1 // indirect github.com/volatiletech/strmangle v0.0.1 // indirect - golang.org/x/crypto v0.9.0 // indirect - golang.org/x/text v0.9.0 // indirect + github.com/ydb-platform/ydb-go-genproto v0.0.0-20250911135631-b3beddd517d9 // indirect + golang.org/x/crypto v0.33.0 // indirect + golang.org/x/net v0.35.0 // indirect + golang.org/x/sync v0.11.0 // indirect + golang.org/x/sys v0.30.0 // indirect + golang.org/x/text v0.22.0 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect + google.golang.org/grpc v1.69.4 // indirect + google.golang.org/protobuf v1.35.1 // indirect ) diff --git a/internal/endtoend/testdata/go.sum b/internal/endtoend/testdata/go.sum index a5819e0a3b..8b6231f9b5 100644 --- a/internal/endtoend/testdata/go.sum +++ b/internal/endtoend/testdata/go.sum @@ -1,4 +1,16 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= +github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= +github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= +github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= @@ -7,17 +19,62 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= +github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/friendsofgo/errors v0.9.2 h1:X6NYxef4efCBdwI7BgS820zFaN7Cphrmb+Pljdzjtgk= github.com/friendsofgo/errors v0.9.2/go.mod h1:yCvFW5AkDIL9qn7suHVLiI/gH228n7PC4Pn44IGoTOI= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-pg/pg/v10 v10.11.0 h1:CMKJqLgTrfpE/aOVeLdybezR2om071Vh38OLZjsyMI0= +github.com/go-pg/pg/v10 v10.11.0/go.mod h1:4BpHRoxE61y4Onpof3x1a2SQvi9c+q1dJnrNdMjsroA= +github.com/go-pg/zerochecker v0.2.0 h1:pp7f72c3DobMWOb2ErtZsnrPaSvHd2W4o9//8HtF4mU= +github.com/go-pg/zerochecker v0.2.0/go.mod h1:NJZ4wKL0NmTtz0GKCoJ8kym6Xn/EQzXRl2OnAe7MmDo= github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI= +github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= -github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hexon/mysqltsv v0.1.0 h1:48wYQlsPH8ZEkKAVCdsOYzMYAlEoevw8ZWD8rqYPdlg= github.com/hexon/mysqltsv v0.1.0/go.mod h1:p3vPBkpxebjHWF1bWKYNcXx5pFu+yAG89QZQEKSvVrY= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= @@ -45,8 +102,6 @@ github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1: github.com/jackc/pgproto3/v2 v2.0.1 h1:Rdjp4NFjwHnEslx2b66FfCI2S0LhO4itac3hXz6WX9M= github.com/jackc/pgproto3/v2 v2.0.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= -github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg= -github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= @@ -64,16 +119,16 @@ github.com/jackc/pgx/v4 v4.5.0/go.mod h1:EpAKPLdnTorwmPUUsqrPxy5fphV18j9q3wrfRXg github.com/jackc/pgx/v4 v4.6.1-0.20200510190926-94ba730bb1e9/go.mod h1:t3/cdRQl6fOLDxqtlyhe9UWgfIi9R8+8v8GKV5TRA/o= github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904 h1:SdGWuGg+Cpxq6Z+ArXt0nafaKeTvtKGEoW+yvycspUU= github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9sW1JMiNn0kdYBaLelIhw7Pg4qd+Vk6tw7Hg= -github.com/jackc/pgx/v5 v5.0.1 h1:JZu9othr7l8so2JMDAGeDUMXqERAuZpovyfl4H50tdg= -github.com/jackc/pgx/v5 v5.0.1/go.mod h1:JBbvW3Hdw77jKl9uJrEDATUZIFM2VFPzRq4RWIhkF4o= -github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU= -github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY= github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I= +github.com/jonboulle/clockwork v0.5.0/go.mod h1:3mZlmanh0g2NDKO5TWZVJAfofYk64M7XN3SzBPjZF60= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -101,6 +156,10 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/rekby/fixenv v0.6.1 h1:jUFiSPpajT4WY2cYuc++7Y1zWrnCxnovGCIX72PZniM= +github.com/rekby/fixenv v0.6.1/go.mod h1:/b5LRc06BYJtslRtHKxsPWFT/ySpHV+rWvzTg+XWk4c= +github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= @@ -123,7 +182,24 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo= +github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs= +github.com/uptrace/bun v1.1.12 h1:sOjDVHxNTuM6dNGaba0wUuz7KvDE1BmNu9Gqs2gJSXQ= +github.com/uptrace/bun v1.1.12/go.mod h1:NPG6JGULBeQ9IU6yHp7YGELRa5Agmd7ATZdz4tGZ6z0= +github.com/uptrace/bun/dialect/pgdialect v1.1.12 h1:m/CM1UfOkoBTglGO5CUTKnIKKOApOYxkcP2qn0F9tJk= +github.com/uptrace/bun/dialect/pgdialect v1.1.12/go.mod h1:Ij6WIxQILxLlL2frUBxUBOZJtLElD2QQNDcu/PWDHTc= +github.com/uptrace/bun/driver/pgdriver v1.1.12 h1:3rRWB1GK0psTJrHwxzNfEij2MLibggiLdTqjTtfHc1w= +github.com/uptrace/bun/driver/pgdriver v1.1.12/go.mod h1:ssYUP+qwSEgeDDS1xm2XBip9el1y9Mi5mTAvLoiADLM= +github.com/vmihailenco/bufpool v0.1.11 h1:gOq2WmBrq0i2yW5QJ16ykccQ4wH9UyEsgLm6czKAd94= +github.com/vmihailenco/bufpool v0.1.11/go.mod h1:AFf/MOy3l2CFTKbxwt0mp2MwnqjNEs5H/UxrkA5jxTQ= +github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= +github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= +github.com/vmihailenco/tagparser v0.1.2 h1:gnjoVuB/kljJ5wICEEOpx98oXMWPLj22G67Vbd1qPqc= +github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= +github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= +github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU= github.com/volatiletech/inflect v0.0.1/go.mod h1:IBti31tG6phkHitLlr5j7shC5SOo//x0AjDzaJU1PLA= github.com/volatiletech/null/v8 v8.1.2 h1:kiTiX1PpwvuugKwfvUNX/SU/5A2KGZMXfGD0DUHdKEI= @@ -132,10 +208,27 @@ github.com/volatiletech/randomize v0.0.1 h1:eE5yajattWqTB2/eN8df4dw+8jwAzBtbdo5s github.com/volatiletech/randomize v0.0.1/go.mod h1:GN3U0QYqfZ9FOJ67bzax1cqZ5q2xuj2mXrXBjWaRTlY= github.com/volatiletech/strmangle v0.0.1 h1:UKQoHmY6be/R3tSvD2nQYrH41k43OJkidwEiC74KIzk= github.com/volatiletech/strmangle v0.0.1/go.mod h1:F6RA6IkB5vq0yTG4GQ0UsbbRcl3ni9P76i+JrTBKFFg= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20250911135631-b3beddd517d9 h1:SKqSRP6/ocY2Z4twOqKEKxpmawVTHTvQiom7hrU6jt0= +github.com/ydb-platform/ydb-go-genproto v0.0.0-20250911135631-b3beddd517d9/go.mod h1:Er+FePu1dNUieD+XTMDduGpQuCPssK5Q4BjF+IIXJ3I= +github.com/ydb-platform/ydb-go-sdk/v3 v3.117.1 h1:SgYE74T+fo40xvJszWhK8IGS5GNjLcbYPzYL+6wsLGw= +github.com/ydb-platform/ydb-go-sdk/v3 v3.117.1/go.mod h1:IgDKkfYE4FyJilTRe2BTtaurb2EWdMIsQbO02UW3wKM= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= +go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY= +go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE= +go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE= +go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY= +go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk= +go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0= +go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc= +go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8= +go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys= +go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A= +go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= +go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= @@ -147,18 +240,36 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM= -golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= -golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus= +golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= +golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= +golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -169,17 +280,22 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= +golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= +golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= @@ -187,10 +303,41 @@ golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 h1:X58yt85/IXCx0Y3ZwN6sEIKZzQtDEYaBWrDvErdXrRE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= +google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= +google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A= +google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= @@ -198,6 +345,12 @@ gopkg.in/guregu/null.v4 v4.0.0 h1:1Wm3S1WEA2I26Kq+6vcW+w0gcDo44YKYD7YIEJNHDjg= gopkg.in/guregu/null.v4 v4.0.0/go.mod h1:YoQhUrADuG3i9WqesrCmpNRwm1ypAgSHYqoOcTu/JrI= gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +mellium.im/sasl v0.3.1 h1:wE0LW6g7U83vhvxjC1IY8DnXM+EU095yeo8XClvCdfo= +mellium.im/sasl v0.3.1/go.mod h1:xm59PUYpZHhgQ9ZqoJ5QaCqzWMi8IeS49dhp6plPCzw= diff --git a/internal/endtoend/testdata/having/ydb/go/db.go b/internal/endtoend/testdata/having/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/having/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/having/ydb/go/models.go b/internal/endtoend/testdata/having/ydb/go/models.go new file mode 100644 index 0000000000..857d2a81f2 --- /dev/null +++ b/internal/endtoend/testdata/having/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Weather struct { + City string + TempLo int32 +} diff --git a/internal/endtoend/testdata/having/ydb/go/query.sql.go b/internal/endtoend/testdata/having/ydb/go/query.sql.go new file mode 100644 index 0000000000..f29863cb3b --- /dev/null +++ b/internal/endtoend/testdata/having/ydb/go/query.sql.go @@ -0,0 +1,40 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const coldCities = `-- name: ColdCities :many +SELECT city +FROM weather +GROUP BY city +HAVING Max(temp_lo) < $max_temp +` + +func (q *Queries) ColdCities(ctx context.Context, maxTemp int32) ([]string, error) { + rows, err := q.db.QueryContext(ctx, coldCities, maxTemp) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var city string + if err := rows.Scan(&city); err != nil { + return nil, err + } + items = append(items, city) + } + 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/having/ydb/query.sql b/internal/endtoend/testdata/having/ydb/query.sql new file mode 100644 index 0000000000..a447b06fe9 --- /dev/null +++ b/internal/endtoend/testdata/having/ydb/query.sql @@ -0,0 +1,5 @@ +-- name: ColdCities :many +SELECT city +FROM weather +GROUP BY city +HAVING Max(temp_lo) < $max_temp; diff --git a/internal/endtoend/testdata/having/ydb/schema.sql b/internal/endtoend/testdata/having/ydb/schema.sql new file mode 100644 index 0000000000..71cd93e293 --- /dev/null +++ b/internal/endtoend/testdata/having/ydb/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE weather ( + city Text NOT NULL, + temp_lo Int32 NOT NULL, + PRIMARY KEY (city, temp_lo) +); + + diff --git a/internal/endtoend/testdata/having/ydb/sqlc.json b/internal/endtoend/testdata/having/ydb/sqlc.json new file mode 100644 index 0000000000..8dc3083c5d --- /dev/null +++ b/internal/endtoend/testdata/having/ydb/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/identical_tables/ydb/stdlib/go/db.go b/internal/endtoend/testdata/identical_tables/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/identical_tables/ydb/stdlib/go/models.go b/internal/endtoend/testdata/identical_tables/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..962e8d9e66 --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/stdlib/go/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID string +} + +type Foo struct { + ID string +} diff --git a/internal/endtoend/testdata/identical_tables/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/identical_tables/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..3d72df8d22 --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/stdlib/go/query.sql.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const identicalTable = `-- name: IdenticalTable :many +SELECT id FROM foo +` + +func (q *Queries) IdenticalTable(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, identicalTable) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + 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/identical_tables/ydb/stdlib/query.sql b/internal/endtoend/testdata/identical_tables/ydb/stdlib/query.sql new file mode 100644 index 0000000000..cf1b7c7f76 --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/stdlib/query.sql @@ -0,0 +1,4 @@ +-- name: IdenticalTable :many +SELECT * FROM foo; + + diff --git a/internal/endtoend/testdata/identical_tables/ydb/stdlib/schema.sql b/internal/endtoend/testdata/identical_tables/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..e639528f7e --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/stdlib/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE foo ( + id Text NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE bar ( + id Text NOT NULL, + PRIMARY KEY (id) +); + + diff --git a/internal/endtoend/testdata/identical_tables/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/identical_tables/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..8dc3083c5d --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/stdlib/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..962e8d9e66 --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID string +} + +type Foo struct { + ID string +} diff --git a/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..64020eff3f --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,39 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const identicalTable = `-- name: IdenticalTable :many +SELECT id FROM foo +` + +func (q *Queries) IdenticalTable(ctx context.Context, opts ...query.ExecuteOption) ([]string, error) { + result, err := q.db.QueryResultSet(ctx, identicalTable, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var id string + if err := row.Scan(&id); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, id) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..cf1b7c7f76 --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,4 @@ +-- name: IdenticalTable :many +SELECT * FROM foo; + + diff --git a/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..e639528f7e --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE foo ( + id Text NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE bar ( + id Text NOT NULL, + PRIMARY KEY (id) +); + + diff --git a/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..fa2f163564 --- /dev/null +++ b/internal/endtoend/testdata/identical_tables/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/in_union/ydb/go/db.go b/internal/endtoend/testdata/in_union/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/in_union/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/in_union/ydb/go/models.go b/internal/endtoend/testdata/in_union/ydb/go/models.go new file mode 100644 index 0000000000..7d54a419c4 --- /dev/null +++ b/internal/endtoend/testdata/in_union/ydb/go/models.go @@ -0,0 +1,21 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int32 + Name string + Bio *string +} + +type Book1 struct { + AuthorID int32 + Name *string +} + +type Book2 struct { + AuthorID int32 + Name *string +} diff --git a/internal/endtoend/testdata/in_union/ydb/go/query.sql.go b/internal/endtoend/testdata/in_union/ydb/go/query.sql.go new file mode 100644 index 0000000000..93ed41d0ee --- /dev/null +++ b/internal/endtoend/testdata/in_union/ydb/go/query.sql.go @@ -0,0 +1,38 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getAuthors = `-- name: GetAuthors :many +SELECT id, name, bio FROM authors +WHERE id IN (SELECT author_id FROM book1 UNION SELECT author_id FROM book2) +` + +func (q *Queries) GetAuthors(ctx context.Context) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, getAuthors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + 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/in_union/ydb/query.sql b/internal/endtoend/testdata/in_union/ydb/query.sql new file mode 100644 index 0000000000..eb50376d6d --- /dev/null +++ b/internal/endtoend/testdata/in_union/ydb/query.sql @@ -0,0 +1,5 @@ +-- name: GetAuthors :many +SELECT * FROM authors +WHERE id IN (SELECT author_id FROM book1 UNION SELECT author_id FROM book2); + + diff --git a/internal/endtoend/testdata/in_union/ydb/schema.sql b/internal/endtoend/testdata/in_union/ydb/schema.sql new file mode 100644 index 0000000000..666b6cff56 --- /dev/null +++ b/internal/endtoend/testdata/in_union/ydb/schema.sql @@ -0,0 +1,20 @@ +CREATE TABLE authors ( + id Int32, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); + +CREATE TABLE book1 ( + author_id Int32, + name Text, + PRIMARY KEY (author_id) +); + +CREATE TABLE book2 ( + author_id Int32, + name Text, + PRIMARY KEY (author_id) +); + + diff --git a/internal/endtoend/testdata/in_union/ydb/sqlc.json b/internal/endtoend/testdata/in_union/ydb/sqlc.json new file mode 100644 index 0000000000..8dc3083c5d --- /dev/null +++ b/internal/endtoend/testdata/in_union/ydb/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/inflection/ydb/go/db.go b/internal/endtoend/testdata/inflection/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/inflection/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/inflection/ydb/go/models.go b/internal/endtoend/testdata/inflection/ydb/go/models.go new file mode 100644 index 0000000000..dc018924d5 --- /dev/null +++ b/internal/endtoend/testdata/inflection/ydb/go/models.go @@ -0,0 +1,25 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Calorie struct { + ID string +} + +type Campus struct { + ID string +} + +type ProductMetadatum struct { + ID string +} + +type ProductMetum struct { + ID string +} + +type Student struct { + ID string +} diff --git a/internal/endtoend/testdata/inflection/ydb/go/query.sql.go b/internal/endtoend/testdata/inflection/ydb/go/query.sql.go new file mode 100644 index 0000000000..9dc173e9bc --- /dev/null +++ b/internal/endtoend/testdata/inflection/ydb/go/query.sql.go @@ -0,0 +1,145 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getProductMetadata = `-- name: GetProductMetadata :many +SELECT id FROM product_metadata +` + +func (q *Queries) GetProductMetadata(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, getProductMetadata) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listCalories = `-- name: ListCalories :many +SELECT id FROM calories +` + +func (q *Queries) ListCalories(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, listCalories) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listCampuses = `-- name: ListCampuses :many +SELECT id FROM campus +` + +func (q *Queries) ListCampuses(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, listCampuses) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listMetadata = `-- name: ListMetadata :many +SELECT id FROM product_meta +` + +func (q *Queries) ListMetadata(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, listMetadata) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listStudents = `-- name: ListStudents :many +SELECT id FROM students +` + +func (q *Queries) ListStudents(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, listStudents) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + 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/inflection/ydb/query.sql b/internal/endtoend/testdata/inflection/ydb/query.sql new file mode 100644 index 0000000000..447c307bbb --- /dev/null +++ b/internal/endtoend/testdata/inflection/ydb/query.sql @@ -0,0 +1,14 @@ +-- name: ListCampuses :many +SELECT * FROM campus; + +-- name: ListStudents :many +SELECT * FROM students; + +-- name: ListMetadata :many +SELECT * FROM product_meta; + +-- name: ListCalories :many +SELECT * FROM calories; + +-- name: GetProductMetadata :many +SELECT * FROM product_metadata; diff --git a/internal/endtoend/testdata/inflection/ydb/schema.sql b/internal/endtoend/testdata/inflection/ydb/schema.sql new file mode 100644 index 0000000000..a4a98cc84a --- /dev/null +++ b/internal/endtoend/testdata/inflection/ydb/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE campus (id Text NOT NULL, PRIMARY KEY (id)); +CREATE TABLE students (id Text NOT NULL, PRIMARY KEY (id)); +CREATE TABLE product_meta (id Text NOT NULL, PRIMARY KEY (id)); +CREATE TABLE calories (id Text NOT NULL, PRIMARY KEY (id)); +CREATE TABLE product_metadata (id Text NOT NULL, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/inflection/ydb/sqlc.json b/internal/endtoend/testdata/inflection/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/inflection/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/db.go b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/models.go b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/models.go new file mode 100644 index 0000000000..42c15bfccc --- /dev/null +++ b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/models.go @@ -0,0 +1,20 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 + Name string +} + +type Exclusions struct { + ID int32 + Name string +} + +type MyData struct { + ID int32 + Name string +} diff --git a/internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/query.sql.go b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/query.sql.go new file mode 100644 index 0000000000..d3afa916c8 --- /dev/null +++ b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/go/query.sql.go @@ -0,0 +1,77 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const deleteBarByID = `-- name: DeleteBarByID :one +DELETE FROM bars WHERE id = $id RETURNING id, name +` + +func (q *Queries) DeleteBarByID(ctx context.Context, id int32, opts ...query.ExecuteOption) (Bar, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int32(id) + row, err := q.db.QueryRow(ctx, deleteBarByID, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i Bar + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.ID, &i.Name) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const deleteExclusionByID = `-- name: DeleteExclusionByID :one +DELETE FROM exclusions WHERE id = $id RETURNING id, name +` + +func (q *Queries) DeleteExclusionByID(ctx context.Context, id int32, opts ...query.ExecuteOption) (Exclusions, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int32(id) + row, err := q.db.QueryRow(ctx, deleteExclusionByID, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i Exclusions + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.ID, &i.Name) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const deleteMyDataByID = `-- name: DeleteMyDataByID :one +DELETE FROM my_data WHERE id = $id RETURNING id, name +` + +func (q *Queries) DeleteMyDataByID(ctx context.Context, id int32, opts ...query.ExecuteOption) (MyData, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int32(id) + row, err := q.db.QueryRow(ctx, deleteMyDataByID, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i MyData + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.ID, &i.Name) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} diff --git a/internal/endtoend/testdata/inflection_exclude_table_names/ydb/query.sql b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/query.sql new file mode 100644 index 0000000000..3d160a3947 --- /dev/null +++ b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/query.sql @@ -0,0 +1,8 @@ +-- name: DeleteBarByID :one +DELETE FROM bars WHERE id = $id RETURNING id, name; + +-- name: DeleteMyDataByID :one +DELETE FROM my_data WHERE id = $id RETURNING id, name; + +-- name: DeleteExclusionByID :one +DELETE FROM exclusions WHERE id = $id RETURNING id, name; diff --git a/internal/endtoend/testdata/inflection_exclude_table_names/ydb/schema.sql b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/schema.sql new file mode 100644 index 0000000000..302c720b56 --- /dev/null +++ b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE bars (id Serial NOT NULL, name Text NOT NULL, PRIMARY KEY (id)); +CREATE TABLE my_data (id Serial NOT NULL, name Text NOT NULL, PRIMARY KEY (id)); +CREATE TABLE exclusions (id Serial NOT NULL, name Text NOT NULL, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/inflection_exclude_table_names/ydb/sqlc.json b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/sqlc.json new file mode 100644 index 0000000000..7b9622d67d --- /dev/null +++ b/internal/endtoend/testdata/inflection_exclude_table_names/ydb/sqlc.json @@ -0,0 +1,21 @@ +{ + "version": "2", + "sql": [ + { + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "gen": { + "go": { + "package": "querytest", + "sql_package": "ydb-go-sdk", + "out": "go", + "inflection_exclude_table_names": [ + "my_data", + "exclusions" + ] + } + } + } + ] +} diff --git a/internal/endtoend/testdata/insert_select/ydb/stdlib/go/db.go b/internal/endtoend/testdata/insert_select/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/insert_select/ydb/stdlib/go/models.go b/internal/endtoend/testdata/insert_select/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..16bc8a120c --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/stdlib/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + Name string + Ready bool +} + +type Foo struct { + Name string + Meta string +} diff --git a/internal/endtoend/testdata/insert_select/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/insert_select/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..b2d0d3733a --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/stdlib/go/query.sql.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const insertSelect = `-- name: InsertSelect :exec +INSERT INTO foo (name, meta) +SELECT name, $meta +FROM bar WHERE ready = $ready +` + +type InsertSelectParams struct { + Meta string + Ready bool +} + +func (q *Queries) InsertSelect(ctx context.Context, arg InsertSelectParams) error { + _, err := q.db.ExecContext(ctx, insertSelect, arg.Meta, arg.Ready) + return err +} diff --git a/internal/endtoend/testdata/insert_select/ydb/stdlib/query.sql b/internal/endtoend/testdata/insert_select/ydb/stdlib/query.sql new file mode 100644 index 0000000000..19e1221e64 --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/stdlib/query.sql @@ -0,0 +1,4 @@ +-- name: InsertSelect :exec +INSERT INTO foo (name, meta) +SELECT name, $meta +FROM bar WHERE ready = $ready; diff --git a/internal/endtoend/testdata/insert_select/ydb/stdlib/schema.sql b/internal/endtoend/testdata/insert_select/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..00888aff44 --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/stdlib/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE bar ( + name Utf8 NOT NULL, + ready Bool NOT NULL, + PRIMARY KEY (name) +); + +CREATE TABLE foo ( + name Utf8 NOT NULL, + meta Utf8 NOT NULL, + PRIMARY KEY (name) +); diff --git a/internal/endtoend/testdata/insert_select/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/insert_select/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..16bc8a120c --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + Name string + Ready bool +} + +type Foo struct { + Name string + Meta string +} diff --git a/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..2ee546c5c2 --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,38 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const insertSelect = `-- name: InsertSelect :exec +INSERT INTO foo (name, meta) +SELECT name, $meta +FROM bar WHERE ready = $ready +` + +type InsertSelectParams struct { + Meta string + Ready bool +} + +func (q *Queries) InsertSelect(ctx context.Context, arg InsertSelectParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$meta").Text(arg.Meta) + parameters = parameters.Param("$ready").Bool(arg.Ready) + err := q.db.Exec(ctx, insertSelect, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..19e1221e64 --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,4 @@ +-- name: InsertSelect :exec +INSERT INTO foo (name, meta) +SELECT name, $meta +FROM bar WHERE ready = $ready; diff --git a/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..00888aff44 --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE bar ( + name Utf8 NOT NULL, + ready Bool NOT NULL, + PRIMARY KEY (name) +); + +CREATE TABLE foo ( + name Utf8 NOT NULL, + meta Utf8 NOT NULL, + PRIMARY KEY (name) +); diff --git a/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/insert_select/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/insert_select_case/ydb/go/db.go b/internal/endtoend/testdata/insert_select_case/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/insert_select_case/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/insert_select_case/ydb/go/models.go b/internal/endtoend/testdata/insert_select_case/ydb/go/models.go new file mode 100644 index 0000000000..af16b72d5f --- /dev/null +++ b/internal/endtoend/testdata/insert_select_case/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Order struct { + ID int64 + Name *string +} diff --git a/internal/endtoend/testdata/insert_select_case/ydb/go/query.sql.go b/internal/endtoend/testdata/insert_select_case/ydb/go/query.sql.go new file mode 100644 index 0000000000..5641387ab1 --- /dev/null +++ b/internal/endtoend/testdata/insert_select_case/ydb/go/query.sql.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const insertOrders = `-- name: InsertOrders :exec +INSERT INTO orders (id, name) +SELECT id, CASE WHEN CAST($name_do_update AS Bool) THEN $name ELSE s.name END AS name +FROM orders s +` + +type InsertOrdersParams struct { + NameDoUpdate bool + Name *string +} + +func (q *Queries) InsertOrders(ctx context.Context, arg InsertOrdersParams) error { + _, err := q.db.ExecContext(ctx, insertOrders, arg.NameDoUpdate, arg.Name) + return err +} diff --git a/internal/endtoend/testdata/insert_select_case/ydb/query.sql b/internal/endtoend/testdata/insert_select_case/ydb/query.sql new file mode 100644 index 0000000000..bcf75b0524 --- /dev/null +++ b/internal/endtoend/testdata/insert_select_case/ydb/query.sql @@ -0,0 +1,4 @@ +-- name: InsertOrders :exec +INSERT INTO orders (id, name) +SELECT id, CASE WHEN CAST($name_do_update AS Bool) THEN $name ELSE s.name END AS name +FROM orders s; diff --git a/internal/endtoend/testdata/insert_select_case/ydb/schema.sql b/internal/endtoend/testdata/insert_select_case/ydb/schema.sql new file mode 100644 index 0000000000..3282c32f67 --- /dev/null +++ b/internal/endtoend/testdata/insert_select_case/ydb/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE orders( + id BigSerial, + name Text, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/insert_select_case/ydb/sqlc.json b/internal/endtoend/testdata/insert_select_case/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/insert_select_case/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/insert_select_param/ydb/go/db.go b/internal/endtoend/testdata/insert_select_param/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/insert_select_param/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/insert_select_param/ydb/go/models.go b/internal/endtoend/testdata/insert_select_param/ydb/go/models.go new file mode 100644 index 0000000000..93e9ce7933 --- /dev/null +++ b/internal/endtoend/testdata/insert_select_param/ydb/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int64 + Name string + Bio *string +} diff --git a/internal/endtoend/testdata/insert_select_param/ydb/go/query.sql.go b/internal/endtoend/testdata/insert_select_param/ydb/go/query.sql.go new file mode 100644 index 0000000000..714e7cdb97 --- /dev/null +++ b/internal/endtoend/testdata/insert_select_param/ydb/go/query.sql.go @@ -0,0 +1,27 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const insertSelect = `-- name: InsertSelect :exec +INSERT INTO authors (id, name, bio) +SELECT $id, a.name, a.bio +FROM authors a +WHERE a.name = $name +` + +type InsertSelectParams struct { + ID int64 + Name string +} + +func (q *Queries) InsertSelect(ctx context.Context, arg InsertSelectParams) error { + _, err := q.db.ExecContext(ctx, insertSelect, arg.ID, arg.Name) + return err +} diff --git a/internal/endtoend/testdata/insert_select_param/ydb/query.sql b/internal/endtoend/testdata/insert_select_param/ydb/query.sql new file mode 100644 index 0000000000..7e5ffbeaaa --- /dev/null +++ b/internal/endtoend/testdata/insert_select_param/ydb/query.sql @@ -0,0 +1,5 @@ +-- name: InsertSelect :exec +INSERT INTO authors (id, name, bio) +SELECT $id, a.name, a.bio +FROM authors a +WHERE a.name = $name; diff --git a/internal/endtoend/testdata/insert_select_param/ydb/schema.sql b/internal/endtoend/testdata/insert_select_param/ydb/schema.sql new file mode 100644 index 0000000000..2ff7655ba6 --- /dev/null +++ b/internal/endtoend/testdata/insert_select_param/ydb/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/insert_select_param/ydb/sqlc.json b/internal/endtoend/testdata/insert_select_param/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/insert_select_param/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/insert_values/ydb/stdlib/go/db.go b/internal/endtoend/testdata/insert_values/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/insert_values/ydb/stdlib/go/models.go b/internal/endtoend/testdata/insert_values/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..62cc9bebd0 --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string + B *int32 +} diff --git a/internal/endtoend/testdata/insert_values/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/insert_values/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..d39f5f54f0 --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/stdlib/go/query.sql.go @@ -0,0 +1,45 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const insertMultipleValues = `-- name: InsertMultipleValues :exec +INSERT INTO foo (a, b) VALUES ($a1, $b1), ($a2, $b2) +` + +type InsertMultipleValuesParams struct { + A1 string + B1 *int32 + A2 string + B2 *int32 +} + +func (q *Queries) InsertMultipleValues(ctx context.Context, arg InsertMultipleValuesParams) error { + _, err := q.db.ExecContext(ctx, insertMultipleValues, + arg.A1, + arg.B1, + arg.A2, + arg.B2, + ) + return err +} + +const insertValues = `-- name: InsertValues :exec +INSERT INTO foo (a, b) VALUES ($a, $b) +` + +type InsertValuesParams struct { + A string + B *int32 +} + +func (q *Queries) InsertValues(ctx context.Context, arg InsertValuesParams) error { + _, err := q.db.ExecContext(ctx, insertValues, arg.A, arg.B) + return err +} diff --git a/internal/endtoend/testdata/insert_values/ydb/stdlib/query.sql b/internal/endtoend/testdata/insert_values/ydb/stdlib/query.sql new file mode 100644 index 0000000000..72d8782410 --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/stdlib/query.sql @@ -0,0 +1,5 @@ +-- name: InsertValues :exec +INSERT INTO foo (a, b) VALUES ($a, $b); + +/* name: InsertMultipleValues :exec */ +INSERT INTO foo (a, b) VALUES ($a1, $b1), ($a2, $b2); diff --git a/internal/endtoend/testdata/insert_values/ydb/stdlib/schema.sql b/internal/endtoend/testdata/insert_values/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..72ffaed0a5 --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/stdlib/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (a Utf8, b Int32, PRIMARY KEY (a)); diff --git a/internal/endtoend/testdata/insert_values/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/insert_values/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..62cc9bebd0 --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string + B *int32 +} diff --git a/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..b4ef8d6917 --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,62 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const insertMultipleValues = `-- name: InsertMultipleValues :exec +INSERT INTO foo (a, b) VALUES ($a1, $b1), ($a2, $b2) +` + +type InsertMultipleValuesParams struct { + A1 string + B1 *int32 + A2 string + B2 *int32 +} + +func (q *Queries) InsertMultipleValues(ctx context.Context, arg InsertMultipleValuesParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$a1").Text(arg.A1) + parameters = parameters.Param("$b1").BeginOptional().Int32(arg.B1).EndOptional() + parameters = parameters.Param("$a2").Text(arg.A2) + parameters = parameters.Param("$b2").BeginOptional().Int32(arg.B2).EndOptional() + err := q.db.Exec(ctx, insertMultipleValues, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} + +const insertValues = `-- name: InsertValues :exec +INSERT INTO foo (a, b) VALUES ($a, $b) +` + +type InsertValuesParams struct { + A string + B *int32 +} + +func (q *Queries) InsertValues(ctx context.Context, arg InsertValuesParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$a").Text(arg.A) + parameters = parameters.Param("$b").BeginOptional().Int32(arg.B).EndOptional() + err := q.db.Exec(ctx, insertValues, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..72d8782410 --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,5 @@ +-- name: InsertValues :exec +INSERT INTO foo (a, b) VALUES ($a, $b); + +/* name: InsertMultipleValues :exec */ +INSERT INTO foo (a, b) VALUES ($a1, $b1), ($a2, $b2); diff --git a/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..72ffaed0a5 --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (a Utf8, b Int32, PRIMARY KEY (a)); diff --git a/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/insert_values/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/insert_values_public/ydb/go/db.go b/internal/endtoend/testdata/insert_values_public/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/insert_values_public/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/insert_values_public/ydb/go/models.go b/internal/endtoend/testdata/insert_values_public/ydb/go/models.go new file mode 100644 index 0000000000..8bdab5abad --- /dev/null +++ b/internal/endtoend/testdata/insert_values_public/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string + B int32 +} diff --git a/internal/endtoend/testdata/insert_values_public/ydb/go/query.sql.go b/internal/endtoend/testdata/insert_values_public/ydb/go/query.sql.go new file mode 100644 index 0000000000..43064f9bc2 --- /dev/null +++ b/internal/endtoend/testdata/insert_values_public/ydb/go/query.sql.go @@ -0,0 +1,24 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const insertValues = `-- name: InsertValues :exec +INSERT INTO foo (a, b) VALUES ($a, $b) +` + +type InsertValuesParams struct { + A string + B int32 +} + +func (q *Queries) InsertValues(ctx context.Context, arg InsertValuesParams) error { + _, err := q.db.ExecContext(ctx, insertValues, arg.A, arg.B) + return err +} diff --git a/internal/endtoend/testdata/insert_values_public/ydb/query.sql b/internal/endtoend/testdata/insert_values_public/ydb/query.sql new file mode 100644 index 0000000000..0988176f16 --- /dev/null +++ b/internal/endtoend/testdata/insert_values_public/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: InsertValues :exec +INSERT INTO foo (a, b) VALUES ($a, $b); diff --git a/internal/endtoend/testdata/insert_values_public/ydb/schema.sql b/internal/endtoend/testdata/insert_values_public/ydb/schema.sql new file mode 100644 index 0000000000..2aed058e44 --- /dev/null +++ b/internal/endtoend/testdata/insert_values_public/ydb/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (a Text, b Int32, PRIMARY KEY (a, b)); diff --git a/internal/endtoend/testdata/insert_values_public/ydb/sqlc.json b/internal/endtoend/testdata/insert_values_public/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/insert_values_public/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/interval/ydb/go/db.go b/internal/endtoend/testdata/interval/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/interval/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/interval/ydb/go/models.go b/internal/endtoend/testdata/interval/ydb/go/models.go new file mode 100644 index 0000000000..47b07d9af1 --- /dev/null +++ b/internal/endtoend/testdata/interval/ydb/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "time" +) + +type Foo struct { + Bar bool + Interval time.Duration +} diff --git a/internal/endtoend/testdata/interval/ydb/go/query.sql.go b/internal/endtoend/testdata/interval/ydb/go/query.sql.go new file mode 100644 index 0000000000..9e9da6d32c --- /dev/null +++ b/internal/endtoend/testdata/interval/ydb/go/query.sql.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const get = `-- name: Get :many +SELECT bar, interval FROM foo LIMIT $limit +` + +func (q *Queries) Get(ctx context.Context, limit uint64) ([]Foo, error) { + rows, err := q.db.QueryContext(ctx, get, limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Foo + for rows.Next() { + var i Foo + if err := rows.Scan(&i.Bar, &i.Interval); err != nil { + return nil, err + } + items = append(items, i) + } + 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/interval/ydb/query.sql b/internal/endtoend/testdata/interval/ydb/query.sql new file mode 100644 index 0000000000..b7845cef3d --- /dev/null +++ b/internal/endtoend/testdata/interval/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: Get :many +SELECT bar, interval FROM foo LIMIT $limit; diff --git a/internal/endtoend/testdata/interval/ydb/schema.sql b/internal/endtoend/testdata/interval/ydb/schema.sql new file mode 100644 index 0000000000..70cd6620f1 --- /dev/null +++ b/internal/endtoend/testdata/interval/ydb/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (bar Bool NOT NULL, interval Interval NOT NULL, PRIMARY KEY (bar, "interval")); diff --git a/internal/endtoend/testdata/interval/ydb/sqlc.json b/internal/endtoend/testdata/interval/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/interval/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_alias/ydb/stdlib/go/db.go b/internal/endtoend/testdata/join_alias/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_alias/ydb/stdlib/go/models.go b/internal/endtoend/testdata/join_alias/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..0cfd332bba --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/stdlib/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 + Title *string +} + +type Foo struct { + ID int32 +} diff --git a/internal/endtoend/testdata/join_alias/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/join_alias/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..a71bd090d4 --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/stdlib/go/query.sql.go @@ -0,0 +1,81 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const aliasExpand = `-- name: AliasExpand :many +SELECT f.id, b.id, title +FROM foo f +JOIN bar b ON b.id = f.id +WHERE f.id = $id +` + +type AliasExpandRow struct { + ID int32 + ID_2 int32 + Title *string +} + +func (q *Queries) AliasExpand(ctx context.Context, id int32) ([]AliasExpandRow, error) { + rows, err := q.db.QueryContext(ctx, aliasExpand, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AliasExpandRow + for rows.Next() { + var i AliasExpandRow + if err := rows.Scan(&i.ID, &i.ID_2, &i.Title); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const aliasJoin = `-- name: AliasJoin :many +SELECT f.id, b.title +FROM foo f +JOIN bar b ON b.id = f.id +WHERE f.id = $id +` + +type AliasJoinRow struct { + ID int32 + Title *string +} + +func (q *Queries) AliasJoin(ctx context.Context, id int32) ([]AliasJoinRow, error) { + rows, err := q.db.QueryContext(ctx, aliasJoin, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AliasJoinRow + for rows.Next() { + var i AliasJoinRow + if err := rows.Scan(&i.ID, &i.Title); err != nil { + return nil, err + } + items = append(items, i) + } + 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/join_alias/ydb/stdlib/query.sql b/internal/endtoend/testdata/join_alias/ydb/stdlib/query.sql new file mode 100644 index 0000000000..4dd86d48ab --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/stdlib/query.sql @@ -0,0 +1,11 @@ +-- name: AliasJoin :many +SELECT f.id, b.title +FROM foo f +JOIN bar b ON b.id = f.id +WHERE f.id = $id; + +-- name: AliasExpand :many +SELECT * +FROM foo f +JOIN bar b ON b.id = f.id +WHERE f.id = $id; diff --git a/internal/endtoend/testdata/join_alias/ydb/stdlib/schema.sql b/internal/endtoend/testdata/join_alias/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..61e133ee1d --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/stdlib/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE foo (id Serial, PRIMARY KEY (id)); +CREATE TABLE bar (id Serial, title Text, PRIMARY KEY (id)); + diff --git a/internal/endtoend/testdata/join_alias/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/join_alias/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..0cfd332bba --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 + Title *string +} + +type Foo struct { + ID int32 +} diff --git a/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..582c8a5359 --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,91 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const aliasExpand = `-- name: AliasExpand :many +SELECT f.id, b.id, title +FROM foo f +JOIN bar b ON b.id = f.id +WHERE f.id = $id +` + +type AliasExpandRow struct { + ID int32 + ID_2 int32 + Title *string +} + +func (q *Queries) AliasExpand(ctx context.Context, id int32, opts ...query.ExecuteOption) ([]AliasExpandRow, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int32(id) + result, err := q.db.QueryResultSet(ctx, aliasExpand, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []AliasExpandRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i AliasExpandRow + if err := row.Scan(&i.ID, &i.ID_2, &i.Title); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const aliasJoin = `-- name: AliasJoin :many +SELECT f.id, b.title +FROM foo f +JOIN bar b ON b.id = f.id +WHERE f.id = $id +` + +type AliasJoinRow struct { + ID int32 + Title *string +} + +func (q *Queries) AliasJoin(ctx context.Context, id int32, opts ...query.ExecuteOption) ([]AliasJoinRow, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int32(id) + result, err := q.db.QueryResultSet(ctx, aliasJoin, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []AliasJoinRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i AliasJoinRow + if err := row.Scan(&i.ID, &i.Title); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..4dd86d48ab --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,11 @@ +-- name: AliasJoin :many +SELECT f.id, b.title +FROM foo f +JOIN bar b ON b.id = f.id +WHERE f.id = $id; + +-- name: AliasExpand :many +SELECT * +FROM foo f +JOIN bar b ON b.id = f.id +WHERE f.id = $id; diff --git a/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..61e133ee1d --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE foo (id Serial, PRIMARY KEY (id)); +CREATE TABLE bar (id Serial, title Text, PRIMARY KEY (id)); + diff --git a/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/join_alias/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_clauses_order/ydb/go/db.go b/internal/endtoend/testdata/join_clauses_order/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_clauses_order/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_clauses_order/ydb/go/models.go b/internal/endtoend/testdata/join_clauses_order/ydb/go/models.go new file mode 100644 index 0000000000..bdf41c2477 --- /dev/null +++ b/internal/endtoend/testdata/join_clauses_order/ydb/go/models.go @@ -0,0 +1,34 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type A struct { + ID int64 + A *string +} + +type B struct { + ID int64 + B *string + AID *int64 +} + +type C struct { + ID int64 + C *string + AID *int64 +} + +type D struct { + ID int64 + D *string + AID *int64 +} + +type E struct { + ID int64 + E *string + AID *int64 +} diff --git a/internal/endtoend/testdata/join_clauses_order/ydb/go/query.sql.go b/internal/endtoend/testdata/join_clauses_order/ydb/go/query.sql.go new file mode 100644 index 0000000000..4f0328bcd5 --- /dev/null +++ b/internal/endtoend/testdata/join_clauses_order/ydb/go/query.sql.go @@ -0,0 +1,174 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const testInnerLeft = `-- name: TestInnerLeft :many +SELECT a.a, b.b, c.c +FROM a +INNER JOIN b ON b.a_id = a.id +LEFT JOIN c ON c.a_id = a.id +` + +type TestInnerLeftRow struct { + A *string + B *string + C *string +} + +func (q *Queries) TestInnerLeft(ctx context.Context) ([]TestInnerLeftRow, error) { + rows, err := q.db.QueryContext(ctx, testInnerLeft) + if err != nil { + return nil, err + } + defer rows.Close() + var items []TestInnerLeftRow + for rows.Next() { + var i TestInnerLeftRow + if err := rows.Scan(&i.A, &i.B, &i.C); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const testInnerLeftInnerLeft = `-- name: TestInnerLeftInnerLeft :many +SELECT a.a, b.b, c.c, d.d, e.e +FROM a +INNER JOIN b ON b.a_id = a.id +LEFT JOIN c ON c.a_id = a.id +INNER JOIN d ON d.a_id = a.id +LEFT JOIN e ON e.a_id = a.id +` + +type TestInnerLeftInnerLeftRow struct { + A *string + B *string + C *string + D *string + E *string +} + +func (q *Queries) TestInnerLeftInnerLeft(ctx context.Context) ([]TestInnerLeftInnerLeftRow, error) { + rows, err := q.db.QueryContext(ctx, testInnerLeftInnerLeft) + if err != nil { + return nil, err + } + defer rows.Close() + var items []TestInnerLeftInnerLeftRow + for rows.Next() { + var i TestInnerLeftInnerLeftRow + if err := rows.Scan( + &i.A, + &i.B, + &i.C, + &i.D, + &i.E, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const testLeftInner = `-- name: TestLeftInner :many +SELECT a.a, b.b, c.c +FROM a +LEFT JOIN b ON b.a_id = a.id +INNER JOIN c ON c.a_id = a.id +` + +type TestLeftInnerRow struct { + A *string + B *string + C *string +} + +func (q *Queries) TestLeftInner(ctx context.Context) ([]TestLeftInnerRow, error) { + rows, err := q.db.QueryContext(ctx, testLeftInner) + if err != nil { + return nil, err + } + defer rows.Close() + var items []TestLeftInnerRow + for rows.Next() { + var i TestLeftInnerRow + if err := rows.Scan(&i.A, &i.B, &i.C); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const testLeftInnerLeftInner = `-- name: TestLeftInnerLeftInner :many +SELECT a.a, b.b, c.c, d.d, e.e +FROM a +LEFT JOIN b ON b.a_id = a.id +INNER JOIN c ON c.a_id = a.id +LEFT JOIN d ON d.a_id = a.id +INNER JOIN e ON e.a_id = a.id +` + +type TestLeftInnerLeftInnerRow struct { + A *string + B *string + C *string + D *string + E *string +} + +func (q *Queries) TestLeftInnerLeftInner(ctx context.Context) ([]TestLeftInnerLeftInnerRow, error) { + rows, err := q.db.QueryContext(ctx, testLeftInnerLeftInner) + if err != nil { + return nil, err + } + defer rows.Close() + var items []TestLeftInnerLeftInnerRow + for rows.Next() { + var i TestLeftInnerLeftInnerRow + if err := rows.Scan( + &i.A, + &i.B, + &i.C, + &i.D, + &i.E, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/join_clauses_order/ydb/query.sql b/internal/endtoend/testdata/join_clauses_order/ydb/query.sql new file mode 100644 index 0000000000..3980181178 --- /dev/null +++ b/internal/endtoend/testdata/join_clauses_order/ydb/query.sql @@ -0,0 +1,27 @@ +-- name: TestLeftInner :many +SELECT a.a, b.b, c.c +FROM a +LEFT JOIN b ON b.a_id = a.id +INNER JOIN c ON c.a_id = a.id; + +-- name: TestInnerLeft :many +SELECT a.a, b.b, c.c +FROM a +INNER JOIN b ON b.a_id = a.id +LEFT JOIN c ON c.a_id = a.id; + +-- name: TestLeftInnerLeftInner :many +SELECT a.a, b.b, c.c, d.d, e.e +FROM a +LEFT JOIN b ON b.a_id = a.id +INNER JOIN c ON c.a_id = a.id +LEFT JOIN d ON d.a_id = a.id +INNER JOIN e ON e.a_id = a.id; + +-- name: TestInnerLeftInnerLeft :many +SELECT a.a, b.b, c.c, d.d, e.e +FROM a +INNER JOIN b ON b.a_id = a.id +LEFT JOIN c ON c.a_id = a.id +INNER JOIN d ON d.a_id = a.id +LEFT JOIN e ON e.a_id = a.id; diff --git a/internal/endtoend/testdata/join_clauses_order/ydb/schema.sql b/internal/endtoend/testdata/join_clauses_order/ydb/schema.sql new file mode 100644 index 0000000000..536afa0d26 --- /dev/null +++ b/internal/endtoend/testdata/join_clauses_order/ydb/schema.sql @@ -0,0 +1,33 @@ +CREATE TABLE a ( + id BigSerial, + a Text, + PRIMARY KEY (id) +); + +CREATE TABLE b ( + id BigSerial, + b Text, + a_id Int64, + PRIMARY KEY (id) +); + +CREATE TABLE c ( + id BigSerial, + c Text, + a_id Int64, + PRIMARY KEY (id) +); + +CREATE TABLE d ( + id BigSerial, + d Text, + a_id Int64, + PRIMARY KEY (id) +); + +CREATE TABLE e ( + id BigSerial, + e Text, + a_id Int64, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/join_clauses_order/ydb/sqlc.json b/internal/endtoend/testdata/join_clauses_order/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_clauses_order/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_from/ydb/stdlib/go/db.go b/internal/endtoend/testdata/join_from/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_from/ydb/stdlib/go/models.go b/internal/endtoend/testdata/join_from/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..024b8245df --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/stdlib/go/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + Login string +} + +type Foo struct { + Email string +} diff --git a/internal/endtoend/testdata/join_from/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/join_from/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..6aa4d90930 --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/stdlib/go/query.sql.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const multiFrom = `-- name: MultiFrom :many +SELECT email FROM bar, foo WHERE login = $login +` + +func (q *Queries) MultiFrom(ctx context.Context, login string) ([]string, error) { + rows, err := q.db.QueryContext(ctx, multiFrom, login) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var email string + if err := rows.Scan(&email); err != nil { + return nil, err + } + items = append(items, email) + } + 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/join_from/ydb/stdlib/query.sql b/internal/endtoend/testdata/join_from/ydb/stdlib/query.sql new file mode 100644 index 0000000000..72079100bb --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: MultiFrom :many +SELECT email FROM bar, foo WHERE login = $login; diff --git a/internal/endtoend/testdata/join_from/ydb/stdlib/schema.sql b/internal/endtoend/testdata/join_from/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..b3615a1c5d --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/stdlib/schema.sql @@ -0,0 +1,2 @@ +CREATE TABLE foo (email Text, PRIMARY KEY (email)); +CREATE TABLE bar (login Text, PRIMARY KEY (login)); diff --git a/internal/endtoend/testdata/join_from/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/join_from/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..024b8245df --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + Login string +} + +type Foo struct { + Email string +} diff --git a/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..7928a83dee --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,44 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const multiFrom = `-- name: MultiFrom :many +SELECT email FROM bar, foo WHERE login = $login +` + +func (q *Queries) MultiFrom(ctx context.Context, login string, opts ...query.ExecuteOption) ([]string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$login").Text(login) + result, err := q.db.QueryResultSet(ctx, multiFrom, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var email string + if err := row.Scan(&email); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, email) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..72079100bb --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: MultiFrom :many +SELECT email FROM bar, foo WHERE login = $login; diff --git a/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..b3615a1c5d --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,2 @@ +CREATE TABLE foo (email Text, PRIMARY KEY (email)); +CREATE TABLE bar (login Text, PRIMARY KEY (login)); diff --git a/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/join_from/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_full/ydb/go/db.go b/internal/endtoend/testdata/join_full/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_full/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_full/ydb/go/models.go b/internal/endtoend/testdata/join_full/ydb/go/models.go new file mode 100644 index 0000000000..f851f23756 --- /dev/null +++ b/internal/endtoend/testdata/join_full/ydb/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} + +type Foo struct { + ID int32 + BarID *int32 +} diff --git a/internal/endtoend/testdata/join_full/ydb/go/query.sql.go b/internal/endtoend/testdata/join_full/ydb/go/query.sql.go new file mode 100644 index 0000000000..c3773e7933 --- /dev/null +++ b/internal/endtoend/testdata/join_full/ydb/go/query.sql.go @@ -0,0 +1,46 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const fullJoin = `-- name: FullJoin :many +SELECT f.id, f.bar_id, b.id +FROM foo f +FULL JOIN bar b ON b.id = f.bar_id +WHERE f.id = $id +` + +type FullJoinRow struct { + ID *int32 + BarID *int32 + ID_2 *int32 +} + +func (q *Queries) FullJoin(ctx context.Context, id int32) ([]FullJoinRow, error) { + rows, err := q.db.QueryContext(ctx, fullJoin, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []FullJoinRow + for rows.Next() { + var i FullJoinRow + if err := rows.Scan(&i.ID, &i.BarID, &i.ID_2); err != nil { + return nil, err + } + items = append(items, i) + } + 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/join_full/ydb/query.sql b/internal/endtoend/testdata/join_full/ydb/query.sql new file mode 100644 index 0000000000..0fc0f34933 --- /dev/null +++ b/internal/endtoend/testdata/join_full/ydb/query.sql @@ -0,0 +1,5 @@ +-- name: FullJoin :many +SELECT f.id, f.bar_id, b.id +FROM foo f +FULL JOIN bar b ON b.id = f.bar_id +WHERE f.id = $id; diff --git a/internal/endtoend/testdata/join_full/ydb/schema.sql b/internal/endtoend/testdata/join_full/ydb/schema.sql new file mode 100644 index 0000000000..2f497e584b --- /dev/null +++ b/internal/endtoend/testdata/join_full/ydb/schema.sql @@ -0,0 +1,12 @@ +CREATE TABLE bar ( + id Int32 NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE foo ( + id Int32 NOT NULL, + bar_id Int32, + PRIMARY KEY (id) +); + + diff --git a/internal/endtoend/testdata/join_full/ydb/sqlc.json b/internal/endtoend/testdata/join_full/ydb/sqlc.json new file mode 100644 index 0000000000..8dc3083c5d --- /dev/null +++ b/internal/endtoend/testdata/join_full/ydb/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/join_group_by_alias/ydb/go/db.go b/internal/endtoend/testdata/join_group_by_alias/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_group_by_alias/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_group_by_alias/ydb/go/models.go b/internal/endtoend/testdata/join_group_by_alias/ydb/go/models.go new file mode 100644 index 0000000000..ae9173ef9e --- /dev/null +++ b/internal/endtoend/testdata/join_group_by_alias/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Email string +} diff --git a/internal/endtoend/testdata/join_group_by_alias/ydb/go/query.sql.go b/internal/endtoend/testdata/join_group_by_alias/ydb/go/query.sql.go new file mode 100644 index 0000000000..13eb1ec3dc --- /dev/null +++ b/internal/endtoend/testdata/join_group_by_alias/ydb/go/query.sql.go @@ -0,0 +1,39 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const columnAsGroupBy = `-- name: ColumnAsGroupBy :many +SELECT a.email AS id +FROM foo a JOIN foo b ON a.email = b.email +GROUP BY a.email +` + +func (q *Queries) ColumnAsGroupBy(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, columnAsGroupBy) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + 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/join_group_by_alias/ydb/query.sql b/internal/endtoend/testdata/join_group_by_alias/ydb/query.sql new file mode 100644 index 0000000000..47946f9775 --- /dev/null +++ b/internal/endtoend/testdata/join_group_by_alias/ydb/query.sql @@ -0,0 +1,4 @@ +-- name: ColumnAsGroupBy :many +SELECT a.email AS id +FROM foo a JOIN foo b ON a.email = b.email +GROUP BY a.email; diff --git a/internal/endtoend/testdata/join_group_by_alias/ydb/schema.sql b/internal/endtoend/testdata/join_group_by_alias/ydb/schema.sql new file mode 100644 index 0000000000..0516b5d4f4 --- /dev/null +++ b/internal/endtoend/testdata/join_group_by_alias/ydb/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (email Text, PRIMARY KEY (email)); diff --git a/internal/endtoend/testdata/join_group_by_alias/ydb/sqlc.json b/internal/endtoend/testdata/join_group_by_alias/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_group_by_alias/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_inner/ydb/go/db.go b/internal/endtoend/testdata/join_inner/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_inner/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_inner/ydb/go/models.go b/internal/endtoend/testdata/join_inner/ydb/go/models.go new file mode 100644 index 0000000000..70ffad94e0 --- /dev/null +++ b/internal/endtoend/testdata/join_inner/ydb/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Event struct { + ID int32 +} + +type HandledEvent struct { + LastHandledID int32 + Handler string +} diff --git a/internal/endtoend/testdata/join_inner/ydb/go/query.sql.go b/internal/endtoend/testdata/join_inner/ydb/go/query.sql.go new file mode 100644 index 0000000000..ee456d9c4a --- /dev/null +++ b/internal/endtoend/testdata/join_inner/ydb/go/query.sql.go @@ -0,0 +1,70 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const selectAllJoined = `-- name: SelectAllJoined :many +SELECT events.id FROM events + INNER JOIN handled_events + ON events.ID = handled_events.last_handled_id +WHERE handled_events.handler = $handler +` + +func (q *Queries) SelectAllJoined(ctx context.Context, handler string) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, selectAllJoined, handler) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var id int32 + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const selectAllJoinedAlias = `-- name: SelectAllJoinedAlias :many +SELECT e.id FROM events AS e + INNER JOIN handled_events AS he + ON e.ID = he.last_handled_id +WHERE he.handler = $handler +` + +func (q *Queries) SelectAllJoinedAlias(ctx context.Context, handler string) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, selectAllJoinedAlias, handler) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var id int32 + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + 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/join_inner/ydb/query.sql b/internal/endtoend/testdata/join_inner/ydb/query.sql new file mode 100644 index 0000000000..223cbaab84 --- /dev/null +++ b/internal/endtoend/testdata/join_inner/ydb/query.sql @@ -0,0 +1,15 @@ +-- name: SelectAllJoined :many +SELECT events.* FROM events + INNER JOIN handled_events + ON events.ID = handled_events.last_handled_id +WHERE handled_events.handler = $handler; + +-- name: SelectAllJoinedAlias :many +SELECT e.* FROM events AS e + INNER JOIN handled_events AS he + ON e.ID = he.last_handled_id +WHERE he.handler = $handler; + + + + diff --git a/internal/endtoend/testdata/join_inner/ydb/schema.sql b/internal/endtoend/testdata/join_inner/ydb/schema.sql new file mode 100644 index 0000000000..06d1ba2347 --- /dev/null +++ b/internal/endtoend/testdata/join_inner/ydb/schema.sql @@ -0,0 +1,14 @@ +CREATE TABLE events ( + ID Int32 NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE handled_events ( + last_handled_id Int32, + handler Utf8, + PRIMARY KEY (last_handled_id, handler) +); + + + + diff --git a/internal/endtoend/testdata/join_inner/ydb/sqlc.json b/internal/endtoend/testdata/join_inner/ydb/sqlc.json new file mode 100644 index 0000000000..e85f2a696f --- /dev/null +++ b/internal/endtoend/testdata/join_inner/ydb/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + + diff --git a/internal/endtoend/testdata/join_left/ydb/go/db.go b/internal/endtoend/testdata/join_left/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_left/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_left/ydb/go/models.go b/internal/endtoend/testdata/join_left/ydb/go/models.go new file mode 100644 index 0000000000..9febc539a0 --- /dev/null +++ b/internal/endtoend/testdata/join_left/ydb/go/models.go @@ -0,0 +1,59 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "time" +) + +type Author struct { + ID int32 + Name string + ParentID *int32 +} + +type City struct { + CityID int32 + MayorID int32 +} + +type Mayor struct { + MayorID int32 + FullName string +} + +type Medium struct { + MediaID string + MediaCreatedAt time.Time + MediaHash string + MediaDirectory string + MediaAuthorID string + MediaWidth int32 + MediaHeight int32 +} + +type SuperAuthor struct { + SuperID int32 + SuperName string + SuperParentID *int32 +} + +type User struct { + UserID int32 + CityID *int32 +} + +type Users2 struct { + UserID string + UserNickname string + UserEmail string + UserDisplayName string + UserPassword *string + UserGoogleID *string + UserAppleID *string + UserBio string + UserCreatedAt time.Time + UserAvatarID *string +} diff --git a/internal/endtoend/testdata/join_left/ydb/go/query.sql.go b/internal/endtoend/testdata/join_left/ydb/go/query.sql.go new file mode 100644 index 0000000000..df1bb56edd --- /dev/null +++ b/internal/endtoend/testdata/join_left/ydb/go/query.sql.go @@ -0,0 +1,409 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + "time" +) + +const allAuthors = `-- name: AllAuthors :many +SELECT a.id, a.name, a.parent_id, p.id, p.name, p.parent_id +FROM authors a +LEFT JOIN authors p ON a.parent_id = p.id +` + +type AllAuthorsRow struct { + ID int32 + Name string + ParentID *int32 + ID_2 *int32 + Name_2 *string + ParentID_2 *int32 +} + +func (q *Queries) AllAuthors(ctx context.Context) ([]AllAuthorsRow, error) { + rows, err := q.db.QueryContext(ctx, allAuthors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AllAuthorsRow + for rows.Next() { + var i AllAuthorsRow + if err := rows.Scan( + &i.ID, + &i.Name, + &i.ParentID, + &i.ID_2, + &i.Name_2, + &i.ParentID_2, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const allAuthorsAliases = `-- name: AllAuthorsAliases :many +SELECT a.id, a.name, a.parent_id, p.id, p.name, p.parent_id +FROM authors a +LEFT JOIN authors p ON a.parent_id = p.id +` + +type AllAuthorsAliasesRow struct { + ID int32 + Name string + ParentID *int32 + ID_2 *int32 + Name_2 *string + ParentID_2 *int32 +} + +func (q *Queries) AllAuthorsAliases(ctx context.Context) ([]AllAuthorsAliasesRow, error) { + rows, err := q.db.QueryContext(ctx, allAuthorsAliases) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AllAuthorsAliasesRow + for rows.Next() { + var i AllAuthorsAliasesRow + if err := rows.Scan( + &i.ID, + &i.Name, + &i.ParentID, + &i.ID_2, + &i.Name_2, + &i.ParentID_2, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const allAuthorsAliases2 = `-- name: AllAuthorsAliases2 :many +SELECT a.id, a.name, a.parent_id, p.id, p.name, p.parent_id +FROM authors a +LEFT JOIN authors p ON a.parent_id = p.id +` + +type AllAuthorsAliases2Row struct { + ID int32 + Name string + ParentID *int32 + ID_2 *int32 + Name_2 *string + ParentID_2 *int32 +} + +func (q *Queries) AllAuthorsAliases2(ctx context.Context) ([]AllAuthorsAliases2Row, error) { + rows, err := q.db.QueryContext(ctx, allAuthorsAliases2) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AllAuthorsAliases2Row + for rows.Next() { + var i AllAuthorsAliases2Row + if err := rows.Scan( + &i.ID, + &i.Name, + &i.ParentID, + &i.ID_2, + &i.Name_2, + &i.ParentID_2, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const allSuperAuthors = `-- name: AllSuperAuthors :many +SELECT id, name, parent_id, super_id, super_name, super_parent_id +FROM authors +LEFT JOIN super_authors ON authors.parent_id = super_authors.super_id +` + +type AllSuperAuthorsRow struct { + ID int32 + Name string + ParentID *int32 + SuperID *int32 + SuperName *string + SuperParentID *int32 +} + +func (q *Queries) AllSuperAuthors(ctx context.Context) ([]AllSuperAuthorsRow, error) { + rows, err := q.db.QueryContext(ctx, allSuperAuthors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AllSuperAuthorsRow + for rows.Next() { + var i AllSuperAuthorsRow + if err := rows.Scan( + &i.ID, + &i.Name, + &i.ParentID, + &i.SuperID, + &i.SuperName, + &i.SuperParentID, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const allSuperAuthorsAliases = `-- name: AllSuperAuthorsAliases :many +SELECT id, name, parent_id, super_id, super_name, super_parent_id +FROM authors a +LEFT JOIN super_authors sa ON a.parent_id = sa.super_id +` + +type AllSuperAuthorsAliasesRow struct { + ID int32 + Name string + ParentID *int32 + SuperID *int32 + SuperName *string + SuperParentID *int32 +} + +func (q *Queries) AllSuperAuthorsAliases(ctx context.Context) ([]AllSuperAuthorsAliasesRow, error) { + rows, err := q.db.QueryContext(ctx, allSuperAuthorsAliases) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AllSuperAuthorsAliasesRow + for rows.Next() { + var i AllSuperAuthorsAliasesRow + if err := rows.Scan( + &i.ID, + &i.Name, + &i.ParentID, + &i.SuperID, + &i.SuperName, + &i.SuperParentID, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const allSuperAuthorsAliases2 = `-- name: AllSuperAuthorsAliases2 :many +SELECT a.id, a.name, a.parent_id, sa.super_id, sa.super_name, sa.super_parent_id +FROM authors a +LEFT JOIN super_authors sa ON a.parent_id = sa.super_id +` + +type AllSuperAuthorsAliases2Row struct { + ID int32 + Name string + ParentID *int32 + SuperID *int32 + SuperName *string + SuperParentID *int32 +} + +func (q *Queries) AllSuperAuthorsAliases2(ctx context.Context) ([]AllSuperAuthorsAliases2Row, error) { + rows, err := q.db.QueryContext(ctx, allSuperAuthorsAliases2) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AllSuperAuthorsAliases2Row + for rows.Next() { + var i AllSuperAuthorsAliases2Row + if err := rows.Scan( + &i.ID, + &i.Name, + &i.ParentID, + &i.SuperID, + &i.SuperName, + &i.SuperParentID, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getMayors = `-- name: GetMayors :many +SELECT user_id FROM users LEFT JOIN cities ON users.city_id = cities.city_id INNER JOIN mayors ON cities.mayor_id = mayors.mayor_id +` + +func (q *Queries) GetMayors(ctx context.Context) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, getMayors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var user_id int32 + if err := rows.Scan(&user_id); err != nil { + return nil, err + } + items = append(items, user_id) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getMayorsOptional = `-- name: GetMayorsOptional :many +SELECT user_id FROM users LEFT JOIN cities ON users.city_id = cities.city_id LEFT JOIN mayors ON cities.mayor_id = mayors.mayor_id +` + +func (q *Queries) GetMayorsOptional(ctx context.Context) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, getMayorsOptional) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var user_id int32 + if err := rows.Scan(&user_id); err != nil { + return nil, err + } + items = append(items, user_id) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getSuggestedUsersByID = `-- name: GetSuggestedUsersByID :many +SELECT DISTINCT u.user_id, u.user_nickname, u.user_email, u.user_display_name, u.user_password, u.user_google_id, u.user_apple_id, u.user_bio, u.user_created_at, u.user_avatar_id, m.media_id, m.media_created_at, m.media_hash, m.media_directory, m.media_author_id, m.media_width, m.media_height +FROM users_2 u +LEFT JOIN media m ON u.user_avatar_id = m.media_id +WHERE u.user_id != $user_id +LIMIT $user_limit +` + +type GetSuggestedUsersByIDParams struct { + UserID string + UserLimit uint64 +} + +type GetSuggestedUsersByIDRow struct { + UserID string + UserNickname string + UserEmail string + UserDisplayName string + UserPassword *string + UserGoogleID *string + UserAppleID *string + UserBio string + UserCreatedAt time.Time + UserAvatarID *string + MediaID *string + MediaCreatedAt *time.Time + MediaHash *string + MediaDirectory *string + MediaAuthorID *string + MediaWidth *int32 + MediaHeight *int32 +} + +func (q *Queries) GetSuggestedUsersByID(ctx context.Context, arg GetSuggestedUsersByIDParams) ([]GetSuggestedUsersByIDRow, error) { + rows, err := q.db.QueryContext(ctx, getSuggestedUsersByID, arg.UserID, arg.UserLimit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetSuggestedUsersByIDRow + for rows.Next() { + var i GetSuggestedUsersByIDRow + if err := rows.Scan( + &i.UserID, + &i.UserNickname, + &i.UserEmail, + &i.UserDisplayName, + &i.UserPassword, + &i.UserGoogleID, + &i.UserAppleID, + &i.UserBio, + &i.UserCreatedAt, + &i.UserAvatarID, + &i.MediaID, + &i.MediaCreatedAt, + &i.MediaHash, + &i.MediaDirectory, + &i.MediaAuthorID, + &i.MediaWidth, + &i.MediaHeight, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/join_left/ydb/query.sql b/internal/endtoend/testdata/join_left/ydb/query.sql new file mode 100644 index 0000000000..7ddd89c1ad --- /dev/null +++ b/internal/endtoend/testdata/join_left/ydb/query.sql @@ -0,0 +1,43 @@ +-- name: GetMayors :many +SELECT user_id FROM users LEFT JOIN cities ON users.city_id = cities.city_id INNER JOIN mayors ON cities.mayor_id = mayors.mayor_id; + +-- name: GetMayorsOptional :many +SELECT user_id FROM users LEFT JOIN cities ON users.city_id = cities.city_id LEFT JOIN mayors ON cities.mayor_id = mayors.mayor_id; + + +-- name: AllAuthors :many +SELECT * +FROM authors a +LEFT JOIN authors p ON a.parent_id = p.id; + +-- name: AllAuthorsAliases :many +SELECT * +FROM authors a +LEFT JOIN authors p ON a.parent_id = p.id; + +-- name: AllAuthorsAliases2 :many +SELECT a.*, p.* +FROM authors a +LEFT JOIN authors p ON a.parent_id = p.id; + +-- name: AllSuperAuthors :many +SELECT * +FROM authors +LEFT JOIN super_authors ON authors.parent_id = super_authors.super_id; + +-- name: AllSuperAuthorsAliases :many +SELECT * +FROM authors a +LEFT JOIN super_authors sa ON a.parent_id = sa.super_id; + +-- name: AllSuperAuthorsAliases2 :many +SELECT a.*, sa.* +FROM authors a +LEFT JOIN super_authors sa ON a.parent_id = sa.super_id; + +-- name: GetSuggestedUsersByID :many +SELECT DISTINCT u.*, m.* +FROM users_2 u +LEFT JOIN media m ON u.user_avatar_id = m.media_id +WHERE u.user_id != $user_id +LIMIT $user_limit; diff --git a/internal/endtoend/testdata/join_left/ydb/schema.sql b/internal/endtoend/testdata/join_left/ydb/schema.sql new file mode 100644 index 0000000000..55ef211444 --- /dev/null +++ b/internal/endtoend/testdata/join_left/ydb/schema.sql @@ -0,0 +1,60 @@ +CREATE TABLE users ( + user_id Int32 NOT NULL, + city_id Int32, + PRIMARY KEY (user_id) +); + +CREATE TABLE cities ( + city_id Int32 NOT NULL, + mayor_id Int32 NOT NULL, + PRIMARY KEY (city_id) +); + +CREATE TABLE mayors ( + mayor_id Int32 NOT NULL, + full_name Utf8 NOT NULL, + PRIMARY KEY (mayor_id) +); + +CREATE TABLE authors ( + id Int32 NOT NULL, + name Utf8 NOT NULL, + parent_id Int32, + PRIMARY KEY (id) +); + +CREATE TABLE super_authors ( + super_id Int32 NOT NULL, + super_name Utf8 NOT NULL, + super_parent_id Int32, + PRIMARY KEY (super_id) +); + +CREATE TABLE users_2 ( + user_id Utf8 NOT NULL, + user_nickname Utf8 NOT NULL, + user_email Utf8 NOT NULL, + user_display_name Utf8 NOT NULL, + user_password Utf8, + user_google_id Utf8, + user_apple_id Utf8, + user_bio Utf8 NOT NULL DEFAULT '', + user_created_at Timestamp NOT NULL, + user_avatar_id Utf8, + PRIMARY KEY (user_id) +); + +CREATE TABLE media ( + media_id Utf8 NOT NULL, + media_created_at Timestamp NOT NULL, + media_hash Utf8 NOT NULL, + media_directory Utf8 NOT NULL, + media_author_id Utf8 NOT NULL, + media_width Int32 NOT NULL, + media_height Int32 NOT NULL, + PRIMARY KEY (media_id) +); + + + + diff --git a/internal/endtoend/testdata/join_left/ydb/sqlc.json b/internal/endtoend/testdata/join_left/ydb/sqlc.json new file mode 100644 index 0000000000..e85f2a696f --- /dev/null +++ b/internal/endtoend/testdata/join_left/ydb/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + + diff --git a/internal/endtoend/testdata/join_left_same_table/ydb/go/db.go b/internal/endtoend/testdata/join_left_same_table/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_left_same_table/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_left_same_table/ydb/go/models.go b/internal/endtoend/testdata/join_left_same_table/ydb/go/models.go new file mode 100644 index 0000000000..34f7c06f5e --- /dev/null +++ b/internal/endtoend/testdata/join_left_same_table/ydb/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int32 + Name string + ParentID *int32 +} diff --git a/internal/endtoend/testdata/join_left_same_table/ydb/go/query.sql.go b/internal/endtoend/testdata/join_left_same_table/ydb/go/query.sql.go new file mode 100644 index 0000000000..dfc6dea3ab --- /dev/null +++ b/internal/endtoend/testdata/join_left_same_table/ydb/go/query.sql.go @@ -0,0 +1,55 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const allAuthors = `-- name: AllAuthors :many +SELECT a.id, + a.name, + p.id as alias_id, + p.name as alias_name +FROM authors AS a + LEFT JOIN authors AS p + ON (a.parent_id = p.id) +` + +type AllAuthorsRow struct { + ID int32 + Name string + AliasID *int32 + AliasName *string +} + +func (q *Queries) AllAuthors(ctx context.Context) ([]AllAuthorsRow, error) { + rows, err := q.db.QueryContext(ctx, allAuthors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AllAuthorsRow + for rows.Next() { + var i AllAuthorsRow + if err := rows.Scan( + &i.ID, + &i.Name, + &i.AliasID, + &i.AliasName, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/join_left_same_table/ydb/query.sql b/internal/endtoend/testdata/join_left_same_table/ydb/query.sql new file mode 100644 index 0000000000..79daa2dfd5 --- /dev/null +++ b/internal/endtoend/testdata/join_left_same_table/ydb/query.sql @@ -0,0 +1,8 @@ +-- name: AllAuthors :many +SELECT a.id, + a.name, + p.id as alias_id, + p.name as alias_name +FROM authors AS a + LEFT JOIN authors AS p + ON (a.parent_id = p.id); diff --git a/internal/endtoend/testdata/join_left_same_table/ydb/schema.sql b/internal/endtoend/testdata/join_left_same_table/ydb/schema.sql new file mode 100644 index 0000000000..70ede5589b --- /dev/null +++ b/internal/endtoend/testdata/join_left_same_table/ydb/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE authors ( + id Int32 NOT NULL, + name Text NOT NULL, + parent_id Int32, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/join_left_same_table/ydb/sqlc.json b/internal/endtoend/testdata/join_left_same_table/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_left_same_table/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_left_table_alias/ydb/go/db.go b/internal/endtoend/testdata/join_left_table_alias/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_left_table_alias/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_left_table_alias/ydb/go/models.go b/internal/endtoend/testdata/join_left_table_alias/ydb/go/models.go new file mode 100644 index 0000000000..53f0503d0f --- /dev/null +++ b/internal/endtoend/testdata/join_left_table_alias/ydb/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + FooID int64 + Info *string +} + +type Foo struct { + ID int64 +} diff --git a/internal/endtoend/testdata/join_left_table_alias/ydb/go/query.sql.go b/internal/endtoend/testdata/join_left_table_alias/ydb/go/query.sql.go new file mode 100644 index 0000000000..8990f63989 --- /dev/null +++ b/internal/endtoend/testdata/join_left_table_alias/ydb/go/query.sql.go @@ -0,0 +1,46 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const joinBar = `-- name: JoinBar :one +SELECT f.id, info +FROM foo f +LEFT JOIN bar b ON b.foo_id = f.id +` + +type JoinBarRow struct { + ID int64 + Info *string +} + +func (q *Queries) JoinBar(ctx context.Context) (JoinBarRow, error) { + row := q.db.QueryRowContext(ctx, joinBar) + var i JoinBarRow + err := row.Scan(&i.ID, &i.Info) + return i, err +} + +const joinBarAlias = `-- name: JoinBarAlias :one +SELECT f.id, b.info +FROM foo f +LEFT JOIN bar b ON b.foo_id = f.id +` + +type JoinBarAliasRow struct { + ID int64 + Info *string +} + +func (q *Queries) JoinBarAlias(ctx context.Context) (JoinBarAliasRow, error) { + row := q.db.QueryRowContext(ctx, joinBarAlias) + var i JoinBarAliasRow + err := row.Scan(&i.ID, &i.Info) + return i, err +} diff --git a/internal/endtoend/testdata/join_left_table_alias/ydb/query.sql b/internal/endtoend/testdata/join_left_table_alias/ydb/query.sql new file mode 100644 index 0000000000..ad61f17b7b --- /dev/null +++ b/internal/endtoend/testdata/join_left_table_alias/ydb/query.sql @@ -0,0 +1,9 @@ +-- name: JoinBar :one +SELECT f.id, info +FROM foo f +LEFT JOIN bar b ON b.foo_id = f.id; + +-- name: JoinBarAlias :one +SELECT f.id, b.info +FROM foo f +LEFT JOIN bar b ON b.foo_id = f.id; diff --git a/internal/endtoend/testdata/join_left_table_alias/ydb/schema.sql b/internal/endtoend/testdata/join_left_table_alias/ydb/schema.sql new file mode 100644 index 0000000000..f8980bffc6 --- /dev/null +++ b/internal/endtoend/testdata/join_left_table_alias/ydb/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE foo ( + id Int64, + PRIMARY KEY (id) +); + +CREATE TABLE bar ( + foo_id Int64, + info Text, + PRIMARY KEY (foo_id) +); diff --git a/internal/endtoend/testdata/join_left_table_alias/ydb/sqlc.json b/internal/endtoend/testdata/join_left_table_alias/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_left_table_alias/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_order_by/ydb/go/db.go b/internal/endtoend/testdata/join_order_by/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_order_by/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_order_by/ydb/go/models.go b/internal/endtoend/testdata/join_order_by/ydb/go/models.go new file mode 100644 index 0000000000..93e9ce7933 --- /dev/null +++ b/internal/endtoend/testdata/join_order_by/ydb/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int64 + Name string + Bio *string +} diff --git a/internal/endtoend/testdata/join_order_by/ydb/go/query.sql.go b/internal/endtoend/testdata/join_order_by/ydb/go/query.sql.go new file mode 100644 index 0000000000..ea31ea0c55 --- /dev/null +++ b/internal/endtoend/testdata/join_order_by/ydb/go/query.sql.go @@ -0,0 +1,23 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getAuthor = `-- name: GetAuthor :one +SELECT a.name +FROM authors a JOIN authors b ON a.id = b.id +ORDER BY a.name +` + +func (q *Queries) GetAuthor(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, getAuthor) + var name string + err := row.Scan(&name) + return name, err +} diff --git a/internal/endtoend/testdata/join_order_by/ydb/query.sql b/internal/endtoend/testdata/join_order_by/ydb/query.sql new file mode 100644 index 0000000000..cca7280f75 --- /dev/null +++ b/internal/endtoend/testdata/join_order_by/ydb/query.sql @@ -0,0 +1,4 @@ +-- name: GetAuthor :one +SELECT a.name +FROM authors a JOIN authors b ON a.id = b.id +ORDER BY a.name; diff --git a/internal/endtoend/testdata/join_order_by/ydb/schema.sql b/internal/endtoend/testdata/join_order_by/ydb/schema.sql new file mode 100644 index 0000000000..cd16312a93 --- /dev/null +++ b/internal/endtoend/testdata/join_order_by/ydb/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/join_order_by/ydb/sqlc.json b/internal/endtoend/testdata/join_order_by/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_order_by/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_order_by_alias/ydb/go/db.go b/internal/endtoend/testdata/join_order_by_alias/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_order_by_alias/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_order_by_alias/ydb/go/models.go b/internal/endtoend/testdata/join_order_by_alias/ydb/go/models.go new file mode 100644 index 0000000000..ae9173ef9e --- /dev/null +++ b/internal/endtoend/testdata/join_order_by_alias/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Email string +} diff --git a/internal/endtoend/testdata/join_order_by_alias/ydb/go/query.sql.go b/internal/endtoend/testdata/join_order_by_alias/ydb/go/query.sql.go new file mode 100644 index 0000000000..167045b212 --- /dev/null +++ b/internal/endtoend/testdata/join_order_by_alias/ydb/go/query.sql.go @@ -0,0 +1,39 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const columnAsOrderBy = `-- name: ColumnAsOrderBy :many +SELECT a.email AS id +FROM foo a JOIN foo b ON a.email = b.email +ORDER BY id +` + +func (q *Queries) ColumnAsOrderBy(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, columnAsOrderBy) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var id string + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + 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/join_order_by_alias/ydb/query.sql b/internal/endtoend/testdata/join_order_by_alias/ydb/query.sql new file mode 100644 index 0000000000..7a47032a4c --- /dev/null +++ b/internal/endtoend/testdata/join_order_by_alias/ydb/query.sql @@ -0,0 +1,4 @@ +-- name: ColumnAsOrderBy :many +SELECT a.email AS id +FROM foo a JOIN foo b ON a.email = b.email +ORDER BY id; diff --git a/internal/endtoend/testdata/join_order_by_alias/ydb/schema.sql b/internal/endtoend/testdata/join_order_by_alias/ydb/schema.sql new file mode 100644 index 0000000000..22b8155e7c --- /dev/null +++ b/internal/endtoend/testdata/join_order_by_alias/ydb/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (email Text NOT NULL, PRIMARY KEY (email)); diff --git a/internal/endtoend/testdata/join_order_by_alias/ydb/sqlc.json b/internal/endtoend/testdata/join_order_by_alias/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_order_by_alias/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_right/ydb/go/db.go b/internal/endtoend/testdata/join_right/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_right/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_right/ydb/go/models.go b/internal/endtoend/testdata/join_right/ydb/go/models.go new file mode 100644 index 0000000000..f851f23756 --- /dev/null +++ b/internal/endtoend/testdata/join_right/ydb/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} + +type Foo struct { + ID int32 + BarID *int32 +} diff --git a/internal/endtoend/testdata/join_right/ydb/go/query.sql.go b/internal/endtoend/testdata/join_right/ydb/go/query.sql.go new file mode 100644 index 0000000000..516316da46 --- /dev/null +++ b/internal/endtoend/testdata/join_right/ydb/go/query.sql.go @@ -0,0 +1,46 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const rightJoin = `-- name: RightJoin :many +SELECT f.id, f.bar_id, b.id +FROM foo f +RIGHT JOIN bar b ON b.id = f.bar_id +WHERE f.id = $id +` + +type RightJoinRow struct { + ID *int32 + BarID *int32 + ID_2 int32 +} + +func (q *Queries) RightJoin(ctx context.Context, id int32) ([]RightJoinRow, error) { + rows, err := q.db.QueryContext(ctx, rightJoin, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []RightJoinRow + for rows.Next() { + var i RightJoinRow + if err := rows.Scan(&i.ID, &i.BarID, &i.ID_2); err != nil { + return nil, err + } + items = append(items, i) + } + 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/join_right/ydb/query.sql b/internal/endtoend/testdata/join_right/ydb/query.sql new file mode 100644 index 0000000000..d0c065246e --- /dev/null +++ b/internal/endtoend/testdata/join_right/ydb/query.sql @@ -0,0 +1,7 @@ +-- name: RightJoin :many +SELECT f.id, f.bar_id, b.id +FROM foo f +RIGHT JOIN bar b ON b.id = f.bar_id +WHERE f.id = $id; + + diff --git a/internal/endtoend/testdata/join_right/ydb/schema.sql b/internal/endtoend/testdata/join_right/ydb/schema.sql new file mode 100644 index 0000000000..2f497e584b --- /dev/null +++ b/internal/endtoend/testdata/join_right/ydb/schema.sql @@ -0,0 +1,12 @@ +CREATE TABLE bar ( + id Int32 NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE foo ( + id Int32 NOT NULL, + bar_id Int32, + PRIMARY KEY (id) +); + + diff --git a/internal/endtoend/testdata/join_right/ydb/sqlc.json b/internal/endtoend/testdata/join_right/ydb/sqlc.json new file mode 100644 index 0000000000..8dc3083c5d --- /dev/null +++ b/internal/endtoend/testdata/join_right/ydb/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + diff --git a/internal/endtoend/testdata/join_table_name/ydb/stdlib/go/db.go b/internal/endtoend/testdata/join_table_name/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_table_name/ydb/stdlib/go/models.go b/internal/endtoend/testdata/join_table_name/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..6118a65541 --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/stdlib/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} + +type Foo struct { + ID int32 + Bar *int32 +} diff --git a/internal/endtoend/testdata/join_table_name/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/join_table_name/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..d394749ebf --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/stdlib/go/query.sql.go @@ -0,0 +1,29 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const tableName = `-- name: TableName :one +SELECT foo.id +FROM foo +JOIN bar ON foo.bar = bar.id +WHERE bar.id = $bar_id AND foo.id = $foo_id +` + +type TableNameParams struct { + BarID int32 + FooID int32 +} + +func (q *Queries) TableName(ctx context.Context, arg TableNameParams) (int32, error) { + row := q.db.QueryRowContext(ctx, tableName, arg.BarID, arg.FooID) + var id int32 + err := row.Scan(&id) + return id, err +} diff --git a/internal/endtoend/testdata/join_table_name/ydb/stdlib/query.sql b/internal/endtoend/testdata/join_table_name/ydb/stdlib/query.sql new file mode 100644 index 0000000000..e82f9599e1 --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/stdlib/query.sql @@ -0,0 +1,5 @@ +-- name: TableName :one +SELECT foo.id +FROM foo +JOIN bar ON foo.bar = bar.id +WHERE bar.id = $bar_id AND foo.id = $foo_id; diff --git a/internal/endtoend/testdata/join_table_name/ydb/stdlib/schema.sql b/internal/endtoend/testdata/join_table_name/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..6371ee5f7e --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/stdlib/schema.sql @@ -0,0 +1,2 @@ +CREATE TABLE bar (id Serial, PRIMARY KEY (id)); +CREATE TABLE foo (id Serial, bar Serial, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/join_table_name/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/join_table_name/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..6118a65541 --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} + +type Foo struct { + ID int32 + Bar *int32 +} diff --git a/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..24604e5e2d --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,44 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const tableName = `-- name: TableName :one +SELECT foo.id +FROM foo +JOIN bar ON foo.bar = bar.id +WHERE bar.id = $bar_id AND foo.id = $foo_id +` + +type TableNameParams struct { + BarID int32 + FooID int32 +} + +func (q *Queries) TableName(ctx context.Context, arg TableNameParams, opts ...query.ExecuteOption) (int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$bar_id").Int32(arg.BarID) + parameters = parameters.Param("$foo_id").Int32(arg.FooID) + row, err := q.db.QueryRow(ctx, tableName, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var id int32 + if err != nil { + return id, xerrors.WithStackTrace(err) + } + err = row.Scan(&id) + if err != nil { + return id, xerrors.WithStackTrace(err) + } + return id, nil +} diff --git a/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..e82f9599e1 --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,5 @@ +-- name: TableName :one +SELECT foo.id +FROM foo +JOIN bar ON foo.bar = bar.id +WHERE bar.id = $bar_id AND foo.id = $foo_id; diff --git a/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..6371ee5f7e --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,2 @@ +CREATE TABLE bar (id Serial, PRIMARY KEY (id)); +CREATE TABLE foo (id Serial, bar Serial, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/join_table_name/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/db.go b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_two_tables/ydb/stdlib/go/models.go b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..ad2b376d3a --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/models.go @@ -0,0 +1,18 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} + +type Baz struct { + ID int32 +} + +type Foo struct { + BarID int32 + BazID int32 +} diff --git a/internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..586b732cb8 --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/go/query.sql.go @@ -0,0 +1,40 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const twoJoins = `-- name: TwoJoins :many +SELECT foo.bar_id, foo.baz_id +FROM foo +JOIN bar ON bar.id = foo.bar_id +JOIN baz ON baz.id = foo.baz_id +` + +func (q *Queries) TwoJoins(ctx context.Context) ([]Foo, error) { + rows, err := q.db.QueryContext(ctx, twoJoins) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Foo + for rows.Next() { + var i Foo + if err := rows.Scan(&i.BarID, &i.BazID); err != nil { + return nil, err + } + items = append(items, i) + } + 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/join_two_tables/ydb/stdlib/query.sql b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/query.sql new file mode 100644 index 0000000000..629a4f61b9 --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/query.sql @@ -0,0 +1,5 @@ +-- name: TwoJoins :many +SELECT foo.* +FROM foo +JOIN bar ON bar.id = foo.bar_id +JOIN baz ON baz.id = foo.baz_id; diff --git a/internal/endtoend/testdata/join_two_tables/ydb/stdlib/schema.sql b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..13c1043a20 --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE foo (bar_id Serial, baz_id Serial, PRIMARY KEY (bar_id, baz_id)); +CREATE TABLE bar (id Serial, PRIMARY KEY (id)); +CREATE TABLE baz (id Serial, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/join_two_tables/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..ad2b376d3a --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,18 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} + +type Baz struct { + ID int32 +} + +type Foo struct { + BarID int32 + BazID int32 +} diff --git a/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..f8c9dbbbf2 --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const twoJoins = `-- name: TwoJoins :many +SELECT foo.bar_id, foo.baz_id +FROM foo +JOIN bar ON bar.id = foo.bar_id +JOIN baz ON baz.id = foo.baz_id +` + +func (q *Queries) TwoJoins(ctx context.Context, opts ...query.ExecuteOption) ([]Foo, error) { + result, err := q.db.QueryResultSet(ctx, twoJoins, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Foo + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Foo + if err := row.Scan(&i.BarID, &i.BazID); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..629a4f61b9 --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,5 @@ +-- name: TwoJoins :many +SELECT foo.* +FROM foo +JOIN bar ON bar.id = foo.bar_id +JOIN baz ON baz.id = foo.baz_id; diff --git a/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..13c1043a20 --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,3 @@ +CREATE TABLE foo (bar_id Serial, baz_id Serial, PRIMARY KEY (bar_id, baz_id)); +CREATE TABLE bar (id Serial, PRIMARY KEY (id)); +CREATE TABLE baz (id Serial, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/join_two_tables/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_update/ydb/go/db.go b/internal/endtoend/testdata/join_update/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_update/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_update/ydb/go/models.go b/internal/endtoend/testdata/join_update/ydb/go/models.go new file mode 100644 index 0000000000..ad3d5722f6 --- /dev/null +++ b/internal/endtoend/testdata/join_update/ydb/go/models.go @@ -0,0 +1,20 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type GroupCalcTotal struct { + Npn *string + GroupID string +} + +type NpnExternalMap struct { + ID string + Npn *string +} + +type ProducerGroupAttribute struct { + NpnExternalMapID *string + GroupID string +} diff --git a/internal/endtoend/testdata/join_update/ydb/go/query.sql.go b/internal/endtoend/testdata/join_update/ydb/go/query.sql.go new file mode 100644 index 0000000000..54edc911d3 --- /dev/null +++ b/internal/endtoend/testdata/join_update/ydb/go/query.sql.go @@ -0,0 +1,23 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const percentile = `-- name: Percentile :exec +UPDATE group_calc_totals ON +SELECT gct.group_id, nem.npn +FROM group_calc_totals gct +JOIN producer_group_attribute ga ON gct.group_id = ga.group_id +JOIN npn_external_map nem ON ga.npn_external_map_id = nem.id +` + +func (q *Queries) Percentile(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, percentile) + return err +} diff --git a/internal/endtoend/testdata/join_update/ydb/query.sql b/internal/endtoend/testdata/join_update/ydb/query.sql new file mode 100644 index 0000000000..6398e7faf9 --- /dev/null +++ b/internal/endtoend/testdata/join_update/ydb/query.sql @@ -0,0 +1,6 @@ +-- name: Percentile :exec +UPDATE group_calc_totals ON +SELECT gct.group_id, nem.npn +FROM group_calc_totals gct +JOIN producer_group_attribute ga ON gct.group_id = ga.group_id +JOIN npn_external_map nem ON ga.npn_external_map_id = nem.id; diff --git a/internal/endtoend/testdata/join_update/ydb/schema.sql b/internal/endtoend/testdata/join_update/ydb/schema.sql new file mode 100644 index 0000000000..70596ecb0c --- /dev/null +++ b/internal/endtoend/testdata/join_update/ydb/schema.sql @@ -0,0 +1,17 @@ +CREATE TABLE group_calc_totals ( + npn Text, + group_id Text, + PRIMARY KEY (group_id) +); + +CREATE TABLE producer_group_attribute ( + npn_external_map_id Text, + group_id Text, + PRIMARY KEY (group_id) +); + +CREATE TABLE npn_external_map ( + id Text, + npn Text, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/join_update/ydb/sqlc.json b/internal/endtoend/testdata/join_update/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_update/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_using/ydb/go/db.go b/internal/endtoend/testdata/join_using/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_using/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_using/ydb/go/models.go b/internal/endtoend/testdata/join_using/ydb/go/models.go new file mode 100644 index 0000000000..f4eaade85e --- /dev/null +++ b/internal/endtoend/testdata/join_using/ydb/go/models.go @@ -0,0 +1,13 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type T1 struct { + Fk int32 +} + +type T2 struct { + Fk int32 +} diff --git a/internal/endtoend/testdata/join_using/ydb/go/query.sql.go b/internal/endtoend/testdata/join_using/ydb/go/query.sql.go new file mode 100644 index 0000000000..b0a017920e --- /dev/null +++ b/internal/endtoend/testdata/join_using/ydb/go/query.sql.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const selectJoinUsing = `-- name: SelectJoinUsing :many +SELECT t1.fk, SUM(t2.fk) FROM t1 JOIN t2 USING (fk) GROUP BY t1.fk +` + +type SelectJoinUsingRow struct { + Fk int32 + Sum interface{} +} + +func (q *Queries) SelectJoinUsing(ctx context.Context) ([]SelectJoinUsingRow, error) { + rows, err := q.db.QueryContext(ctx, selectJoinUsing) + if err != nil { + return nil, err + } + defer rows.Close() + var items []SelectJoinUsingRow + for rows.Next() { + var i SelectJoinUsingRow + if err := rows.Scan(&i.Fk, &i.Sum); err != nil { + return nil, err + } + items = append(items, i) + } + 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/join_using/ydb/query.sql b/internal/endtoend/testdata/join_using/ydb/query.sql new file mode 100644 index 0000000000..a9a80f2e7f --- /dev/null +++ b/internal/endtoend/testdata/join_using/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: SelectJoinUsing :many +SELECT t1.fk, SUM(t2.fk) FROM t1 JOIN t2 USING (fk) GROUP BY t1.fk; diff --git a/internal/endtoend/testdata/join_using/ydb/schema.sql b/internal/endtoend/testdata/join_using/ydb/schema.sql new file mode 100644 index 0000000000..1d1dc9c471 --- /dev/null +++ b/internal/endtoend/testdata/join_using/ydb/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE t1 ( + fk Int32, + PRIMARY KEY (fk) +); + +CREATE TABLE t2 ( + fk Int32, + PRIMARY KEY (fk) +); + diff --git a/internal/endtoend/testdata/join_using/ydb/sqlc.json b/internal/endtoend/testdata/join_using/ydb/sqlc.json new file mode 100644 index 0000000000..3e245cf4a5 --- /dev/null +++ b/internal/endtoend/testdata/join_using/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/db.go b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/join_where_clause/ydb/stdlib/go/models.go b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..b133b28e36 --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 + Owner string +} + +type Foo struct { + Barid int32 +} diff --git a/internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..a87dc870fa --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/go/query.sql.go @@ -0,0 +1,110 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const joinNoConstraints = `-- name: JoinNoConstraints :many +SELECT foo.barid +FROM foo +CROSS JOIN bar +WHERE bar.id = $bar_id AND owner = $owner +` + +type JoinNoConstraintsParams struct { + BarID int32 + Owner string +} + +func (q *Queries) JoinNoConstraints(ctx context.Context, arg JoinNoConstraintsParams) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, joinNoConstraints, arg.BarID, arg.Owner) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var barid int32 + if err := rows.Scan(&barid); err != nil { + return nil, err + } + items = append(items, barid) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const joinParamWhereClause = `-- name: JoinParamWhereClause :many +SELECT foo.barid +FROM foo +JOIN bar ON bar.id = $bar_id +WHERE owner = $owner +` + +type JoinParamWhereClauseParams struct { + BarID int32 + Owner string +} + +func (q *Queries) JoinParamWhereClause(ctx context.Context, arg JoinParamWhereClauseParams) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, joinParamWhereClause, arg.BarID, arg.Owner) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var barid int32 + if err := rows.Scan(&barid); err != nil { + return nil, err + } + items = append(items, barid) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const joinWhereClause = `-- name: JoinWhereClause :many +SELECT foo.barid +FROM foo +JOIN bar ON bar.id = barid +WHERE owner = $owner +` + +func (q *Queries) JoinWhereClause(ctx context.Context, owner string) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, joinWhereClause, owner) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var barid int32 + if err := rows.Scan(&barid); err != nil { + return nil, err + } + items = append(items, barid) + } + 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/join_where_clause/ydb/stdlib/query.sql b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/query.sql new file mode 100644 index 0000000000..c4695381ef --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/query.sql @@ -0,0 +1,17 @@ +-- name: JoinWhereClause :many +SELECT foo.* +FROM foo +JOIN bar ON bar.id = barid +WHERE owner = $owner; + +-- name: JoinParamWhereClause :many +SELECT foo.* +FROM foo +JOIN bar ON bar.id = $bar_id +WHERE owner = $owner; + +-- name: JoinNoConstraints :many +SELECT foo.* +FROM foo +CROSS JOIN bar +WHERE bar.id = $bar_id AND owner = $owner; diff --git a/internal/endtoend/testdata/join_where_clause/ydb/stdlib/schema.sql b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..855a6a8285 --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/schema.sql @@ -0,0 +1,2 @@ +CREATE TABLE foo (barid Serial, PRIMARY KEY (barid)); +CREATE TABLE bar (id Serial, owner Text NOT NULL, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/join_where_clause/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..b133b28e36 --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 + Owner string +} + +type Foo struct { + Barid int32 +} diff --git a/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..31cd751993 --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,125 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const joinNoConstraints = `-- name: JoinNoConstraints :many +SELECT foo.barid +FROM foo +CROSS JOIN bar +WHERE bar.id = $bar_id AND owner = $owner +` + +type JoinNoConstraintsParams struct { + BarID int32 + Owner string +} + +func (q *Queries) JoinNoConstraints(ctx context.Context, arg JoinNoConstraintsParams, opts ...query.ExecuteOption) ([]int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$bar_id").Int32(arg.BarID) + parameters = parameters.Param("$owner").Text(arg.Owner) + result, err := q.db.QueryResultSet(ctx, joinNoConstraints, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []int32 + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var barid int32 + if err := row.Scan(&barid); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, barid) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const joinParamWhereClause = `-- name: JoinParamWhereClause :many +SELECT f.barid +FROM foo AS f +JOIN bar AS b ON b.id = f.barid +WHERE b.id = $bar_id AND b.owner = $owner +` + +type JoinParamWhereClauseParams struct { + BarID int32 + Owner string +} + +func (q *Queries) JoinParamWhereClause(ctx context.Context, arg JoinParamWhereClauseParams, opts ...query.ExecuteOption) ([]int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$bar_id").Int32(arg.BarID) + parameters = parameters.Param("$owner").Text(arg.Owner) + result, err := q.db.QueryResultSet(ctx, joinParamWhereClause, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []int32 + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var barid int32 + if err := row.Scan(&barid); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, barid) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const joinWhereClause = `-- name: JoinWhereClause :many +SELECT foo.barid +FROM foo +JOIN bar ON bar.id = barid +WHERE owner = $owner +` + +func (q *Queries) JoinWhereClause(ctx context.Context, owner string, opts ...query.ExecuteOption) ([]int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$owner").Text(owner) + result, err := q.db.QueryResultSet(ctx, joinWhereClause, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []int32 + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var barid int32 + if err := row.Scan(&barid); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, barid) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..3f7334f836 --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,17 @@ +-- name: JoinWhereClause :many +SELECT foo.* +FROM foo +JOIN bar ON bar.id = barid +WHERE owner = $owner; + +-- name: JoinParamWhereClause :many +SELECT f.* +FROM foo AS f +JOIN bar AS b ON b.id = f.barid +WHERE b.id = $bar_id AND b.owner = $owner; + +-- name: JoinNoConstraints :many +SELECT foo.* +FROM foo +CROSS JOIN bar +WHERE bar.id = $bar_id AND owner = $owner; diff --git a/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..855a6a8285 --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,2 @@ +CREATE TABLE foo (barid Serial, PRIMARY KEY (barid)); +CREATE TABLE bar (id Serial, owner Text NOT NULL, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/join_where_clause/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/json/ydb/stdlib/go/db.go b/internal/endtoend/testdata/json/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/json/ydb/stdlib/go/models.go b/internal/endtoend/testdata/json/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..ef5c3a0328 --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/stdlib/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string + B []byte + C *string + D *[]byte +} diff --git a/internal/endtoend/testdata/json/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/json/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..7144c0f706 --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/stdlib/go/query.sql.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const selectFoo = `-- name: SelectFoo :exec +SELECT a, b, c, d FROM foo +` + +func (q *Queries) SelectFoo(ctx context.Context) error { + _, err := q.db.ExecContext(ctx, selectFoo) + return err +} diff --git a/internal/endtoend/testdata/json/ydb/stdlib/query.sql b/internal/endtoend/testdata/json/ydb/stdlib/query.sql new file mode 100644 index 0000000000..a8629cc2ae --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: SelectFoo :exec +SELECT * FROM foo; diff --git a/internal/endtoend/testdata/json/ydb/stdlib/schema.sql b/internal/endtoend/testdata/json/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..06d8b557f4 --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/stdlib/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE foo ( + a Json NOT NULL, + b Yson NOT NULL, + c Json, + d Yson, + PRIMARY KEY (a, b) +); diff --git a/internal/endtoend/testdata/json/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/json/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..ef5c3a0328 --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string + B []byte + C *string + D *[]byte +} diff --git a/internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..9ff535bf23 --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,25 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const selectFoo = `-- name: SelectFoo :exec +SELECT a, b, c, d FROM foo +` + +func (q *Queries) SelectFoo(ctx context.Context, opts ...query.ExecuteOption) error { + err := q.db.Exec(ctx, selectFoo, opts...) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/json/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..a8629cc2ae --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: SelectFoo :exec +SELECT * FROM foo; diff --git a/internal/endtoend/testdata/json/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..06d8b557f4 --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE foo ( + a Json NOT NULL, + b Yson NOT NULL, + c Json, + d Yson, + PRIMARY KEY (a, b) +); diff --git a/internal/endtoend/testdata/json/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..485a8c1752 --- /dev/null +++ b/internal/endtoend/testdata/json/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "sql_package": "ydb-go-sdk", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/limit/ydb/go/db.go b/internal/endtoend/testdata/limit/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/limit/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/limit/ydb/go/models.go b/internal/endtoend/testdata/limit/ydb/go/models.go new file mode 100644 index 0000000000..04bc70ad65 --- /dev/null +++ b/internal/endtoend/testdata/limit/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar bool +} diff --git a/internal/endtoend/testdata/limit/ydb/go/query.sql.go b/internal/endtoend/testdata/limit/ydb/go/query.sql.go new file mode 100644 index 0000000000..c229c698a2 --- /dev/null +++ b/internal/endtoend/testdata/limit/ydb/go/query.sql.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const limitMe = `-- name: LimitMe :many +SELECT bar FROM foo LIMIT $limit +` + +func (q *Queries) LimitMe(ctx context.Context, limit uint64) ([]bool, error) { + rows, err := q.db.QueryContext(ctx, limitMe, limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []bool + for rows.Next() { + var bar bool + if err := rows.Scan(&bar); err != nil { + return nil, err + } + items = append(items, bar) + } + 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/limit/ydb/query.sql b/internal/endtoend/testdata/limit/ydb/query.sql new file mode 100644 index 0000000000..eee7776f34 --- /dev/null +++ b/internal/endtoend/testdata/limit/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: LimitMe :many +SELECT bar FROM foo LIMIT $limit; diff --git a/internal/endtoend/testdata/limit/ydb/schema.sql b/internal/endtoend/testdata/limit/ydb/schema.sql new file mode 100644 index 0000000000..1c8e454a7f --- /dev/null +++ b/internal/endtoend/testdata/limit/ydb/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (bar Bool NOT NULL, PRIMARY KEY (bar)); diff --git a/internal/endtoend/testdata/limit/ydb/sqlc.json b/internal/endtoend/testdata/limit/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/limit/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/lower/ydb/go/db.go b/internal/endtoend/testdata/lower/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/lower/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/lower/ydb/go/models.go b/internal/endtoend/testdata/lower/ydb/go/models.go new file mode 100644 index 0000000000..061b030b06 --- /dev/null +++ b/internal/endtoend/testdata/lower/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string + Bat string +} diff --git a/internal/endtoend/testdata/lower/ydb/go/query.sql.go b/internal/endtoend/testdata/lower/ydb/go/query.sql.go new file mode 100644 index 0000000000..d5c1f04d4f --- /dev/null +++ b/internal/endtoend/testdata/lower/ydb/go/query.sql.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const lower = `-- name: Lower :many +SELECT bar FROM foo WHERE bar = $bar AND Unicode::ToLower(bat) = $bat_lower +` + +type LowerParams struct { + Bar string + BatLower string +} + +func (q *Queries) Lower(ctx context.Context, arg LowerParams) ([]string, error) { + rows, err := q.db.QueryContext(ctx, lower, arg.Bar, arg.BatLower) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var bar string + if err := rows.Scan(&bar); err != nil { + return nil, err + } + items = append(items, bar) + } + 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/lower/ydb/query.sql b/internal/endtoend/testdata/lower/ydb/query.sql new file mode 100644 index 0000000000..a4ce95c06e --- /dev/null +++ b/internal/endtoend/testdata/lower/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: Lower :many +SELECT bar FROM foo WHERE bar = $bar AND Unicode::ToLower(bat) = $bat_lower; diff --git a/internal/endtoend/testdata/lower/ydb/schema.sql b/internal/endtoend/testdata/lower/ydb/schema.sql new file mode 100644 index 0000000000..fb51686ecf --- /dev/null +++ b/internal/endtoend/testdata/lower/ydb/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (bar Text NOT NULL, bat Text NOT NULL, PRIMARY KEY (bar, bat)); diff --git a/internal/endtoend/testdata/lower/ydb/sqlc.json b/internal/endtoend/testdata/lower/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/lower/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/lower_switched_order/ydb/go/db.go b/internal/endtoend/testdata/lower_switched_order/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/lower_switched_order/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/lower_switched_order/ydb/go/models.go b/internal/endtoend/testdata/lower_switched_order/ydb/go/models.go new file mode 100644 index 0000000000..061b030b06 --- /dev/null +++ b/internal/endtoend/testdata/lower_switched_order/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string + Bat string +} diff --git a/internal/endtoend/testdata/lower_switched_order/ydb/go/query.sql.go b/internal/endtoend/testdata/lower_switched_order/ydb/go/query.sql.go new file mode 100644 index 0000000000..7b1fe15945 --- /dev/null +++ b/internal/endtoend/testdata/lower_switched_order/ydb/go/query.sql.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const lowerSwitchedOrder = `-- name: LowerSwitchedOrder :many +SELECT bar FROM foo WHERE bar = $bar AND bat = Unicode::ToLower($bat_lower) +` + +type LowerSwitchedOrderParams struct { + Bar string + BatLower string +} + +func (q *Queries) LowerSwitchedOrder(ctx context.Context, arg LowerSwitchedOrderParams) ([]string, error) { + rows, err := q.db.QueryContext(ctx, lowerSwitchedOrder, arg.Bar, arg.BatLower) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var bar string + if err := rows.Scan(&bar); err != nil { + return nil, err + } + items = append(items, bar) + } + 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/lower_switched_order/ydb/query.sql b/internal/endtoend/testdata/lower_switched_order/ydb/query.sql new file mode 100644 index 0000000000..d8a6cc9a38 --- /dev/null +++ b/internal/endtoend/testdata/lower_switched_order/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: LowerSwitchedOrder :many +SELECT bar FROM foo WHERE bar = $bar AND bat = Unicode::ToLower($bat_lower); diff --git a/internal/endtoend/testdata/lower_switched_order/ydb/schema.sql b/internal/endtoend/testdata/lower_switched_order/ydb/schema.sql new file mode 100644 index 0000000000..fb51686ecf --- /dev/null +++ b/internal/endtoend/testdata/lower_switched_order/ydb/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (bar Text NOT NULL, bat Text NOT NULL, PRIMARY KEY (bar, bat)); diff --git a/internal/endtoend/testdata/lower_switched_order/ydb/sqlc.json b/internal/endtoend/testdata/lower_switched_order/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/lower_switched_order/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/mathmatical_operator/ydb/go/db.go b/internal/endtoend/testdata/mathmatical_operator/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/mathmatical_operator/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/mathmatical_operator/ydb/go/models.go b/internal/endtoend/testdata/mathmatical_operator/ydb/go/models.go new file mode 100644 index 0000000000..8a66a8cf24 --- /dev/null +++ b/internal/endtoend/testdata/mathmatical_operator/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Num int32 +} diff --git a/internal/endtoend/testdata/mathmatical_operator/ydb/go/query.sql.go b/internal/endtoend/testdata/mathmatical_operator/ydb/go/query.sql.go new file mode 100644 index 0000000000..20064cca04 --- /dev/null +++ b/internal/endtoend/testdata/mathmatical_operator/ydb/go/query.sql.go @@ -0,0 +1,42 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const math = `-- name: Math :many +SELECT num, num / 1024 AS division FROM foo +` + +type MathRow struct { + Num int32 + Division int32 +} + +func (q *Queries) Math(ctx context.Context) ([]MathRow, error) { + rows, err := q.db.QueryContext(ctx, math) + if err != nil { + return nil, err + } + defer rows.Close() + var items []MathRow + for rows.Next() { + var i MathRow + if err := rows.Scan(&i.Num, &i.Division); err != nil { + return nil, err + } + items = append(items, i) + } + 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/mathmatical_operator/ydb/query.sql b/internal/endtoend/testdata/mathmatical_operator/ydb/query.sql new file mode 100644 index 0000000000..62fec765cd --- /dev/null +++ b/internal/endtoend/testdata/mathmatical_operator/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: Math :many +SELECT *, num / 1024 AS division FROM foo; diff --git a/internal/endtoend/testdata/mathmatical_operator/ydb/schema.sql b/internal/endtoend/testdata/mathmatical_operator/ydb/schema.sql new file mode 100644 index 0000000000..995f0a34b3 --- /dev/null +++ b/internal/endtoend/testdata/mathmatical_operator/ydb/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (num Int32 NOT NULL, PRIMARY KEY (num)); diff --git a/internal/endtoend/testdata/mathmatical_operator/ydb/sqlc.json b/internal/endtoend/testdata/mathmatical_operator/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/mathmatical_operator/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/min_max_date/ydb/go/db.go b/internal/endtoend/testdata/min_max_date/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/min_max_date/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/min_max_date/ydb/go/models.go b/internal/endtoend/testdata/min_max_date/ydb/go/models.go new file mode 100644 index 0000000000..afe5257532 --- /dev/null +++ b/internal/endtoend/testdata/min_max_date/ydb/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "time" +) + +type Activity struct { + AccountID int64 + EventTime time.Time +} diff --git a/internal/endtoend/testdata/min_max_date/ydb/go/query.sql.go b/internal/endtoend/testdata/min_max_date/ydb/go/query.sql.go new file mode 100644 index 0000000000..f3579ba64b --- /dev/null +++ b/internal/endtoend/testdata/min_max_date/ydb/go/query.sql.go @@ -0,0 +1,32 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + "time" +) + +const activityStats = `-- name: ActivityStats :one +SELECT COUNT(*) AS NumOfActivities, + CAST(MIN(event_time) AS Timestamp) AS MinDate, + CAST(MAX(event_time) AS Timestamp) AS MaxDate +FROM activities +WHERE account_id = $account_id +` + +type ActivityStatsRow struct { + Numofactivities uint64 + Mindate time.Time + Maxdate time.Time +} + +func (q *Queries) ActivityStats(ctx context.Context, accountID int64) (ActivityStatsRow, error) { + row := q.db.QueryRowContext(ctx, activityStats, accountID) + var i ActivityStatsRow + err := row.Scan(&i.Numofactivities, &i.Mindate, &i.Maxdate) + return i, err +} diff --git a/internal/endtoend/testdata/min_max_date/ydb/query.sql b/internal/endtoend/testdata/min_max_date/ydb/query.sql new file mode 100644 index 0000000000..abfb18e8cb --- /dev/null +++ b/internal/endtoend/testdata/min_max_date/ydb/query.sql @@ -0,0 +1,7 @@ +-- name: ActivityStats :one +SELECT COUNT(*) AS NumOfActivities, + CAST(MIN(event_time) AS Timestamp) AS MinDate, + CAST(MAX(event_time) AS Timestamp) AS MaxDate +FROM activities +WHERE account_id = $account_id; + diff --git a/internal/endtoend/testdata/min_max_date/ydb/schema.sql b/internal/endtoend/testdata/min_max_date/ydb/schema.sql new file mode 100644 index 0000000000..e927d59752 --- /dev/null +++ b/internal/endtoend/testdata/min_max_date/ydb/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE activities ( + account_id Int64 NOT NULL, + event_time Timestamp NOT NULL, + PRIMARY KEY (account_id, event_time) +); + diff --git a/internal/endtoend/testdata/min_max_date/ydb/sqlc.json b/internal/endtoend/testdata/min_max_date/ydb/sqlc.json new file mode 100644 index 0000000000..3e245cf4a5 --- /dev/null +++ b/internal/endtoend/testdata/min_max_date/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/mix_param_types/ydb/go/db.go b/internal/endtoend/testdata/mix_param_types/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/mix_param_types/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/mix_param_types/ydb/go/models.go b/internal/endtoend/testdata/mix_param_types/ydb/go/models.go new file mode 100644 index 0000000000..2f0803b319 --- /dev/null +++ b/internal/endtoend/testdata/mix_param_types/ydb/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 + Name string + Phone string +} diff --git a/internal/endtoend/testdata/mix_param_types/ydb/go/test.sql.go b/internal/endtoend/testdata/mix_param_types/ydb/go/test.sql.go new file mode 100644 index 0000000000..73bc8daf42 --- /dev/null +++ b/internal/endtoend/testdata/mix_param_types/ydb/go/test.sql.go @@ -0,0 +1,60 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: test.sql + +package querytest + +import ( + "context" +) + +const countOne = `-- name: CountOne :one +SELECT COUNT(1) FROM bar WHERE id = $id AND name <> $name LIMIT $limit +` + +type CountOneParams struct { + ID int32 + Name string + Limit uint64 +} + +func (q *Queries) CountOne(ctx context.Context, arg CountOneParams) (uint64, error) { + row := q.db.QueryRowContext(ctx, countOne, arg.ID, arg.Name, arg.Limit) + var count uint64 + err := row.Scan(&count) + return count, err +} + +const countThree = `-- name: CountThree :one +SELECT COUNT(1) FROM bar WHERE id > $id_gt AND phone <> $phone AND name <> $name +` + +type CountThreeParams struct { + IDGt int32 + Phone string + Name string +} + +func (q *Queries) CountThree(ctx context.Context, arg CountThreeParams) (uint64, error) { + row := q.db.QueryRowContext(ctx, countThree, arg.IDGt, arg.Phone, arg.Name) + var count uint64 + err := row.Scan(&count) + return count, err +} + +const countTwo = `-- name: CountTwo :one +SELECT COUNT(1) FROM bar WHERE id = $id AND name <> $name +` + +type CountTwoParams struct { + ID int32 + Name string +} + +func (q *Queries) CountTwo(ctx context.Context, arg CountTwoParams) (uint64, error) { + row := q.db.QueryRowContext(ctx, countTwo, arg.ID, arg.Name) + var count uint64 + err := row.Scan(&count) + return count, err +} diff --git a/internal/endtoend/testdata/mix_param_types/ydb/schema.sql b/internal/endtoend/testdata/mix_param_types/ydb/schema.sql new file mode 100644 index 0000000000..50f75de4d5 --- /dev/null +++ b/internal/endtoend/testdata/mix_param_types/ydb/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE bar ( + id Serial NOT NULL, + name Text NOT NULL, + phone Text NOT NULL, + PRIMARY KEY (id) +); + diff --git a/internal/endtoend/testdata/mix_param_types/ydb/sqlc.json b/internal/endtoend/testdata/mix_param_types/ydb/sqlc.json new file mode 100644 index 0000000000..773da22c68 --- /dev/null +++ b/internal/endtoend/testdata/mix_param_types/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "test.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/mix_param_types/ydb/test.sql b/internal/endtoend/testdata/mix_param_types/ydb/test.sql new file mode 100644 index 0000000000..ba70955e54 --- /dev/null +++ b/internal/endtoend/testdata/mix_param_types/ydb/test.sql @@ -0,0 +1,9 @@ +-- name: CountOne :one +SELECT COUNT(1) FROM bar WHERE id = $id AND name <> $name LIMIT $limit; + +-- name: CountTwo :one +SELECT COUNT(1) FROM bar WHERE id = $id AND name <> $name; + +-- name: CountThree :one +SELECT COUNT(1) FROM bar WHERE id > $id_gt AND phone <> $phone AND name <> $name; + diff --git a/internal/endtoend/testdata/named_param/ydb/go/db.go b/internal/endtoend/testdata/named_param/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/named_param/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/named_param/ydb/go/models.go b/internal/endtoend/testdata/named_param/ydb/go/models.go new file mode 100644 index 0000000000..7d01ec0654 --- /dev/null +++ b/internal/endtoend/testdata/named_param/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Name string + Bio string +} diff --git a/internal/endtoend/testdata/named_param/ydb/go/query.sql.go b/internal/endtoend/testdata/named_param/ydb/go/query.sql.go new file mode 100644 index 0000000000..777be0c5bb --- /dev/null +++ b/internal/endtoend/testdata/named_param/ydb/go/query.sql.go @@ -0,0 +1,128 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const atParams = `-- name: AtParams :many +SELECT name FROM foo WHERE name = $slug AND CAST($filter AS Bool) +` + +type AtParamsParams struct { + Slug string + Filter bool +} + +func (q *Queries) AtParams(ctx context.Context, arg AtParamsParams) ([]string, error) { + rows, err := q.db.QueryContext(ctx, atParams, arg.Slug, arg.Filter) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + return nil, err + } + items = append(items, name) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const funcParams = `-- name: FuncParams :many +SELECT name FROM foo WHERE name = $slug AND CAST($filter AS Bool) +` + +type FuncParamsParams struct { + Slug string + Filter bool +} + +func (q *Queries) FuncParams(ctx context.Context, arg FuncParamsParams) ([]string, error) { + rows, err := q.db.QueryContext(ctx, funcParams, arg.Slug, arg.Filter) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + return nil, err + } + items = append(items, name) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const insertAtParams = `-- name: InsertAtParams :one +INSERT INTO foo(name, bio) VALUES ($name, $bio) RETURNING name +` + +type InsertAtParamsParams struct { + Name string + Bio string +} + +func (q *Queries) InsertAtParams(ctx context.Context, arg InsertAtParamsParams) (string, error) { + row := q.db.QueryRowContext(ctx, insertAtParams, arg.Name, arg.Bio) + var name string + err := row.Scan(&name) + return name, err +} + +const insertFuncParams = `-- name: InsertFuncParams :one +INSERT INTO foo(name, bio) VALUES ($name, $bio) RETURNING name +` + +type InsertFuncParamsParams struct { + Name string + Bio string +} + +func (q *Queries) InsertFuncParams(ctx context.Context, arg InsertFuncParamsParams) (string, error) { + row := q.db.QueryRowContext(ctx, insertFuncParams, arg.Name, arg.Bio) + var name string + err := row.Scan(&name) + return name, err +} + +const update = `-- name: Update :one +UPDATE foo +SET + name = CASE WHEN CAST($set_name AS Bool) + THEN CAST($name AS Text) + ELSE name + END +RETURNING name, bio +` + +type UpdateParams struct { + SetName bool + Name string +} + +func (q *Queries) Update(ctx context.Context, arg UpdateParams) (Foo, error) { + row := q.db.QueryRowContext(ctx, update, arg.SetName, arg.Name) + var i Foo + err := row.Scan(&i.Name, &i.Bio) + return i, err +} diff --git a/internal/endtoend/testdata/named_param/ydb/query.sql b/internal/endtoend/testdata/named_param/ydb/query.sql new file mode 100644 index 0000000000..ba617568cc --- /dev/null +++ b/internal/endtoend/testdata/named_param/ydb/query.sql @@ -0,0 +1,23 @@ +-- name: FuncParams :many +SELECT name FROM foo WHERE name = sqlc.arg(slug) AND CAST(sqlc.arg(filter) AS Bool); + +-- name: AtParams :many +SELECT name FROM foo WHERE name = $slug AND CAST($filter AS Bool); + +-- name: InsertFuncParams :one +INSERT INTO foo(name, bio) VALUES (sqlc.arg(name), sqlc.arg(bio)) RETURNING name; + +-- name: InsertAtParams :one +INSERT INTO foo(name, bio) VALUES ($name, $bio) RETURNING name; + +-- name: Update :one +UPDATE foo +SET + name = CASE WHEN CAST($set_name AS Bool) + THEN CAST($name AS Text) + ELSE name + END +RETURNING *; + + + diff --git a/internal/endtoend/testdata/named_param/ydb/schema.sql b/internal/endtoend/testdata/named_param/ydb/schema.sql new file mode 100644 index 0000000000..f5b3431310 --- /dev/null +++ b/internal/endtoend/testdata/named_param/ydb/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo (name Text NOT NULL, bio Text NOT NULL, PRIMARY KEY (name)); + + + diff --git a/internal/endtoend/testdata/named_param/ydb/sqlc.json b/internal/endtoend/testdata/named_param/ydb/sqlc.json new file mode 100644 index 0000000000..c5959ba446 --- /dev/null +++ b/internal/endtoend/testdata/named_param/ydb/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/nested_select/ydb/go/db.go b/internal/endtoend/testdata/nested_select/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/nested_select/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/nested_select/ydb/go/models.go b/internal/endtoend/testdata/nested_select/ydb/go/models.go new file mode 100644 index 0000000000..b3f22ae1ba --- /dev/null +++ b/internal/endtoend/testdata/nested_select/ydb/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Test struct { + ID int64 + UpdateTime int64 + Count int64 +} diff --git a/internal/endtoend/testdata/nested_select/ydb/go/query.sql.go b/internal/endtoend/testdata/nested_select/ydb/go/query.sql.go new file mode 100644 index 0000000000..c12aa83e48 --- /dev/null +++ b/internal/endtoend/testdata/nested_select/ydb/go/query.sql.go @@ -0,0 +1,39 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const nestedSelect = `-- name: NestedSelect :one +SELECT latest.id, t.count +FROM ( + SELECT id, MAX(update_time) AS update_time + FROM test + WHERE test.id IN $ids + AND test.update_time >= $start_time + GROUP BY id +) latest +INNER JOIN test t USING (id, update_time) +` + +type NestedSelectParams struct { + Ids []int64 + StartTime int64 +} + +type NestedSelectRow struct { + ID int64 + Count int64 +} + +func (q *Queries) NestedSelect(ctx context.Context, arg NestedSelectParams) (NestedSelectRow, error) { + row := q.db.QueryRowContext(ctx, nestedSelect, arg.Ids, arg.StartTime) + var i NestedSelectRow + err := row.Scan(&i.ID, &i.Count) + return i, err +} diff --git a/internal/endtoend/testdata/nested_select/ydb/query.sql b/internal/endtoend/testdata/nested_select/ydb/query.sql new file mode 100644 index 0000000000..8121c59e1e --- /dev/null +++ b/internal/endtoend/testdata/nested_select/ydb/query.sql @@ -0,0 +1,11 @@ +-- name: NestedSelect :one +SELECT latest.id, t.count +FROM ( + SELECT id, MAX(update_time) AS update_time + FROM test + WHERE test.id IN sqlc.slice(ids) + AND test.update_time >= $start_time + GROUP BY id +) latest +INNER JOIN test t USING (id, update_time); + diff --git a/internal/endtoend/testdata/nested_select/ydb/schema.sql b/internal/endtoend/testdata/nested_select/ydb/schema.sql new file mode 100644 index 0000000000..11b66bf3b0 --- /dev/null +++ b/internal/endtoend/testdata/nested_select/ydb/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE test ( + id Int64 NOT NULL, + update_time Int64 NOT NULL, + count Int64 NOT NULL, + PRIMARY KEY (id, update_time) +); + diff --git a/internal/endtoend/testdata/nested_select/ydb/sqlc.json b/internal/endtoend/testdata/nested_select/ydb/sqlc.json new file mode 100644 index 0000000000..3e245cf4a5 --- /dev/null +++ b/internal/endtoend/testdata/nested_select/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/on_duplicate_key_update/ydb/go/db.go b/internal/endtoend/testdata/on_duplicate_key_update/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/on_duplicate_key_update/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/on_duplicate_key_update/ydb/go/models.go b/internal/endtoend/testdata/on_duplicate_key_update/ydb/go/models.go new file mode 100644 index 0000000000..93e9ce7933 --- /dev/null +++ b/internal/endtoend/testdata/on_duplicate_key_update/ydb/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int64 + Name string + Bio *string +} diff --git a/internal/endtoend/testdata/on_duplicate_key_update/ydb/go/query.sql.go b/internal/endtoend/testdata/on_duplicate_key_update/ydb/go/query.sql.go new file mode 100644 index 0000000000..0ce41ee7d7 --- /dev/null +++ b/internal/endtoend/testdata/on_duplicate_key_update/ydb/go/query.sql.go @@ -0,0 +1,40 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const upsertAuthor = `-- name: UpsertAuthor :exec +UPSERT INTO authors (name, bio) +VALUES ($name, $bio) +` + +type UpsertAuthorParams struct { + Name string + Bio *string +} + +func (q *Queries) UpsertAuthor(ctx context.Context, arg UpsertAuthorParams) error { + _, err := q.db.ExecContext(ctx, upsertAuthor, arg.Name, arg.Bio) + return err +} + +const upsertAuthorNamed = `-- name: UpsertAuthorNamed :exec +UPSERT INTO authors (name, bio) +VALUES ($name, $bio) +` + +type UpsertAuthorNamedParams struct { + Name string + Bio *string +} + +func (q *Queries) UpsertAuthorNamed(ctx context.Context, arg UpsertAuthorNamedParams) error { + _, err := q.db.ExecContext(ctx, upsertAuthorNamed, arg.Name, arg.Bio) + return err +} diff --git a/internal/endtoend/testdata/on_duplicate_key_update/ydb/query.sql b/internal/endtoend/testdata/on_duplicate_key_update/ydb/query.sql new file mode 100644 index 0000000000..54efc099e8 --- /dev/null +++ b/internal/endtoend/testdata/on_duplicate_key_update/ydb/query.sql @@ -0,0 +1,8 @@ +-- name: UpsertAuthor :exec +UPSERT INTO authors (name, bio) +VALUES ($name, $bio); + +-- name: UpsertAuthorNamed :exec +UPSERT INTO authors (name, bio) +VALUES ($name, $bio); + diff --git a/internal/endtoend/testdata/on_duplicate_key_update/ydb/schema.sql b/internal/endtoend/testdata/on_duplicate_key_update/ydb/schema.sql new file mode 100644 index 0000000000..1c99aaacc5 --- /dev/null +++ b/internal/endtoend/testdata/on_duplicate_key_update/ydb/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); + diff --git a/internal/endtoend/testdata/on_duplicate_key_update/ydb/sqlc.json b/internal/endtoend/testdata/on_duplicate_key_update/ydb/sqlc.json new file mode 100644 index 0000000000..3e245cf4a5 --- /dev/null +++ b/internal/endtoend/testdata/on_duplicate_key_update/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/order_by_binds/ydb/go/db.go b/internal/endtoend/testdata/order_by_binds/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/order_by_binds/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/order_by_binds/ydb/go/models.go b/internal/endtoend/testdata/order_by_binds/ydb/go/models.go new file mode 100644 index 0000000000..93e9ce7933 --- /dev/null +++ b/internal/endtoend/testdata/order_by_binds/ydb/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int64 + Name string + Bio *string +} diff --git a/internal/endtoend/testdata/order_by_binds/ydb/go/query.sql.go b/internal/endtoend/testdata/order_by_binds/ydb/go/query.sql.go new file mode 100644 index 0000000000..2005beff5d --- /dev/null +++ b/internal/endtoend/testdata/order_by_binds/ydb/go/query.sql.go @@ -0,0 +1,101 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const listAuthorsColumnSort = `-- name: ListAuthorsColumnSort :many +SELECT id, name, bio FROM authors +WHERE id > $min_id +ORDER BY CASE WHEN $sort_column = 'name' THEN name END +` + +type ListAuthorsColumnSortParams struct { + MinID int64 + SortColumn interface{} +} + +func (q *Queries) ListAuthorsColumnSort(ctx context.Context, arg ListAuthorsColumnSortParams) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthorsColumnSort, arg.MinID, arg.SortColumn) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listAuthorsColumnSortFnWtihArg = `-- name: ListAuthorsColumnSortFnWtihArg :many +SELECT id, name, bio FROM authors +ORDER BY Math::mod(id, $mod_arg) +` + +func (q *Queries) ListAuthorsColumnSortFnWtihArg(ctx context.Context, modArg int64) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthorsColumnSortFnWtihArg, modArg) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listAuthorsNameSort = `-- name: ListAuthorsNameSort :many +SELECT id, name, bio FROM authors +WHERE id > $min_id +ORDER BY name ASC +` + +func (q *Queries) ListAuthorsNameSort(ctx context.Context, minID int64) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthorsNameSort, minID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + 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/order_by_binds/ydb/query.sql b/internal/endtoend/testdata/order_by_binds/ydb/query.sql new file mode 100644 index 0000000000..332d2b9a26 --- /dev/null +++ b/internal/endtoend/testdata/order_by_binds/ydb/query.sql @@ -0,0 +1,14 @@ +-- name: ListAuthorsColumnSort :many +SELECT * FROM authors +WHERE id > $min_id +ORDER BY CASE WHEN $sort_column = 'name' THEN name END; + +-- name: ListAuthorsColumnSortFnWtihArg :many +SELECT * FROM authors +ORDER BY Math::mod(id, $mod_arg); + +-- name: ListAuthorsNameSort :many +SELECT * FROM authors +WHERE id > $min_id +ORDER BY name ASC; + diff --git a/internal/endtoend/testdata/order_by_binds/ydb/schema.sql b/internal/endtoend/testdata/order_by_binds/ydb/schema.sql new file mode 100644 index 0000000000..1c99aaacc5 --- /dev/null +++ b/internal/endtoend/testdata/order_by_binds/ydb/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); + diff --git a/internal/endtoend/testdata/order_by_binds/ydb/sqlc.json b/internal/endtoend/testdata/order_by_binds/ydb/sqlc.json new file mode 100644 index 0000000000..3e245cf4a5 --- /dev/null +++ b/internal/endtoend/testdata/order_by_binds/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/order_by_union/ydb/go/db.go b/internal/endtoend/testdata/order_by_union/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/order_by_union/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/order_by_union/ydb/go/models.go b/internal/endtoend/testdata/order_by_union/ydb/go/models.go new file mode 100644 index 0000000000..f7fc5cab3e --- /dev/null +++ b/internal/endtoend/testdata/order_by_union/ydb/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int64 + Name string + Bio *string +} + +type Person struct { + FirstName string +} diff --git a/internal/endtoend/testdata/order_by_union/ydb/go/query.sql.go b/internal/endtoend/testdata/order_by_union/ydb/go/query.sql.go new file mode 100644 index 0000000000..8c539e7245 --- /dev/null +++ b/internal/endtoend/testdata/order_by_union/ydb/go/query.sql.go @@ -0,0 +1,40 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const listAuthorsUnion = `-- name: ListAuthorsUnion :many +SELECT name AS foo FROM authors +UNION +SELECT first_name AS foo FROM people +ORDER BY foo +` + +func (q *Queries) ListAuthorsUnion(ctx context.Context) ([]string, error) { + rows, err := q.db.QueryContext(ctx, listAuthorsUnion) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var foo string + if err := rows.Scan(&foo); err != nil { + return nil, err + } + items = append(items, foo) + } + 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/order_by_union/ydb/query.sql b/internal/endtoend/testdata/order_by_union/ydb/query.sql new file mode 100644 index 0000000000..53879ba32d --- /dev/null +++ b/internal/endtoend/testdata/order_by_union/ydb/query.sql @@ -0,0 +1,6 @@ +-- name: ListAuthorsUnion :many +SELECT name AS foo FROM authors +UNION +SELECT first_name AS foo FROM people +ORDER BY foo; + diff --git a/internal/endtoend/testdata/order_by_union/ydb/schema.sql b/internal/endtoend/testdata/order_by_union/ydb/schema.sql new file mode 100644 index 0000000000..becb9404fc --- /dev/null +++ b/internal/endtoend/testdata/order_by_union/ydb/schema.sql @@ -0,0 +1,12 @@ +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); + +CREATE TABLE people ( + first_name Text NOT NULL, + PRIMARY KEY (first_name) +); + diff --git a/internal/endtoend/testdata/order_by_union/ydb/sqlc.json b/internal/endtoend/testdata/order_by_union/ydb/sqlc.json new file mode 100644 index 0000000000..3e245cf4a5 --- /dev/null +++ b/internal/endtoend/testdata/order_by_union/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/output_file_names/ydb/go/db_gen.go b/internal/endtoend/testdata/output_file_names/ydb/go/db_gen.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/output_file_names/ydb/go/db_gen.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/output_file_names/ydb/go/models_gen.go b/internal/endtoend/testdata/output_file_names/ydb/go/models_gen.go new file mode 100644 index 0000000000..1e2b476e23 --- /dev/null +++ b/internal/endtoend/testdata/output_file_names/ydb/go/models_gen.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type UserTable struct { + ID int64 +} diff --git a/internal/endtoend/testdata/output_file_names/ydb/go/querier_gen.go b/internal/endtoend/testdata/output_file_names/ydb/go/querier_gen.go new file mode 100644 index 0000000000..8008c65e53 --- /dev/null +++ b/internal/endtoend/testdata/output_file_names/ydb/go/querier_gen.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" +) + +type Querier interface { + User(ctx context.Context) ([]int64, error) +} + +var _ Querier = (*Queries)(nil) diff --git a/internal/endtoend/testdata/output_file_names/ydb/go/query.sql.go b/internal/endtoend/testdata/output_file_names/ydb/go/query.sql.go new file mode 100644 index 0000000000..4e4e3228c6 --- /dev/null +++ b/internal/endtoend/testdata/output_file_names/ydb/go/query.sql.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const user = `-- name: User :many +SELECT user_table.id FROM user_table +` + +func (q *Queries) User(ctx context.Context) ([]int64, error) { + rows, err := q.db.QueryContext(ctx, user) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int64 + for rows.Next() { + var id int64 + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + 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/output_file_names/ydb/query.sql b/internal/endtoend/testdata/output_file_names/ydb/query.sql new file mode 100644 index 0000000000..4f7333943c --- /dev/null +++ b/internal/endtoend/testdata/output_file_names/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: User :many +SELECT user_table.* FROM user_table; diff --git a/internal/endtoend/testdata/output_file_names/ydb/schema.sql b/internal/endtoend/testdata/output_file_names/ydb/schema.sql new file mode 100644 index 0000000000..0766577d24 --- /dev/null +++ b/internal/endtoend/testdata/output_file_names/ydb/schema.sql @@ -0,0 +1 @@ +CREATE TABLE user_table (id BigSerial NOT NULL, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/output_file_names/ydb/sqlc.json b/internal/endtoend/testdata/output_file_names/ydb/sqlc.json new file mode 100644 index 0000000000..cc0e0134a7 --- /dev/null +++ b/internal/endtoend/testdata/output_file_names/ydb/sqlc.json @@ -0,0 +1,18 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "emit_interface": true, + "output_db_file_name": "db_gen.go", + "output_models_file_name": "models_gen.go", + "output_querier_file_name": "querier_gen.go", + "output_copyfrom_file_name": "copyfrom_gen.go" + } + ] +} + diff --git a/internal/endtoend/testdata/output_files_suffix/ydb/go/db.go b/internal/endtoend/testdata/output_files_suffix/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/output_files_suffix/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/output_files_suffix/ydb/go/models.go b/internal/endtoend/testdata/output_files_suffix/ydb/go/models.go new file mode 100644 index 0000000000..1e2b476e23 --- /dev/null +++ b/internal/endtoend/testdata/output_files_suffix/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type UserTable struct { + ID int64 +} diff --git a/internal/endtoend/testdata/output_files_suffix/ydb/go/query.sql_gen.go b/internal/endtoend/testdata/output_files_suffix/ydb/go/query.sql_gen.go new file mode 100644 index 0000000000..4e4e3228c6 --- /dev/null +++ b/internal/endtoend/testdata/output_files_suffix/ydb/go/query.sql_gen.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const user = `-- name: User :many +SELECT user_table.id FROM user_table +` + +func (q *Queries) User(ctx context.Context) ([]int64, error) { + rows, err := q.db.QueryContext(ctx, user) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int64 + for rows.Next() { + var id int64 + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + 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/output_files_suffix/ydb/query.sql b/internal/endtoend/testdata/output_files_suffix/ydb/query.sql new file mode 100644 index 0000000000..96756b4bf9 --- /dev/null +++ b/internal/endtoend/testdata/output_files_suffix/ydb/query.sql @@ -0,0 +1,3 @@ +-- name: User :many +SELECT user_table.* FROM user_table; + diff --git a/internal/endtoend/testdata/output_files_suffix/ydb/schema.sql b/internal/endtoend/testdata/output_files_suffix/ydb/schema.sql new file mode 100644 index 0000000000..8cb0cc766e --- /dev/null +++ b/internal/endtoend/testdata/output_files_suffix/ydb/schema.sql @@ -0,0 +1,2 @@ +CREATE TABLE user_table (id BigSerial NOT NULL, PRIMARY KEY (id)); + diff --git a/internal/endtoend/testdata/output_files_suffix/ydb/sqlc.json b/internal/endtoend/testdata/output_files_suffix/ydb/sqlc.json new file mode 100644 index 0000000000..b3e333b697 --- /dev/null +++ b/internal/endtoend/testdata/output_files_suffix/ydb/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "output_files_suffix": "_gen.go" + } + ] +} + diff --git a/internal/endtoend/testdata/overrides/ydb/go/db.go b/internal/endtoend/testdata/overrides/ydb/go/db.go new file mode 100644 index 0000000000..9c19dd4a09 --- /dev/null +++ b/internal/endtoend/testdata/overrides/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +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/overrides/ydb/go/models.go b/internal/endtoend/testdata/overrides/ydb/go/models.go new file mode 100644 index 0000000000..e6ba74a5a0 --- /dev/null +++ b/internal/endtoend/testdata/overrides/ydb/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +import ( + "github.com/sqlc-dev/sqlc-testdata/pkg" +) + +type Foo struct { + Other string + Total int64 + Retyped pkg.CustomType +} diff --git a/internal/endtoend/testdata/overrides/ydb/go/query.sql.go b/internal/endtoend/testdata/overrides/ydb/go/query.sql.go new file mode 100644 index 0000000000..0faba2cde4 --- /dev/null +++ b/internal/endtoend/testdata/overrides/ydb/go/query.sql.go @@ -0,0 +1,21 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package override + +import ( + "context" +) + +const test = `-- name: Test :one +SELECT 1 +` + +func (q *Queries) Test(ctx context.Context) (int32, error) { + row := q.db.QueryRowContext(ctx, test) + var column_1 int32 + err := row.Scan(&column_1) + return column_1, err +} diff --git a/internal/endtoend/testdata/overrides/ydb/query.sql b/internal/endtoend/testdata/overrides/ydb/query.sql new file mode 100644 index 0000000000..f25a508451 --- /dev/null +++ b/internal/endtoend/testdata/overrides/ydb/query.sql @@ -0,0 +1,3 @@ +-- name: Test :one +SELECT 1; + diff --git a/internal/endtoend/testdata/overrides/ydb/schema.sql b/internal/endtoend/testdata/overrides/ydb/schema.sql new file mode 100644 index 0000000000..a9d8a78142 --- /dev/null +++ b/internal/endtoend/testdata/overrides/ydb/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE foo ( + other Text, + total Int64, + retyped Text, + PRIMARY KEY (other, total, retyped) +); + diff --git a/internal/endtoend/testdata/overrides/ydb/sqlc.json b/internal/endtoend/testdata/overrides/ydb/sqlc.json new file mode 100644 index 0000000000..ee8e61cbf4 --- /dev/null +++ b/internal/endtoend/testdata/overrides/ydb/sqlc.json @@ -0,0 +1,19 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "override", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "overrides": [ + { + "go_type": "github.com/sqlc-dev/sqlc-testdata/pkg.CustomType", + "column": "foo.retyped" + } + ] + } + ] +} + diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/db.go b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..9c19dd4a09 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +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/overrides_go_struct_tags/ydb/stdlib/go/models.go b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..06ef973c29 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +type Foo struct { + ID string `utype:"notnull_text" x:"y"` + OtherID string `utype:"nullable_text"` + Notnulltext string `utype:"notnull_text"` +} diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..0faba2cde4 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/go/query.sql.go @@ -0,0 +1,21 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package override + +import ( + "context" +) + +const test = `-- name: Test :one +SELECT 1 +` + +func (q *Queries) Test(ctx context.Context) (int32, error) { + row := q.db.QueryRowContext(ctx, test) + var column_1 int32 + err := row.Scan(&column_1) + return column_1, err +} diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/query.sql b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/query.sql new file mode 100644 index 0000000000..9da604b57e --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: Test :one +SELECT 1; diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/schema.sql b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..da46a1f46c --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE foo ( + id Text, + other_id Text, + notnulltext Text NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..3e71c81237 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/stdlib/sqlc.json @@ -0,0 +1,28 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "override", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "overrides": [ + { + "column": "foo.id", + "go_struct_tag": "x:\"y\"" + }, + { + "db_type": "Text", + "go_struct_tag": "utype:\"notnull_text\"" + }, + { + "db_type": "Text", + "go_type": "string", + "nullable": true, + "go_struct_tag": "utype:\"nullable_text\"" + } + ] + } + ] +} diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..060435891a --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..06ef973c29 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +type Foo struct { + ID string `utype:"notnull_text" x:"y"` + OtherID string `utype:"nullable_text"` + Notnulltext string `utype:"notnull_text"` +} diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..6cc951bc6c --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,30 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package override + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const test = `-- name: Test :one +SELECT 1 +` + +func (q *Queries) Test(ctx context.Context, opts ...query.ExecuteOption) (int32, error) { + row, err := q.db.QueryRow(ctx, test, opts...) + var column_1 int32 + if err != nil { + return column_1, xerrors.WithStackTrace(err) + } + err = row.Scan(&column_1) + if err != nil { + return column_1, xerrors.WithStackTrace(err) + } + return column_1, nil +} diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..9da604b57e --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: Test :one +SELECT 1; diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..da46a1f46c --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE foo ( + id Text, + other_id Text, + notnulltext Text NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..8c0b2366bc --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_struct_tags/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,29 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "override", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk", + "overrides": [ + { + "column": "foo.id", + "go_struct_tag": "x:\"y\"" + }, + { + "db_type": "Text", + "go_struct_tag": "utype:\"notnull_text\"" + }, + { + "db_type": "Text", + "go_type": "string", + "nullable": true, + "go_struct_tag": "utype:\"nullable_text\"" + } + ] + } + ] +} diff --git a/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/db.go b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..9c19dd4a09 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +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/overrides_go_types/ydb/stdlib/go/models.go b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..e86b5539c9 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/models.go @@ -0,0 +1,22 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +import ( + orm "database/sql" + "github.com/gofrs/uuid" + fuid "github.com/gofrs/uuid" + null "github.com/volatiletech/null/v8" + null_v4 "gopkg.in/guregu/null.v4" +) + +type Foo struct { + ID uuid.UUID + OtherID fuid.UUID + Age orm.NullInt32 + Balance null.Float32 + Bio null_v4.String + About *string +} diff --git a/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..8c68b44ba7 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/go/query.sql.go @@ -0,0 +1,46 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package override + +import ( + "context" + + "github.com/gofrs/uuid" +) + +const loadFoo = `-- name: LoadFoo :many +SELECT id, other_id, age, balance, bio, about FROM foo WHERE id = $id +` + +func (q *Queries) LoadFoo(ctx context.Context, id uuid.UUID) ([]Foo, error) { + rows, err := q.db.QueryContext(ctx, loadFoo, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Foo + for rows.Next() { + var i Foo + if err := rows.Scan( + &i.ID, + &i.OtherID, + &i.Age, + &i.Balance, + &i.Bio, + &i.About, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/overrides_go_types/ydb/stdlib/query.sql b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/query.sql new file mode 100644 index 0000000000..8c7fb44672 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/query.sql @@ -0,0 +1,3 @@ +-- name: LoadFoo :many +SELECT * FROM foo WHERE id = $id; + diff --git a/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/schema.sql b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..d5136ad0a2 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE foo ( + id Uuid NOT NULL, + other_id Uuid NOT NULL, + age Int32, + balance Double, + bio Text, + about Text, + PRIMARY KEY (id) +); + diff --git a/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..ff3c3ad8f9 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/stdlib/sqlc.json @@ -0,0 +1,63 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "override", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "overrides": [ + { + "column": "foo.id", + "go_type": { + "import": "github.com/gofrs/uuid", + "type": "UUID" + } + }, + { + "column": "foo.other_id", + "go_type": { + "import": "github.com/gofrs/uuid", + "package": "fuid", + "type": "UUID" + } + }, + { + "column": "foo.age", + "nullable": true, + "go_type": { + "import": "database/sql", + "package": "orm", + "type": "NullInt32" + } + }, + { + "column": "foo.balance", + "nullable": true, + "go_type": { + "import": "github.com/volatiletech/null/v8", + "type": "Float32" + } + }, + { + "column": "foo.bio", + "nullable": true, + "go_type": { + "import": "gopkg.in/guregu/null.v4", + "type": "String" + } + }, + { + "column": "foo.about", + "nullable": true, + "go_type": { + "type": "string", + "pointer": true + } + } + ] + } + ] +} + diff --git a/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..060435891a --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..47089344a1 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,22 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +import ( + orm "database/sql" + fuid "github.com/gofrs/uuid" + "github.com/google/uuid" + null "github.com/volatiletech/null/v8" + null_v4 "gopkg.in/guregu/null.v4" +) + +type Foo struct { + ID uuid.UUID + OtherID fuid.UUID + Age orm.NullInt32 + Balance null.Float32 + Bio null_v4.String + About *string +} diff --git a/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..ed3211d7b5 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,52 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package override + +import ( + "context" + + "github.com/google/uuid" + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const loadFoo = `-- name: LoadFoo :many +SELECT id, other_id, age, balance, bio, about FROM foo WHERE id = $id +` + +func (q *Queries) LoadFoo(ctx context.Context, id uuid.UUID, opts ...query.ExecuteOption) ([]Foo, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Uuid(id) + result, err := q.db.QueryResultSet(ctx, loadFoo, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Foo + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Foo + if err := row.Scan( + &i.ID, + &i.OtherID, + &i.Age, + &i.Balance, + &i.Bio, + &i.About, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..8c7fb44672 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,3 @@ +-- name: LoadFoo :many +SELECT * FROM foo WHERE id = $id; + diff --git a/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..d5136ad0a2 --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,10 @@ +CREATE TABLE foo ( + id Uuid NOT NULL, + other_id Uuid NOT NULL, + age Int32, + balance Double, + bio Text, + about Text, + PRIMARY KEY (id) +); + diff --git a/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..570ad35f4c --- /dev/null +++ b/internal/endtoend/testdata/overrides_go_types/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,57 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "override", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "sql_package": "ydb-go-sdk", + "overrides": [ + { + "column": "foo.other_id", + "go_type": { + "import": "github.com/gofrs/uuid", + "package": "fuid", + "type": "UUID" + } + }, + { + "column": "foo.age", + "nullable": true, + "go_type": { + "import": "database/sql", + "package": "orm", + "type": "NullInt32" + } + }, + { + "column": "foo.balance", + "nullable": true, + "go_type": { + "import": "github.com/volatiletech/null/v8", + "type": "Float32" + } + }, + { + "column": "foo.bio", + "nullable": true, + "go_type": { + "import": "gopkg.in/guregu/null.v4", + "type": "String" + } + }, + { + "column": "foo.about", + "nullable": true, + "go_type": { + "type": "string", + "pointer": true + } + } + ] + } + ] +} + diff --git a/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/db.go b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..9c19dd4a09 --- /dev/null +++ b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +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/overrides_pointers/ydb/stdlib/go/models.go b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..5d3c519a64 --- /dev/null +++ b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/models.go @@ -0,0 +1,18 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package override + +import ( + t "github.com/jackc/pgtype" +) + +type Foo struct { + Other string + Total int64 + Tags string + ByteSeq []byte + Retyped string + Langs *t.Text +} diff --git a/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..3fb15c1110 --- /dev/null +++ b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/go/query.sql.go @@ -0,0 +1,21 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package override + +import ( + "context" + + t "github.com/jackc/pgtype" +) + +const test = `-- name: test :exec +UPDATE foo SET langs = $langs +` + +func (q *Queries) test(ctx context.Context, langs *t.Text) error { + _, err := q.db.ExecContext(ctx, test, langs) + return err +} diff --git a/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/query.sql b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/query.sql new file mode 100644 index 0000000000..445ed8ad8d --- /dev/null +++ b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/query.sql @@ -0,0 +1,3 @@ +-- name: test :exec +UPDATE foo SET langs = $langs; + diff --git a/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/schema.sql b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..dd551c5426 --- /dev/null +++ b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/schema.sql @@ -0,0 +1,9 @@ +CREATE TABLE foo ( + other Text NOT NULL, + total Int64 NOT NULL, + tags Text NOT NULL, + byte_seq String NOT NULL, + retyped Text NOT NULL, + langs Text, + PRIMARY KEY (other, total) +); diff --git a/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..0d2cfbfc3f --- /dev/null +++ b/internal/endtoend/testdata/overrides_pointers/ydb/stdlib/sqlc.json @@ -0,0 +1,24 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "name": "override", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "overrides": [ + { + "go_type": { + "import": "github.com/jackc/pgtype", + "type": "Text", + "package": "t", + "pointer": true + }, + "column": "foo.langs" + } + ] + } + ] +} + diff --git a/internal/endtoend/testdata/params_duplicate/ydb/go/db.go b/internal/endtoend/testdata/params_duplicate/ydb/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/params_duplicate/ydb/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/params_duplicate/ydb/go/models.go b/internal/endtoend/testdata/params_duplicate/ydb/go/models.go new file mode 100644 index 0000000000..898463dfd3 --- /dev/null +++ b/internal/endtoend/testdata/params_duplicate/ydb/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int64 + FirstName *string + LastName *string +} diff --git a/internal/endtoend/testdata/params_duplicate/ydb/go/query.sql.go b/internal/endtoend/testdata/params_duplicate/ydb/go/query.sql.go new file mode 100644 index 0000000000..cde028cafc --- /dev/null +++ b/internal/endtoend/testdata/params_duplicate/ydb/go/query.sql.go @@ -0,0 +1,109 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const selectUserByID = `-- name: SelectUserByID :many +SELECT first_name from +users where ($id = id OR $id = 0) +` + +func (q *Queries) SelectUserByID(ctx context.Context, id int64, opts ...query.ExecuteOption) ([]*string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int64(id) + result, err := q.db.QueryResultSet(ctx, selectUserByID, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []*string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var first_name *string + if err := row.Scan(&first_name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, first_name) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const selectUserByName = `-- name: SelectUserByName :many +SELECT first_name +FROM users +WHERE first_name = $name + OR last_name = $name +` + +func (q *Queries) SelectUserByName(ctx context.Context, name *string, opts ...query.ExecuteOption) ([]*string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").BeginOptional().Text(name).EndOptional() + result, err := q.db.QueryResultSet(ctx, selectUserByName, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []*string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var first_name *string + if err := row.Scan(&first_name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, first_name) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const selectUserQuestion = `-- name: SelectUserQuestion :many +SELECT first_name from +users where ($question = id OR $question = 0) +` + +func (q *Queries) SelectUserQuestion(ctx context.Context, question int64, opts ...query.ExecuteOption) ([]*string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$question").Int64(question) + result, err := q.db.QueryResultSet(ctx, selectUserQuestion, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []*string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var first_name *string + if err := row.Scan(&first_name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, first_name) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/params_duplicate/ydb/query.sql b/internal/endtoend/testdata/params_duplicate/ydb/query.sql new file mode 100644 index 0000000000..3332f3e6ee --- /dev/null +++ b/internal/endtoend/testdata/params_duplicate/ydb/query.sql @@ -0,0 +1,13 @@ +-- name: SelectUserByID :many +SELECT first_name from +users where ($id = id OR $id = 0); + +-- name: SelectUserByName :many +SELECT first_name +FROM users +WHERE first_name = $name + OR last_name = $name; + +-- name: SelectUserQuestion :many +SELECT first_name from +users where ($question = id OR $question = 0); diff --git a/internal/endtoend/testdata/params_duplicate/ydb/schema.sql b/internal/endtoend/testdata/params_duplicate/ydb/schema.sql new file mode 100644 index 0000000000..a4f0faf889 --- /dev/null +++ b/internal/endtoend/testdata/params_duplicate/ydb/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE users ( + id Int64, + first_name Utf8, + last_name Utf8, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/params_duplicate/ydb/sqlc.json b/internal/endtoend/testdata/params_duplicate/ydb/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/params_duplicate/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/params_go_keywords/ydb/go/db.go b/internal/endtoend/testdata/params_go_keywords/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/params_go_keywords/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/params_go_keywords/ydb/go/models.go b/internal/endtoend/testdata/params_go_keywords/ydb/go/models.go new file mode 100644 index 0000000000..89a26a6be8 --- /dev/null +++ b/internal/endtoend/testdata/params_go_keywords/ydb/go/models.go @@ -0,0 +1,34 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type GoKeyword struct { + Break *string + Default *string + Func *string + Interface *string + Select *string + Case *string + Defer *string + Go *string + Map *string + Struct *string + Chan *string + Else *string + Goto *string + Package *string + Switch *string + Const *string + Fallthrough *string + If *string + Range *string + Type *string + Continue *string + For *string + Import *string + Return *string + Var *string + Q *string +} diff --git a/internal/endtoend/testdata/params_go_keywords/ydb/go/query.sql.go b/internal/endtoend/testdata/params_go_keywords/ydb/go/query.sql.go new file mode 100644 index 0000000000..e53fad1718 --- /dev/null +++ b/internal/endtoend/testdata/params_go_keywords/ydb/go/query.sql.go @@ -0,0 +1,530 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const keywordBreak = `-- name: KeywordBreak :exec +SELECT CAST($break AS Text) +` + +func (q *Queries) KeywordBreak(ctx context.Context, break_ string) error { + _, err := q.db.ExecContext(ctx, keywordBreak, break_) + return err +} + +const keywordCase = `-- name: KeywordCase :exec +SELECT CAST($case AS Text) +` + +func (q *Queries) KeywordCase(ctx context.Context, case_ string) error { + _, err := q.db.ExecContext(ctx, keywordCase, case_) + return err +} + +const keywordChan = `-- name: KeywordChan :exec +SELECT CAST($chan AS Text) +` + +func (q *Queries) KeywordChan(ctx context.Context, chan_ string) error { + _, err := q.db.ExecContext(ctx, keywordChan, chan_) + return err +} + +const keywordConst = `-- name: KeywordConst :exec +SELECT CAST($const AS Text) +` + +func (q *Queries) KeywordConst(ctx context.Context, const_ string) error { + _, err := q.db.ExecContext(ctx, keywordConst, const_) + return err +} + +const keywordContinue = `-- name: KeywordContinue :exec +SELECT CAST($continue AS Text) +` + +func (q *Queries) KeywordContinue(ctx context.Context, continue_ string) error { + _, err := q.db.ExecContext(ctx, keywordContinue, continue_) + return err +} + +const keywordDefault = `-- name: KeywordDefault :exec +SELECT CAST($default AS Text) +` + +func (q *Queries) KeywordDefault(ctx context.Context, default_ string) error { + _, err := q.db.ExecContext(ctx, keywordDefault, default_) + return err +} + +const keywordDefer = `-- name: KeywordDefer :exec +SELECT CAST($defer AS Text) +` + +func (q *Queries) KeywordDefer(ctx context.Context, defer_ string) error { + _, err := q.db.ExecContext(ctx, keywordDefer, defer_) + return err +} + +const keywordElse = `-- name: KeywordElse :exec +SELECT CAST($else AS Text) +` + +func (q *Queries) KeywordElse(ctx context.Context, else_ string) error { + _, err := q.db.ExecContext(ctx, keywordElse, else_) + return err +} + +const keywordFallthrough = `-- name: KeywordFallthrough :exec +SELECT CAST($fallthrough AS Text) +` + +func (q *Queries) KeywordFallthrough(ctx context.Context, fallthrough_ string) error { + _, err := q.db.ExecContext(ctx, keywordFallthrough, fallthrough_) + return err +} + +const keywordFor = `-- name: KeywordFor :exec +SELECT CAST($for AS Text) +` + +func (q *Queries) KeywordFor(ctx context.Context, for_ string) error { + _, err := q.db.ExecContext(ctx, keywordFor, for_) + return err +} + +const keywordFunc = `-- name: KeywordFunc :exec +SELECT CAST($func AS Text) +` + +func (q *Queries) KeywordFunc(ctx context.Context, func_ string) error { + _, err := q.db.ExecContext(ctx, keywordFunc, func_) + return err +} + +const keywordGo = `-- name: KeywordGo :exec +SELECT CAST($go AS Text) +` + +func (q *Queries) KeywordGo(ctx context.Context, go_ string) error { + _, err := q.db.ExecContext(ctx, keywordGo, go_) + return err +} + +const keywordGoto = `-- name: KeywordGoto :exec +SELECT CAST($goto AS Text) +` + +func (q *Queries) KeywordGoto(ctx context.Context, goto_ string) error { + _, err := q.db.ExecContext(ctx, keywordGoto, goto_) + return err +} + +const keywordIf = `-- name: KeywordIf :exec +SELECT CAST($if AS Text) +` + +func (q *Queries) KeywordIf(ctx context.Context, if_ string) error { + _, err := q.db.ExecContext(ctx, keywordIf, if_) + return err +} + +const keywordImport = `-- name: KeywordImport :exec +SELECT CAST($import AS Text) +` + +func (q *Queries) KeywordImport(ctx context.Context, import_ string) error { + _, err := q.db.ExecContext(ctx, keywordImport, import_) + return err +} + +const keywordInterface = `-- name: KeywordInterface :exec +SELECT CAST($interface AS Text) +` + +func (q *Queries) KeywordInterface(ctx context.Context, interface_ string) error { + _, err := q.db.ExecContext(ctx, keywordInterface, interface_) + return err +} + +const keywordMap = `-- name: KeywordMap :exec +SELECT CAST($map AS Text) +` + +func (q *Queries) KeywordMap(ctx context.Context, map_ string) error { + _, err := q.db.ExecContext(ctx, keywordMap, map_) + return err +} + +const keywordPackage = `-- name: KeywordPackage :exec +SELECT CAST($package AS Text) +` + +func (q *Queries) KeywordPackage(ctx context.Context, package_ string) error { + _, err := q.db.ExecContext(ctx, keywordPackage, package_) + return err +} + +const keywordQ = `-- name: KeywordQ :exec +SELECT CAST($q AS Text) +` + +func (q *Queries) KeywordQ(ctx context.Context, q_ string) error { + _, err := q.db.ExecContext(ctx, keywordQ, q_) + return err +} + +const keywordRange = `-- name: KeywordRange :exec +SELECT CAST($range AS Text) +` + +func (q *Queries) KeywordRange(ctx context.Context, range_ string) error { + _, err := q.db.ExecContext(ctx, keywordRange, range_) + return err +} + +const keywordReturn = `-- name: KeywordReturn :exec +SELECT CAST($return AS Text) +` + +func (q *Queries) KeywordReturn(ctx context.Context, return_ string) error { + _, err := q.db.ExecContext(ctx, keywordReturn, return_) + return err +} + +const keywordSelect = `-- name: KeywordSelect :exec +SELECT CAST($select AS Text) +` + +func (q *Queries) KeywordSelect(ctx context.Context, select_ string) error { + _, err := q.db.ExecContext(ctx, keywordSelect, select_) + return err +} + +const keywordStruct = `-- name: KeywordStruct :exec +SELECT CAST($struct AS Text) +` + +func (q *Queries) KeywordStruct(ctx context.Context, struct_ string) error { + _, err := q.db.ExecContext(ctx, keywordStruct, struct_) + return err +} + +const keywordSwitch = `-- name: KeywordSwitch :exec +SELECT CAST($switch AS Text) +` + +func (q *Queries) KeywordSwitch(ctx context.Context, switch_ string) error { + _, err := q.db.ExecContext(ctx, keywordSwitch, switch_) + return err +} + +const keywordType = `-- name: KeywordType :exec +SELECT CAST($type AS Text) +` + +func (q *Queries) KeywordType(ctx context.Context, type_ string) error { + _, err := q.db.ExecContext(ctx, keywordType, type_) + return err +} + +const keywordVar = `-- name: KeywordVar :exec +SELECT CAST($var AS Text) +` + +func (q *Queries) KeywordVar(ctx context.Context, var_ string) error { + _, err := q.db.ExecContext(ctx, keywordVar, var_) + return err +} + +const selectBreak = `-- name: SelectBreak :one +SELECT "break" FROM go_keywords +` + +func (q *Queries) SelectBreak(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectBreak) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectCase = `-- name: SelectCase :one +SELECT "case" FROM go_keywords +` + +func (q *Queries) SelectCase(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectCase) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectChan = `-- name: SelectChan :one +SELECT "chan" FROM go_keywords +` + +func (q *Queries) SelectChan(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectChan) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectConst = `-- name: SelectConst :one +SELECT "const" FROM go_keywords +` + +func (q *Queries) SelectConst(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectConst) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectContinue = `-- name: SelectContinue :one +SELECT "continue" FROM go_keywords +` + +func (q *Queries) SelectContinue(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectContinue) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectDefault = `-- name: SelectDefault :one +SELECT "default" FROM go_keywords +` + +func (q *Queries) SelectDefault(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectDefault) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectDefer = `-- name: SelectDefer :one +SELECT "defer" FROM go_keywords +` + +func (q *Queries) SelectDefer(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectDefer) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectElse = `-- name: SelectElse :one +SELECT "else" FROM go_keywords +` + +func (q *Queries) SelectElse(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectElse) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectFallthrough = `-- name: SelectFallthrough :one +SELECT "fallthrough" FROM go_keywords +` + +func (q *Queries) SelectFallthrough(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectFallthrough) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectFor = `-- name: SelectFor :one +SELECT "for" FROM go_keywords +` + +func (q *Queries) SelectFor(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectFor) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectFunc = `-- name: SelectFunc :one +SELECT "func" FROM go_keywords +` + +func (q *Queries) SelectFunc(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectFunc) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectGo = `-- name: SelectGo :one +SELECT "go" FROM go_keywords +` + +func (q *Queries) SelectGo(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectGo) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectGoto = `-- name: SelectGoto :one +SELECT "goto" FROM go_keywords +` + +func (q *Queries) SelectGoto(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectGoto) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectIf = `-- name: SelectIf :one +SELECT "if" FROM go_keywords +` + +func (q *Queries) SelectIf(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectIf) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectImport = `-- name: SelectImport :one +SELECT "import" FROM go_keywords +` + +func (q *Queries) SelectImport(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectImport) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectInterface = `-- name: SelectInterface :one +SELECT "interface" FROM go_keywords +` + +func (q *Queries) SelectInterface(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectInterface) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectMap = `-- name: SelectMap :one +SELECT "map" FROM go_keywords +` + +func (q *Queries) SelectMap(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectMap) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectPackage = `-- name: SelectPackage :one +SELECT "package" FROM go_keywords +` + +func (q *Queries) SelectPackage(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectPackage) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectQ = `-- name: SelectQ :one +SELECT "q" FROM go_keywords +` + +func (q *Queries) SelectQ(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectQ) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectRange = `-- name: SelectRange :one +SELECT "range" FROM go_keywords +` + +func (q *Queries) SelectRange(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectRange) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectReturn = `-- name: SelectReturn :one +SELECT "return" FROM go_keywords +` + +func (q *Queries) SelectReturn(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectReturn) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectSelect = `-- name: SelectSelect :one +SELECT "select" FROM go_keywords +` + +func (q *Queries) SelectSelect(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectSelect) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectStruct = `-- name: SelectStruct :one +SELECT "struct" FROM go_keywords +` + +func (q *Queries) SelectStruct(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectStruct) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectSwitch = `-- name: SelectSwitch :one +SELECT "switch" FROM go_keywords +` + +func (q *Queries) SelectSwitch(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectSwitch) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectType = `-- name: SelectType :one +SELECT "type" FROM go_keywords +` + +func (q *Queries) SelectType(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectType) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} + +const selectVar = `-- name: SelectVar :one +SELECT "var" FROM go_keywords +` + +func (q *Queries) SelectVar(ctx context.Context) (string, error) { + row := q.db.QueryRowContext(ctx, selectVar) + var column_1 string + err := row.Scan(&column_1) + return column_1, err +} diff --git a/internal/endtoend/testdata/params_go_keywords/ydb/query.sql b/internal/endtoend/testdata/params_go_keywords/ydb/query.sql new file mode 100644 index 0000000000..2176b1a390 --- /dev/null +++ b/internal/endtoend/testdata/params_go_keywords/ydb/query.sql @@ -0,0 +1,155 @@ +-- name: KeywordBreak :exec +SELECT CAST(sqlc.arg('break') AS Text); + +-- name: KeywordDefault :exec +SELECT CAST(sqlc.arg('default') AS Text); + +-- name: KeywordFunc :exec +SELECT CAST(sqlc.arg('func') AS Text); + +-- name: KeywordInterface :exec +SELECT CAST(sqlc.arg('interface') AS Text); + +-- name: KeywordSelect :exec +SELECT CAST(sqlc.arg('select') AS Text); + +-- name: KeywordCase :exec +SELECT CAST(sqlc.arg('case') AS Text); + +-- name: KeywordDefer :exec +SELECT CAST(sqlc.arg('defer') AS Text); + +-- name: KeywordGo :exec +SELECT CAST(sqlc.arg('go') AS Text); + +-- name: KeywordMap :exec +SELECT CAST(sqlc.arg('map') AS Text); + +-- name: KeywordStruct :exec +SELECT CAST(sqlc.arg('struct') AS Text); + +-- name: KeywordChan :exec +SELECT CAST(sqlc.arg('chan') AS Text); + +-- name: KeywordElse :exec +SELECT CAST(sqlc.arg('else') AS Text); + +-- name: KeywordGoto :exec +SELECT CAST(sqlc.arg('goto') AS Text); + +-- name: KeywordPackage :exec +SELECT CAST(sqlc.arg('package') AS Text); + +-- name: KeywordSwitch :exec +SELECT CAST(sqlc.arg('switch') AS Text); + +-- name: KeywordConst :exec +SELECT CAST(sqlc.arg('const') AS Text); + +-- name: KeywordFallthrough :exec +SELECT CAST(sqlc.arg('fallthrough') AS Text); + +-- name: KeywordIf :exec +SELECT CAST(sqlc.arg('if') AS Text); + +-- name: KeywordRange :exec +SELECT CAST(sqlc.arg('range') AS Text); + +-- name: KeywordType :exec +SELECT CAST(sqlc.arg('type') AS Text); + +-- name: KeywordContinue :exec +SELECT CAST(sqlc.arg('continue') AS Text); + +-- name: KeywordFor :exec +SELECT CAST(sqlc.arg('for') AS Text); + +-- name: KeywordImport :exec +SELECT CAST(sqlc.arg('import') AS Text); + +-- name: KeywordReturn :exec +SELECT CAST(sqlc.arg('return') AS Text); + +-- name: KeywordVar :exec +SELECT CAST(sqlc.arg('var') AS Text); + +-- name: KeywordQ :exec +SELECT CAST(sqlc.arg('q') AS Text); + +-- name: SelectBreak :one +SELECT "break" FROM go_keywords; + +-- name: SelectDefault :one +SELECT "default" FROM go_keywords; + +-- name: SelectFunc :one +SELECT "func" FROM go_keywords; + +-- name: SelectInterface :one +SELECT "interface" FROM go_keywords; + +-- name: SelectSelect :one +SELECT "select" FROM go_keywords; + +-- name: SelectCase :one +SELECT "case" FROM go_keywords; + +-- name: SelectDefer :one +SELECT "defer" FROM go_keywords; + +-- name: SelectGo :one +SELECT "go" FROM go_keywords; + +-- name: SelectMap :one +SELECT "map" FROM go_keywords; + +-- name: SelectStruct :one +SELECT "struct" FROM go_keywords; + +-- name: SelectChan :one +SELECT "chan" FROM go_keywords; + +-- name: SelectElse :one +SELECT "else" FROM go_keywords; + +-- name: SelectGoto :one +SELECT "goto" FROM go_keywords; + +-- name: SelectPackage :one +SELECT "package" FROM go_keywords; + +-- name: SelectSwitch :one +SELECT "switch" FROM go_keywords; + +-- name: SelectConst :one +SELECT "const" FROM go_keywords; + +-- name: SelectFallthrough :one +SELECT "fallthrough" FROM go_keywords; + +-- name: SelectIf :one +SELECT "if" FROM go_keywords; + +-- name: SelectRange :one +SELECT "range" FROM go_keywords; + +-- name: SelectType :one +SELECT "type" FROM go_keywords; + +-- name: SelectContinue :one +SELECT "continue" FROM go_keywords; + +-- name: SelectFor :one +SELECT "for" FROM go_keywords; + +-- name: SelectImport :one +SELECT "import" FROM go_keywords; + +-- name: SelectReturn :one +SELECT "return" FROM go_keywords; + +-- name: SelectVar :one +SELECT "var" FROM go_keywords; + +-- name: SelectQ :one +SELECT "q" FROM go_keywords; diff --git a/internal/endtoend/testdata/params_go_keywords/ydb/schema.sql b/internal/endtoend/testdata/params_go_keywords/ydb/schema.sql new file mode 100644 index 0000000000..afaf14ee4a --- /dev/null +++ b/internal/endtoend/testdata/params_go_keywords/ydb/schema.sql @@ -0,0 +1,32 @@ +CREATE TABLE go_keywords ( + "break" Text, + "default" Text, + "func" Text, + "interface" Text, + "select" Text, + "case" Text, + "defer" Text, + "go" Text, + "map" Text, + "struct" Text, + "chan" Text, + "else" Text, + "goto" Text, + "package" Text, + "switch" Text, + "const" Text, + "fallthrough" Text, + "if" Text, + "range" Text, + "type" Text, + "continue" Text, + "for" Text, + "import" Text, + "return" Text, + "var" Text, + "q" Text, + PRIMARY KEY ("break") +); + + + diff --git a/internal/endtoend/testdata/params_go_keywords/ydb/sqlc.json b/internal/endtoend/testdata/params_go_keywords/ydb/sqlc.json new file mode 100644 index 0000000000..c5959ba446 --- /dev/null +++ b/internal/endtoend/testdata/params_go_keywords/ydb/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/params_in_nested_func/ydb/db/db.go b/internal/endtoend/testdata/params_in_nested_func/ydb/db/db.go new file mode 100644 index 0000000000..cd5bbb8e08 --- /dev/null +++ b/internal/endtoend/testdata/params_in_nested_func/ydb/db/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package db + +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/params_in_nested_func/ydb/db/models.go b/internal/endtoend/testdata/params_in_nested_func/ydb/db/models.go new file mode 100644 index 0000000000..6ed185db01 --- /dev/null +++ b/internal/endtoend/testdata/params_in_nested_func/ydb/db/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package db + +type Routergroup struct { + Groupid *int32 + Groupname string + Defaultconfigid *int32 + Defaultfirmwareversion *string + Parentgroupid *int32 + Firmwarepolicy *string + Styles *string +} diff --git a/internal/endtoend/testdata/params_in_nested_func/ydb/db/query.sql.go b/internal/endtoend/testdata/params_in_nested_func/ydb/db/query.sql.go new file mode 100644 index 0000000000..9807199538 --- /dev/null +++ b/internal/endtoend/testdata/params_in_nested_func/ydb/db/query.sql.go @@ -0,0 +1,54 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package db + +import ( + "context" +) + +const getGroups = `-- name: GetGroups :many +SELECT + rg.groupId, + rg.groupName +FROM + routergroup rg +WHERE + rg.groupName LIKE '%' || COALESCE($groupname, rg.groupName) || '%' AND + rg.groupId = COALESCE($groupid, rg.groupId) +` + +type GetGroupsParams struct { + Groupname string + Groupid *int32 +} + +type GetGroupsRow struct { + Groupid *int32 + Groupname string +} + +func (q *Queries) GetGroups(ctx context.Context, arg GetGroupsParams) ([]GetGroupsRow, error) { + rows, err := q.db.QueryContext(ctx, getGroups, arg.Groupname, arg.Groupid) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetGroupsRow + for rows.Next() { + var i GetGroupsRow + if err := rows.Scan(&i.Groupid, &i.Groupname); err != nil { + return nil, err + } + items = append(items, i) + } + 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/params_in_nested_func/ydb/query.sql b/internal/endtoend/testdata/params_in_nested_func/ydb/query.sql new file mode 100644 index 0000000000..33a0cade30 --- /dev/null +++ b/internal/endtoend/testdata/params_in_nested_func/ydb/query.sql @@ -0,0 +1,10 @@ +-- name: GetGroups :many +SELECT + rg.groupId, + rg.groupName +FROM + routergroup rg +WHERE + rg.groupName LIKE '%' || COALESCE($groupName, rg.groupName) || '%' AND + rg.groupId = COALESCE($groupId, rg.groupId); + diff --git a/internal/endtoend/testdata/params_in_nested_func/ydb/schema.sql b/internal/endtoend/testdata/params_in_nested_func/ydb/schema.sql new file mode 100644 index 0000000000..b0a1f71f54 --- /dev/null +++ b/internal/endtoend/testdata/params_in_nested_func/ydb/schema.sql @@ -0,0 +1,11 @@ +CREATE TABLE routergroup ( + groupId Serial, + groupName Text NOT NULL, + defaultConfigId Int32, + defaultFirmwareVersion Text, + parentGroupId Int32, + firmwarePolicy Text, + styles Text, + PRIMARY KEY (groupId) +); + diff --git a/internal/endtoend/testdata/params_in_nested_func/ydb/sqlc.yaml b/internal/endtoend/testdata/params_in_nested_func/ydb/sqlc.yaml new file mode 100644 index 0000000000..47b2237157 --- /dev/null +++ b/internal/endtoend/testdata/params_in_nested_func/ydb/sqlc.yaml @@ -0,0 +1,9 @@ +version: '2' +sql: +- schema: schema.sql + queries: query.sql + engine: ydb + gen: + go: + out: db + diff --git a/internal/endtoend/testdata/params_location/ydb/stdlib/go/db.go b/internal/endtoend/testdata/params_location/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/params_location/ydb/stdlib/go/models.go b/internal/endtoend/testdata/params_location/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..e2b69577ec --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/stdlib/go/models.go @@ -0,0 +1,23 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "github.com/ydb-platform/ydb-go-sdk/v3/table/types" +) + +type Order struct { + ID int64 + Price *types.Decimal + UserID *int64 +} + +type User struct { + ID int64 + FirstName *string + LastName *string + Age *int64 + JobStatus *string +} diff --git a/internal/endtoend/testdata/params_location/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/params_location/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..1cd5693779 --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/stdlib/go/query.sql.go @@ -0,0 +1,258 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/table/types" +) + +const getUserByID = `-- name: GetUserByID :one +SELECT first_name, id, last_name FROM users WHERE id = $target_id +` + +type GetUserByIDRow struct { + FirstName *string + ID int64 + LastName *string +} + +func (q *Queries) GetUserByID(ctx context.Context, targetID int64) (GetUserByIDRow, error) { + row := q.db.QueryRowContext(ctx, getUserByID, targetID) + var i GetUserByIDRow + err := row.Scan(&i.FirstName, &i.ID, &i.LastName) + return i, err +} + +const insertNewUser = `-- name: InsertNewUser :exec +INSERT INTO users (first_name, last_name) VALUES ($first_name, $last_name) +` + +type InsertNewUserParams struct { + FirstName *string + LastName *string +} + +func (q *Queries) InsertNewUser(ctx context.Context, arg InsertNewUserParams) error { + _, err := q.db.ExecContext(ctx, insertNewUser, arg.FirstName, arg.LastName) + return err +} + +const limitSQLCArg = `-- name: LimitSQLCArg :many +select first_name, id FROM users LIMIT $limit +` + +type LimitSQLCArgRow struct { + FirstName *string + ID int64 +} + +func (q *Queries) LimitSQLCArg(ctx context.Context, limit uint64) ([]LimitSQLCArgRow, error) { + rows, err := q.db.QueryContext(ctx, limitSQLCArg, limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []LimitSQLCArgRow + for rows.Next() { + var i LimitSQLCArgRow + if err := rows.Scan(&i.FirstName, &i.ID); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listUserOrders = `-- name: ListUserOrders :many +SELECT + users.id, + users.first_name, + orders.price +FROM + orders +LEFT JOIN users ON orders.user_id = users.id +WHERE orders.price > $min_price +` + +type ListUserOrdersRow struct { + ID *int64 + FirstName *string + Price *types.Decimal +} + +func (q *Queries) ListUserOrders(ctx context.Context, minPrice *types.Decimal) ([]ListUserOrdersRow, error) { + rows, err := q.db.QueryContext(ctx, listUserOrders, minPrice) + if err != nil { + return nil, err + } + defer rows.Close() + var items []ListUserOrdersRow + for rows.Next() { + var i ListUserOrdersRow + if err := rows.Scan(&i.ID, &i.FirstName, &i.Price); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listUserParenExpr = `-- name: ListUserParenExpr :many +SELECT id, first_name, last_name, age, job_status FROM users WHERE (job_status = 'APPLIED' OR job_status = 'PENDING') +AND id > $id +ORDER BY id +LIMIT $limit +` + +type ListUserParenExprParams struct { + ID int64 + Limit uint64 +} + +func (q *Queries) ListUserParenExpr(ctx context.Context, arg ListUserParenExprParams) ([]User, error) { + rows, err := q.db.QueryContext(ctx, listUserParenExpr, arg.ID, arg.Limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []User + for rows.Next() { + var i User + if err := rows.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + &i.JobStatus, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listUsersByFamily = `-- name: ListUsersByFamily :many +SELECT first_name, last_name FROM users WHERE age < $max_age AND last_name = $in_family +` + +type ListUsersByFamilyParams struct { + MaxAge *int64 + InFamily *string +} + +type ListUsersByFamilyRow struct { + FirstName *string + LastName *string +} + +func (q *Queries) ListUsersByFamily(ctx context.Context, arg ListUsersByFamilyParams) ([]ListUsersByFamilyRow, error) { + rows, err := q.db.QueryContext(ctx, listUsersByFamily, arg.MaxAge, arg.InFamily) + if err != nil { + return nil, err + } + defer rows.Close() + var items []ListUsersByFamilyRow + for rows.Next() { + var i ListUsersByFamilyRow + if err := rows.Scan(&i.FirstName, &i.LastName); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listUsersByID = `-- name: ListUsersByID :many +SELECT first_name, id, last_name FROM users WHERE id < $id +` + +type ListUsersByIDRow struct { + FirstName *string + ID int64 + LastName *string +} + +func (q *Queries) ListUsersByID(ctx context.Context, id int64) ([]ListUsersByIDRow, error) { + rows, err := q.db.QueryContext(ctx, listUsersByID, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []ListUsersByIDRow + for rows.Next() { + var i ListUsersByIDRow + if err := rows.Scan(&i.FirstName, &i.ID, &i.LastName); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listUsersWithLimit = `-- name: ListUsersWithLimit :many +SELECT first_name, last_name FROM users LIMIT $limit +` + +type ListUsersWithLimitRow struct { + FirstName *string + LastName *string +} + +func (q *Queries) ListUsersWithLimit(ctx context.Context, limit uint64) ([]ListUsersWithLimitRow, error) { + rows, err := q.db.QueryContext(ctx, listUsersWithLimit, limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []ListUsersWithLimitRow + for rows.Next() { + var i ListUsersWithLimitRow + if err := rows.Scan(&i.FirstName, &i.LastName); err != nil { + return nil, err + } + items = append(items, i) + } + 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/params_location/ydb/stdlib/query.sql b/internal/endtoend/testdata/params_location/ydb/stdlib/query.sql new file mode 100644 index 0000000000..60cddb5501 --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/stdlib/query.sql @@ -0,0 +1,45 @@ +-- name: ListUsersByID :many +SELECT first_name, id, last_name FROM users WHERE id < $id; + +-- name: ListUserOrders :many +SELECT + users.id, + users.first_name, + orders.price +FROM + orders +LEFT JOIN users ON orders.user_id = users.id +WHERE orders.price > $min_price; + +-- name: GetUserByID :one +SELECT first_name, id, last_name FROM users WHERE id = $target_id; + +-- name: ListUsersByFamily :many +SELECT first_name, last_name FROM users WHERE age < $max_age AND last_name = $in_family; + +-- name: ListUsersWithLimit :many +SELECT first_name, last_name FROM users LIMIT $limit; + +-- name: LimitSQLCArg :many +select first_name, id FROM users LIMIT $limit; + +-- name: InsertNewUser :exec +INSERT INTO users (first_name, last_name) VALUES ($first_name, $last_name); + +-- name: ListUserParenExpr :many +SELECT * FROM users WHERE (job_status = 'APPLIED' OR job_status = 'PENDING') +AND id > $id +ORDER BY id +LIMIT $limit; + + + + + + + + + + + + diff --git a/internal/endtoend/testdata/params_location/ydb/stdlib/schema.sql b/internal/endtoend/testdata/params_location/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..49e4adf991 --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/stdlib/schema.sql @@ -0,0 +1,28 @@ +CREATE TABLE users ( + id Int64, + first_name Utf8, + last_name Utf8, + age Int64, + job_status Utf8, + PRIMARY KEY (id) +); + +CREATE TABLE orders ( + id Int64, + price Decimal(13, 4), + user_id Int64, + PRIMARY KEY (id) +); + + + + + + + + + + + + + diff --git a/internal/endtoend/testdata/params_location/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/params_location/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..17d4acefc5 --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/stdlib/sqlc.json @@ -0,0 +1,25 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + + + + + + + + + + + diff --git a/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..e2b69577ec --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,23 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "github.com/ydb-platform/ydb-go-sdk/v3/table/types" +) + +type Order struct { + ID int64 + Price *types.Decimal + UserID *int64 +} + +type User struct { + ID int64 + FirstName *string + LastName *string + Age *int64 + JobStatus *string +} diff --git a/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..932001ec89 --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,299 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" + "github.com/ydb-platform/ydb-go-sdk/v3/table/types" +) + +const getUserByID = `-- name: GetUserByID :one +SELECT first_name, id, last_name FROM users WHERE id = $target_id +` + +type GetUserByIDRow struct { + FirstName *string + ID int64 + LastName *string +} + +func (q *Queries) GetUserByID(ctx context.Context, targetID int64, opts ...query.ExecuteOption) (GetUserByIDRow, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$target_id").Int64(targetID) + row, err := q.db.QueryRow(ctx, getUserByID, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i GetUserByIDRow + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.FirstName, &i.ID, &i.LastName) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const insertNewUser = `-- name: InsertNewUser :exec +INSERT INTO users (first_name, last_name) VALUES ($first_name, $last_name) +` + +type InsertNewUserParams struct { + FirstName *string + LastName *string +} + +func (q *Queries) InsertNewUser(ctx context.Context, arg InsertNewUserParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$first_name").BeginOptional().Text(arg.FirstName).EndOptional() + parameters = parameters.Param("$last_name").BeginOptional().Text(arg.LastName).EndOptional() + err := q.db.Exec(ctx, insertNewUser, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} + +const limitSQLCArg = `-- name: LimitSQLCArg :many +select first_name, id FROM users LIMIT $limit +` + +type LimitSQLCArgRow struct { + FirstName *string + ID int64 +} + +func (q *Queries) LimitSQLCArg(ctx context.Context, limit uint64, opts ...query.ExecuteOption) ([]LimitSQLCArgRow, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$limit").Uint64(limit) + result, err := q.db.QueryResultSet(ctx, limitSQLCArg, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []LimitSQLCArgRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i LimitSQLCArgRow + if err := row.Scan(&i.FirstName, &i.ID); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const listUserOrders = `-- name: ListUserOrders :many +SELECT + users.id, + users.first_name, + orders.price +FROM + orders +LEFT JOIN users ON orders.user_id = users.id +WHERE orders.price > $min_price +` + +type ListUserOrdersRow struct { + ID *int64 + FirstName *string + Price *types.Decimal +} + +func (q *Queries) ListUserOrders(ctx context.Context, minPrice *types.Decimal, opts ...query.ExecuteOption) ([]ListUserOrdersRow, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$min_price").BeginOptional().Decimal(&minPrice.Bytes, minPrice.Precision, minPrice.Scale).EndOptional() + result, err := q.db.QueryResultSet(ctx, listUserOrders, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []ListUserOrdersRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i ListUserOrdersRow + if err := row.Scan(&i.ID, &i.FirstName, &i.Price); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const listUserParenExpr = `-- name: ListUserParenExpr :many +SELECT id, first_name, last_name, age, job_status FROM users WHERE (job_status = 'APPLIED' OR job_status = 'PENDING') +AND id > $id +ORDER BY id +LIMIT $limit +` + +type ListUserParenExprParams struct { + ID int64 + Limit uint64 +} + +func (q *Queries) ListUserParenExpr(ctx context.Context, arg ListUserParenExprParams, opts ...query.ExecuteOption) ([]User, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int64(arg.ID) + parameters = parameters.Param("$limit").Uint64(arg.Limit) + result, err := q.db.QueryResultSet(ctx, listUserParenExpr, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []User + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i User + if err := row.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + &i.JobStatus, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const listUsersByFamily = `-- name: ListUsersByFamily :many +SELECT first_name, last_name FROM users WHERE age < $max_age AND last_name = $in_family +` + +type ListUsersByFamilyParams struct { + MaxAge *int64 + InFamily *string +} + +type ListUsersByFamilyRow struct { + FirstName *string + LastName *string +} + +func (q *Queries) ListUsersByFamily(ctx context.Context, arg ListUsersByFamilyParams, opts ...query.ExecuteOption) ([]ListUsersByFamilyRow, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$max_age").BeginOptional().Int64(arg.MaxAge).EndOptional() + parameters = parameters.Param("$in_family").BeginOptional().Text(arg.InFamily).EndOptional() + result, err := q.db.QueryResultSet(ctx, listUsersByFamily, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []ListUsersByFamilyRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i ListUsersByFamilyRow + if err := row.Scan(&i.FirstName, &i.LastName); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const listUsersByID = `-- name: ListUsersByID :many +SELECT first_name, id, last_name FROM users WHERE id < $id +` + +type ListUsersByIDRow struct { + FirstName *string + ID int64 + LastName *string +} + +func (q *Queries) ListUsersByID(ctx context.Context, id int64, opts ...query.ExecuteOption) ([]ListUsersByIDRow, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int64(id) + result, err := q.db.QueryResultSet(ctx, listUsersByID, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []ListUsersByIDRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i ListUsersByIDRow + if err := row.Scan(&i.FirstName, &i.ID, &i.LastName); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const listUsersWithLimit = `-- name: ListUsersWithLimit :many +SELECT first_name, last_name FROM users LIMIT $limit +` + +type ListUsersWithLimitRow struct { + FirstName *string + LastName *string +} + +func (q *Queries) ListUsersWithLimit(ctx context.Context, limit uint64, opts ...query.ExecuteOption) ([]ListUsersWithLimitRow, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$limit").Uint64(limit) + result, err := q.db.QueryResultSet(ctx, listUsersWithLimit, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []ListUsersWithLimitRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i ListUsersWithLimitRow + if err := row.Scan(&i.FirstName, &i.LastName); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..36e036a6a2 --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,46 @@ +-- name: ListUsersByID :many +SELECT first_name, id, last_name FROM users WHERE id < $id; + +-- name: ListUserOrders :many +SELECT + users.id, + users.first_name, + orders.price +FROM + orders +LEFT JOIN users ON orders.user_id = users.id +WHERE orders.price > $min_price; + +-- name: GetUserByID :one +SELECT first_name, id, last_name FROM users WHERE id = $target_id; + +-- name: ListUsersByFamily :many +SELECT first_name, last_name FROM users WHERE age < $max_age AND last_name = $in_family; + +-- name: ListUsersWithLimit :many +SELECT first_name, last_name FROM users LIMIT $limit; + +-- name: LimitSQLCArg :many +select first_name, id FROM users LIMIT $limit; + +-- name: InsertNewUser :exec +INSERT INTO users (first_name, last_name) VALUES ($first_name, $last_name); + +-- name: ListUserParenExpr :many +SELECT * FROM users WHERE (job_status = 'APPLIED' OR job_status = 'PENDING') +AND id > $id +ORDER BY id +LIMIT $limit; + + + + + + + + + + + + + diff --git a/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..49e4adf991 --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,28 @@ +CREATE TABLE users ( + id Int64, + first_name Utf8, + last_name Utf8, + age Int64, + job_status Utf8, + PRIMARY KEY (id) +); + +CREATE TABLE orders ( + id Int64, + price Decimal(13, 4), + user_id Int64, + PRIMARY KEY (id) +); + + + + + + + + + + + + + diff --git a/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..9cf331d753 --- /dev/null +++ b/internal/endtoend/testdata/params_location/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,26 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + + + + + + + + + + + diff --git a/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/db.go b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/params_placeholder_in_left_expr/ydb/go/models.go b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/models.go new file mode 100644 index 0000000000..2c4452e14c --- /dev/null +++ b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int32 + Name *string +} diff --git a/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/query.sql.go b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/query.sql.go new file mode 100644 index 0000000000..52e7022ffd --- /dev/null +++ b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/go/query.sql.go @@ -0,0 +1,64 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const findByID = `-- name: FindByID :many +SELECT id, name FROM users WHERE $id = id +` + +func (q *Queries) FindByID(ctx context.Context, id int32) ([]User, error) { + rows, err := q.db.QueryContext(ctx, findByID, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []User + for rows.Next() { + var i User + if err := rows.Scan(&i.ID, &i.Name); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const findByIDAndName = `-- name: FindByIDAndName :many +SELECT id, name FROM users WHERE $id = id AND $id = name +` + +func (q *Queries) FindByIDAndName(ctx context.Context, id int32) ([]User, error) { + rows, err := q.db.QueryContext(ctx, findByIDAndName, id) + if err != nil { + return nil, err + } + defer rows.Close() + var items []User + for rows.Next() { + var i User + if err := rows.Scan(&i.ID, &i.Name); err != nil { + return nil, err + } + items = append(items, i) + } + 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/params_placeholder_in_left_expr/ydb/query.sql b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/query.sql new file mode 100644 index 0000000000..9ae72f6dea --- /dev/null +++ b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/query.sql @@ -0,0 +1,5 @@ +-- name: FindByID :many +SELECT * FROM users WHERE $id = id; + +-- name: FindByIDAndName :many +SELECT * FROM users WHERE $id = id AND $id = name; diff --git a/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/schema.sql b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/schema.sql new file mode 100644 index 0000000000..4e80b3506a --- /dev/null +++ b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE users ( + id Int32, + name Text, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/sqlc.json b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/params_placeholder_in_left_expr/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/params_two/ydb/stdlib/go/db.go b/internal/endtoend/testdata/params_two/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/params_two/ydb/stdlib/go/models.go b/internal/endtoend/testdata/params_two/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..5eebad25b8 --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string + B string +} diff --git a/internal/endtoend/testdata/params_two/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/params_two/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..7d25aa2b5e --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/stdlib/go/query.sql.go @@ -0,0 +1,43 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const fooByAandB = `-- name: FooByAandB :many +SELECT a, b FROM foo +WHERE a = $a and b = $b +` + +type FooByAandBParams struct { + A string + B string +} + +func (q *Queries) FooByAandB(ctx context.Context, arg FooByAandBParams) ([]Foo, error) { + rows, err := q.db.QueryContext(ctx, fooByAandB, arg.A, arg.B) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Foo + for rows.Next() { + var i Foo + if err := rows.Scan(&i.A, &i.B); err != nil { + return nil, err + } + items = append(items, i) + } + 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/params_two/ydb/stdlib/query.sql b/internal/endtoend/testdata/params_two/ydb/stdlib/query.sql new file mode 100644 index 0000000000..25f2d83032 --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/stdlib/query.sql @@ -0,0 +1,3 @@ +-- name: FooByAandB :many +SELECT a, b FROM foo +WHERE a = $a and b = $b; diff --git a/internal/endtoend/testdata/params_two/ydb/stdlib/schema.sql b/internal/endtoend/testdata/params_two/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..b9d4618806 --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/stdlib/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + a Utf8, + b Utf8, + PRIMARY KEY (a, b) +); diff --git a/internal/endtoend/testdata/params_two/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/params_two/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..5eebad25b8 --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string + B string +} diff --git a/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..1074b46f9d --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,51 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const fooByAandB = `-- name: FooByAandB :many +SELECT a, b FROM foo +WHERE a = $a and b = $b +` + +type FooByAandBParams struct { + A string + B string +} + +func (q *Queries) FooByAandB(ctx context.Context, arg FooByAandBParams, opts ...query.ExecuteOption) ([]Foo, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$a").Text(arg.A) + parameters = parameters.Param("$b").Text(arg.B) + result, err := q.db.QueryResultSet(ctx, fooByAandB, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Foo + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Foo + if err := row.Scan(&i.A, &i.B); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..25f2d83032 --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,3 @@ +-- name: FooByAandB :many +SELECT a, b FROM foo +WHERE a = $a and b = $b; diff --git a/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..b9d4618806 --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + a Utf8, + b Utf8, + PRIMARY KEY (a, b) +); diff --git a/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/params_two/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/pattern_matching/ydb/go/db.go b/internal/endtoend/testdata/pattern_matching/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/pattern_matching/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/pattern_matching/ydb/go/models.go b/internal/endtoend/testdata/pattern_matching/ydb/go/models.go new file mode 100644 index 0000000000..dc21afed6e --- /dev/null +++ b/internal/endtoend/testdata/pattern_matching/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Pet struct { + Name string +} diff --git a/internal/endtoend/testdata/pattern_matching/ydb/go/query.sql.go b/internal/endtoend/testdata/pattern_matching/ydb/go/query.sql.go new file mode 100644 index 0000000000..dce05c3561 --- /dev/null +++ b/internal/endtoend/testdata/pattern_matching/ydb/go/query.sql.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const petsByName = `-- name: PetsByName :many +SELECT name FROM pet WHERE name LIKE $pattern +` + +func (q *Queries) PetsByName(ctx context.Context, pattern string) ([]string, error) { + rows, err := q.db.QueryContext(ctx, petsByName, pattern) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + return nil, err + } + items = append(items, name) + } + 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/pattern_matching/ydb/query.sql b/internal/endtoend/testdata/pattern_matching/ydb/query.sql new file mode 100644 index 0000000000..6ee2c2583b --- /dev/null +++ b/internal/endtoend/testdata/pattern_matching/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: PetsByName :many +SELECT * FROM pet WHERE name LIKE $pattern; diff --git a/internal/endtoend/testdata/pattern_matching/ydb/schema.sql b/internal/endtoend/testdata/pattern_matching/ydb/schema.sql new file mode 100644 index 0000000000..9b9d139a9e --- /dev/null +++ b/internal/endtoend/testdata/pattern_matching/ydb/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE pet ( + name Text, + PRIMARY KEY (name) +); diff --git a/internal/endtoend/testdata/pattern_matching/ydb/sqlc.json b/internal/endtoend/testdata/pattern_matching/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/pattern_matching/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/db.go b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/query_parameter_limit_param_only/ydb/go/models.go b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/models.go new file mode 100644 index 0000000000..fdd5caa33f --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/models.go @@ -0,0 +1,17 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "time" +) + +type Notice struct { + ID int32 + Cnt int32 + Status string + NoticeAt *time.Time + CreatedAt time.Time +} diff --git a/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/querier.go b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/querier.go new file mode 100644 index 0000000000..70b9b5a396 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/querier.go @@ -0,0 +1,17 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + "time" +) + +type Querier interface { + CreateNotice(ctx context.Context, cnt int32, createdAt time.Time) error + MarkNoticeDone(ctx context.Context, noticeAt *time.Time, iD int32) error +} + +var _ Querier = (*Queries)(nil) diff --git a/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/query.sql.go b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/query.sql.go new file mode 100644 index 0000000000..fca23a0100 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/go/query.sql.go @@ -0,0 +1,32 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + "time" +) + +const createNotice = `-- name: CreateNotice :exec +INSERT INTO notice (cnt, created_at) +VALUES ($cnt, $created_at) +` + +func (q *Queries) CreateNotice(ctx context.Context, cnt int32, createdAt time.Time) error { + _, err := q.db.ExecContext(ctx, createNotice, cnt, createdAt) + return err +} + +const markNoticeDone = `-- name: MarkNoticeDone :exec +UPDATE notice +SET status='done', notice_at=$notice_at +WHERE id=$id +` + +func (q *Queries) MarkNoticeDone(ctx context.Context, noticeAt *time.Time, iD int32) error { + _, err := q.db.ExecContext(ctx, markNoticeDone, noticeAt, iD) + return err +} diff --git a/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/query.sql b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/query.sql new file mode 100644 index 0000000000..d4703bc494 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/query.sql @@ -0,0 +1,8 @@ +-- name: MarkNoticeDone :exec +UPDATE notice +SET status='done', notice_at=$notice_at +WHERE id=$id; + +-- name: CreateNotice :exec +INSERT INTO notice (cnt, created_at) +VALUES ($cnt, $created_at); diff --git a/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/schema.sql b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/schema.sql new file mode 100644 index 0000000000..b9d76f9347 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/schema.sql @@ -0,0 +1,8 @@ +CREATE TABLE notice ( + id Int32 NOT NULL, + cnt Int32 NOT NULL, + status Text NOT NULL, + notice_at Timestamp, + created_at Timestamp NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/sqlc.json b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/sqlc.json new file mode 100644 index 0000000000..e7449f5bdb --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_param_only/ydb/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "schema": "schema.sql", + "queries": "query.sql", + "query_parameter_limit": 2, + "emit_interface": true, + "name": "querytest" + } + ] +} diff --git a/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/db.go b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/query_parameter_limit_to_two/ydb/go/models.go b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/models.go new file mode 100644 index 0000000000..e3699fc2e9 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/models.go @@ -0,0 +1,18 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int64 + Name string + Bio *string + CountryCode string + Titles *string +} + +type Client struct { + ID int32 + Name string +} diff --git a/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/query.sql.go b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/query.sql.go new file mode 100644 index 0000000000..477ad28a7a --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/go/query.sql.go @@ -0,0 +1,149 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const addNewClient = `-- name: AddNewClient :one +INSERT INTO clients ( + id, name +) VALUES ( + $id, $name +) +RETURNING id, name +` + +func (q *Queries) AddNewClient(ctx context.Context, iD int32, name string) (Client, error) { + row := q.db.QueryRowContext(ctx, addNewClient, iD, name) + var i Client + err := row.Scan(&i.ID, &i.Name) + return i, err +} + +const createAuthor = `-- name: CreateAuthor :one +INSERT INTO authors ( + name, bio, country_code, titles +) VALUES ( + $name, $bio, $country_code, $titles +) +RETURNING id, name, bio, country_code, titles +` + +type CreateAuthorParams struct { + Name string + Bio *string + CountryCode string + Titles *string +} + +func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { + row := q.db.QueryRowContext(ctx, createAuthor, + arg.Name, + arg.Bio, + arg.CountryCode, + arg.Titles, + ) + var i Author + err := row.Scan( + &i.ID, + &i.Name, + &i.Bio, + &i.CountryCode, + &i.Titles, + ) + return i, err +} + +const createAuthorOnlyTitles = `-- name: CreateAuthorOnlyTitles :one +INSERT INTO authors (name, titles) VALUES ($name, $titles) RETURNING id, name, bio, country_code, titles +` + +func (q *Queries) CreateAuthorOnlyTitles(ctx context.Context, name string, titles *string) (Author, error) { + row := q.db.QueryRowContext(ctx, createAuthorOnlyTitles, name, titles) + var i Author + err := row.Scan( + &i.ID, + &i.Name, + &i.Bio, + &i.CountryCode, + &i.Titles, + ) + return i, err +} + +const deleteAuthor = `-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $id +` + +func (q *Queries) DeleteAuthor(ctx context.Context, id int64) error { + _, err := q.db.ExecContext(ctx, deleteAuthor, id) + return err +} + +const deleteAuthors = `-- name: DeleteAuthors :exec +DELETE FROM authors +WHERE id IN $ids AND name = $name +` + +func (q *Queries) DeleteAuthors(ctx context.Context, ids []int64, name string) error { + _, err := q.db.ExecContext(ctx, deleteAuthors, ids, name) + return err +} + +const getAuthor = `-- name: GetAuthor :one +SELECT id, name, bio, country_code, titles FROM authors +WHERE name = $name AND country_code = $country_code LIMIT 1 +` + +func (q *Queries) GetAuthor(ctx context.Context, name string, countryCode string) (Author, error) { + row := q.db.QueryRowContext(ctx, getAuthor, name, countryCode) + var i Author + err := row.Scan( + &i.ID, + &i.Name, + &i.Bio, + &i.CountryCode, + &i.Titles, + ) + return i, err +} + +const listAuthors = `-- name: ListAuthors :many +SELECT id, name, bio, country_code, titles FROM authors +ORDER BY name +` + +func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan( + &i.ID, + &i.Name, + &i.Bio, + &i.CountryCode, + &i.Titles, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/query_parameter_limit_to_two/ydb/query.sql b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/query.sql new file mode 100644 index 0000000000..2db5f44b13 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/query.sql @@ -0,0 +1,34 @@ +-- name: GetAuthor :one +SELECT * FROM authors +WHERE name = $name AND country_code = $country_code LIMIT 1; + +-- name: ListAuthors :many +SELECT * FROM authors +ORDER BY name; + +-- name: CreateAuthor :one +INSERT INTO authors ( + name, bio, country_code, titles +) VALUES ( + $name, $bio, $country_code, $titles +) +RETURNING *; + +-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $id; + +-- name: DeleteAuthors :exec +DELETE FROM authors +WHERE id IN sqlc.slice(ids) AND name = $name; + +-- name: CreateAuthorOnlyTitles :one +INSERT INTO authors (name, titles) VALUES ($name, $titles) RETURNING *; + +-- name: AddNewClient :one +INSERT INTO clients ( + id, name +) VALUES ( + $id, $name +) +RETURNING *; diff --git a/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/schema.sql b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/schema.sql new file mode 100644 index 0000000000..ab228b3942 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/schema.sql @@ -0,0 +1,15 @@ +-- Example queries for sqlc +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + country_code Text NOT NULL, + titles Text, + PRIMARY KEY (id) +); + +CREATE TABLE clients ( + id Int32, + name Text NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/sqlc.json b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/sqlc.json new file mode 100644 index 0000000000..90ba79dcf3 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_two/ydb/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "query_parameter_limit": 2 + } + ] + } diff --git a/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/db.go b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/query_parameter_limit_to_zero/ydb/go/models.go b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/models.go new file mode 100644 index 0000000000..2dd7d523f8 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int64 + Name string + Bio *string + CountryCode string +} diff --git a/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/querier.go b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/querier.go new file mode 100644 index 0000000000..0d2ece1477 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/querier.go @@ -0,0 +1,18 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" +) + +type Querier interface { + CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) + DeleteAuthor(ctx context.Context, arg DeleteAuthorParams) error + GetAuthor(ctx context.Context, arg GetAuthorParams) (Author, error) + ListAuthors(ctx context.Context) ([]Author, error) +} + +var _ Querier = (*Queries)(nil) diff --git a/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/query.sql.go b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/query.sql.go new file mode 100644 index 0000000000..bd06c190a6 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/go/query.sql.go @@ -0,0 +1,106 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const createAuthor = `-- name: CreateAuthor :one +INSERT INTO authors ( + name, bio, country_code +) VALUES ( + $name, $bio, $country_code +) +RETURNING id, name, bio, country_code +` + +type CreateAuthorParams struct { + Name string + Bio *string + CountryCode string +} + +func (q *Queries) CreateAuthor(ctx context.Context, arg CreateAuthorParams) (Author, error) { + row := q.db.QueryRowContext(ctx, createAuthor, arg.Name, arg.Bio, arg.CountryCode) + var i Author + err := row.Scan( + &i.ID, + &i.Name, + &i.Bio, + &i.CountryCode, + ) + return i, err +} + +const deleteAuthor = `-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $id +` + +type DeleteAuthorParams struct { + ID int64 +} + +func (q *Queries) DeleteAuthor(ctx context.Context, arg DeleteAuthorParams) error { + _, err := q.db.ExecContext(ctx, deleteAuthor, arg.ID) + return err +} + +const getAuthor = `-- name: GetAuthor :one +SELECT id, name, bio, country_code FROM authors +WHERE name = $name AND country_code = $country_code LIMIT 1 +` + +type GetAuthorParams struct { + Name string + CountryCode string +} + +func (q *Queries) GetAuthor(ctx context.Context, arg GetAuthorParams) (Author, error) { + row := q.db.QueryRowContext(ctx, getAuthor, arg.Name, arg.CountryCode) + var i Author + err := row.Scan( + &i.ID, + &i.Name, + &i.Bio, + &i.CountryCode, + ) + return i, err +} + +const listAuthors = `-- name: ListAuthors :many +SELECT id, name, bio, country_code FROM authors +ORDER BY name +` + +func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan( + &i.ID, + &i.Name, + &i.Bio, + &i.CountryCode, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/query_parameter_limit_to_zero/ydb/query.sql b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/query.sql new file mode 100644 index 0000000000..147bc056cc --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/query.sql @@ -0,0 +1,19 @@ +-- name: GetAuthor :one +SELECT * FROM authors +WHERE name = $name AND country_code = $country_code LIMIT 1; + +-- name: ListAuthors :many +SELECT * FROM authors +ORDER BY name; + +-- name: CreateAuthor :one +INSERT INTO authors ( + name, bio, country_code +) VALUES ( + $name, $bio, $country_code +) +RETURNING *; + +-- name: DeleteAuthor :exec +DELETE FROM authors +WHERE id = $id; diff --git a/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/schema.sql b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/schema.sql new file mode 100644 index 0000000000..8f92b42588 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/schema.sql @@ -0,0 +1,8 @@ +-- Example queries for sqlc +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + country_code Text NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/sqlc.json b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/sqlc.json new file mode 100644 index 0000000000..33b80d3781 --- /dev/null +++ b/internal/endtoend/testdata/query_parameter_limit_to_zero/ydb/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql", + "query_parameter_limit": 0, + "emit_interface": true + } + ] + } diff --git a/internal/endtoend/testdata/returning/ydb/stdlib/go/db.go b/internal/endtoend/testdata/returning/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/returning/ydb/stdlib/go/models.go b/internal/endtoend/testdata/returning/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..6dac5a4bf2 --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + Name *string + ID int32 +} diff --git a/internal/endtoend/testdata/returning/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/returning/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..24ebfc198e --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/stdlib/go/query.sql.go @@ -0,0 +1,96 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const deleteUserAndReturnID = `-- name: DeleteUserAndReturnID :one +DELETE FROM users + WHERE name = $name + RETURNING id +` + +func (q *Queries) DeleteUserAndReturnID(ctx context.Context, name *string) (int32, error) { + row := q.db.QueryRowContext(ctx, deleteUserAndReturnID, name) + var id int32 + err := row.Scan(&id) + return id, err +} + +const deleteUserAndReturnUser = `-- name: DeleteUserAndReturnUser :one +DELETE FROM users + WHERE name = $name + RETURNING name, id +` + +func (q *Queries) DeleteUserAndReturnUser(ctx context.Context, name *string) (User, error) { + row := q.db.QueryRowContext(ctx, deleteUserAndReturnUser, name) + var i User + err := row.Scan(&i.Name, &i.ID) + return i, err +} + +const insertUserAndReturnID = `-- name: InsertUserAndReturnID :one +INSERT INTO users (name) VALUES ($name) + RETURNING id +` + +func (q *Queries) InsertUserAndReturnID(ctx context.Context, name *string) (int32, error) { + row := q.db.QueryRowContext(ctx, insertUserAndReturnID, name) + var id int32 + err := row.Scan(&id) + return id, err +} + +const insertUserAndReturnUser = `-- name: InsertUserAndReturnUser :one +INSERT INTO users (name) VALUES ($name) + RETURNING name, id +` + +func (q *Queries) InsertUserAndReturnUser(ctx context.Context, name *string) (User, error) { + row := q.db.QueryRowContext(ctx, insertUserAndReturnUser, name) + var i User + err := row.Scan(&i.Name, &i.ID) + return i, err +} + +const updateUserAndReturnID = `-- name: UpdateUserAndReturnID :one +UPDATE users SET name = $name + WHERE name = $name_2 + RETURNING id +` + +type UpdateUserAndReturnIDParams struct { + Name *string + Name2 *string +} + +func (q *Queries) UpdateUserAndReturnID(ctx context.Context, arg UpdateUserAndReturnIDParams) (int32, error) { + row := q.db.QueryRowContext(ctx, updateUserAndReturnID, arg.Name, arg.Name2) + var id int32 + err := row.Scan(&id) + return id, err +} + +const updateUserAndReturnUser = `-- name: UpdateUserAndReturnUser :one +UPDATE users SET name = $name + WHERE name = $name_2 + RETURNING name, id +` + +type UpdateUserAndReturnUserParams struct { + Name *string + Name2 *string +} + +func (q *Queries) UpdateUserAndReturnUser(ctx context.Context, arg UpdateUserAndReturnUserParams) (User, error) { + row := q.db.QueryRowContext(ctx, updateUserAndReturnUser, arg.Name, arg.Name2) + var i User + err := row.Scan(&i.Name, &i.ID) + return i, err +} diff --git a/internal/endtoend/testdata/returning/ydb/stdlib/query.sql b/internal/endtoend/testdata/returning/ydb/stdlib/query.sql new file mode 100644 index 0000000000..c694aa85b5 --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/stdlib/query.sql @@ -0,0 +1,27 @@ +-- name: InsertUserAndReturnID :one +INSERT INTO users (name) VALUES ($name) + RETURNING id; + +-- name: InsertUserAndReturnUser :one +INSERT INTO users (name) VALUES ($name) + RETURNING *; + +-- name: UpdateUserAndReturnID :one +UPDATE users SET name = $name + WHERE name = $name_2 + RETURNING id; + +-- name: UpdateUserAndReturnUser :one +UPDATE users SET name = $name + WHERE name = $name_2 + RETURNING *; + +-- name: DeleteUserAndReturnID :one +DELETE FROM users + WHERE name = $name + RETURNING id; + +-- name: DeleteUserAndReturnUser :one +DELETE FROM users + WHERE name = $name + RETURNING *; diff --git a/internal/endtoend/testdata/returning/ydb/stdlib/schema.sql b/internal/endtoend/testdata/returning/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..9d8695d968 --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/stdlib/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE users ( + name Utf8, + id Serial, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/returning/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/returning/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..6dac5a4bf2 --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + Name *string + ID int32 +} diff --git a/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..7f6c0bb5a7 --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,162 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const deleteUserAndReturnID = `-- name: DeleteUserAndReturnID :one +DELETE FROM users + WHERE name = $name + RETURNING id +` + +func (q *Queries) DeleteUserAndReturnID(ctx context.Context, name *string, opts ...query.ExecuteOption) (int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").BeginOptional().Text(name).EndOptional() + row, err := q.db.QueryRow(ctx, deleteUserAndReturnID, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var id int32 + if err != nil { + return id, xerrors.WithStackTrace(err) + } + err = row.Scan(&id) + if err != nil { + return id, xerrors.WithStackTrace(err) + } + return id, nil +} + +const deleteUserAndReturnUser = `-- name: DeleteUserAndReturnUser :one +DELETE FROM users + WHERE name = $name + RETURNING name, id +` + +func (q *Queries) DeleteUserAndReturnUser(ctx context.Context, name *string, opts ...query.ExecuteOption) (User, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").BeginOptional().Text(name).EndOptional() + row, err := q.db.QueryRow(ctx, deleteUserAndReturnUser, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i User + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.Name, &i.ID) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const insertUserAndReturnID = `-- name: InsertUserAndReturnID :one +INSERT INTO users (name) VALUES ($name) + RETURNING id +` + +func (q *Queries) InsertUserAndReturnID(ctx context.Context, name *string, opts ...query.ExecuteOption) (int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").BeginOptional().Text(name).EndOptional() + row, err := q.db.QueryRow(ctx, insertUserAndReturnID, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var id int32 + if err != nil { + return id, xerrors.WithStackTrace(err) + } + err = row.Scan(&id) + if err != nil { + return id, xerrors.WithStackTrace(err) + } + return id, nil +} + +const insertUserAndReturnUser = `-- name: InsertUserAndReturnUser :one +INSERT INTO users (name) VALUES ($name) + RETURNING name, id +` + +func (q *Queries) InsertUserAndReturnUser(ctx context.Context, name *string, opts ...query.ExecuteOption) (User, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").BeginOptional().Text(name).EndOptional() + row, err := q.db.QueryRow(ctx, insertUserAndReturnUser, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i User + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.Name, &i.ID) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const updateUserAndReturnID = `-- name: UpdateUserAndReturnID :one +UPDATE users SET name = $name + WHERE name = $name_2 + RETURNING id +` + +type UpdateUserAndReturnIDParams struct { + Name *string + Name2 *string +} + +func (q *Queries) UpdateUserAndReturnID(ctx context.Context, arg UpdateUserAndReturnIDParams, opts ...query.ExecuteOption) (int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").BeginOptional().Text(arg.Name).EndOptional() + parameters = parameters.Param("$name_2").BeginOptional().Text(arg.Name2).EndOptional() + row, err := q.db.QueryRow(ctx, updateUserAndReturnID, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var id int32 + if err != nil { + return id, xerrors.WithStackTrace(err) + } + err = row.Scan(&id) + if err != nil { + return id, xerrors.WithStackTrace(err) + } + return id, nil +} + +const updateUserAndReturnUser = `-- name: UpdateUserAndReturnUser :one +UPDATE users SET name = $name + WHERE name = $name_2 + RETURNING name, id +` + +type UpdateUserAndReturnUserParams struct { + Name *string + Name2 *string +} + +func (q *Queries) UpdateUserAndReturnUser(ctx context.Context, arg UpdateUserAndReturnUserParams, opts ...query.ExecuteOption) (User, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").BeginOptional().Text(arg.Name).EndOptional() + parameters = parameters.Param("$name_2").BeginOptional().Text(arg.Name2).EndOptional() + row, err := q.db.QueryRow(ctx, updateUserAndReturnUser, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i User + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.Name, &i.ID) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} diff --git a/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..c694aa85b5 --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,27 @@ +-- name: InsertUserAndReturnID :one +INSERT INTO users (name) VALUES ($name) + RETURNING id; + +-- name: InsertUserAndReturnUser :one +INSERT INTO users (name) VALUES ($name) + RETURNING *; + +-- name: UpdateUserAndReturnID :one +UPDATE users SET name = $name + WHERE name = $name_2 + RETURNING id; + +-- name: UpdateUserAndReturnUser :one +UPDATE users SET name = $name + WHERE name = $name_2 + RETURNING *; + +-- name: DeleteUserAndReturnID :one +DELETE FROM users + WHERE name = $name + RETURNING id; + +-- name: DeleteUserAndReturnUser :one +DELETE FROM users + WHERE name = $name + RETURNING *; diff --git a/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..9d8695d968 --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE users ( + name Utf8, + id Serial, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/returning/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/select_column_cast/ydb/go/db.go b/internal/endtoend/testdata/select_column_cast/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/select_column_cast/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/select_column_cast/ydb/go/models.go b/internal/endtoend/testdata/select_column_cast/ydb/go/models.go new file mode 100644 index 0000000000..04bc70ad65 --- /dev/null +++ b/internal/endtoend/testdata/select_column_cast/ydb/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar bool +} diff --git a/internal/endtoend/testdata/select_column_cast/ydb/go/query.sql.go b/internal/endtoend/testdata/select_column_cast/ydb/go/query.sql.go new file mode 100644 index 0000000000..b5a04c2fe8 --- /dev/null +++ b/internal/endtoend/testdata/select_column_cast/ydb/go/query.sql.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const selectColumnCast = `-- name: SelectColumnCast :many +SELECT CAST(bar AS Int32) FROM foo +` + +func (q *Queries) SelectColumnCast(ctx context.Context) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, selectColumnCast) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var bar int32 + if err := rows.Scan(&bar); err != nil { + return nil, err + } + items = append(items, bar) + } + 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/select_column_cast/ydb/query.sql b/internal/endtoend/testdata/select_column_cast/ydb/query.sql new file mode 100644 index 0000000000..90070b46ec --- /dev/null +++ b/internal/endtoend/testdata/select_column_cast/ydb/query.sql @@ -0,0 +1,2 @@ +-- name: SelectColumnCast :many +SELECT CAST(bar AS Int32) FROM foo; diff --git a/internal/endtoend/testdata/select_column_cast/ydb/schema.sql b/internal/endtoend/testdata/select_column_cast/ydb/schema.sql new file mode 100644 index 0000000000..bb793068c3 --- /dev/null +++ b/internal/endtoend/testdata/select_column_cast/ydb/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo ( + bar Bool NOT NULL, + PRIMARY KEY (bar) +); diff --git a/internal/endtoend/testdata/select_column_cast/ydb/sqlc.json b/internal/endtoend/testdata/select_column_cast/ydb/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/select_column_cast/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/select_distinct/ydb/stdlib/go/db.go b/internal/endtoend/testdata/select_distinct/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/select_distinct/ydb/stdlib/go/models.go b/internal/endtoend/testdata/select_distinct/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..3f902fb339 --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 + Name *string +} diff --git a/internal/endtoend/testdata/select_distinct/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/select_distinct/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..59a12d4046 --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/stdlib/go/query.sql.go @@ -0,0 +1,38 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getBars = `-- name: GetBars :many +SELECT DISTINCT id, name +FROM bar +` + +func (q *Queries) GetBars(ctx context.Context) ([]Bar, error) { + rows, err := q.db.QueryContext(ctx, getBars) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Bar + for rows.Next() { + var i Bar + if err := rows.Scan(&i.ID, &i.Name); err != nil { + return nil, err + } + items = append(items, i) + } + 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/select_distinct/ydb/stdlib/query.sql b/internal/endtoend/testdata/select_distinct/ydb/stdlib/query.sql new file mode 100644 index 0000000000..13c029d904 --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/stdlib/query.sql @@ -0,0 +1,3 @@ +-- name: GetBars :many +SELECT DISTINCT id, name +FROM bar; diff --git a/internal/endtoend/testdata/select_distinct/ydb/stdlib/schema.sql b/internal/endtoend/testdata/select_distinct/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..3604ffebdc --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/stdlib/schema.sql @@ -0,0 +1 @@ +CREATE TABLE bar (id Serial, name Utf8, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/select_distinct/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/select_distinct/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..3f902fb339 --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 + Name *string +} diff --git a/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..72977df92e --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,40 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const getBars = `-- name: GetBars :many +SELECT DISTINCT id, name +FROM bar +` + +func (q *Queries) GetBars(ctx context.Context, opts ...query.ExecuteOption) ([]Bar, error) { + result, err := q.db.QueryResultSet(ctx, getBars, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Bar + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Bar + if err := row.Scan(&i.ID, &i.Name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..13c029d904 --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,3 @@ +-- name: GetBars :many +SELECT DISTINCT id, name +FROM bar; diff --git a/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..3604ffebdc --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1 @@ +CREATE TABLE bar (id Serial, name Utf8, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/select_distinct/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/select_exists/ydb/stdlib/go/db.go b/internal/endtoend/testdata/select_exists/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/select_exists/ydb/stdlib/go/models.go b/internal/endtoend/testdata/select_exists/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/select_exists/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/select_exists/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..93a3d6b98d --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/stdlib/go/query.sql.go @@ -0,0 +1,29 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const barExists = `-- name: BarExists :one +SELECT + EXISTS ( + SELECT + 1 + FROM + bar + where + id = $id + ) +` + +func (q *Queries) BarExists(ctx context.Context, id int32) (bool, error) { + row := q.db.QueryRowContext(ctx, barExists, id) + var exists bool + err := row.Scan(&exists) + return exists, err +} diff --git a/internal/endtoend/testdata/select_exists/ydb/stdlib/query.sql b/internal/endtoend/testdata/select_exists/ydb/stdlib/query.sql new file mode 100644 index 0000000000..02df281523 --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/stdlib/query.sql @@ -0,0 +1,10 @@ +-- name: BarExists :one +SELECT + EXISTS ( + SELECT + 1 + FROM + bar + where + id = $id + ); diff --git a/internal/endtoend/testdata/select_exists/ydb/stdlib/schema.sql b/internal/endtoend/testdata/select_exists/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..a81897d939 --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/stdlib/schema.sql @@ -0,0 +1 @@ +CREATE TABLE bar (id Serial, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/select_exists/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/select_exists/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..bbb8a0891d --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,43 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const barExists = `-- name: BarExists :one +SELECT + EXISTS ( + SELECT + 1 + FROM + bar + where + id = $id + ) +` + +func (q *Queries) BarExists(ctx context.Context, id int32, opts ...query.ExecuteOption) (bool, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int32(id) + row, err := q.db.QueryRow(ctx, barExists, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var exists bool + if err != nil { + return exists, xerrors.WithStackTrace(err) + } + err = row.Scan(&exists) + if err != nil { + return exists, xerrors.WithStackTrace(err) + } + return exists, nil +} diff --git a/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..02df281523 --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,10 @@ +-- name: BarExists :one +SELECT + EXISTS ( + SELECT + 1 + FROM + bar + where + id = $id + ); diff --git a/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..a81897d939 --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1 @@ +CREATE TABLE bar (id Serial, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/select_exists/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/select_in_and/ydb/go/db.go b/internal/endtoend/testdata/select_in_and/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/select_in_and/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/select_in_and/ydb/go/models.go b/internal/endtoend/testdata/select_in_and/ydb/go/models.go new file mode 100644 index 0000000000..7ad29a9af1 --- /dev/null +++ b/internal/endtoend/testdata/select_in_and/ydb/go/models.go @@ -0,0 +1,24 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int32 + Name string + Age *int32 +} + +type Book struct { + ID int32 + Author string + Translator string + Year *int32 +} + +type Translator struct { + ID int32 + Name string + Age *int32 +} diff --git a/internal/endtoend/testdata/select_in_and/ydb/go/query.sql.go b/internal/endtoend/testdata/select_in_and/ydb/go/query.sql.go new file mode 100644 index 0000000000..59c0c3b085 --- /dev/null +++ b/internal/endtoend/testdata/select_in_and/ydb/go/query.sql.go @@ -0,0 +1,44 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const deleteAuthor = `-- name: DeleteAuthor :exec +DELETE FROM + books +WHERE + author NOT IN ( + SELECT + a.name + FROM + authors a + WHERE + a.age >= $min_author_age + ) + AND translator NOT IN ( + SELECT + t.name + FROM + translators t + WHERE + t.age >= $min_translator_age + ) + AND year <= $max_year +` + +type DeleteAuthorParams struct { + MinAuthorAge *int32 + MinTranslatorAge *int32 + MaxYear *int32 +} + +func (q *Queries) DeleteAuthor(ctx context.Context, arg DeleteAuthorParams) error { + _, err := q.db.ExecContext(ctx, deleteAuthor, arg.MinAuthorAge, arg.MinTranslatorAge, arg.MaxYear) + return err +} diff --git a/internal/endtoend/testdata/select_in_and/ydb/query.sql b/internal/endtoend/testdata/select_in_and/ydb/query.sql new file mode 100644 index 0000000000..efab80870b --- /dev/null +++ b/internal/endtoend/testdata/select_in_and/ydb/query.sql @@ -0,0 +1,21 @@ +-- name: DeleteAuthor :exec +DELETE FROM + books +WHERE + author NOT IN ( + SELECT + a.name + FROM + authors a + WHERE + a.age >= $min_author_age + ) + AND translator NOT IN ( + SELECT + t.name + FROM + translators t + WHERE + t.age >= $min_translator_age + ) + AND year <= $max_year; diff --git a/internal/endtoend/testdata/select_in_and/ydb/schema.sql b/internal/endtoend/testdata/select_in_and/ydb/schema.sql new file mode 100644 index 0000000000..387fdc0fa0 --- /dev/null +++ b/internal/endtoend/testdata/select_in_and/ydb/schema.sql @@ -0,0 +1,25 @@ +-- Example queries for sqlc +CREATE TABLE authors ( + id Int32, + name Text NOT NULL, + age Int32, + PRIMARY KEY (id) +); + +CREATE TABLE translators ( + id Int32, + name Text NOT NULL, + age Int32, + PRIMARY KEY (id) +); + +CREATE TABLE books ( + id Int32, + author Text NOT NULL, + translator Text NOT NULL, + year Int32, + PRIMARY KEY (id) +); + + + diff --git a/internal/endtoend/testdata/select_in_and/ydb/sqlc.json b/internal/endtoend/testdata/select_in_and/ydb/sqlc.json new file mode 100644 index 0000000000..c5959ba446 --- /dev/null +++ b/internal/endtoend/testdata/select_in_and/ydb/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/select_limit/ydb/stdlib/go/db.go b/internal/endtoend/testdata/select_limit/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/select_limit/ydb/stdlib/go/models.go b/internal/endtoend/testdata/select_limit/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..0315a45010 --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string +} diff --git a/internal/endtoend/testdata/select_limit/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/select_limit/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..861f1988dc --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/stdlib/go/query.sql.go @@ -0,0 +1,71 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const fooLimit = `-- name: FooLimit :many +SELECT a FROM foo +LIMIT $limit +` + +func (q *Queries) FooLimit(ctx context.Context, limit uint64) ([]string, error) { + rows, err := q.db.QueryContext(ctx, fooLimit, limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var a string + if err := rows.Scan(&a); err != nil { + return nil, err + } + items = append(items, a) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const fooLimitOffset = `-- name: FooLimitOffset :many +SELECT a FROM foo +LIMIT $limit OFFSET $offset +` + +type FooLimitOffsetParams struct { + Offset uint64 + Limit uint64 +} + +func (q *Queries) FooLimitOffset(ctx context.Context, arg FooLimitOffsetParams) ([]string, error) { + rows, err := q.db.QueryContext(ctx, fooLimitOffset, arg.Offset, arg.Limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var a string + if err := rows.Scan(&a); err != nil { + return nil, err + } + items = append(items, a) + } + 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/select_limit/ydb/stdlib/query.sql b/internal/endtoend/testdata/select_limit/ydb/stdlib/query.sql new file mode 100644 index 0000000000..55f3ed95f7 --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/stdlib/query.sql @@ -0,0 +1,8 @@ +-- name: FooLimit :many +SELECT a FROM foo +LIMIT $limit; + +-- name: FooLimitOffset :many +SELECT a FROM foo +LIMIT $limit OFFSET $offset; + diff --git a/internal/endtoend/testdata/select_limit/ydb/stdlib/schema.sql b/internal/endtoend/testdata/select_limit/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..2c11be972d --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/stdlib/schema.sql @@ -0,0 +1,2 @@ +CREATE TABLE foo (a Utf8, PRIMARY KEY (a)); + diff --git a/internal/endtoend/testdata/select_limit/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/select_limit/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..3e245cf4a5 --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/stdlib/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..0315a45010 --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string +} diff --git a/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..ec42f11fb6 --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,82 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const fooLimit = `-- name: FooLimit :many +SELECT a FROM foo +LIMIT $limit +` + +func (q *Queries) FooLimit(ctx context.Context, limit uint64, opts ...query.ExecuteOption) ([]string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$limit").Uint64(limit) + result, err := q.db.QueryResultSet(ctx, fooLimit, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var a string + if err := row.Scan(&a); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, a) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const fooLimitOffset = `-- name: FooLimitOffset :many +SELECT a FROM foo +LIMIT $limit OFFSET $offset +` + +type FooLimitOffsetParams struct { + Offset uint64 + Limit uint64 +} + +func (q *Queries) FooLimitOffset(ctx context.Context, arg FooLimitOffsetParams, opts ...query.ExecuteOption) ([]string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$offset").Uint64(arg.Offset) + parameters = parameters.Param("$limit").Uint64(arg.Limit) + result, err := q.db.QueryResultSet(ctx, fooLimitOffset, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var a string + if err := row.Scan(&a); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, a) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..55f3ed95f7 --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,8 @@ +-- name: FooLimit :many +SELECT a FROM foo +LIMIT $limit; + +-- name: FooLimitOffset :many +SELECT a FROM foo +LIMIT $limit OFFSET $offset; + diff --git a/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..2c11be972d --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,2 @@ +CREATE TABLE foo (a Utf8, PRIMARY KEY (a)); + diff --git a/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..ab1d73a6ea --- /dev/null +++ b/internal/endtoend/testdata/select_limit/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/select_nested_count/ydb/go/db.go b/internal/endtoend/testdata/select_nested_count/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/select_nested_count/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/select_nested_count/ydb/go/models.go b/internal/endtoend/testdata/select_nested_count/ydb/go/models.go new file mode 100644 index 0000000000..eb74ffbb19 --- /dev/null +++ b/internal/endtoend/testdata/select_nested_count/ydb/go/models.go @@ -0,0 +1,17 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Author struct { + ID int64 + Name string + Bio *string +} + +type Book struct { + ID int64 + AuthorID int64 + Title string +} diff --git a/internal/endtoend/testdata/select_nested_count/ydb/go/query.sql.go b/internal/endtoend/testdata/select_nested_count/ydb/go/query.sql.go new file mode 100644 index 0000000000..98ebd42b74 --- /dev/null +++ b/internal/endtoend/testdata/select_nested_count/ydb/go/query.sql.go @@ -0,0 +1,56 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getAuthorsWithBooksCount = `-- name: GetAuthorsWithBooksCount :many +SELECT + a.id, + a.name, + a.bio, + COUNT(b.id) AS books_count +FROM authors a +LEFT JOIN books b ON b.author_id = a.id +GROUP BY a.id, a.name, a.bio +` + +type GetAuthorsWithBooksCountRow struct { + ID int64 + Name string + Bio *string + BooksCount uint64 +} + +func (q *Queries) GetAuthorsWithBooksCount(ctx context.Context) ([]GetAuthorsWithBooksCountRow, error) { + rows, err := q.db.QueryContext(ctx, getAuthorsWithBooksCount) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GetAuthorsWithBooksCountRow + for rows.Next() { + var i GetAuthorsWithBooksCountRow + if err := rows.Scan( + &i.ID, + &i.Name, + &i.Bio, + &i.BooksCount, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/select_nested_count/ydb/query.sql b/internal/endtoend/testdata/select_nested_count/ydb/query.sql new file mode 100644 index 0000000000..9a5451fd97 --- /dev/null +++ b/internal/endtoend/testdata/select_nested_count/ydb/query.sql @@ -0,0 +1,9 @@ +-- name: GetAuthorsWithBooksCount :many +SELECT + a.id, + a.name, + a.bio, + COUNT(b.id) AS books_count +FROM authors a +LEFT JOIN books b ON b.author_id = a.id +GROUP BY a.id, a.name, a.bio; diff --git a/internal/endtoend/testdata/select_nested_count/ydb/schema.sql b/internal/endtoend/testdata/select_nested_count/ydb/schema.sql new file mode 100644 index 0000000000..409781b9b1 --- /dev/null +++ b/internal/endtoend/testdata/select_nested_count/ydb/schema.sql @@ -0,0 +1,16 @@ +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); + +CREATE TABLE books ( + id BigSerial, + author_id BigSerial NOT NULL, + title Text NOT NULL, + PRIMARY KEY (id) +); + + + diff --git a/internal/endtoend/testdata/select_nested_count/ydb/sqlc.json b/internal/endtoend/testdata/select_nested_count/ydb/sqlc.json new file mode 100644 index 0000000000..c5959ba446 --- /dev/null +++ b/internal/endtoend/testdata/select_nested_count/ydb/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..4f106ee2e3 --- /dev/null +++ b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + ID int32 +} diff --git a/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..e9d9702c03 --- /dev/null +++ b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,43 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const barNotExists = `-- name: BarNotExists :one +SELECT + NOT EXISTS ( + SELECT + 1 + FROM + bar + where + id = $id + ) +` + +func (q *Queries) BarNotExists(ctx context.Context, id int32, opts ...query.ExecuteOption) (bool, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int32(id) + row, err := q.db.QueryRow(ctx, barNotExists, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var not_exists bool + if err != nil { + return not_exists, xerrors.WithStackTrace(err) + } + err = row.Scan(¬_exists) + if err != nil { + return not_exists, xerrors.WithStackTrace(err) + } + return not_exists, nil +} diff --git a/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/query.sql b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..497c85bfcf --- /dev/null +++ b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/query.sql @@ -0,0 +1,10 @@ +-- name: BarNotExists :one +SELECT + NOT EXISTS ( + SELECT + 1 + FROM + bar + where + id = $id + ); diff --git a/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..a81897d939 --- /dev/null +++ b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/schema.sql @@ -0,0 +1 @@ +CREATE TABLE bar (id Serial, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..058e6d525f --- /dev/null +++ b/internal/endtoend/testdata/select_not_exists/ydb-go-sdk/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] + } + + \ No newline at end of file diff --git a/internal/endtoend/testdata/select_star/ydb/stdlib/go/db.go b/internal/endtoend/testdata/select_star/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/select_star/ydb/stdlib/go/models.go b/internal/endtoend/testdata/select_star/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..1957832e2a --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/stdlib/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int32 + FirstName string + LastName *string + Age int32 +} diff --git a/internal/endtoend/testdata/select_star/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/select_star/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..dd10b59022 --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/stdlib/go/query.sql.go @@ -0,0 +1,69 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const getAll = `-- name: GetAll :many +SELECT id, first_name, last_name, age FROM users +` + +func (q *Queries) GetAll(ctx context.Context) ([]User, error) { + rows, err := q.db.QueryContext(ctx, getAll) + if err != nil { + return nil, err + } + defer rows.Close() + var items []User + for rows.Next() { + var i User + if err := rows.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getIDAll = `-- name: GetIDAll :many +SELECT id FROM (SELECT id FROM users) t +` + +func (q *Queries) GetIDAll(ctx context.Context) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, getIDAll) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var id int32 + if err := rows.Scan(&id); err != nil { + return nil, err + } + items = append(items, id) + } + 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/select_star/ydb/stdlib/query.sql b/internal/endtoend/testdata/select_star/ydb/stdlib/query.sql new file mode 100644 index 0000000000..fc9cfc21ce --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/stdlib/query.sql @@ -0,0 +1,5 @@ +-- name: GetAll :many +SELECT * FROM users; + +/* name: GetIDAll :many */ +SELECT * FROM (SELECT id FROM users) t; diff --git a/internal/endtoend/testdata/select_star/ydb/stdlib/schema.sql b/internal/endtoend/testdata/select_star/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..ea12994b65 --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/stdlib/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE users ( + id Serial, + first_name Utf8 NOT NULL, + last_name Utf8, + age Int32 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/select_star/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/select_star/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..1957832e2a --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,12 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type User struct { + ID int32 + FirstName string + LastName *string + Age int32 +} diff --git a/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..a9246a7ea3 --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,70 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const getAll = `-- name: GetAll :many +SELECT id, first_name, last_name, age FROM users +` + +func (q *Queries) GetAll(ctx context.Context, opts ...query.ExecuteOption) ([]User, error) { + result, err := q.db.QueryResultSet(ctx, getAll, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []User + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i User + if err := row.Scan( + &i.ID, + &i.FirstName, + &i.LastName, + &i.Age, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const getIDAll = `-- name: GetIDAll :many +SELECT id FROM (SELECT id FROM users) t +` + +func (q *Queries) GetIDAll(ctx context.Context, opts ...query.ExecuteOption) ([]int32, error) { + result, err := q.db.QueryResultSet(ctx, getIDAll, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []int32 + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var id int32 + if err := row.Scan(&id); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, id) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..fc9cfc21ce --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,5 @@ +-- name: GetAll :many +SELECT * FROM users; + +/* name: GetIDAll :many */ +SELECT * FROM (SELECT id FROM users) t; diff --git a/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..ea12994b65 --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE users ( + id Serial, + first_name Utf8 NOT NULL, + last_name Utf8, + age Int32 NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/select_star/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..0d14021994 --- /dev/null +++ b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Dummy struct { + ID int32 +} diff --git a/internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..3f625960fb --- /dev/null +++ b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,48 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const selectTextArray = `-- name: SelectTextArray :many +SELECT CAST($param AS List) +` + +func (q *Queries) SelectTextArray(ctx context.Context, param []string, opts ...query.ExecuteOption) ([][]string, error) { + parameters := ydb.ParamsBuilder() + var list = parameters.Param("$param").BeginList() + for _, param := range param { + list = list.Add().Text(param) + } + parameters = list.EndList() + result, err := q.db.QueryResultSet(ctx, selectTextArray, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items [][]string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var column_1 []string + if err := row.Scan(&column_1); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, column_1) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/select_text_array/ydb-go-sdk/query.sql b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..8cbf5f1961 --- /dev/null +++ b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: SelectTextArray :many +SELECT CAST($param AS List); diff --git a/internal/endtoend/testdata/select_text_array/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..5a49020ad6 --- /dev/null +++ b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/schema.sql @@ -0,0 +1 @@ +CREATE TABLE dummy (id Int32, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/select_text_array/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/select_text_array/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/select_union/ydb/stdlib/go/db.go b/internal/endtoend/testdata/select_union/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/select_union/ydb/stdlib/go/models.go b/internal/endtoend/testdata/select_union/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..392035a7af --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/stdlib/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + A string + B string +} + +type Foo struct { + A string + B string +} diff --git a/internal/endtoend/testdata/select_union/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/select_union/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..b472a72a5b --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/stdlib/go/query.sql.go @@ -0,0 +1,132 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const selectUnion = `-- name: SelectUnion :many +SELECT a, b FROM foo +UNION +SELECT a, b FROM foo +` + +func (q *Queries) SelectUnion(ctx context.Context) ([]Foo, error) { + rows, err := q.db.QueryContext(ctx, selectUnion) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Foo + for rows.Next() { + var i Foo + if err := rows.Scan(&i.A, &i.B); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const selectUnionAliased = `-- name: SelectUnionAliased :many +(SELECT a, b FROM foo) +UNION +SELECT a, b FROM foo +` + +func (q *Queries) SelectUnionAliased(ctx context.Context) ([]Foo, error) { + rows, err := q.db.QueryContext(ctx, selectUnionAliased) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Foo + for rows.Next() { + var i Foo + if err := rows.Scan(&i.A, &i.B); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const selectUnionOther = `-- name: SelectUnionOther :many +SELECT a, b FROM foo +UNION +SELECT a, b FROM bar +` + +func (q *Queries) SelectUnionOther(ctx context.Context) ([]Foo, error) { + rows, err := q.db.QueryContext(ctx, selectUnionOther) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Foo + for rows.Next() { + var i Foo + if err := rows.Scan(&i.A, &i.B); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const selectUnionWithLimit = `-- name: SelectUnionWithLimit :many +SELECT a, b FROM foo +UNION +SELECT a, b FROM foo +LIMIT $limit OFFSET $offset +` + +type SelectUnionWithLimitParams struct { + Offset uint64 + Limit uint64 +} + +func (q *Queries) SelectUnionWithLimit(ctx context.Context, arg SelectUnionWithLimitParams) ([]Foo, error) { + rows, err := q.db.QueryContext(ctx, selectUnionWithLimit, arg.Offset, arg.Limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Foo + for rows.Next() { + var i Foo + if err := rows.Scan(&i.A, &i.B); err != nil { + return nil, err + } + items = append(items, i) + } + 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/select_union/ydb/stdlib/query.sql b/internal/endtoend/testdata/select_union/ydb/stdlib/query.sql new file mode 100644 index 0000000000..59cafb6370 --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/stdlib/query.sql @@ -0,0 +1,23 @@ +-- name: SelectUnion :many +SELECT * FROM foo +UNION +SELECT * FROM foo; + +-- name: SelectUnionWithLimit :many +SELECT * FROM foo +UNION +SELECT * FROM foo +LIMIT $limit OFFSET $offset; + +-- name: SelectUnionOther :many +SELECT * FROM foo +UNION +SELECT * FROM bar; + +-- name: SelectUnionAliased :many +(SELECT * FROM foo) +UNION +SELECT * FROM foo; + + + diff --git a/internal/endtoend/testdata/select_union/ydb/stdlib/schema.sql b/internal/endtoend/testdata/select_union/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..8673db0ad5 --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/stdlib/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo (a Text, b Text, PRIMARY KEY (a, b)); +CREATE TABLE bar (a Text, b Text, PRIMARY KEY (a, b)); + + + diff --git a/internal/endtoend/testdata/select_union/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/select_union/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..c5959ba446 --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/stdlib/sqlc.json @@ -0,0 +1,15 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..392035a7af --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + A string + B string +} + +type Foo struct { + A string + B string +} diff --git a/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..66889546a7 --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,137 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const selectUnion = `-- name: SelectUnion :many +SELECT a, b FROM foo +UNION +SELECT a, b FROM foo +` + +func (q *Queries) SelectUnion(ctx context.Context, opts ...query.ExecuteOption) ([]Foo, error) { + result, err := q.db.QueryResultSet(ctx, selectUnion, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Foo + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Foo + if err := row.Scan(&i.A, &i.B); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const selectUnionAliased = `-- name: SelectUnionAliased :many +(SELECT a, b FROM foo) +UNION +SELECT a, b FROM foo +` + +func (q *Queries) SelectUnionAliased(ctx context.Context, opts ...query.ExecuteOption) ([]Foo, error) { + result, err := q.db.QueryResultSet(ctx, selectUnionAliased, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Foo + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Foo + if err := row.Scan(&i.A, &i.B); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const selectUnionOther = `-- name: SelectUnionOther :many +SELECT a, b FROM foo +UNION +SELECT a, b FROM bar +` + +func (q *Queries) SelectUnionOther(ctx context.Context, opts ...query.ExecuteOption) ([]Foo, error) { + result, err := q.db.QueryResultSet(ctx, selectUnionOther, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Foo + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Foo + if err := row.Scan(&i.A, &i.B); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const selectUnionWithLimit = `-- name: SelectUnionWithLimit :many +SELECT a, b FROM foo +UNION +SELECT a, b FROM foo +LIMIT $limit OFFSET $offset +` + +type SelectUnionWithLimitParams struct { + Offset uint64 + Limit uint64 +} + +func (q *Queries) SelectUnionWithLimit(ctx context.Context, arg SelectUnionWithLimitParams, opts ...query.ExecuteOption) ([]Foo, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$offset").Uint64(arg.Offset) + parameters = parameters.Param("$limit").Uint64(arg.Limit) + result, err := q.db.QueryResultSet(ctx, selectUnionWithLimit, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Foo + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Foo + if err := row.Scan(&i.A, &i.B); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..59cafb6370 --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,23 @@ +-- name: SelectUnion :many +SELECT * FROM foo +UNION +SELECT * FROM foo; + +-- name: SelectUnionWithLimit :many +SELECT * FROM foo +UNION +SELECT * FROM foo +LIMIT $limit OFFSET $offset; + +-- name: SelectUnionOther :many +SELECT * FROM foo +UNION +SELECT * FROM bar; + +-- name: SelectUnionAliased :many +(SELECT * FROM foo) +UNION +SELECT * FROM foo; + + + diff --git a/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..8673db0ad5 --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo (a Text, b Text, PRIMARY KEY (a, b)); +CREATE TABLE bar (a Text, b Text, PRIMARY KEY (a, b)); + + + diff --git a/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..a210888689 --- /dev/null +++ b/internal/endtoend/testdata/select_union/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/single_param_conflict/ydb/go/db.go b/internal/endtoend/testdata/single_param_conflict/ydb/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/single_param_conflict/ydb/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/single_param_conflict/ydb/go/models.go b/internal/endtoend/testdata/single_param_conflict/ydb/go/models.go new file mode 100644 index 0000000000..873490bee4 --- /dev/null +++ b/internal/endtoend/testdata/single_param_conflict/ydb/go/models.go @@ -0,0 +1,19 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "github.com/google/uuid" +) + +type Author struct { + ID int64 + Name string + Bio *string +} + +type User struct { + Sub uuid.UUID +} diff --git a/internal/endtoend/testdata/single_param_conflict/ydb/go/query.sql.go b/internal/endtoend/testdata/single_param_conflict/ydb/go/query.sql.go new file mode 100644 index 0000000000..b359da9e1c --- /dev/null +++ b/internal/endtoend/testdata/single_param_conflict/ydb/go/query.sql.go @@ -0,0 +1,67 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/google/uuid" +) + +const getAuthorByID = `-- name: GetAuthorByID :one +SELECT id, name, bio +FROM authors +WHERE id = $id +LIMIT 1 +` + +func (q *Queries) GetAuthorByID(ctx context.Context, id int64) (Author, error) { + row := q.db.QueryRowContext(ctx, getAuthorByID, id) + var i Author + err := row.Scan(&i.ID, &i.Name, &i.Bio) + return i, err +} + +const getAuthorIDByID = `-- name: GetAuthorIDByID :one +SELECT id +FROM authors +WHERE id = $id +LIMIT 1 +` + +func (q *Queries) GetAuthorIDByID(ctx context.Context, id int64) (int64, error) { + row := q.db.QueryRowContext(ctx, getAuthorIDByID, id) + err := row.Scan(&id) + return id, err +} + +const getUser = `-- name: GetUser :one +SELECT sub +FROM users +WHERE sub = $sub +LIMIT 1 +` + +func (q *Queries) GetUser(ctx context.Context, sub uuid.UUID) (uuid.UUID, error) { + row := q.db.QueryRowContext(ctx, getUser, sub) + err := row.Scan(&sub) + return sub, err +} + +const setDefaultName = `-- name: SetDefaultName :one + +UPDATE authors +SET name = 'Default Name' +WHERE id = $id +RETURNING id +` + +// https://github.com/sqlc-dev/sqlc/issues/1235 +func (q *Queries) SetDefaultName(ctx context.Context, id int64) (int64, error) { + row := q.db.QueryRowContext(ctx, setDefaultName, id) + err := row.Scan(&id) + return id, err +} diff --git a/internal/endtoend/testdata/single_param_conflict/ydb/query.sql b/internal/endtoend/testdata/single_param_conflict/ydb/query.sql new file mode 100644 index 0000000000..9004d10728 --- /dev/null +++ b/internal/endtoend/testdata/single_param_conflict/ydb/query.sql @@ -0,0 +1,25 @@ +-- name: GetAuthorIDByID :one +SELECT id +FROM authors +WHERE id = $id +LIMIT 1; + +-- name: GetAuthorByID :one +SELECT id, name, bio +FROM authors +WHERE id = $id +LIMIT 1; + +-- name: GetUser :one +SELECT sub +FROM users +WHERE sub = $sub +LIMIT 1; + +-- https://github.com/sqlc-dev/sqlc/issues/1235 + +-- name: SetDefaultName :one +UPDATE authors +SET name = 'Default Name' +WHERE id = $id +RETURNING id; diff --git a/internal/endtoend/testdata/single_param_conflict/ydb/schema.sql b/internal/endtoend/testdata/single_param_conflict/ydb/schema.sql new file mode 100644 index 0000000000..e66bafd766 --- /dev/null +++ b/internal/endtoend/testdata/single_param_conflict/ydb/schema.sql @@ -0,0 +1,13 @@ +-- Example queries for sqlc +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); + +-- https://github.com/sqlc-dev/sqlc/issues/1290 +CREATE TABLE users ( + sub Uuid, + PRIMARY KEY (sub) +); diff --git a/internal/endtoend/testdata/single_param_conflict/ydb/sqlc.json b/internal/endtoend/testdata/single_param_conflict/ydb/sqlc.json new file mode 100644 index 0000000000..a539f95ae7 --- /dev/null +++ b/internal/endtoend/testdata/single_param_conflict/ydb/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/query.sql b/internal/endtoend/testdata/sqlc_arg/ydb/query.sql new file mode 100644 index 0000000000..7fb0228e4f --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/query.sql @@ -0,0 +1,6 @@ +-- name: FuncParamIdent :many +SELECT name FROM foo WHERE name = $slug; + +-- name: FuncParamString :many +SELECT name FROM foo WHERE name = $slug; + diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/db.go b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/sqlc_arg/ydb/stdlib/go/models.go b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..d870bb7cde --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Name string +} diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..cd010d1161 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/go/query.sql.go @@ -0,0 +1,64 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const funcParamIdent = `-- name: FuncParamIdent :many +SELECT name FROM foo WHERE name = $slug +` + +func (q *Queries) FuncParamIdent(ctx context.Context, slug string) ([]string, error) { + rows, err := q.db.QueryContext(ctx, funcParamIdent, slug) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + return nil, err + } + items = append(items, name) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const funcParamString = `-- name: FuncParamString :many +SELECT name FROM foo WHERE name = $slug +` + +func (q *Queries) FuncParamString(ctx context.Context, slug string) ([]string, error) { + rows, err := q.db.QueryContext(ctx, funcParamString, slug) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + return nil, err + } + items = append(items, name) + } + 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/sqlc_arg/ydb/stdlib/query.sql b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/query.sql new file mode 100644 index 0000000000..2dfaa9cd5c --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/query.sql @@ -0,0 +1,5 @@ +-- name: FuncParamIdent :many +SELECT name FROM foo WHERE name = sqlc.arg(slug); + +-- name: FuncParamString :many +SELECT name FROM foo WHERE name = sqlc.arg('slug'); diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/schema.sql b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..931b5714ff --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo ( + name Text NOT NULL, + PRIMARY KEY (name) +); diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..d8c24916cd --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..d870bb7cde --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,9 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Name string +} diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..8d138a3b5c --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,74 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const funcParamIdent = `-- name: FuncParamIdent :many +SELECT name FROM foo WHERE name = $slug +` + +func (q *Queries) FuncParamIdent(ctx context.Context, slug string, opts ...query.ExecuteOption) ([]string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$slug").Text(slug) + result, err := q.db.QueryResultSet(ctx, funcParamIdent, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var name string + if err := row.Scan(&name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, name) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const funcParamString = `-- name: FuncParamString :many +SELECT name FROM foo WHERE name = $slug +` + +func (q *Queries) FuncParamString(ctx context.Context, slug string, opts ...query.ExecuteOption) ([]string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$slug").Text(slug) + result, err := q.db.QueryResultSet(ctx, funcParamString, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var name string + if err := row.Scan(&name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, name) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..2dfaa9cd5c --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,5 @@ +-- name: FuncParamIdent :many +SELECT name FROM foo WHERE name = sqlc.arg(slug); + +-- name: FuncParamString :many +SELECT name FROM foo WHERE name = sqlc.arg('slug'); diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..931b5714ff --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,4 @@ +CREATE TABLE foo ( + name Text NOT NULL, + PRIMARY KEY (name) +); diff --git a/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..d7b476c328 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_arg/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/db.go b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/sqlc_embed/ydb/stdlib/go/models.go b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..11141dad1f --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/models.go @@ -0,0 +1,17 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Post struct { + ID int32 + UserID int32 + Likes string +} + +type User struct { + ID int32 + Name string + Age *int32 +} diff --git a/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..ea9d5854a8 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/go/query.sql.go @@ -0,0 +1,149 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const duplicate = `-- name: Duplicate :one +SELECT users.id, users.name, users.age, users.id, users.name, users.age FROM users +` + +type DuplicateRow struct { + User User + User_2 User +} + +func (q *Queries) Duplicate(ctx context.Context) (DuplicateRow, error) { + row := q.db.QueryRowContext(ctx, duplicate) + var i DuplicateRow + err := row.Scan( + &i.User.ID, + &i.User.Name, + &i.User.Age, + &i.User_2.ID, + &i.User_2.Name, + &i.User_2.Age, + ) + return i, err +} + +const join = `-- name: Join :one +SELECT users.id, users.name, users.age, posts.id, posts.user_id, posts.likes FROM posts +INNER JOIN users ON posts.user_id = users.id +` + +type JoinRow struct { + User User + Post Post +} + +func (q *Queries) Join(ctx context.Context) (JoinRow, error) { + row := q.db.QueryRowContext(ctx, join) + var i JoinRow + err := row.Scan( + &i.User.ID, + &i.User.Name, + &i.User.Age, + &i.Post.ID, + &i.Post.UserID, + &i.Post.Likes, + ) + return i, err +} + +const only = `-- name: Only :one +SELECT users.id, users.name, users.age FROM users +` + +type OnlyRow struct { + User User +} + +func (q *Queries) Only(ctx context.Context) (OnlyRow, error) { + row := q.db.QueryRowContext(ctx, only) + var i OnlyRow + err := row.Scan(&i.User.ID, &i.User.Name, &i.User.Age) + return i, err +} + +const withAlias = `-- name: WithAlias :one +SELECT u.id, u.name, u.age FROM users u +` + +type WithAliasRow struct { + User User +} + +func (q *Queries) WithAlias(ctx context.Context) (WithAliasRow, error) { + row := q.db.QueryRowContext(ctx, withAlias) + var i WithAliasRow + err := row.Scan(&i.User.ID, &i.User.Name, &i.User.Age) + return i, err +} + +const withAsterisk = `-- name: WithAsterisk :one +SELECT users.id, users.name, users.age, id, name, age FROM users +` + +type WithAsteriskRow struct { + User User + ID int32 + Name string + Age *int32 +} + +func (q *Queries) WithAsterisk(ctx context.Context) (WithAsteriskRow, error) { + row := q.db.QueryRowContext(ctx, withAsterisk) + var i WithAsteriskRow + err := row.Scan( + &i.User.ID, + &i.User.Name, + &i.User.Age, + &i.ID, + &i.Name, + &i.Age, + ) + return i, err +} + +const withSubquery = `-- name: WithSubquery :many +SELECT users.id, users.name, users.age, Count(*) AS total_count FROM users +` + +type WithSubqueryRow struct { + User User + TotalCount uint64 +} + +func (q *Queries) WithSubquery(ctx context.Context) ([]WithSubqueryRow, error) { + rows, err := q.db.QueryContext(ctx, withSubquery) + if err != nil { + return nil, err + } + defer rows.Close() + var items []WithSubqueryRow + for rows.Next() { + var i WithSubqueryRow + if err := rows.Scan( + &i.User.ID, + &i.User.Name, + &i.User.Age, + &i.TotalCount, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/sqlc_embed/ydb/stdlib/query.sql b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/query.sql new file mode 100644 index 0000000000..b93f139ab5 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/query.sql @@ -0,0 +1,18 @@ +-- name: Only :one +SELECT sqlc.embed(users) FROM users; + +-- name: WithAlias :one +SELECT sqlc.embed(u) FROM users u; + +-- name: WithSubquery :many +SELECT sqlc.embed(users), Count(*) AS total_count FROM users; + +-- name: WithAsterisk :one +SELECT sqlc.embed(users), * FROM users; + +-- name: Duplicate :one +SELECT sqlc.embed(users), sqlc.embed(users) FROM users; + +-- name: Join :one +SELECT sqlc.embed(users), sqlc.embed(posts) FROM posts +INNER JOIN users ON posts.user_id = users.id; diff --git a/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/schema.sql b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..a5b6bb73ec --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/schema.sql @@ -0,0 +1,13 @@ +CREATE TABLE users ( + id Int32 NOT NULL, + name Text NOT NULL, + age Int32, + PRIMARY KEY (id) +); + +CREATE TABLE posts ( + id Int32 NOT NULL, + user_id Int32 NOT NULL, + likes Text NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..d8c24916cd --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..11141dad1f --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,17 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Post struct { + ID int32 + UserID int32 + Likes string +} + +type User struct { + ID int32 + Name string + Age *int32 +} diff --git a/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..d313950863 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,181 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const duplicate = `-- name: Duplicate :one +SELECT users.id, users.name, users.age, users.id, users.name, users.age FROM users +` + +type DuplicateRow struct { + User User + User_2 User +} + +func (q *Queries) Duplicate(ctx context.Context, opts ...query.ExecuteOption) (DuplicateRow, error) { + row, err := q.db.QueryRow(ctx, duplicate, opts...) + var i DuplicateRow + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan( + &i.User.ID, + &i.User.Name, + &i.User.Age, + &i.User_2.ID, + &i.User_2.Name, + &i.User_2.Age, + ) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const join = `-- name: Join :one +SELECT users.id, users.name, users.age, posts.id, posts.user_id, posts.likes FROM posts +INNER JOIN users ON posts.user_id = users.id +` + +type JoinRow struct { + User User + Post Post +} + +func (q *Queries) Join(ctx context.Context, opts ...query.ExecuteOption) (JoinRow, error) { + row, err := q.db.QueryRow(ctx, join, opts...) + var i JoinRow + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan( + &i.User.ID, + &i.User.Name, + &i.User.Age, + &i.Post.ID, + &i.Post.UserID, + &i.Post.Likes, + ) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const only = `-- name: Only :one +SELECT users.id, users.name, users.age FROM users +` + +type OnlyRow struct { + User User +} + +func (q *Queries) Only(ctx context.Context, opts ...query.ExecuteOption) (OnlyRow, error) { + row, err := q.db.QueryRow(ctx, only, opts...) + var i OnlyRow + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.User.ID, &i.User.Name, &i.User.Age) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const withAlias = `-- name: WithAlias :one +SELECT u.id, u.name, u.age FROM users u +` + +type WithAliasRow struct { + User User +} + +func (q *Queries) WithAlias(ctx context.Context, opts ...query.ExecuteOption) (WithAliasRow, error) { + row, err := q.db.QueryRow(ctx, withAlias, opts...) + var i WithAliasRow + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.User.ID, &i.User.Name, &i.User.Age) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const withAsterisk = `-- name: WithAsterisk :one +SELECT users.id, users.name, users.age, id, name, age FROM users +` + +type WithAsteriskRow struct { + User User + ID int32 + Name string + Age *int32 +} + +func (q *Queries) WithAsterisk(ctx context.Context, opts ...query.ExecuteOption) (WithAsteriskRow, error) { + row, err := q.db.QueryRow(ctx, withAsterisk, opts...) + var i WithAsteriskRow + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan( + &i.User.ID, + &i.User.Name, + &i.User.Age, + &i.ID, + &i.Name, + &i.Age, + ) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const withSubquery = `-- name: WithSubquery :many +SELECT users.id, users.name, users.age, Count(*) AS total_count FROM users +` + +type WithSubqueryRow struct { + User User + TotalCount uint64 +} + +func (q *Queries) WithSubquery(ctx context.Context, opts ...query.ExecuteOption) ([]WithSubqueryRow, error) { + result, err := q.db.QueryResultSet(ctx, withSubquery, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []WithSubqueryRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i WithSubqueryRow + if err := row.Scan( + &i.User.ID, + &i.User.Name, + &i.User.Age, + &i.TotalCount, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..b93f139ab5 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,18 @@ +-- name: Only :one +SELECT sqlc.embed(users) FROM users; + +-- name: WithAlias :one +SELECT sqlc.embed(u) FROM users u; + +-- name: WithSubquery :many +SELECT sqlc.embed(users), Count(*) AS total_count FROM users; + +-- name: WithAsterisk :one +SELECT sqlc.embed(users), * FROM users; + +-- name: Duplicate :one +SELECT sqlc.embed(users), sqlc.embed(users) FROM users; + +-- name: Join :one +SELECT sqlc.embed(users), sqlc.embed(posts) FROM posts +INNER JOIN users ON posts.user_id = users.id; diff --git a/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..a5b6bb73ec --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,13 @@ +CREATE TABLE users ( + id Int32 NOT NULL, + name Text NOT NULL, + age Int32, + PRIMARY KEY (id) +); + +CREATE TABLE posts ( + id Int32 NOT NULL, + user_id Int32 NOT NULL, + likes Text NOT NULL, + PRIMARY KEY (id) +); diff --git a/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..d7b476c328 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_embed/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/db.go b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/sqlc_narg/ydb/stdlib/go/models.go b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..3267e09252 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string + MaybeBar *string +} diff --git a/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..d54a5745e7 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/go/query.sql.go @@ -0,0 +1,118 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const identOnNonNullable = `-- name: IdentOnNonNullable :many +SELECT bar FROM foo WHERE bar = $bar +` + +func (q *Queries) IdentOnNonNullable(ctx context.Context, bar *string) ([]string, error) { + rows, err := q.db.QueryContext(ctx, identOnNonNullable, bar) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var bar string + if err := rows.Scan(&bar); err != nil { + return nil, err + } + items = append(items, bar) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const identOnNullable = `-- name: IdentOnNullable :many +SELECT maybe_bar FROM foo WHERE maybe_bar = $maybe_bar +` + +func (q *Queries) IdentOnNullable(ctx context.Context, maybeBar *string) ([]*string, error) { + rows, err := q.db.QueryContext(ctx, identOnNullable, maybeBar) + if err != nil { + return nil, err + } + defer rows.Close() + var items []*string + for rows.Next() { + var maybe_bar *string + if err := rows.Scan(&maybe_bar); err != nil { + return nil, err + } + items = append(items, maybe_bar) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const stringOnNonNullable = `-- name: StringOnNonNullable :many +SELECT bar FROM foo WHERE bar = $bar +` + +func (q *Queries) StringOnNonNullable(ctx context.Context, bar *string) ([]string, error) { + rows, err := q.db.QueryContext(ctx, stringOnNonNullable, bar) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var bar string + if err := rows.Scan(&bar); err != nil { + return nil, err + } + items = append(items, bar) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const stringOnNullable = `-- name: StringOnNullable :many +SELECT maybe_bar FROM foo WHERE maybe_bar = $maybe_bar +` + +func (q *Queries) StringOnNullable(ctx context.Context, maybeBar *string) ([]*string, error) { + rows, err := q.db.QueryContext(ctx, stringOnNullable, maybeBar) + if err != nil { + return nil, err + } + defer rows.Close() + var items []*string + for rows.Next() { + var maybe_bar *string + if err := rows.Scan(&maybe_bar); err != nil { + return nil, err + } + items = append(items, maybe_bar) + } + 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/sqlc_narg/ydb/stdlib/query.sql b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/query.sql new file mode 100644 index 0000000000..103c7378b8 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/query.sql @@ -0,0 +1,11 @@ +-- name: IdentOnNonNullable :many +SELECT bar FROM foo WHERE bar = sqlc.narg(bar); + +-- name: IdentOnNullable :many +SELECT maybe_bar FROM foo WHERE maybe_bar = sqlc.narg(maybe_bar); + +-- name: StringOnNonNullable :many +SELECT bar FROM foo WHERE bar = sqlc.narg('bar'); + +-- name: StringOnNullable :many +SELECT maybe_bar FROM foo WHERE maybe_bar = sqlc.narg('maybe_bar'); diff --git a/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/schema.sql b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..03b21cefe9 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + bar Text NOT NULL, + maybe_bar Text, + PRIMARY KEY (bar) +); diff --git a/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..d8c24916cd --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..3267e09252 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Bar string + MaybeBar *string +} diff --git a/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..fa5a934c95 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,134 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const identOnNonNullable = `-- name: IdentOnNonNullable :many +SELECT bar FROM foo WHERE bar = $bar +` + +func (q *Queries) IdentOnNonNullable(ctx context.Context, bar *string, opts ...query.ExecuteOption) ([]string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$bar").BeginOptional().Text(bar).EndOptional() + result, err := q.db.QueryResultSet(ctx, identOnNonNullable, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var bar string + if err := row.Scan(&bar); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, bar) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const identOnNullable = `-- name: IdentOnNullable :many +SELECT maybe_bar FROM foo WHERE maybe_bar = $maybe_bar +` + +func (q *Queries) IdentOnNullable(ctx context.Context, maybeBar *string, opts ...query.ExecuteOption) ([]*string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$maybe_bar").BeginOptional().Text(maybeBar).EndOptional() + result, err := q.db.QueryResultSet(ctx, identOnNullable, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []*string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var maybe_bar *string + if err := row.Scan(&maybe_bar); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, maybe_bar) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const stringOnNonNullable = `-- name: StringOnNonNullable :many +SELECT bar FROM foo WHERE bar = $bar +` + +func (q *Queries) StringOnNonNullable(ctx context.Context, bar *string, opts ...query.ExecuteOption) ([]string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$bar").BeginOptional().Text(bar).EndOptional() + result, err := q.db.QueryResultSet(ctx, stringOnNonNullable, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var bar string + if err := row.Scan(&bar); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, bar) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const stringOnNullable = `-- name: StringOnNullable :many +SELECT maybe_bar FROM foo WHERE maybe_bar = $maybe_bar +` + +func (q *Queries) StringOnNullable(ctx context.Context, maybeBar *string, opts ...query.ExecuteOption) ([]*string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$maybe_bar").BeginOptional().Text(maybeBar).EndOptional() + result, err := q.db.QueryResultSet(ctx, stringOnNullable, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []*string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var maybe_bar *string + if err := row.Scan(&maybe_bar); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, maybe_bar) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..103c7378b8 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,11 @@ +-- name: IdentOnNonNullable :many +SELECT bar FROM foo WHERE bar = sqlc.narg(bar); + +-- name: IdentOnNullable :many +SELECT maybe_bar FROM foo WHERE maybe_bar = sqlc.narg(maybe_bar); + +-- name: StringOnNonNullable :many +SELECT bar FROM foo WHERE bar = sqlc.narg('bar'); + +-- name: StringOnNullable :many +SELECT maybe_bar FROM foo WHERE maybe_bar = sqlc.narg('maybe_bar'); diff --git a/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..03b21cefe9 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + bar Text NOT NULL, + maybe_bar Text, + PRIMARY KEY (bar) +); diff --git a/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..d7b476c328 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_narg/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/db.go b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/sqlc_slice/ydb/stdlib/go/models.go b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..927aa685d4 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + ID int32 + Name string + Bar *string +} diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..2e43628d8e --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/go/query.sql.go @@ -0,0 +1,177 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const funcNullable = `-- name: FuncNullable :many +SELECT bar FROM foo +WHERE id IN $favourites +` + +func (q *Queries) FuncNullable(ctx context.Context, favourites []int32) ([]*string, error) { + rows, err := q.db.QueryContext(ctx, funcNullable, favourites) + if err != nil { + return nil, err + } + defer rows.Close() + var items []*string + for rows.Next() { + var bar *string + if err := rows.Scan(&bar); err != nil { + return nil, err + } + items = append(items, bar) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const funcNullableNot = `-- name: FuncNullableNot :many +SELECT bar FROM foo +WHERE id NOT IN $favourites +` + +func (q *Queries) FuncNullableNot(ctx context.Context, favourites []int32) ([]*string, error) { + rows, err := q.db.QueryContext(ctx, funcNullableNot, favourites) + if err != nil { + return nil, err + } + defer rows.Close() + var items []*string + for rows.Next() { + var bar *string + if err := rows.Scan(&bar); err != nil { + return nil, err + } + items = append(items, bar) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const funcParamIdent = `-- name: FuncParamIdent :many +SELECT name FROM foo +WHERE name = $slug + AND id IN $favourites +` + +type FuncParamIdentParams struct { + Slug string + Favourites []int32 +} + +func (q *Queries) FuncParamIdent(ctx context.Context, arg FuncParamIdentParams) ([]string, error) { + rows, err := q.db.QueryContext(ctx, funcParamIdent, arg.Slug, arg.Favourites) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + return nil, err + } + items = append(items, name) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const funcParamSoloArg = `-- name: FuncParamSoloArg :many +SELECT name FROM foo +WHERE id IN $favourites +` + +func (q *Queries) FuncParamSoloArg(ctx context.Context, favourites []int32) ([]string, error) { + rows, err := q.db.QueryContext(ctx, funcParamSoloArg, favourites) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + return nil, err + } + items = append(items, name) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const funcParamString = `-- name: FuncParamString :many +SELECT name FROM foo +WHERE name = $slug + AND id IN $favourites +` + +type FuncParamStringParams struct { + Slug string + Favourites []int32 +} + +func (q *Queries) FuncParamString(ctx context.Context, arg FuncParamStringParams) ([]string, error) { + rows, err := q.db.QueryContext(ctx, funcParamString, arg.Slug, arg.Favourites) + if err != nil { + return nil, err + } + defer rows.Close() + var items []string + for rows.Next() { + var name string + if err := rows.Scan(&name); err != nil { + return nil, err + } + items = append(items, name) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const sliceExec = `-- name: SliceExec :exec +UPDATE foo SET name = $slug +WHERE id IN $favourites +` + +type SliceExecParams struct { + Slug string + Favourites []int32 +} + +func (q *Queries) SliceExec(ctx context.Context, arg SliceExecParams) error { + _, err := q.db.ExecContext(ctx, sliceExec, arg.Slug, arg.Favourites) + return err +} diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/query.sql b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/query.sql new file mode 100644 index 0000000000..97a200ee75 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/query.sql @@ -0,0 +1,25 @@ +/* name: FuncParamIdent :many */ +SELECT name FROM foo +WHERE name = sqlc.arg(slug) + AND id IN sqlc.slice(favourites); + +/* name: FuncParamString :many */ +SELECT name FROM foo +WHERE name = sqlc.arg('slug') + AND id IN sqlc.slice('favourites'); + +/* name: FuncParamSoloArg :many */ +SELECT name FROM foo +WHERE id IN sqlc.slice('favourites'); + +/* name: SliceExec :exec */ +UPDATE foo SET name = sqlc.arg(slug) +WHERE id IN sqlc.slice(favourites); + +/* name: FuncNullable :many */ +SELECT bar FROM foo +WHERE id IN sqlc.slice('favourites'); + +/* name: FuncNullableNot :many */ +SELECT bar FROM foo +WHERE id NOT IN sqlc.slice('favourites'); diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/schema.sql b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..bfb536f297 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (id Int32 NOT NULL, name Utf8 NOT NULL, bar Utf8, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..927aa685d4 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,11 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + ID int32 + Name string + Bar *string +} diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..9d3d8e8eb5 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,230 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const funcNullable = `-- name: FuncNullable :many +SELECT bar FROM foo +WHERE id IN $favourites +` + +func (q *Queries) FuncNullable(ctx context.Context, favourites []int32, opts ...query.ExecuteOption) ([]*string, error) { + parameters := ydb.ParamsBuilder() + var list = parameters.Param("$favourites").BeginList() + for _, param := range favourites { + list = list.Add().Int32(param) + } + parameters = list.EndList() + result, err := q.db.QueryResultSet(ctx, funcNullable, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []*string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var bar *string + if err := row.Scan(&bar); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, bar) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const funcNullableNot = `-- name: FuncNullableNot :many +SELECT bar FROM foo +WHERE id NOT IN $favourites +` + +func (q *Queries) FuncNullableNot(ctx context.Context, favourites []int32, opts ...query.ExecuteOption) ([]*string, error) { + parameters := ydb.ParamsBuilder() + var list = parameters.Param("$favourites").BeginList() + for _, param := range favourites { + list = list.Add().Int32(param) + } + parameters = list.EndList() + result, err := q.db.QueryResultSet(ctx, funcNullableNot, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []*string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var bar *string + if err := row.Scan(&bar); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, bar) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const funcParamIdent = `-- name: FuncParamIdent :many +SELECT name FROM foo +WHERE name = $slug + AND id IN $favourites +` + +type FuncParamIdentParams struct { + Slug string + Favourites []int32 +} + +func (q *Queries) FuncParamIdent(ctx context.Context, arg FuncParamIdentParams, opts ...query.ExecuteOption) ([]string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$slug").Text(arg.Slug) + var list = parameters.Param("$favourites").BeginList() + for _, param := range arg.Favourites { + list = list.Add().Int32(param) + } + parameters = list.EndList() + result, err := q.db.QueryResultSet(ctx, funcParamIdent, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var name string + if err := row.Scan(&name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, name) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const funcParamSoloArg = `-- name: FuncParamSoloArg :many +SELECT name FROM foo +WHERE id IN $favourites +` + +func (q *Queries) FuncParamSoloArg(ctx context.Context, favourites []int32, opts ...query.ExecuteOption) ([]string, error) { + parameters := ydb.ParamsBuilder() + var list = parameters.Param("$favourites").BeginList() + for _, param := range favourites { + list = list.Add().Int32(param) + } + parameters = list.EndList() + result, err := q.db.QueryResultSet(ctx, funcParamSoloArg, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var name string + if err := row.Scan(&name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, name) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const funcParamString = `-- name: FuncParamString :many +SELECT name FROM foo +WHERE name = $slug + AND id IN $favourites +` + +type FuncParamStringParams struct { + Slug string + Favourites []int32 +} + +func (q *Queries) FuncParamString(ctx context.Context, arg FuncParamStringParams, opts ...query.ExecuteOption) ([]string, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$slug").Text(arg.Slug) + var list = parameters.Param("$favourites").BeginList() + for _, param := range arg.Favourites { + list = list.Add().Int32(param) + } + parameters = list.EndList() + result, err := q.db.QueryResultSet(ctx, funcParamString, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []string + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var name string + if err := row.Scan(&name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, name) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const sliceExec = `-- name: SliceExec :exec +UPDATE foo SET name = $slug +WHERE id IN $favourites +` + +type SliceExecParams struct { + Slug string + Favourites []int32 +} + +func (q *Queries) SliceExec(ctx context.Context, arg SliceExecParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$slug").Text(arg.Slug) + var list = parameters.Param("$favourites").BeginList() + for _, param := range arg.Favourites { + list = list.Add().Int32(param) + } + parameters = list.EndList() + err := q.db.Exec(ctx, sliceExec, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..97a200ee75 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,25 @@ +/* name: FuncParamIdent :many */ +SELECT name FROM foo +WHERE name = sqlc.arg(slug) + AND id IN sqlc.slice(favourites); + +/* name: FuncParamString :many */ +SELECT name FROM foo +WHERE name = sqlc.arg('slug') + AND id IN sqlc.slice('favourites'); + +/* name: FuncParamSoloArg :many */ +SELECT name FROM foo +WHERE id IN sqlc.slice('favourites'); + +/* name: SliceExec :exec */ +UPDATE foo SET name = sqlc.arg(slug) +WHERE id IN sqlc.slice(favourites); + +/* name: FuncNullable :many */ +SELECT bar FROM foo +WHERE id IN sqlc.slice('favourites'); + +/* name: FuncNullableNot :many */ +SELECT bar FROM foo +WHERE id NOT IN sqlc.slice('favourites'); diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..bfb536f297 --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1 @@ +CREATE TABLE foo (id Int32 NOT NULL, name Utf8 NOT NULL, bar Utf8, PRIMARY KEY (id)); diff --git a/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/sqlc_slice/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/star_expansion/ydb/stdlib/go/db.go b/internal/endtoend/testdata/star_expansion/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/star_expansion/ydb/stdlib/go/models.go b/internal/endtoend/testdata/star_expansion/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..5eebad25b8 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string + B string +} diff --git a/internal/endtoend/testdata/star_expansion/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/star_expansion/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..bab6a8c623 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/stdlib/go/query.sql.go @@ -0,0 +1,80 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const starExpansion = `-- name: StarExpansion :many +SELECT a, b, a, b, foo.a, foo.b FROM foo +` + +type StarExpansionRow struct { + A string + B string + A_2 string + B_2 string + A_3 string + B_3 string +} + +func (q *Queries) StarExpansion(ctx context.Context) ([]StarExpansionRow, error) { + rows, err := q.db.QueryContext(ctx, starExpansion) + if err != nil { + return nil, err + } + defer rows.Close() + var items []StarExpansionRow + for rows.Next() { + var i StarExpansionRow + if err := rows.Scan( + &i.A, + &i.B, + &i.A_2, + &i.B_2, + &i.A_3, + &i.B_3, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const starQuotedExpansion = `-- name: StarQuotedExpansion :many +SELECT t.a, t.b FROM foo t +` + +func (q *Queries) StarQuotedExpansion(ctx context.Context) ([]Foo, error) { + rows, err := q.db.QueryContext(ctx, starQuotedExpansion) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Foo + for rows.Next() { + var i Foo + if err := rows.Scan(&i.A, &i.B); err != nil { + return nil, err + } + items = append(items, i) + } + 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/star_expansion/ydb/stdlib/query.sql b/internal/endtoend/testdata/star_expansion/ydb/stdlib/query.sql new file mode 100644 index 0000000000..070b7830cd --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/stdlib/query.sql @@ -0,0 +1,5 @@ +-- name: StarExpansion :many +SELECT *, *, foo.* FROM foo; + +-- name: StarQuotedExpansion :many +SELECT t.* FROM foo t; diff --git a/internal/endtoend/testdata/star_expansion/ydb/stdlib/schema.sql b/internal/endtoend/testdata/star_expansion/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..c197ae9eb3 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/stdlib/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + a Text, + b Text, + PRIMARY KEY (a, b) +); diff --git a/internal/endtoend/testdata/star_expansion/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/star_expansion/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..d8c24916cd --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..5eebad25b8 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A string + B string +} diff --git a/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..fde739eae0 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,81 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const starExpansion = `-- name: StarExpansion :many +SELECT a, b, a, b, foo.a, foo.b FROM foo +` + +type StarExpansionRow struct { + A string + B string + A_2 string + B_2 string + A_3 string + B_3 string +} + +func (q *Queries) StarExpansion(ctx context.Context, opts ...query.ExecuteOption) ([]StarExpansionRow, error) { + result, err := q.db.QueryResultSet(ctx, starExpansion, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []StarExpansionRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i StarExpansionRow + if err := row.Scan( + &i.A, + &i.B, + &i.A_2, + &i.B_2, + &i.A_3, + &i.B_3, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const starQuotedExpansion = `-- name: StarQuotedExpansion :many +SELECT t.a, t.b FROM foo t +` + +func (q *Queries) StarQuotedExpansion(ctx context.Context, opts ...query.ExecuteOption) ([]Foo, error) { + result, err := q.db.QueryResultSet(ctx, starQuotedExpansion, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Foo + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Foo + if err := row.Scan(&i.A, &i.B); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..070b7830cd --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,5 @@ +-- name: StarExpansion :many +SELECT *, *, foo.* FROM foo; + +-- name: StarQuotedExpansion :many +SELECT t.* FROM foo t; diff --git a/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..c197ae9eb3 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + a Text, + b Text, + PRIMARY KEY (a, b) +); diff --git a/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..d7b476c328 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/db.go b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/star_expansion_join/ydb/stdlib/go/models.go b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..b0a2b24f86 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + C string + D string +} + +type Foo struct { + A string + B string +} diff --git a/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..5262133f91 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/go/query.sql.go @@ -0,0 +1,49 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const starExpansionJoin = `-- name: StarExpansionJoin :many +SELECT a, b, c, d FROM foo, bar +` + +type StarExpansionJoinRow struct { + A string + B string + C string + D string +} + +func (q *Queries) StarExpansionJoin(ctx context.Context) ([]StarExpansionJoinRow, error) { + rows, err := q.db.QueryContext(ctx, starExpansionJoin) + if err != nil { + return nil, err + } + defer rows.Close() + var items []StarExpansionJoinRow + for rows.Next() { + var i StarExpansionJoinRow + if err := rows.Scan( + &i.A, + &i.B, + &i.C, + &i.D, + ); err != nil { + return nil, err + } + items = append(items, i) + } + 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/star_expansion_join/ydb/stdlib/query.sql b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/query.sql new file mode 100644 index 0000000000..c9fd836c46 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/query.sql @@ -0,0 +1,3 @@ +-- name: StarExpansionJoin :many +SELECT * FROM foo, bar; + diff --git a/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/schema.sql b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..9291752901 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/schema.sql @@ -0,0 +1,12 @@ +CREATE TABLE foo ( + a Text, + b Text, + PRIMARY KEY (a, b) +); + +CREATE TABLE bar ( + c Text, + d Text, + PRIMARY KEY (c, d) +); + diff --git a/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..b2b893aad1 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/stdlib/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..b0a2b24f86 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Bar struct { + C string + D string +} + +type Foo struct { + A string + B string +} diff --git a/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..7f6ffb02a7 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,51 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const starExpansionJoin = `-- name: StarExpansionJoin :many +SELECT a, b, c, d FROM foo, bar +` + +type StarExpansionJoinRow struct { + A string + B string + C string + D string +} + +func (q *Queries) StarExpansionJoin(ctx context.Context, opts ...query.ExecuteOption) ([]StarExpansionJoinRow, error) { + result, err := q.db.QueryResultSet(ctx, starExpansionJoin, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []StarExpansionJoinRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i StarExpansionJoinRow + if err := row.Scan( + &i.A, + &i.B, + &i.C, + &i.D, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..c9fd836c46 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,3 @@ +-- name: StarExpansionJoin :many +SELECT * FROM foo, bar; + diff --git a/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..9291752901 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,12 @@ +CREATE TABLE foo ( + a Text, + b Text, + PRIMARY KEY (a, b) +); + +CREATE TABLE bar ( + c Text, + d Text, + PRIMARY KEY (c, d) +); + diff --git a/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..799d3a9e06 --- /dev/null +++ b/internal/endtoend/testdata/star_expansion_join/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/db.go b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/subquery_calculated_column/ydb/stdlib/go/models.go b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..d6eb5ef403 --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A int32 + B int32 +} diff --git a/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..769c49f53c --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/go/query.sql.go @@ -0,0 +1,37 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const subqueryCalcColumn = `-- name: SubqueryCalcColumn :many +SELECT sum FROM (SELECT a + b AS sum FROM foo) AS f +` + +func (q *Queries) SubqueryCalcColumn(ctx context.Context) ([]int32, error) { + rows, err := q.db.QueryContext(ctx, subqueryCalcColumn) + if err != nil { + return nil, err + } + defer rows.Close() + var items []int32 + for rows.Next() { + var sum int32 + if err := rows.Scan(&sum); err != nil { + return nil, err + } + items = append(items, sum) + } + 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/subquery_calculated_column/ydb/stdlib/query.sql b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/query.sql new file mode 100644 index 0000000000..b0f85df783 --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/query.sql @@ -0,0 +1,3 @@ +-- name: SubqueryCalcColumn :many +SELECT sum FROM (SELECT a + b AS sum FROM foo) AS f; + diff --git a/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/schema.sql b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..68003be1e8 --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE foo ( + a Int32, + b Int32, + PRIMARY KEY (a, b) +); + diff --git a/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..b2b893aad1 --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/stdlib/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..d6eb5ef403 --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + A int32 + B int32 +} diff --git a/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..11d5080765 --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,39 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const subqueryCalcColumn = `-- name: SubqueryCalcColumn :many +SELECT sum FROM (SELECT a + b AS sum FROM foo) AS f +` + +func (q *Queries) SubqueryCalcColumn(ctx context.Context, opts ...query.ExecuteOption) ([]int32, error) { + result, err := q.db.QueryResultSet(ctx, subqueryCalcColumn, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []int32 + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var sum int32 + if err := row.Scan(&sum); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, sum) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..b0f85df783 --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,3 @@ +-- name: SubqueryCalcColumn :many +SELECT sum FROM (SELECT a + b AS sum FROM foo) AS f; + diff --git a/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..68003be1e8 --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE foo ( + a Int32, + b Int32, + PRIMARY KEY (a, b) +); + diff --git a/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..799d3a9e06 --- /dev/null +++ b/internal/endtoend/testdata/subquery_calculated_column/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/types_uuid/ydb/stdlib/go/db.go b/internal/endtoend/testdata/types_uuid/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/types_uuid/ydb/stdlib/go/models.go b/internal/endtoend/testdata/types_uuid/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..2afd2c4308 --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/stdlib/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "github.com/google/uuid" +) + +type Foo struct { + Description *string + Bar *uuid.UUID + Baz uuid.UUID +} diff --git a/internal/endtoend/testdata/types_uuid/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/types_uuid/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..6d5d6630f1 --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/stdlib/go/query.sql.go @@ -0,0 +1,50 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/google/uuid" +) + +const find = `-- name: Find :one +SELECT bar FROM foo WHERE baz = $baz +` + +func (q *Queries) Find(ctx context.Context, baz uuid.UUID) (*uuid.UUID, error) { + row := q.db.QueryRowContext(ctx, find, baz) + var bar *uuid.UUID + err := row.Scan(&bar) + return bar, err +} + +const list = `-- name: List :many +SELECT description, bar, baz FROM foo +` + +func (q *Queries) List(ctx context.Context) ([]Foo, error) { + rows, err := q.db.QueryContext(ctx, list) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Foo + for rows.Next() { + var i Foo + if err := rows.Scan(&i.Description, &i.Bar, &i.Baz); err != nil { + return nil, err + } + items = append(items, i) + } + 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/types_uuid/ydb/stdlib/query.sql b/internal/endtoend/testdata/types_uuid/ydb/stdlib/query.sql new file mode 100644 index 0000000000..7c8226661d --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/stdlib/query.sql @@ -0,0 +1,6 @@ +-- name: List :many +SELECT * FROM foo; + +-- name: Find :one +SELECT bar FROM foo WHERE baz = $baz; + diff --git a/internal/endtoend/testdata/types_uuid/ydb/stdlib/schema.sql b/internal/endtoend/testdata/types_uuid/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..7a887c1ca1 --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/stdlib/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE foo ( + description Text, + bar Uuid, + baz Uuid NOT NULL, + PRIMARY KEY (baz) +); + diff --git a/internal/endtoend/testdata/types_uuid/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/types_uuid/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..b2b893aad1 --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/stdlib/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..2afd2c4308 --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,15 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "github.com/google/uuid" +) + +type Foo struct { + Description *string + Bar *uuid.UUID + Baz uuid.UUID +} diff --git a/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..4173783643 --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,62 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/google/uuid" + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const find = `-- name: Find :one +SELECT bar FROM foo WHERE baz = $baz +` + +func (q *Queries) Find(ctx context.Context, baz uuid.UUID, opts ...query.ExecuteOption) (*uuid.UUID, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$baz").Uuid(baz) + row, err := q.db.QueryRow(ctx, find, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var bar *uuid.UUID + if err != nil { + return bar, xerrors.WithStackTrace(err) + } + err = row.Scan(&bar) + if err != nil { + return bar, xerrors.WithStackTrace(err) + } + return bar, nil +} + +const list = `-- name: List :many +SELECT description, bar, baz FROM foo +` + +func (q *Queries) List(ctx context.Context, opts ...query.ExecuteOption) ([]Foo, error) { + result, err := q.db.QueryResultSet(ctx, list, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Foo + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Foo + if err := row.Scan(&i.Description, &i.Bar, &i.Baz); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..7c8226661d --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,6 @@ +-- name: List :many +SELECT * FROM foo; + +-- name: Find :one +SELECT bar FROM foo WHERE baz = $baz; + diff --git a/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..7a887c1ca1 --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE foo ( + description Text, + bar Uuid, + baz Uuid NOT NULL, + PRIMARY KEY (baz) +); + diff --git a/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..799d3a9e06 --- /dev/null +++ b/internal/endtoend/testdata/types_uuid/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/update_set/ydb/stdlib/go/db.go b/internal/endtoend/testdata/update_set/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/update_set/ydb/stdlib/go/models.go b/internal/endtoend/testdata/update_set/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..ee2c5c5577 --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Name string + Slug string +} diff --git a/internal/endtoend/testdata/update_set/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/update_set/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..1bcae2f893 --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/stdlib/go/query.sql.go @@ -0,0 +1,24 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const updateSet = `-- name: UpdateSet :exec +UPDATE foo SET name = $name WHERE slug = $slug +` + +type UpdateSetParams struct { + Name string + Slug string +} + +func (q *Queries) UpdateSet(ctx context.Context, arg UpdateSetParams) error { + _, err := q.db.ExecContext(ctx, updateSet, arg.Name, arg.Slug) + return err +} diff --git a/internal/endtoend/testdata/update_set/ydb/stdlib/query.sql b/internal/endtoend/testdata/update_set/ydb/stdlib/query.sql new file mode 100644 index 0000000000..c5180f3e7b --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/stdlib/query.sql @@ -0,0 +1,2 @@ +-- name: UpdateSet :exec +UPDATE foo SET name = $name WHERE slug = $slug; diff --git a/internal/endtoend/testdata/update_set/ydb/stdlib/schema.sql b/internal/endtoend/testdata/update_set/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..70ea3dc428 --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/stdlib/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + name Utf8 NOT NULL, + slug Utf8 NOT NULL, + PRIMARY KEY (slug) +); diff --git a/internal/endtoend/testdata/update_set/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/update_set/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..257bc9d140 --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/stdlib/sqlc.json @@ -0,0 +1,12 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..ee2c5c5577 --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Name string + Slug string +} diff --git a/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..70f64e83b9 --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,36 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const updateSet = `-- name: UpdateSet :exec +UPDATE foo SET name = $name WHERE slug = $slug +` + +type UpdateSetParams struct { + Name string + Slug string +} + +func (q *Queries) UpdateSet(ctx context.Context, arg UpdateSetParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").Text(arg.Name) + parameters = parameters.Param("$slug").Text(arg.Slug) + err := q.db.Exec(ctx, updateSet, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..c5180f3e7b --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,2 @@ +-- name: UpdateSet :exec +UPDATE foo SET name = $name WHERE slug = $slug; diff --git a/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..70ea3dc428 --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE foo ( + name Utf8 NOT NULL, + slug Utf8 NOT NULL, + PRIMARY KEY (slug) +); diff --git a/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..f87545f35c --- /dev/null +++ b/internal/endtoend/testdata/update_set/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/db.go b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/update_set_multiple/ydb/stdlib/go/models.go b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..ee2c5c5577 --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Name string + Slug string +} diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..09d2aecd57 --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/go/query.sql.go @@ -0,0 +1,24 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const updateSetMultiple = `-- name: UpdateSetMultiple :exec +UPDATE foo SET name = $name, slug = $slug +` + +type UpdateSetMultipleParams struct { + Name string + Slug string +} + +func (q *Queries) UpdateSetMultiple(ctx context.Context, arg UpdateSetMultipleParams) error { + _, err := q.db.ExecContext(ctx, updateSetMultiple, arg.Name, arg.Slug) + return err +} diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/query.sql b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/query.sql new file mode 100644 index 0000000000..d478e98345 --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/query.sql @@ -0,0 +1,3 @@ +-- name: UpdateSetMultiple :exec +UPDATE foo SET name = $name, slug = $slug; + diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/schema.sql b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..ae52c193a5 --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE foo ( + name Text NOT NULL, + slug Text NOT NULL, + PRIMARY KEY (name, slug) +); + diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..b2b893aad1 --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/stdlib/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..ee2c5c5577 --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,10 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Foo struct { + Name string + Slug string +} diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..fc5baf4b7f --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,36 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const updateSetMultiple = `-- name: UpdateSetMultiple :exec +UPDATE foo SET name = $name, slug = $slug +` + +type UpdateSetMultipleParams struct { + Name string + Slug string +} + +func (q *Queries) UpdateSetMultiple(ctx context.Context, arg UpdateSetMultipleParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").Text(arg.Name) + parameters = parameters.Param("$slug").Text(arg.Slug) + err := q.db.Exec(ctx, updateSetMultiple, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..d478e98345 --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,3 @@ +-- name: UpdateSetMultiple :exec +UPDATE foo SET name = $name, slug = $slug; + diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..ae52c193a5 --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE foo ( + name Text NOT NULL, + slug Text NOT NULL, + PRIMARY KEY (name, slug) +); + diff --git a/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..799d3a9e06 --- /dev/null +++ b/internal/endtoend/testdata/update_set_multiple/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/upsert/ydb/go/db.go b/internal/endtoend/testdata/upsert/ydb/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/upsert/ydb/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/upsert/ydb/go/models.go b/internal/endtoend/testdata/upsert/ydb/go/models.go new file mode 100644 index 0000000000..e272cd58c6 --- /dev/null +++ b/internal/endtoend/testdata/upsert/ydb/go/models.go @@ -0,0 +1,14 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +type Location struct { + ID int32 + Name string + Address string + ZipCode int32 + Latitude float64 + Longitude float64 +} diff --git a/internal/endtoend/testdata/upsert/ydb/go/query.sql.go b/internal/endtoend/testdata/upsert/ydb/go/query.sql.go new file mode 100644 index 0000000000..dde037594f --- /dev/null +++ b/internal/endtoend/testdata/upsert/ydb/go/query.sql.go @@ -0,0 +1,52 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const upsertLocation = `-- name: UpsertLocation :exec +UPSERT INTO locations ( + id, + name, + address, + zip_code, + latitude, + longitude +) +VALUES ($id, $name, $address, $zip_code, $latitude, $longitude) +` + +type UpsertLocationParams struct { + ID int32 + Name string + Address string + ZipCode int32 + Latitude float64 + Longitude float64 +} + +func (q *Queries) UpsertLocation(ctx context.Context, arg UpsertLocationParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int32(arg.ID) + parameters = parameters.Param("$name").Text(arg.Name) + parameters = parameters.Param("$address").Text(arg.Address) + parameters = parameters.Param("$zip_code").Int32(arg.ZipCode) + parameters = parameters.Param("$latitude").Double(arg.Latitude) + parameters = parameters.Param("$longitude").Double(arg.Longitude) + err := q.db.Exec(ctx, upsertLocation, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/internal/endtoend/testdata/upsert/ydb/query.sql b/internal/endtoend/testdata/upsert/ydb/query.sql new file mode 100644 index 0000000000..2811eb05e1 --- /dev/null +++ b/internal/endtoend/testdata/upsert/ydb/query.sql @@ -0,0 +1,13 @@ +-- name: UpsertLocation :exec +UPSERT INTO locations ( + id, + name, + address, + zip_code, + latitude, + longitude +) +VALUES ($id, $name, $address, $zip_code, $latitude, $longitude); + + + diff --git a/internal/endtoend/testdata/upsert/ydb/schema.sql b/internal/endtoend/testdata/upsert/ydb/schema.sql new file mode 100644 index 0000000000..7e5774df83 --- /dev/null +++ b/internal/endtoend/testdata/upsert/ydb/schema.sql @@ -0,0 +1,14 @@ +-- https://github.com/sqlc-dev/sqlc/issues/1728 + +CREATE TABLE locations ( + id Serial, + name Text NOT NULL, + address Text NOT NULL, + zip_code Int32 NOT NULL, + latitude Double NOT NULL, + longitude Double NOT NULL, + PRIMARY KEY (id) +); + + + diff --git a/internal/endtoend/testdata/upsert/ydb/sqlc.json b/internal/endtoend/testdata/upsert/ydb/sqlc.json new file mode 100644 index 0000000000..a210888689 --- /dev/null +++ b/internal/endtoend/testdata/upsert/ydb/sqlc.json @@ -0,0 +1,16 @@ +{ + "version": "1", + "packages": [ + { + "path": "go", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + + + diff --git a/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/db.go b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/db.go new file mode 100644 index 0000000000..3b320aa168 --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +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/valid_group_by_reference/ydb/stdlib/go/models.go b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/models.go new file mode 100644 index 0000000000..6f29248f82 --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/models.go @@ -0,0 +1,35 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "time" +) + +type Author struct { + ID int64 + Name string + Bio *string +} + +type WeatherMetric struct { + Time time.Time + TimezoneShift *int32 + CityName string + TempC *float64 + FeelsLikeC *float64 + TempMinC *float64 + TempMaxC *float64 + PressureHpa *float64 + HumidityPercent *float64 + WindSpeedMs *float64 + WindDeg *int32 + Rain1hMm *float64 + Rain3hMm *float64 + Snow1hMm *float64 + Snow3hMm *float64 + CloudsPercent *int32 + WeatherTypeID *int32 +} diff --git a/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/query.sql.go b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/query.sql.go new file mode 100644 index 0000000000..6d0bbc69d6 --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/go/query.sql.go @@ -0,0 +1,103 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" +) + +const listAuthors = `-- name: ListAuthors :many +SELECT id, name AS name, bio +FROM authors +` + +func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthors) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listAuthorsIdenticalAlias = `-- name: ListAuthorsIdenticalAlias :many +SELECT id, name AS name, bio +FROM authors +` + +func (q *Queries) ListAuthorsIdenticalAlias(ctx context.Context) ([]Author, error) { + rows, err := q.db.QueryContext(ctx, listAuthorsIdenticalAlias) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Author + for rows.Next() { + var i Author + if err := rows.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listMetrics = `-- name: ListMetrics :many +SELECT DateTime::Format("%Y-%m-%d")(time) AS bucket, city_name, Avg(temp_c) +FROM weather_metrics +WHERE time > DateTime::MakeTimestamp(DateTime::Now()) - Interval("P6M") +GROUP BY bucket, city_name +ORDER BY bucket DESC +` + +type ListMetricsRow struct { + Bucket []byte + CityName string + Avg interface{} +} + +func (q *Queries) ListMetrics(ctx context.Context) ([]ListMetricsRow, error) { + rows, err := q.db.QueryContext(ctx, listMetrics) + if err != nil { + return nil, err + } + defer rows.Close() + var items []ListMetricsRow + for rows.Next() { + var i ListMetricsRow + if err := rows.Scan(&i.Bucket, &i.CityName, &i.Avg); err != nil { + return nil, err + } + items = append(items, i) + } + 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/valid_group_by_reference/ydb/stdlib/query.sql b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/query.sql new file mode 100644 index 0000000000..13b1943886 --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/query.sql @@ -0,0 +1,15 @@ +-- name: ListAuthors :many +SELECT id, name AS name, bio +FROM authors; + +-- name: ListAuthorsIdenticalAlias :many +SELECT id, name AS name, bio +FROM authors; + +-- name: ListMetrics :many +SELECT DateTime::Format("%Y-%m-%d")(time) AS bucket, city_name, Avg(temp_c) +FROM weather_metrics +WHERE time > DateTime::MakeTimestamp(DateTime::Now()) - Interval("P6M") +GROUP BY bucket, city_name +ORDER BY bucket DESC; + diff --git a/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/schema.sql b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/schema.sql new file mode 100644 index 0000000000..a1ec1a0101 --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/schema.sql @@ -0,0 +1,28 @@ +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); + +CREATE TABLE weather_metrics ( + time Timestamp NOT NULL, + timezone_shift Int32, + city_name Text, + temp_c Double, + feels_like_c Double, + temp_min_c Double, + temp_max_c Double, + pressure_hpa Double, + humidity_percent Double, + wind_speed_ms Double, + wind_deg Int32, + rain_1h_mm Double, + rain_3h_mm Double, + snow_1h_mm Double, + snow_3h_mm Double, + clouds_percent Int32, + weather_type_id Int32, + PRIMARY KEY (time, city_name) +); + diff --git a/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/sqlc.json b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/sqlc.json new file mode 100644 index 0000000000..b2b893aad1 --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/stdlib/sqlc.json @@ -0,0 +1,13 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/db.go b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/db.go new file mode 100644 index 0000000000..68d478eceb --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/models.go b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/models.go new file mode 100644 index 0000000000..6f29248f82 --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/models.go @@ -0,0 +1,35 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package querytest + +import ( + "time" +) + +type Author struct { + ID int64 + Name string + Bio *string +} + +type WeatherMetric struct { + Time time.Time + TimezoneShift *int32 + CityName string + TempC *float64 + FeelsLikeC *float64 + TempMinC *float64 + TempMaxC *float64 + PressureHpa *float64 + HumidityPercent *float64 + WindSpeedMs *float64 + WindDeg *int32 + Rain1hMm *float64 + Rain3hMm *float64 + Snow1hMm *float64 + Snow3hMm *float64 + CloudsPercent *int32 + WeatherTypeID *int32 +} diff --git a/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/query.sql.go b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/query.sql.go new file mode 100644 index 0000000000..0082d0de6a --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/go/query.sql.go @@ -0,0 +1,103 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package querytest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const listAuthors = `-- name: ListAuthors :many +SELECT id, name AS name, bio +FROM authors +` + +func (q *Queries) ListAuthors(ctx context.Context, opts ...query.ExecuteOption) ([]Author, error) { + result, err := q.db.QueryResultSet(ctx, listAuthors, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Author + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Author + if err := row.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const listAuthorsIdenticalAlias = `-- name: ListAuthorsIdenticalAlias :many +SELECT id, name AS name, bio +FROM authors +` + +func (q *Queries) ListAuthorsIdenticalAlias(ctx context.Context, opts ...query.ExecuteOption) ([]Author, error) { + result, err := q.db.QueryResultSet(ctx, listAuthorsIdenticalAlias, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Author + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Author + if err := row.Scan(&i.ID, &i.Name, &i.Bio); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const listMetrics = `-- name: ListMetrics :many +SELECT DateTime::Format("%Y-%m-%d")(time) AS bucket, city_name, Avg(temp_c) +FROM weather_metrics +WHERE time > DateTime::MakeTimestamp(DateTime::Now()) - Interval("P6M") +GROUP BY bucket, city_name +ORDER BY bucket DESC +` + +type ListMetricsRow struct { + Bucket []byte + CityName string + Avg interface{} +} + +func (q *Queries) ListMetrics(ctx context.Context, opts ...query.ExecuteOption) ([]ListMetricsRow, error) { + result, err := q.db.QueryResultSet(ctx, listMetrics, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []ListMetricsRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i ListMetricsRow + if err := row.Scan(&i.Bucket, &i.CityName, &i.Avg); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/query.sql b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/query.sql new file mode 100644 index 0000000000..13b1943886 --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/query.sql @@ -0,0 +1,15 @@ +-- name: ListAuthors :many +SELECT id, name AS name, bio +FROM authors; + +-- name: ListAuthorsIdenticalAlias :many +SELECT id, name AS name, bio +FROM authors; + +-- name: ListMetrics :many +SELECT DateTime::Format("%Y-%m-%d")(time) AS bucket, city_name, Avg(temp_c) +FROM weather_metrics +WHERE time > DateTime::MakeTimestamp(DateTime::Now()) - Interval("P6M") +GROUP BY bucket, city_name +ORDER BY bucket DESC; + diff --git a/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/schema.sql b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/schema.sql new file mode 100644 index 0000000000..a1ec1a0101 --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/schema.sql @@ -0,0 +1,28 @@ +CREATE TABLE authors ( + id BigSerial, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); + +CREATE TABLE weather_metrics ( + time Timestamp NOT NULL, + timezone_shift Int32, + city_name Text, + temp_c Double, + feels_like_c Double, + temp_min_c Double, + temp_max_c Double, + pressure_hpa Double, + humidity_percent Double, + wind_speed_ms Double, + wind_deg Int32, + rain_1h_mm Double, + rain_3h_mm Double, + snow_1h_mm Double, + snow_3h_mm Double, + clouds_percent Int32, + weather_type_id Int32, + PRIMARY KEY (time, city_name) +); + diff --git a/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/sqlc.json b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/sqlc.json new file mode 100644 index 0000000000..799d3a9e06 --- /dev/null +++ b/internal/endtoend/testdata/valid_group_by_reference/ydb/ydb-go-sdk/sqlc.json @@ -0,0 +1,14 @@ +{ + "version": "1", + "packages": [ + { + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "path": "go", + "name": "querytest", + "schema": "schema.sql", + "queries": "query.sql" + } + ] +} + diff --git a/internal/engine/ydb/catalog_tests/create_table_test.go b/internal/engine/ydb/catalog_tests/create_table_test.go index 7761118927..ec22ced8fe 100644 --- a/internal/engine/ydb/catalog_tests/create_table_test.go +++ b/internal/engine/ydb/catalog_tests/create_table_test.go @@ -106,13 +106,7 @@ func TestCreateTable(t *testing.T) { { Name: "amount", Type: ast.TypeName{ - Name: "decimal", - Names: &ast.List{ - Items: []ast.Node{ - &ast.Integer{Ival: 22}, - &ast.Integer{Ival: 9}, - }, - }, + Name: "Decimal(22,9)", }, }, { diff --git a/internal/engine/ydb/catalog_tests/delete_test.go b/internal/engine/ydb/catalog_tests/delete_test.go index 1885deb9ce..5a1d37c0fc 100644 --- a/internal/engine/ydb/catalog_tests/delete_test.go +++ b/internal/engine/ydb/catalog_tests/delete_test.go @@ -22,7 +22,7 @@ func TestDelete(t *testing.T) { Stmt: &ast.DeleteStmt{ Relations: &ast.List{ Items: []ast.Node{ - &ast.RangeVar{Relname: strPtr("users")}, + &ast.RangeVar{Relname: strPtr("users"), Inh: true}, }, }, WhereClause: &ast.A_Expr{ @@ -47,7 +47,7 @@ func TestDelete(t *testing.T) { }, }, Batch: false, - OnCols: nil, + OnCols: &ast.List{Items: []ast.Node{}}, OnSelectStmt: nil, }, }, @@ -60,7 +60,7 @@ func TestDelete(t *testing.T) { Stmt: &ast.DeleteStmt{ Relations: &ast.List{ Items: []ast.Node{ - &ast.RangeVar{Relname: strPtr("users")}, + &ast.RangeVar{Relname: strPtr("users"), Inh: true}, }, }, WhereClause: &ast.A_Expr{ @@ -83,7 +83,7 @@ func TestDelete(t *testing.T) { }, }, Batch: true, - OnCols: nil, + OnCols: &ast.List{Items: []ast.Node{}}, OnSelectStmt: nil, }, }, @@ -94,7 +94,7 @@ func TestDelete(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.DeleteStmt{ - Relations: &ast.List{Items: []ast.Node{&ast.RangeVar{Relname: strPtr("users")}}}, + Relations: &ast.List{Items: []ast.Node{&ast.RangeVar{Relname: strPtr("users"), Inh: true}}}, OnCols: &ast.List{ Items: []ast.Node{ &ast.ResTarget{Name: strPtr("id")}, @@ -143,7 +143,7 @@ func TestDelete(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.DeleteStmt{ - Relations: &ast.List{Items: []ast.Node{&ast.RangeVar{Relname: strPtr("users")}}}, + Relations: &ast.List{Items: []ast.Node{&ast.RangeVar{Relname: strPtr("users"), Inh: true}}}, OnCols: &ast.List{ Items: []ast.Node{ &ast.ResTarget{Name: strPtr("id")}, diff --git a/internal/engine/ydb/catalog_tests/insert_test.go b/internal/engine/ydb/catalog_tests/insert_test.go index c60d0920da..d990576cdc 100644 --- a/internal/engine/ydb/catalog_tests/insert_test.go +++ b/internal/engine/ydb/catalog_tests/insert_test.go @@ -20,7 +20,7 @@ func TestInsert(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.InsertStmt{ - Relation: &ast.RangeVar{Relname: strPtr("users")}, + Relation: &ast.RangeVar{Relname: strPtr("users"), Inh: true}, Cols: &ast.List{ Items: []ast.Node{ &ast.ResTarget{Name: strPtr("id")}, @@ -39,11 +39,11 @@ func TestInsert(t *testing.T) { }, }, }, - TargetList: &ast.List{}, - FromClause: &ast.List{}, - GroupClause: &ast.List{}, - WindowClause: &ast.List{}, - SortClause: &ast.List{}, + TargetList: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + SortClause: &ast.List{}, LockingClause: &ast.List{}, }, OnConflictClause: &ast.OnConflictClause{}, @@ -66,7 +66,7 @@ func TestInsert(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.InsertStmt{ - Relation: &ast.RangeVar{Relname: strPtr("users")}, + Relation: &ast.RangeVar{Relname: strPtr("users"), Inh: true}, Cols: &ast.List{ Items: []ast.Node{ &ast.ResTarget{Name: strPtr("id")}, @@ -83,11 +83,11 @@ func TestInsert(t *testing.T) { }, }, }, - TargetList: &ast.List{}, - FromClause: &ast.List{}, - GroupClause: &ast.List{}, - WindowClause: &ast.List{}, - SortClause: &ast.List{}, + TargetList: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + SortClause: &ast.List{}, LockingClause: &ast.List{}, }, OnConflictClause: &ast.OnConflictClause{ @@ -114,17 +114,17 @@ func TestInsert(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.InsertStmt{ - Relation: &ast.RangeVar{Relname: strPtr("users")}, - Cols: &ast.List{Items: []ast.Node{&ast.ResTarget{Name: strPtr("id")}}}, + Relation: &ast.RangeVar{Relname: strPtr("users"), Inh: true}, + Cols: &ast.List{Items: []ast.Node{&ast.ResTarget{Name: strPtr("id")}}}, SelectStmt: &ast.SelectStmt{ DistinctClause: &ast.List{}, - ValuesLists: &ast.List{Items: []ast.Node{&ast.List{Items: []ast.Node{&ast.A_Const{Val: &ast.Integer{Ival: 4}}}}}}, - TargetList: &ast.List{}, - FromClause: &ast.List{}, - GroupClause: &ast.List{}, - WindowClause: &ast.List{}, - SortClause: &ast.List{}, - LockingClause: &ast.List{}, + ValuesLists: &ast.List{Items: []ast.Node{&ast.List{Items: []ast.Node{&ast.A_Const{Val: &ast.Integer{Ival: 4}}}}}}, + TargetList: &ast.List{}, + FromClause: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + SortClause: &ast.List{}, + LockingClause: &ast.List{}, }, OnConflictClause: &ast.OnConflictClause{Action: ast.OnConflictAction_UPSERT}, ReturningList: &ast.List{Items: []ast.Node{&ast.ResTarget{Val: &ast.ColumnRef{Fields: &ast.List{Items: []ast.Node{&ast.String{Str: "id"}}}}, Indirection: &ast.List{}}}}, diff --git a/internal/engine/ydb/catalog_tests/select_test.go b/internal/engine/ydb/catalog_tests/select_test.go index f01171f12a..da3adab71b 100644 --- a/internal/engine/ydb/catalog_tests/select_test.go +++ b/internal/engine/ydb/catalog_tests/select_test.go @@ -238,6 +238,7 @@ func TestSelect(t *testing.T) { Items: []ast.Node{ &ast.RangeVar{ Relname: strPtr("users"), + Inh: true, }, }, }, @@ -274,6 +275,7 @@ func TestSelect(t *testing.T) { Items: []ast.Node{ &ast.RangeVar{ Relname: strPtr("users"), + Inh: true, }, }, }, @@ -311,6 +313,7 @@ func TestSelect(t *testing.T) { Items: []ast.Node{ &ast.RangeVar{ Relname: strPtr("table"), + Inh: true, }, }, }, @@ -365,6 +368,7 @@ func TestSelect(t *testing.T) { Items: []ast.Node{ &ast.RangeVar{ Relname: strPtr("users"), + Inh: true, }, }, }, @@ -409,6 +413,7 @@ func TestSelect(t *testing.T) { Items: []ast.Node{ &ast.RangeVar{ Relname: strPtr("users"), + Inh: true, }, }, }, @@ -516,6 +521,7 @@ func TestSelect(t *testing.T) { Items: []ast.Node{ &ast.RangeVar{ Relname: strPtr("users"), + Inh: true, }, }, }, @@ -565,6 +571,7 @@ func TestSelect(t *testing.T) { Items: []ast.Node{ &ast.RangeVar{ Relname: strPtr("users"), + Inh: true, }, }, }, @@ -606,10 +613,11 @@ func TestSelect(t *testing.T) { Items: []ast.Node{ &ast.RangeVar{ Relname: strPtr("users"), + Inh: true, }, }, }, - GroupClause: &ast.List{ + GroupClause: &ast.List{ Items: []ast.Node{ &ast.ColumnRef{ Fields: &ast.List{ @@ -685,6 +693,7 @@ func TestSelect(t *testing.T) { Items: []ast.Node{ &ast.RangeVar{ Relname: strPtr("users"), + Inh: true, }, }, }, diff --git a/internal/engine/ydb/catalog_tests/update_test.go b/internal/engine/ydb/catalog_tests/update_test.go index b7ebeb3d6a..f98333b16d 100644 --- a/internal/engine/ydb/catalog_tests/update_test.go +++ b/internal/engine/ydb/catalog_tests/update_test.go @@ -22,7 +22,7 @@ func TestUpdate(t *testing.T) { Stmt: &ast.UpdateStmt{ Relations: &ast.List{ Items: []ast.Node{ - &ast.RangeVar{Relname: strPtr("users")}, + &ast.RangeVar{Relname: strPtr("users"), Inh: true}, }, }, TargetList: &ast.List{ @@ -57,7 +57,7 @@ func TestUpdate(t *testing.T) { FromClause: &ast.List{}, WithClause: nil, Batch: false, - OnCols: nil, + OnCols: &ast.List{Items: []ast.Node{}}, OnSelectStmt: nil, }, }, @@ -70,7 +70,7 @@ func TestUpdate(t *testing.T) { Stmt: &ast.UpdateStmt{ Relations: &ast.List{ Items: []ast.Node{ - &ast.RangeVar{Relname: strPtr("users")}, + &ast.RangeVar{Relname: strPtr("users"), Inh: true}, }, }, TargetList: &ast.List{ @@ -103,7 +103,7 @@ func TestUpdate(t *testing.T) { FromClause: &ast.List{}, WithClause: nil, Batch: true, - OnCols: nil, + OnCols: &ast.List{Items: []ast.Node{}}, OnSelectStmt: nil, }, }, @@ -114,7 +114,7 @@ func TestUpdate(t *testing.T) { expected: &ast.Statement{ Raw: &ast.RawStmt{ Stmt: &ast.UpdateStmt{ - Relations: &ast.List{Items: []ast.Node{&ast.RangeVar{Relname: strPtr("users")}}}, + Relations: &ast.List{Items: []ast.Node{&ast.RangeVar{Relname: strPtr("users"), Inh: true}}}, OnCols: &ast.List{ Items: []ast.Node{ &ast.ResTarget{Name: strPtr("id")}, @@ -131,11 +131,11 @@ func TestUpdate(t *testing.T) { }, }, }, - FromClause: &ast.List{}, - TargetList: &ast.List{}, - GroupClause: &ast.List{}, - WindowClause: &ast.List{}, - SortClause: &ast.List{}, + FromClause: &ast.List{}, + TargetList: &ast.List{}, + GroupClause: &ast.List{}, + WindowClause: &ast.List{}, + SortClause: &ast.List{}, LockingClause: &ast.List{}, }, ReturningList: &ast.List{ @@ -155,7 +155,7 @@ func TestUpdate(t *testing.T) { FromClause: &ast.List{}, WithClause: nil, Batch: false, - TargetList: nil, + TargetList: &ast.List{Items: []ast.Node{}}, WhereClause: nil, }, }, diff --git a/internal/engine/ydb/convert.go b/internal/engine/ydb/convert.go index fb818a5d5b..a48334afd8 100755 --- a/internal/engine/ydb/convert.go +++ b/internal/engine/ydb/convert.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/antlr4-go/antlr/v4" + "github.com/davecgh/go-spew/spew" "github.com/sqlc-dev/sqlc/internal/debug" "github.com/sqlc-dev/sqlc/internal/sql/ast" parser "github.com/ydb-platform/yql-parsers/go" @@ -322,6 +323,196 @@ func (c *cc) VisitUse_stmt(n *parser.Use_stmtContext) interface{} { return todo("VisitUse_stmt", n) } +func (c *cc) VisitCreate_view_stmt(n *parser.Create_view_stmtContext) interface{} { + if n.CREATE() == nil || n.VIEW() == nil || n.Object_ref() == nil || n.AS() == nil || n.Select_stmt() == nil { + return todo("VisitCreate_view_stmt", n) + } + + viewName := parseObjectRef(n.Object_ref()) + if viewName == nil { + return todo("VisitCreate_view_stmt", n.Object_ref()) + } + + viewRangeVar := &ast.RangeVar{ + Relname: &viewName.Name, + Inh: true, + Location: c.pos(n.Object_ref().GetStart()), + } + + options := &ast.List{Items: []ast.Node{}} + if ctf := n.Create_object_features(); ctf != nil && ctf.Object_features() != nil { + optionsResult := ctf.Object_features().Accept(c) + if optionsList, ok := optionsResult.(*ast.List); ok { + options = optionsList + } else { + return optionsResult + } + } + + selectStmt, ok := n.Select_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitCreate_view_stmt", n.Select_stmt()) + } + + stmt := &ast.ViewStmt{ + View: viewRangeVar, + Query: selectStmt, + Replace: n.IF() == nil && n.NOT() == nil && n.EXISTS() == nil, + Options: options, + } + + return stmt +} + +func (c *cc) VisitObject_features(n *parser.Object_featuresContext) interface{} { + if n == nil { + return todo("VisitObject_features", n) + } + + var features []ast.Node + + if n.Object_feature(0) != nil { + feature, ok := n.Object_feature(0).Accept(c).(ast.Node) + if !ok { + return todo("VisitObject_features", n.Object_feature(0)) + } + features = append(features, feature) + } + + for _, featureCtx := range n.AllObject_feature() { + feature, ok := featureCtx.Accept(c).(ast.Node) + if !ok { + return todo("VisitObject_features", featureCtx) + } + features = append(features, feature) + } + + if len(features) == 0 { + return todo("VisitObject_features", n) + } + + return &ast.List{Items: features} +} + +func (c *cc) VisitObject_feature(n *parser.Object_featureContext) interface{} { + if n == nil { + return todo("VisitObject_feature", n) + } + + if kv := n.Object_feature_kv(); kv != nil { + expr, ok := kv.Accept(c).(ast.Node) + if !ok { + return todo("VisitObject_feature", n) + } + return expr + } + + if flag := n.Object_feature_flag(); flag != nil { + expr, ok := flag.Accept(c).(ast.Node) + if !ok { + return todo("VisitObject_feature", n) + } + return expr + } + + return todo("VisitObject_feature", n) +} + +func (c *cc) VisitObject_feature_kv(n *parser.Object_feature_kvContext) interface{} { + if n == nil || n.An_id_or_type() == nil || n.EQUALS() == nil || n.Object_feature_value() == nil { + return todo("VisitObject_feature_kv", n) + } + + optionName := parseAnIdOrType(n.An_id_or_type()) + if optionName == "" { + return todo("VisitObject_feature_kv", n.An_id_or_type()) + } + + valueNode, ok := n.Object_feature_value().Accept(c).(ast.Node) + if !ok { + return nil + } + + return &ast.DefElem{ + Defname: &optionName, + Arg: valueNode, + Defaction: ast.DefElemAction(1), + Location: c.pos(n.GetStart()), + } +} + +func (c *cc) VisitObject_feature_flag(n *parser.Object_feature_flagContext) interface{} { + if n == nil || n.An_id_or_type() == nil { + return todo("VisitObject_feature_flag", n) + } + + flagName := parseAnIdOrType(n.An_id_or_type()) + if flagName == "" { + return todo("VisitObject_feature_flag", n.An_id_or_type()) + } + + trueValue := &ast.A_Const{Val: &ast.Boolean{Boolval: false}, Location: c.pos(n.GetStart())} + + return &ast.DefElem{ + Defname: &flagName, + Arg: trueValue, + Defaction: ast.DefElemAction(1), + Location: c.pos(n.GetStart()), + } +} + +func (c *cc) VisitObject_feature_value(n *parser.Object_feature_valueContext) interface{} { + if n == nil { + return todo("VisitObject_feature_value", n) + } + + switch { + case n.Id_or_type() != nil: + value := parseIdOrType(n.Id_or_type()) + return &ast.A_Const{Val: &ast.String{Str: value}, Location: c.pos(n.GetStart())} + + case n.Bind_parameter() != nil: + bindPar, ok := n.Bind_parameter().Accept(c).(ast.Node) + if !ok { + return todo("VisitObject_feature_value", n.Bind_parameter()) + } + return bindPar + + case n.STRING_VALUE() != nil: + value, _ := parseStringLiteral(n.STRING_VALUE().GetText()) + return &ast.A_Const{Val: NewIdentifier(value), Location: c.pos(n.GetStart())} + + case n.Bool_value() != nil: + return &ast.A_Const{Location: c.pos(n.GetStart()), Val: &ast.Boolean{Boolval: n.Bool_value().TRUE() != nil}} + } + + return todo("VisitObject_feature_value", n) +} + +func (c *cc) VisitDrop_view_stmt(n *parser.Drop_view_stmtContext) interface{} { + if n.DROP() == nil || n.VIEW() == nil || n.Object_ref() == nil { + return todo("VisitDrop_view_stmt", n) + } + + viewName := parseObjectRef(n.Object_ref()) + if viewName == nil { + return todo("VisitDrop_view_stmt", n.Object_ref()) + } + + table := &ast.TableName{ + Name: viewName.Name, + Schema: viewName.Schema, + Catalog: viewName.Catalog, + } + + stmt := &ast.DropTableStmt{ + IfExists: n.IF() == nil && n.EXISTS() == nil, + Tables: []*ast.TableName{table}, + } + + return stmt +} + func (c *cc) VisitCluster_expr(n *parser.Cluster_exprContext) interface{} { var node ast.Node @@ -680,7 +871,10 @@ func (c *cc) VisitDelete_stmt(n *parser.Delete_stmtContext) interface{} { batch := n.BATCH() != nil tableName := identifier(n.Simple_table_ref().Simple_table_ref_core().GetText()) - rel := &ast.RangeVar{Relname: &tableName} + rel := &ast.RangeVar{ + Relname: &tableName, + Inh: true, + } var where ast.Node if n.WHERE() != nil && n.Expr() != nil { @@ -690,7 +884,7 @@ func (c *cc) VisitDelete_stmt(n *parser.Delete_stmtContext) interface{} { } where = whereNode } - var cols *ast.List + var cols = &ast.List{Items: []ast.Node{}} var source ast.Node if n.ON() != nil && n.Into_values_source() != nil { nVal := n.Into_values_source() @@ -731,7 +925,7 @@ func (c *cc) VisitDelete_stmt(n *parser.Delete_stmtContext) interface{} { } } - returning := &ast.List{} + returning := &ast.List{Items: []ast.Node{}} if ret := n.Returning_columns_list(); ret != nil { temp, ok := ret.Accept(c).(ast.Node) if !ok { @@ -850,11 +1044,14 @@ func (c *cc) VisitUpdate_stmt(n *parser.Update_stmtContext) interface{} { batch := n.BATCH() != nil tableName := identifier(n.Simple_table_ref().Simple_table_ref_core().GetText()) - rel := &ast.RangeVar{Relname: &tableName} + rel := &ast.RangeVar{ + Relname: &tableName, + Inh: true, + } var where ast.Node - var setList *ast.List - var cols *ast.List + setList := &ast.List{Items: []ast.Node{}} + cols := &ast.List{Items: []ast.Node{}} var source ast.Node if n.SET() != nil && n.Set_clause_choice() != nil { @@ -998,6 +1195,7 @@ func (c *cc) VisitInto_table_stmt(n *parser.Into_table_stmtContext) interface{} tableName := identifier(n.Into_simple_table_ref().Simple_table_ref().Simple_table_ref_core().GetText()) rel := &ast.RangeVar{ Relname: &tableName, + Inh: true, Location: c.pos(n.Into_simple_table_ref().GetStart()), } @@ -1015,7 +1213,7 @@ func (c *cc) VisitInto_table_stmt(n *parser.Into_table_stmtContext) interface{} onConflict.Action = ast.OnConflictAction_REPLACE } - var cols *ast.List + cols := &ast.List{Items: []ast.Node{}} var source ast.Node if nVal := n.Into_values_source(); nVal != nil { // todo: handle default values when implemented @@ -1056,7 +1254,7 @@ func (c *cc) VisitInto_table_stmt(n *parser.Into_table_stmtContext) interface{} } } - returning := &ast.List{} + returning := &ast.List{Items: []ast.Node{}} if ret := n.Returning_columns_list(); ret != nil { temp, ok := ret.Accept(c).(ast.Node) if !ok { @@ -1491,8 +1689,15 @@ func (c *cc) VisitResult_column(n *parser.Result_columnContext) interface{} { case n.AS() != nil && n.An_id_or_type() != nil: name := parseAnIdOrType(n.An_id_or_type()) target.Name = &name - case n.An_id_as_compat() != nil: //nolint - // todo: parse as_compat + case n.An_id_as_compat() != nil: + // Handle aliases without AS keyword (compatibility mode) + aliasText := n.An_id_as_compat().GetText() + // Remove quotes if present + if len(aliasText) >= 2 && ((aliasText[0] == '"' && aliasText[len(aliasText)-1] == '"') || + (aliasText[0] == '\'' && aliasText[len(aliasText)-1] == '\'')) { + aliasText = aliasText[1 : len(aliasText)-1] + } + target.Name = &aliasText } target.Val = val return target @@ -1605,12 +1810,44 @@ func (c *cc) VisitNamed_single_source(n *parser.Named_single_sourceContext) inte switch source := base.(type) { case *ast.RangeVar: source.Alias = &ast.Alias{Aliasname: &aliasText} + source.Inh = true + case *ast.RangeSubselect: + source.Alias = &ast.Alias{Aliasname: &aliasText} + case *ast.RangeFunction: + source.Alias = &ast.Alias{Aliasname: &aliasText} + default: + return todo("VisitNamed_single_source", n.An_id()) + } + } else if n.An_id_as_compat() != nil { + aliasText := n.An_id_as_compat().GetText() + + switch source := base.(type) { + case *ast.RangeVar: + source.Alias = &ast.Alias{Aliasname: &aliasText} + source.Inh = true case *ast.RangeSubselect: source.Alias = &ast.Alias{Aliasname: &aliasText} + case *ast.RangeFunction: + source.Alias = &ast.Alias{Aliasname: &aliasText} + default: + return todo("VisitNamed_single_source", n.An_id_as_compat()) + } + } + + if n.Pure_column_list() != nil { + if rangeFunc, ok := base.(*ast.RangeFunction); ok { + colList := &ast.List{} + for _, anID := range n.Pure_column_list().AllAn_id() { + colName := parseAnId(anID) + colList.Items = append(colList.Items, &ast.String{Str: colName}) + } + if rangeFunc.Alias == nil { + rangeFunc.Alias = &ast.Alias{} + } + rangeFunc.Alias.Colnames = colList } - } else if n.An_id_as_compat() != nil { //nolint - // todo: parse as_compat } + return base } @@ -1620,11 +1857,11 @@ func (c *cc) VisitSingle_source(n *parser.Single_sourceContext) interface{} { } if n.Table_ref() != nil { - tableName := n.Table_ref().GetText() // !! debug !! - return &ast.RangeVar{ - Relname: &tableName, - Location: c.pos(n.GetStart()), + result := n.Table_ref().Accept(c) + if result == nil { + return todo("VisitSingle_source table_ref", n.Table_ref()) } + return result } if n.Select_stmt() != nil { @@ -1635,13 +1872,88 @@ func (c *cc) VisitSingle_source(n *parser.Single_sourceContext) interface{} { return &ast.RangeSubselect{ Subquery: subquery, } + } + if n.Values_stmt() != nil { + valuesStmt, ok := n.Values_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitSingle_source values_stmt", n.Values_stmt()) + } + return &ast.RangeSubselect{ + Subquery: valuesStmt, + } } - // todo: Values stmt return todo("VisitSingle_source", n) } +func (c *cc) VisitTable_ref(n *parser.Table_refContext) interface{} { + if n == nil { + return todo("VisitTable_ref", n) + } + + if n.Bind_parameter() != nil { + tableName := n.Bind_parameter().GetText() + log.Println("SQLC doesn't support named parameters for table names (FROM $param)") // FIXME: support named parameters for table names + return &ast.RangeVar{ + Relname: &tableName, + Inh: false, + Location: c.pos(n.GetStart()), + } + } + + if n.An_id_expr() != nil && n.LPAREN() != nil && n.RPAREN() != nil { + funcName := "" + if n.An_id_expr().STRING_VALUE() != nil { + funcName = n.An_id_expr().STRING_VALUE().GetText() + } else if n.An_id_expr().Id_expr() != nil { + funcName = n.An_id_expr().Id_expr().GetText() + } else { + return todo("VisitTable_ref an_id_expr", n.An_id_expr()) + } + + funcCall := &ast.FuncCall{ + Func: &ast.FuncName{ + Name: funcName, + }, + Funcname: &ast.List{ + Items: []ast.Node{&ast.String{Str: funcName}}, + }, + Args: &ast.List{}, + AggOrder: &ast.List{}, + } + + if n.AllTable_arg() != nil { + for _, tableArg := range n.AllTable_arg() { + + if tableArg.Named_expr() != nil { + argNode, ok := tableArg.Named_expr().Accept(c).(ast.Node) + if ok { + funcCall.Args.Items = append(funcCall.Args.Items, argNode) + } + } + } + } + + return &ast.RangeFunction{ + Functions: &ast.List{ + Items: []ast.Node{funcCall}, + }, + } + } + + if n.Table_key() != nil { + tableName := n.Table_key().GetText() + return &ast.RangeVar{ + Relname: &tableName, + Inh: true, + Location: c.pos(n.GetStart()), + } + } + + return todo("VisitTable_ref", n) +} + func (c *cc) VisitBind_parameter(n *parser.Bind_parameterContext) interface{} { if n == nil || n.DOLLAR() == nil { return todo("VisitBind_parameter", n) @@ -1733,6 +2045,12 @@ func (c *cc) VisitCreate_table_stmt(n *parser.Create_table_stmtContext) interfac return todo("VisitCreate_table_stmt", def.Changefeed()) } } + + if n.Table_inherits() != nil { + log.Fatalf("INNERITS is not implemented yet") + return todo("VisitCreate_table_stmt", n) + } + return stmt } @@ -1824,36 +2142,33 @@ func (c *cc) VisitType_name(n *parser.Type_nameContext) interface{} { if decimal := n.Type_name_decimal(); decimal != nil { if integerOrBinds := decimal.AllInteger_or_bind(); len(integerOrBinds) >= 2 { - first, ok := integerOrBinds[0].Accept(c).(ast.Node) - if !ok { - return todo("VisitType_name", decimal.Integer_or_bind(0)) - } - second, ok := integerOrBinds[1].Accept(c).(ast.Node) - if !ok { - return todo("VisitType_name", decimal.Integer_or_bind(1)) - } - name := "decimal" + first := integerOrBinds[0].GetText() + second := integerOrBinds[1].GetText() + name := fmt.Sprintf("Decimal(%s,%s)", first, second) if questionCount > 0 { name = name + "?" } return &ast.TypeName{ Name: name, TypeOid: 0, - Names: &ast.List{ - Items: []ast.Node{ - first, - second, - }, - }, } } } if simple := n.Type_name_simple(); simple != nil { name := simple.GetText() + + if name == "Integer" { + return &ast.TypeName{ + Name: "any", + TypeOid: 0, + } + } + if questionCount > 0 { name = name + "?" } + return &ast.TypeName{ Name: name, TypeOid: 0, @@ -2694,9 +3009,18 @@ func (c *cc) VisitCon_subexpr(n *parser.Con_subexprContext) interface{} { if !ok { return todo("VisitCon_subexpr", opCtx) } + + if strings.ToUpper(op) == "NOT" { + return &ast.BoolExpr{ + Boolop: ast.BoolExprTypeNot, + Args: &ast.List{Items: []ast.Node{operand}}, + Location: c.pos(n.GetStart()), + } + } + return &ast.A_Expr{ Name: &ast.List{Items: []ast.Node{&ast.String{Str: op}}}, - Rexpr: operand, + Lexpr: operand, Location: c.pos(n.GetStart()), } } @@ -2800,48 +3124,87 @@ func (c *cc) VisitId_expr_in(n *parser.Id_expr_inContext) interface{} { func (c *cc) VisitIn_atom_expr(n *parser.In_atom_exprContext) interface{} { if n == nil { - return todo("VisitAtom_expr", n) + return todo("VisitIn_atom_expr", n) } switch { - case n.An_id_or_type() != nil: - if n.NAMESPACE() != nil { - return NewIdentifier(parseAnIdOrType(n.An_id_or_type()) + "::" + parseIdOrType(n.Id_or_type())) - } - return NewIdentifier(parseAnIdOrType(n.An_id_or_type())) case n.Literal_value() != nil: expr, ok := n.Literal_value().Accept(c).(ast.Node) if !ok { - return todo("VisitAtom_expr", n.Literal_value()) + return todo("VisitIn_atom_expr", n.Literal_value()) } return expr + case n.Bind_parameter() != nil: expr, ok := n.Bind_parameter().Accept(c).(ast.Node) if !ok { - return todo("VisitAtom_expr", n.Bind_parameter()) + return todo("VisitIn_atom_expr", n.Bind_parameter()) + } + return expr + + case n.Lambda() != nil: + expr, ok := n.Lambda().Accept(c).(ast.Node) + if !ok { + return todo("VisitIn_atom_expr", n.Lambda()) } return expr + case n.Cast_expr() != nil: expr, ok := n.Cast_expr().Accept(c).(ast.Node) if !ok { - return todo("VisitAtom_expr", n.Cast_expr()) + return todo("VisitIn_atom_expr", n.Cast_expr()) + } + return expr + + case n.Case_expr() != nil: + expr, ok := n.Case_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitIn_atom_expr", n.Case_expr()) } return expr - case n.LPAREN() != nil && n.Select_stmt() != nil && n.RPAREN() != nil: + case n.An_id_or_type() != nil: + if n.NAMESPACE() != nil { + left := parseAnIdOrType(n.An_id_or_type()) + right := parseIdOrType(n.Id_or_type()) + name := left + "_" + right + return &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{NewIdentifier(name)}}, + Location: c.pos(n.GetStart()), + } + } + name := parseAnIdOrType(n.An_id_or_type()) + return &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{NewIdentifier(name)}}, + Location: c.pos(n.GetStart()), + } + + case n.Select_stmt() != nil: selectStmt, ok := n.Select_stmt().Accept(c).(ast.Node) if !ok { - return todo("VisitAtom_expr", n.Select_stmt()) + return todo("VisitIn_atom_expr", n.Select_stmt()) } return selectStmt + case n.Value_constructor() != nil: + return todo("VisitIn_atom_expr", n.Value_constructor()) + + case n.Bitcast_expr() != nil: + return todo("VisitIn_atom_expr", n.Bitcast_expr()) + case n.List_literal() != nil: list, ok := n.List_literal().Accept(c).(ast.Node) if !ok { - return todo("VisitAtom_expr", n.List_literal()) + return todo("VisitIn_atom_expr", n.List_literal()) } return list + case n.Dict_literal() != nil: + return todo("VisitIn_atom_expr", n.Dict_literal()) + + case n.Struct_literal() != nil: + return todo("VisitIn_atom_expr", n.Struct_literal()) + // TODO: check other cases default: return todo("VisitAtom_expr", n) @@ -2957,6 +3320,14 @@ func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprCont } switch baseNode := base.(type) { + case *ast.FuncCall: + funcCall.Func = baseNode.Func + + funcCall.Func.Name = baseNode.Func.Name + "_call" + + funcCall.Funcname.Items = append(funcCall.Funcname.Items, &ast.String{Str: funcCall.Func.Name}) + return funcCall + case *ast.ColumnRef: if len(baseNode.Fields.Items) > 0 { var nameParts []string @@ -2966,7 +3337,7 @@ func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprCont } } funcCall.Func = &ast.FuncName{} - if len(nameParts) == 2 { + if len(nameParts) == 2 && nameParts[0] == "sqlc" { funcCall.Func.Schema = nameParts[0] funcCall.Func.Name = nameParts[1] } else { @@ -2999,7 +3370,8 @@ func (c *cc) handleInvokeSuffix(base ast.Node, invokeCtx *parser.Invoke_exprCont return funcCall } default: - return todo("VisitInvoke_expr", invokeCtx) + spew.Dump(baseNode) + return todo("VisitInvoke_exp", invokeCtx) } stmt := &ast.FuncExpr{ @@ -3200,16 +3572,34 @@ func (c *cc) VisitAtom_expr(n *parser.Atom_exprContext) interface{} { return expr case n.Exists_expr() != nil: - return todo("VisitAtom_expr", n.Exists_expr()) + expr, ok := n.Exists_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Exists_expr()) + } + return expr case n.Case_expr() != nil: - return todo("VisitAtom_expr", n.Case_expr()) + expr, ok := n.Case_expr().Accept(c).(ast.Node) + if !ok { + return todo("VisitAtom_expr", n.Case_expr()) + } + return expr case n.An_id_or_type() != nil: if n.NAMESPACE() != nil { - return NewIdentifier(parseAnIdOrType(n.An_id_or_type()) + "::" + parseIdOrType(n.Id_or_type())) + left := parseAnIdOrType(n.An_id_or_type()) + right := parseIdOrType(n.Id_or_type()) + name := left + "_" + right + return &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{NewIdentifier(name)}}, + Location: c.pos(n.GetStart()), + } + } + name := parseAnIdOrType(n.An_id_or_type()) + return &ast.ColumnRef{ + Fields: &ast.List{Items: []ast.Node{NewIdentifier(name)}}, + Location: c.pos(n.GetStart()), } - return NewIdentifier(parseAnIdOrType(n.An_id_or_type())) case n.Value_constructor() != nil: return todo("VisitAtom_expr", n.Value_constructor()) @@ -3262,6 +3652,38 @@ func (c *cc) VisitCast_expr(n *parser.Cast_exprContext) interface{} { } } +func (c *cc) VisitExists_expr(n *parser.Exists_exprContext) interface{} { + if n == nil || n.EXISTS() == nil || n.LPAREN() == nil || n.RPAREN() == nil || (n.Select_stmt() == nil && n.Values_stmt() == nil) { + return todo("VisitExists_expr", n) + } + + exists := &ast.SubLink{ + Xpr: &ast.TODO{}, + SubLinkType: ast.EXISTS_SUBLINK, + Location: c.pos(n.GetStart()), + } + + switch { + case n.Select_stmt() != nil: + Subselect, ok := n.Select_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitExists_expr", n.Select_stmt()) + } + exists.Subselect = Subselect + case n.Values_stmt() != nil: + Subselect, ok := n.Values_stmt().Accept(c).(ast.Node) + if !ok { + return todo("VisitExists_expr", n.Values_stmt()) + } + exists.Subselect = Subselect + + default: + return todo("VisitExists_expr", n) + } + + return exists +} + func (c *cc) VisitList_literal(n *parser.List_literalContext) interface{} { if n == nil || n.LBRACE_SQUARE() == nil || n.RBRACE_SQUARE() == nil || n.Expr_list() == nil { return todo("VisitList_literal", n) @@ -3305,11 +3727,10 @@ func (c *cc) VisitLiteral_value(n *parser.Literal_valueContext) interface{} { return &ast.A_Const{Val: &ast.Float{Str: text}, Location: c.pos(n.GetStart())} case n.STRING_VALUE() != nil: // !!! debug !!! (problem with quoted strings) - val := n.STRING_VALUE().GetText() - if len(val) >= 2 { - val = val[1 : len(val)-1] - } - return &ast.A_Const{Val: &ast.String{Str: val}, Location: c.pos(n.GetStart())} + originalText := n.STRING_VALUE().GetText() + content, _ := parseStringLiteral(originalText) + + return &ast.A_Const{Val: &ast.String{Str: content}, Location: c.pos(n.GetStart())} case n.Bool_value() != nil: var i bool @@ -3386,6 +3807,88 @@ func (c *cc) VisitSmart_parenthesis(n *parser.Smart_parenthesisContext) interfac } } +func (c *cc) VisitCase_expr(n *parser.Case_exprContext) interface{} { + if n == nil || n.CASE() == nil || n.END() == nil { + return todo("VisitCase_expr", n) + } + + caseExpr := &ast.CaseExpr{ + Args: &ast.List{Items: []ast.Node{}}, + Location: c.pos(n.GetStart()), + } + + whenExprs := n.AllWhen_expr() + if len(whenExprs) == 0 { + return todo("VisitCase_expr", n) + } + + allExprs := n.AllExpr() + if len(allExprs) > 0 { + firstWhenStart := whenExprs[0].GetStart().GetStart() + firstExprStart := allExprs[0].GetStart().GetStart() + + if firstExprStart < firstWhenStart { + arg, ok := allExprs[0].Accept(c).(ast.Node) + if !ok { + return todo("VisitCase_expr", allExprs[0]) + } + caseExpr.Arg = arg + } + } + + for _, whenExpr := range whenExprs { + whenNode, ok := whenExpr.Accept(c).(ast.Node) + if !ok { + return todo("VisitCase_expr", whenExpr) + } + caseExpr.Args.Items = append(caseExpr.Args.Items, whenNode) + } + + if n.ELSE() != nil { + elseStart := n.ELSE().GetSymbol().GetStart() + for _, expr := range allExprs { + exprStart := expr.GetStart().GetStart() + if exprStart > elseStart { + elseExpr, ok := expr.Accept(c).(ast.Node) + if !ok { + return todo("VisitCase_expr", expr) + } + caseExpr.Defresult = elseExpr + break + } + } + } + + return caseExpr +} + +func (c *cc) VisitWhen_expr(n *parser.When_exprContext) interface{} { + if n == nil || n.WHEN() == nil || n.THEN() == nil { + return todo("VisitWhen_expr", n) + } + + whenExprs := n.AllExpr() + if len(whenExprs) < 2 { + return todo("VisitWhen_expr", n) + } + + condition, ok := whenExprs[0].Accept(c).(ast.Node) + if !ok { + return todo("VisitWhen_expr", whenExprs[0]) + } + + result, ok := whenExprs[1].Accept(c).(ast.Node) + if !ok { + return todo("VisitWhen_expr", whenExprs[1]) + } + + return &ast.CaseWhen{ + Expr: condition, + Result: result, + Location: c.pos(n.GetStart()), + } +} + func (c *cc) VisitSql_stmt(n *parser.Sql_stmtContext) interface{} { if n == nil || n.Sql_stmt_core() == nil { return todo("VisitSql_stmt", n) @@ -3415,3 +3918,151 @@ func (c *cc) VisitSql_stmt(n *parser.Sql_stmtContext) interface{} { return expr } + +func (c *cc) VisitNamed_nodes_stmt(n *parser.Named_nodes_stmtContext) interface{} { + return todo("VisitNamed_nodes_stmt", n) +} + +func (c *cc) VisitDeclare_stmt(n *parser.Declare_stmtContext) interface{} { + return todo("VisitDeclare_stmt", n) +} + +func (c *cc) VisitImport_stmt(n *parser.Import_stmtContext) interface{} { + return todo("VisitImport_stmt", n) +} + +func (c *cc) VisitExport_stmt(n *parser.Export_stmtContext) interface{} { + return todo("VisitExport_stmt", n) +} + +func (c *cc) VisitAlter_external_table_stmt(n *parser.Alter_external_table_stmtContext) interface{} { + return todo("VisitAlter_external_table_stmt", n) +} + +func (c *cc) VisitDefine_action_or_subquery_stmt(n *parser.Define_action_or_subquery_stmtContext) interface{} { + return todo("VisitDefine_action_or_subquery_stmt", n) +} + +func (c *cc) VisitIf_stmt(n *parser.If_stmtContext) interface{} { + return todo("VisitIf_stmt", n) +} + +func (c *cc) VisitFor_stmt(n *parser.For_stmtContext) interface{} { + return todo("VisitFor_stmt", n) +} + +func (c *cc) VisitCreate_object_stmt(n *parser.Create_object_stmtContext) interface{} { + return todo("VisitCreate_object_stmt", n) +} + +func (c *cc) VisitAlter_object_stmt(n *parser.Alter_object_stmtContext) interface{} { + return todo("VisitAlter_object_stmt", n) +} + +func (c *cc) VisitDrop_object_stmt(n *parser.Drop_object_stmtContext) interface{} { + return todo("VisitDrop_object_stmt", n) +} + +func (c *cc) VisitCreate_external_data_source_stmt(n *parser.Create_external_data_source_stmtContext) interface{} { + return todo("VisitCreate_external_data_source_stmt", n) +} + +func (c *cc) VisitAlter_external_data_source_stmt(n *parser.Alter_external_data_source_stmtContext) interface{} { + return todo("VisitAlter_external_data_source_stmt", n) +} + +func (c *cc) VisitDrop_external_data_source_stmt(n *parser.Drop_external_data_source_stmtContext) interface{} { + return todo("VisitDrop_external_data_source_stmt", n) +} + +func (c *cc) VisitCreate_replication_stmt(n *parser.Create_replication_stmtContext) interface{} { + return todo("VisitCreate_replication_stmt", n) +} + +func (c *cc) VisitDrop_replication_stmt(n *parser.Drop_replication_stmtContext) interface{} { + return todo("VisitDrop_replication_stmt", n) +} + +func (c *cc) VisitCreate_topic_stmt(n *parser.Create_topic_stmtContext) interface{} { + return todo("VisitCreate_topic_stmt", n) +} + +func (c *cc) VisitAlter_topic_stmt(n *parser.Alter_topic_stmtContext) interface{} { + return todo("VisitAlter_topic_stmt", n) +} + +func (c *cc) VisitDrop_topic_stmt(n *parser.Drop_topic_stmtContext) interface{} { + return todo("VisitDrop_topic_stmt", n) +} + +func (c *cc) VisitGrant_permissions_stmt(n *parser.Grant_permissions_stmtContext) interface{} { + return todo("VisitGrant_permissions_stmt", n) +} + +func (c *cc) VisitRevoke_permissions_stmt(n *parser.Revoke_permissions_stmtContext) interface{} { + return todo("VisitRevoke_permissions_stmt", n) +} + +func (c *cc) VisitAlter_table_store_stmt(n *parser.Alter_table_store_stmtContext) interface{} { + return todo("VisitAlter_table_store_stmt", n) +} + +func (c *cc) VisitUpsert_object_stmt(n *parser.Upsert_object_stmtContext) interface{} { + return todo("VisitUpsert_object_stmt", n) +} + +func (c *cc) VisitAlter_replication_stmt(n *parser.Alter_replication_stmtContext) interface{} { + return todo("VisitAlter_replication_stmt", n) +} + +func (c *cc) VisitCreate_resource_pool_stmt(n *parser.Create_resource_pool_stmtContext) interface{} { + return todo("VisitCreate_resource_pool_stmt", n) +} + +func (c *cc) VisitAlter_resource_pool_stmt(n *parser.Alter_resource_pool_stmtContext) interface{} { + return todo("VisitAlter_resource_pool_stmt", n) +} + +func (c *cc) VisitDrop_resource_pool_stmt(n *parser.Drop_resource_pool_stmtContext) interface{} { + return todo("VisitDrop_resource_pool_stmt", n) +} + +func (c *cc) VisitCreate_backup_collection_stmt(n *parser.Create_backup_collection_stmtContext) interface{} { + return todo("VisitCreate_backup_collection_stmt", n) +} + +func (c *cc) VisitAlter_backup_collection_stmt(n *parser.Alter_backup_collection_stmtContext) interface{} { + return todo("VisitAlter_backup_collection_stmt", n) +} + +func (c *cc) VisitDrop_backup_collection_stmt(n *parser.Drop_backup_collection_stmtContext) interface{} { + return todo("VisitDrop_backup_collection_stmt", n) +} + +func (c *cc) VisitAnalyze_stmt(n *parser.Analyze_stmtContext) interface{} { + return todo("VisitAnalyze_stmt", n) +} + +func (c *cc) VisitCreate_resource_pool_classifier_stmt(n *parser.Create_resource_pool_classifier_stmtContext) interface{} { + return todo("VisitCreate_resource_pool_classifier_stmt", n) +} + +func (c *cc) VisitAlter_resource_pool_classifier_stmt(n *parser.Alter_resource_pool_classifier_stmtContext) interface{} { + return todo("VisitAlter_resource_pool_classifier_stmt", n) +} + +func (c *cc) VisitDrop_resource_pool_classifier_stmt(n *parser.Drop_resource_pool_classifier_stmtContext) interface{} { + return todo("VisitDrop_resource_pool_classifier_stmt", n) +} + +func (c *cc) VisitBackup_stmt(n *parser.Backup_stmtContext) interface{} { + return todo("VisitBackup_stmt", n) +} + +func (c *cc) VisitRestore_stmt(n *parser.Restore_stmtContext) interface{} { + return todo("VisitRestore_stmt", n) +} + +func (c *cc) VisitAlter_sequence_stmt(n *parser.Alter_sequence_stmtContext) interface{} { + return todo("VisitAlter_sequence_stmt", n) +} diff --git a/internal/engine/ydb/lib/aggregate.go b/internal/engine/ydb/lib/aggregate.go index 7c5d795eca..d5746d5114 100644 --- a/internal/engine/ydb/lib/aggregate.go +++ b/internal/engine/ydb/lib/aggregate.go @@ -36,7 +36,10 @@ func countFuncs() []*catalog.Function { { Name: "COUNT", Args: []*catalog.Argument{ - {Type: &ast.TypeName{Name: "any"}}, + { + Type: &ast.TypeName{Name: "any"}, + Mode: ast.FuncParamVariadic, + }, }, ReturnType: &ast.TypeName{Name: "Uint64"}, }, diff --git a/internal/engine/ydb/lib/basic.go b/internal/engine/ydb/lib/basic.go index d5cbfda950..6f800fe594 100644 --- a/internal/engine/ydb/lib/basic.go +++ b/internal/engine/ydb/lib/basic.go @@ -33,6 +33,7 @@ func BasicFunctions() []*catalog.Function { funcs = append(funcs, absFuncs()...) funcs = append(funcs, justUnwrapNothingFuncs()...) funcs = append(funcs, pickleUnpickleFuncs()...) + funcs = append(funcs, asTableFuncs()...) // todo: implement functions: // Udf, AsTuple, AsStruct, AsList, AsDict, AsSet, AsListStrict, AsDictStrict, AsSetStrict, @@ -711,3 +712,14 @@ func pickleUnpickleFuncs() []*catalog.Function { }, } } + +func asTableFuncs() []*catalog.Function { + return []*catalog.Function{ + { + Name: "AS_TABLE", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + }, + } +} diff --git a/internal/engine/ydb/lib/cpp/datetime.go b/internal/engine/ydb/lib/cpp/datetime.go index ca6f6bc6b6..ecd2342e3f 100644 --- a/internal/engine/ydb/lib/cpp/datetime.go +++ b/internal/engine/ydb/lib/cpp/datetime.go @@ -24,77 +24,77 @@ func DateTimeFunctions() []*catalog.Function { func dateTimeMakeFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "DateTime::MakeDate", + Name: "datetime_makedate", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Date"}, }, { - Name: "DateTime::MakeDate32", + Name: "datetime_makedate32", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Date32"}, }, { - Name: "DateTime::MakeTzDate32", + Name: "datetime_maketzdate32", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "TzDate32"}, }, { - Name: "DateTime::MakeDatetime", + Name: "datetime_makedatetime", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Datetime"}, }, { - Name: "DateTime::MakeTzDatetime", + Name: "datetime_maketzdatetime", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "TzDatetime"}, }, { - Name: "DateTime::MakeDatetime64", + Name: "datetime_makedatetime64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Datetime64"}, }, { - Name: "DateTime::MakeTzDatetime64", + Name: "datetime_maketzdatetime64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "TzDatetime64"}, }, { - Name: "DateTime::MakeTimestamp", + Name: "datetime_maketimestamp", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Timestamp"}, }, { - Name: "DateTime::MakeTzTimestamp", + Name: "datetime_maketztimestamp", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "TzTimestamp"}, }, { - Name: "DateTime::MakeTimestamp64", + Name: "datetime_maketimestamp64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Timestamp64"}, }, { - Name: "DateTime::MakeTzTimestamp64", + Name: "datetime_maketztimestamp64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -106,119 +106,119 @@ func dateTimeMakeFuncs() []*catalog.Function { func dateTimeGetFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "DateTime::GetYear", + Name: "datetime_getyear", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint16"}, }, { - Name: "DateTime::GetYear", + Name: "datetime_getyear", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Int32"}, }, { - Name: "DateTime::GetDayOfYear", + Name: "datetime_getdayofyear", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint16"}, }, { - Name: "DateTime::GetMonth", + Name: "datetime_getmonth", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint8"}, }, { - Name: "DateTime::GetMonthName", + Name: "datetime_getmonthname", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "DateTime::GetWeekOfYear", + Name: "datetime_getweekofyear", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint8"}, }, { - Name: "DateTime::GetWeekOfYearIso8601", + Name: "datetime_getweekofyeariso8601", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint8"}, }, { - Name: "DateTime::GetDayOfMonth", + Name: "datetime_getdayofmonth", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint8"}, }, { - Name: "DateTime::GetDayOfWeek", + Name: "datetime_getdayofweek", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint8"}, }, { - Name: "DateTime::GetDayOfWeekName", + Name: "datetime_getdayofweekname", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "DateTime::GetHour", + Name: "datetime_gethour", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint8"}, }, { - Name: "DateTime::GetMinute", + Name: "datetime_getminute", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint8"}, }, { - Name: "DateTime::GetSecond", + Name: "datetime_getsecond", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint8"}, }, { - Name: "DateTime::GetMillisecondOfSecond", + Name: "datetime_getmillisecondofsecond", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint32"}, }, { - Name: "DateTime::GetMicrosecondOfSecond", + Name: "datetime_getmicrosecondofsecond", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint32"}, }, { - Name: "DateTime::GetTimezoneId", + Name: "datetime_gettimezoneid", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Uint16"}, }, { - Name: "DateTime::GetTimezoneName", + Name: "datetime_gettimezonename", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -230,7 +230,7 @@ func dateTimeGetFuncs() []*catalog.Function { func dateTimeUpdateFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "DateTime::Update", + Name: "datetime_update", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -238,7 +238,7 @@ func dateTimeUpdateFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::Update", + Name: "datetime_update", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -247,7 +247,7 @@ func dateTimeUpdateFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::Update", + Name: "datetime_update", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -257,7 +257,7 @@ func dateTimeUpdateFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::Update", + Name: "datetime_update", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -268,7 +268,7 @@ func dateTimeUpdateFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::Update", + Name: "datetime_update", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -280,7 +280,7 @@ func dateTimeUpdateFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::Update", + Name: "datetime_update", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -293,7 +293,7 @@ func dateTimeUpdateFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::Update", + Name: "datetime_update", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -307,7 +307,7 @@ func dateTimeUpdateFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::Update", + Name: "datetime_update", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -327,42 +327,42 @@ func dateTimeUpdateFuncs() []*catalog.Function { func dateTimeFromFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "DateTime::FromSeconds", + Name: "datetime_fromseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Uint32"}}, }, ReturnType: &ast.TypeName{Name: "Timestamp"}, }, { - Name: "DateTime::FromSeconds64", + Name: "datetime_fromseconds64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, ReturnType: &ast.TypeName{Name: "Timestamp64"}, }, { - Name: "DateTime::FromMilliseconds", + Name: "datetime_frommilliseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Uint64"}}, }, ReturnType: &ast.TypeName{Name: "Timestamp"}, }, { - Name: "DateTime::FromMilliseconds64", + Name: "datetime_frommilliseconds64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, ReturnType: &ast.TypeName{Name: "Timestamp64"}, }, { - Name: "DateTime::FromMicroseconds", + Name: "datetime_frommicroseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Uint64"}}, }, ReturnType: &ast.TypeName{Name: "Timestamp"}, }, { - Name: "DateTime::FromMicroseconds64", + Name: "datetime_frommicroseconds64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, @@ -374,21 +374,21 @@ func dateTimeFromFuncs() []*catalog.Function { func dateTimeToFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "DateTime::ToSeconds", + Name: "datetime_toseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "DateTime::ToMilliseconds", + Name: "datetime_tomilliseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "DateTime::ToMicroseconds", + Name: "datetime_tomicroseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -400,126 +400,126 @@ func dateTimeToFuncs() []*catalog.Function { func dateTimeIntervalFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "DateTime::ToDays", + Name: "datetime_todays", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "DateTime::ToHours", + Name: "datetime_tohours", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "DateTime::ToMinutes", + Name: "datetime_tominutes", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "DateTime::ToSeconds", + Name: "datetime_toseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "DateTime::ToMilliseconds", + Name: "datetime_tomilliseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "DateTime::ToMicroseconds", + Name: "datetime_tomicroseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "DateTime::IntervalFromDays", + Name: "datetime_intervalfromdays", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int32"}}, }, ReturnType: &ast.TypeName{Name: "Interval"}, }, { - Name: "DateTime::Interval64FromDays", + Name: "datetime_interval64fromdays", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int32"}}, }, ReturnType: &ast.TypeName{Name: "Interval64"}, }, { - Name: "DateTime::IntervalFromHours", + Name: "datetime_intervalfromhours", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int32"}}, }, ReturnType: &ast.TypeName{Name: "Interval"}, }, { - Name: "DateTime::Interval64FromHours", + Name: "datetime_interval64fromhours", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, ReturnType: &ast.TypeName{Name: "Interval64"}, }, { - Name: "DateTime::IntervalFromMinutes", + Name: "datetime_intervalfromminutes", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int32"}}, }, ReturnType: &ast.TypeName{Name: "Interval"}, }, { - Name: "DateTime::Interval64FromMinutes", + Name: "datetime_interval64fromminutes", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, ReturnType: &ast.TypeName{Name: "Interval64"}, }, { - Name: "DateTime::IntervalFromSeconds", + Name: "datetime_intervalfromseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, ReturnType: &ast.TypeName{Name: "Interval"}, }, { - Name: "DateTime::Interval64FromSeconds", + Name: "datetime_interval64fromseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, ReturnType: &ast.TypeName{Name: "Interval64"}, }, { - Name: "DateTime::IntervalFromMilliseconds", + Name: "datetime_intervalfrommilliseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, ReturnType: &ast.TypeName{Name: "Interval"}, }, { - Name: "DateTime::Interval64FromMilliseconds", + Name: "datetime_interval64frommilliseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, ReturnType: &ast.TypeName{Name: "Interval64"}, }, { - Name: "DateTime::IntervalFromMicroseconds", + Name: "datetime_intervalfrommicroseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, ReturnType: &ast.TypeName{Name: "Interval"}, }, { - Name: "DateTime::Interval64FromMicroseconds", + Name: "datetime_interval64frommicroseconds", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, }, @@ -531,7 +531,7 @@ func dateTimeIntervalFuncs() []*catalog.Function { func dateTimeStartEndFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "DateTime::StartOfYear", + Name: "datetime_startofyear", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -539,7 +539,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::EndOfYear", + Name: "datetime_endofyear", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -547,7 +547,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::StartOfQuarter", + Name: "datetime_startofquarter", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -555,7 +555,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::EndOfQuarter", + Name: "datetime_endofquarter", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -563,7 +563,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::StartOfMonth", + Name: "datetime_startofmonth", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -571,7 +571,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::EndOfMonth", + Name: "datetime_endofmonth", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -579,7 +579,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::StartOfWeek", + Name: "datetime_startofweek", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -587,7 +587,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::EndOfWeek", + Name: "datetime_endofweek", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -595,7 +595,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::StartOfDay", + Name: "datetime_startofday", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -603,7 +603,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::EndOfDay", + Name: "datetime_endofday", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -611,7 +611,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::StartOf", + Name: "datetime_startof", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -620,7 +620,7 @@ func dateTimeStartEndFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::EndOf", + Name: "datetime_endof", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -634,33 +634,40 @@ func dateTimeStartEndFuncs() []*catalog.Function { func dateTimeFormatFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "DateTime::Format", + Name: "datetime_format", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, + { + Name: "datetime_format_call", + Args: []*catalog.Argument{ + {Type: &ast.TypeName{Name: "any"}}, + }, + ReturnType: &ast.TypeName{Name: "string"}, + }, } } func dateTimeParseFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "DateTime::Parse", + Name: "datetime_parse", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "DateTime::Parse64", + Name: "datetime_parse64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "DateTime::ParseRfc822", + Name: "datetime_parserfc822", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -668,7 +675,7 @@ func dateTimeParseFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::ParseIso8601", + Name: "datetime_parseiso8601", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -676,7 +683,7 @@ func dateTimeParseFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::ParseHttp", + Name: "datetime_parsehttp", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -684,7 +691,7 @@ func dateTimeParseFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "DateTime::ParseX509", + Name: "datetime_parsex509", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, diff --git a/internal/engine/ydb/lib/cpp/digest.go b/internal/engine/ydb/lib/cpp/digest.go index dccdb8509b..2e65aeea5e 100644 --- a/internal/engine/ydb/lib/cpp/digest.go +++ b/internal/engine/ydb/lib/cpp/digest.go @@ -19,21 +19,21 @@ func DigestFunctions() []*catalog.Function { func digestCrcFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Digest::Crc32c", + Name: "digest_crc32c", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Uint32"}, }, { - Name: "Digest::Crc64", + Name: "digest_crc64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Digest::Crc64", + Name: "digest_crc64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Uint64"}}, @@ -46,14 +46,14 @@ func digestCrcFuncs() []*catalog.Function { func digestFnvFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Digest::Fnv32", + Name: "digest_fnv32", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Uint32"}, }, { - Name: "Digest::Fnv32", + Name: "digest_fnv32", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Uint32"}}, @@ -61,14 +61,14 @@ func digestFnvFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Uint32"}, }, { - Name: "Digest::Fnv64", + Name: "digest_fnv64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Digest::Fnv64", + Name: "digest_fnv64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Uint64"}}, @@ -81,14 +81,14 @@ func digestFnvFuncs() []*catalog.Function { func digestMurmurFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Digest::MurMurHash", + Name: "digest_murmurhash", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Digest::MurMurHash", + Name: "digest_murmurhash", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Uint64"}}, @@ -96,14 +96,14 @@ func digestMurmurFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Digest::MurMurHash32", + Name: "digest_murmurhash32", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Uint32"}, }, { - Name: "Digest::MurMurHash32", + Name: "digest_murmurhash32", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Uint32"}}, @@ -111,14 +111,14 @@ func digestMurmurFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Uint32"}, }, { - Name: "Digest::MurMurHash2A", + Name: "digest_murmurhash2a", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Digest::MurMurHash2A", + Name: "digest_murmurhash2a", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Uint64"}}, @@ -126,14 +126,14 @@ func digestMurmurFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Digest::MurMurHash2A32", + Name: "digest_murmurhash2a32", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Uint32"}, }, { - Name: "Digest::MurMurHash2A32", + Name: "digest_murmurhash2a32", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Uint32"}}, @@ -146,14 +146,14 @@ func digestMurmurFuncs() []*catalog.Function { func digestCityFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Digest::CityHash", + Name: "digest_cityhash", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Digest::CityHash", + Name: "digest_cityhash", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Uint64"}}, @@ -161,7 +161,7 @@ func digestCityFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Digest::CityHash128", + Name: "digest_cityhash128", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, diff --git a/internal/engine/ydb/lib/cpp/hyperscan.go b/internal/engine/ydb/lib/cpp/hyperscan.go index be3aa968e2..4430f0232f 100644 --- a/internal/engine/ydb/lib/cpp/hyperscan.go +++ b/internal/engine/ydb/lib/cpp/hyperscan.go @@ -21,7 +21,7 @@ func HyperscanFunctions() []*catalog.Function { func hyperscanGrepFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Hyperscan::Grep", + Name: "hyperscan_grep", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -33,7 +33,7 @@ func hyperscanGrepFuncs() []*catalog.Function { func hyperscanMatchFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Hyperscan::Match", + Name: "hyperscan_match", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -45,14 +45,14 @@ func hyperscanMatchFuncs() []*catalog.Function { func hyperscanBacktrackingFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Hyperscan::BacktrackingGrep", + Name: "hyperscan_backtrackinggrep", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Hyperscan::BacktrackingMatch", + Name: "hyperscan_backtrackingmatch", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -64,14 +64,14 @@ func hyperscanBacktrackingFuncs() []*catalog.Function { func hyperscanMultiFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Hyperscan::MultiGrep", + Name: "hyperscan_multigrep", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Hyperscan::MultiMatch", + Name: "hyperscan_multimatch", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -83,7 +83,7 @@ func hyperscanMultiFuncs() []*catalog.Function { func hyperscanCaptureFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Hyperscan::Capture", + Name: "hyperscan_capture", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -95,7 +95,7 @@ func hyperscanCaptureFuncs() []*catalog.Function { func hyperscanReplaceFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Hyperscan::Replace", + Name: "hyperscan_replace", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, diff --git a/internal/engine/ydb/lib/cpp/ip.go b/internal/engine/ydb/lib/cpp/ip.go index a644da910c..a5e460a1b2 100644 --- a/internal/engine/ydb/lib/cpp/ip.go +++ b/internal/engine/ydb/lib/cpp/ip.go @@ -21,7 +21,7 @@ func IpFunctions() []*catalog.Function { func ipFromStringFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Ip::FromString", + Name: "ip_fromstring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -29,7 +29,7 @@ func ipFromStringFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Ip::SubnetFromString", + Name: "ip_subnetfromstring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -42,7 +42,7 @@ func ipFromStringFuncs() []*catalog.Function { func ipToStringFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Ip::ToString", + Name: "ip_tostring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -50,7 +50,7 @@ func ipToStringFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Ip::ToString", + Name: "ip_tostring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -63,21 +63,21 @@ func ipToStringFuncs() []*catalog.Function { func ipCheckFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Ip::IsIPv4", + Name: "ip_isipv4", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Ip::IsIPv6", + Name: "ip_isipv6", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Ip::IsEmbeddedIPv4", + Name: "ip_isembeddedipv4", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -89,7 +89,7 @@ func ipCheckFuncs() []*catalog.Function { func ipConvertFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Ip::ConvertToIPv6", + Name: "ip_converttoipv6", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -101,14 +101,14 @@ func ipConvertFuncs() []*catalog.Function { func ipSubnetFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Ip::GetSubnet", + Name: "ip_getsubnet", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "Ip::GetSubnet", + Name: "ip_getsubnet", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Uint8"}}, @@ -116,7 +116,7 @@ func ipSubnetFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "Ip::GetSubnetByMask", + Name: "ip_getsubnetbymask", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -129,7 +129,7 @@ func ipSubnetFuncs() []*catalog.Function { func ipMatchFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Ip::SubnetMatch", + Name: "ip_subnetmatch", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "String"}}, diff --git a/internal/engine/ydb/lib/cpp/math.go b/internal/engine/ydb/lib/cpp/math.go index 288464ad0d..b50182fbd9 100644 --- a/internal/engine/ydb/lib/cpp/math.go +++ b/internal/engine/ydb/lib/cpp/math.go @@ -25,17 +25,17 @@ func MathFunctions() []*catalog.Function { func mathConstantsFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Math::Pi", + Name: "math_pi", Args: []*catalog.Argument{}, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::E", + Name: "math_e", Args: []*catalog.Argument{}, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Eps", + Name: "math_eps", Args: []*catalog.Argument{}, ReturnType: &ast.TypeName{Name: "Double"}, }, @@ -45,21 +45,21 @@ func mathConstantsFuncs() []*catalog.Function { func mathCheckFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Math::IsInf", + Name: "math_isinf", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Math::IsNaN", + Name: "math_isnan", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Math::IsFinite", + Name: "math_isfinite", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, @@ -71,203 +71,203 @@ func mathCheckFuncs() []*catalog.Function { func mathUnaryFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Math::Abs", + Name: "math_abs", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Acos", + Name: "math_acos", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Asin", + Name: "math_asin", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Asinh", + Name: "math_asinh", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Atan", + Name: "math_atan", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Cbrt", + Name: "math_cbrt", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Ceil", + Name: "math_ceil", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Cos", + Name: "math_cos", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Cosh", + Name: "math_cosh", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Erf", + Name: "math_erf", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::ErfInv", + Name: "math_erfinv", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::ErfcInv", + Name: "math_erfcinv", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Exp", + Name: "math_exp", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Exp2", + Name: "math_exp2", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Fabs", + Name: "math_fabs", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Floor", + Name: "math_floor", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Lgamma", + Name: "math_lgamma", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Rint", + Name: "math_rint", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Sigmoid", + Name: "math_sigmoid", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Sin", + Name: "math_sin", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Sinh", + Name: "math_sinh", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Sqrt", + Name: "math_sqrt", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Tan", + Name: "math_tan", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Tanh", + Name: "math_tanh", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Tgamma", + Name: "math_tgamma", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Trunc", + Name: "math_trunc", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Log", + Name: "math_log", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Log2", + Name: "math_log2", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Log10", + Name: "math_log10", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, @@ -279,7 +279,7 @@ func mathUnaryFuncs() []*catalog.Function { func mathBinaryFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Math::Atan2", + Name: "math_atan2", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Double"}}, @@ -287,7 +287,7 @@ func mathBinaryFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Fmod", + Name: "math_fmod", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Double"}}, @@ -295,7 +295,7 @@ func mathBinaryFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Hypot", + Name: "math_hypot", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Double"}}, @@ -303,7 +303,7 @@ func mathBinaryFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Pow", + Name: "math_pow", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Double"}}, @@ -311,7 +311,7 @@ func mathBinaryFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Remainder", + Name: "math_remainder", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Double"}}, @@ -324,7 +324,7 @@ func mathBinaryFuncs() []*catalog.Function { func mathLdexpFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Math::Ldexp", + Name: "math_ldexp", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Int32"}}, @@ -337,14 +337,14 @@ func mathLdexpFuncs() []*catalog.Function { func mathRoundFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Math::Round", + Name: "math_round", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, }, ReturnType: &ast.TypeName{Name: "Double"}, }, { - Name: "Math::Round", + Name: "math_round", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Int32"}}, @@ -357,7 +357,7 @@ func mathRoundFuncs() []*catalog.Function { func mathFuzzyEqualsFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Math::FuzzyEquals", + Name: "math_fuzzyequals", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Double"}}, @@ -365,7 +365,7 @@ func mathFuzzyEqualsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Math::FuzzyEquals", + Name: "math_fuzzyequals", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "Double"}}, @@ -379,7 +379,7 @@ func mathFuzzyEqualsFuncs() []*catalog.Function { func mathModRemFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Math::Mod", + Name: "math_mod", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, {Type: &ast.TypeName{Name: "Int64"}}, @@ -388,7 +388,7 @@ func mathModRemFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Math::Rem", + Name: "math_rem", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Int64"}}, {Type: &ast.TypeName{Name: "Int64"}}, @@ -402,22 +402,22 @@ func mathModRemFuncs() []*catalog.Function { func mathRoundingModeFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Math::RoundDownward", + Name: "math_rounddownward", Args: []*catalog.Argument{}, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Math::RoundToNearest", + Name: "math_roundtonearest", Args: []*catalog.Argument{}, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Math::RoundTowardZero", + Name: "math_roundtowardzero", Args: []*catalog.Argument{}, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Math::RoundUpward", + Name: "math_roundupward", Args: []*catalog.Argument{}, ReturnType: &ast.TypeName{Name: "any"}, }, @@ -427,7 +427,7 @@ func mathRoundingModeFuncs() []*catalog.Function { func mathNearbyIntFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Math::NearbyInt", + Name: "math_nearbyint", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Double"}}, {Type: &ast.TypeName{Name: "any"}}, diff --git a/internal/engine/ydb/lib/cpp/pcre.go b/internal/engine/ydb/lib/cpp/pcre.go index 4b313ff80f..09b7e7ce55 100644 --- a/internal/engine/ydb/lib/cpp/pcre.go +++ b/internal/engine/ydb/lib/cpp/pcre.go @@ -21,7 +21,7 @@ func PcreFunctions() []*catalog.Function { func pcreGrepFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pcre::Grep", + Name: "pcre_grep", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -33,7 +33,7 @@ func pcreGrepFuncs() []*catalog.Function { func pcreMatchFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pcre::Match", + Name: "pcre_match", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -45,14 +45,14 @@ func pcreMatchFuncs() []*catalog.Function { func pcreBacktrackingFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pcre::BacktrackingGrep", + Name: "pcre_backtrackinggrep", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Pcre::BacktrackingMatch", + Name: "pcre_backtrackingmatch", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -64,14 +64,14 @@ func pcreBacktrackingFuncs() []*catalog.Function { func pcreMultiFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pcre::MultiGrep", + Name: "pcre_multigrep", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Pcre::MultiMatch", + Name: "pcre_multimatch", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -83,7 +83,7 @@ func pcreMultiFuncs() []*catalog.Function { func pcreCaptureFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pcre::Capture", + Name: "pcre_capture", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -95,7 +95,7 @@ func pcreCaptureFuncs() []*catalog.Function { func pcreReplaceFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pcre::Replace", + Name: "pcre_replace", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, diff --git a/internal/engine/ydb/lib/cpp/pire.go b/internal/engine/ydb/lib/cpp/pire.go index ae7eece256..f29cde64de 100644 --- a/internal/engine/ydb/lib/cpp/pire.go +++ b/internal/engine/ydb/lib/cpp/pire.go @@ -20,7 +20,7 @@ func PireFunctions() []*catalog.Function { func pireGrepFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pire::Grep", + Name: "pire_grep", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -32,7 +32,7 @@ func pireGrepFuncs() []*catalog.Function { func pireMatchFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pire::Match", + Name: "pire_match", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -44,14 +44,14 @@ func pireMatchFuncs() []*catalog.Function { func pireMultiFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pire::MultiGrep", + Name: "pire_multigrep", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Pire::MultiMatch", + Name: "pire_multimatch", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -63,7 +63,7 @@ func pireMultiFuncs() []*catalog.Function { func pireCaptureFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pire::Capture", + Name: "pire_capture", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -75,7 +75,7 @@ func pireCaptureFuncs() []*catalog.Function { func pireReplaceFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Pire::Replace", + Name: "pire_replace", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, diff --git a/internal/engine/ydb/lib/cpp/re2.go b/internal/engine/ydb/lib/cpp/re2.go index 667c0f57e0..d3a83a1f6f 100644 --- a/internal/engine/ydb/lib/cpp/re2.go +++ b/internal/engine/ydb/lib/cpp/re2.go @@ -22,14 +22,14 @@ func Re2Functions() []*catalog.Function { func re2GrepFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Re2::Grep", + Name: "re2_grep", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Grep", + Name: "re2_grep", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -42,14 +42,14 @@ func re2GrepFuncs() []*catalog.Function { func re2MatchFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Re2::Match", + Name: "re2_match", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Match", + Name: "re2_match", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -62,14 +62,14 @@ func re2MatchFuncs() []*catalog.Function { func re2CaptureFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Re2::Capture", + Name: "re2_capture", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Capture", + Name: "re2_capture", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -82,14 +82,14 @@ func re2CaptureFuncs() []*catalog.Function { func re2FindAndConsumeFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Re2::FindAndConsume", + Name: "re2_findandconsume", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::FindAndConsume", + Name: "re2_findandconsume", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -102,14 +102,14 @@ func re2FindAndConsumeFuncs() []*catalog.Function { func re2ReplaceFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Re2::Replace", + Name: "re2_replace", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Replace", + Name: "re2_replace", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -122,14 +122,14 @@ func re2ReplaceFuncs() []*catalog.Function { func re2CountFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Re2::Count", + Name: "re2_count", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Count", + Name: "re2_count", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -142,19 +142,19 @@ func re2CountFuncs() []*catalog.Function { func re2OptionsFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{}, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -162,7 +162,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -171,7 +171,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -181,7 +181,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -192,7 +192,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -204,7 +204,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -217,7 +217,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -231,7 +231,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -246,7 +246,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -262,7 +262,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -279,7 +279,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -297,7 +297,7 @@ func re2OptionsFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Re2::Options", + Name: "re2_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, diff --git a/internal/engine/ydb/lib/cpp/string.go b/internal/engine/ydb/lib/cpp/string.go index 291dd10eec..cc5fa4aef4 100644 --- a/internal/engine/ydb/lib/cpp/string.go +++ b/internal/engine/ydb/lib/cpp/string.go @@ -21,14 +21,14 @@ func StringFunctions() []*catalog.Function { func stringBase32Funcs() []*catalog.Function { return []*catalog.Function{ { - Name: "String::Base32Encode", + Name: "string_base32encode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "String::Base32Decode", + Name: "string_base32decode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -36,7 +36,7 @@ func stringBase32Funcs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "String::Base32StrictDecode", + Name: "string_base32strictdecode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -49,14 +49,14 @@ func stringBase32Funcs() []*catalog.Function { func stringBase64Funcs() []*catalog.Function { return []*catalog.Function{ { - Name: "String::Base64Encode", + Name: "string_base64encode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "String::Base64Decode", + Name: "string_base64decode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -64,7 +64,7 @@ func stringBase64Funcs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "String::Base64StrictDecode", + Name: "string_base64strictdecode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -77,14 +77,14 @@ func stringBase64Funcs() []*catalog.Function { func stringEscapeFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "String::EscapeC", + Name: "string_escapec", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "String::UnescapeC", + Name: "string_unescapec", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -96,14 +96,14 @@ func stringEscapeFuncs() []*catalog.Function { func stringHexFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "String::HexEncode", + Name: "string_hexencode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "String::HexDecode", + Name: "string_hexdecode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -116,14 +116,14 @@ func stringHexFuncs() []*catalog.Function { func stringHtmlFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "String::EncodeHtml", + Name: "string_encodehtml", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "String::DecodeHtml", + Name: "string_decodehtml", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -135,14 +135,14 @@ func stringHtmlFuncs() []*catalog.Function { func stringCgiFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "String::CgiEscape", + Name: "string_cgiescape", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "String::CgiUnescape", + Name: "string_cgiunescape", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, diff --git a/internal/engine/ydb/lib/cpp/unicode.go b/internal/engine/ydb/lib/cpp/unicode.go index e8c967020d..9a722fef76 100644 --- a/internal/engine/ydb/lib/cpp/unicode.go +++ b/internal/engine/ydb/lib/cpp/unicode.go @@ -33,7 +33,7 @@ func UnicodeFunctions() []*catalog.Function { func unicodeCheckFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::IsUtf", + Name: "unicode_isutf", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -45,7 +45,7 @@ func unicodeCheckFuncs() []*catalog.Function { func unicodeLengthFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::GetLength", + Name: "unicode_getlength", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, @@ -57,7 +57,7 @@ func unicodeLengthFuncs() []*catalog.Function { func unicodeFindFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::Find", + Name: "unicode_find", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -66,7 +66,7 @@ func unicodeFindFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Unicode::Find", + Name: "unicode_find", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -76,7 +76,7 @@ func unicodeFindFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Unicode::RFind", + Name: "unicode_rfind", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -85,7 +85,7 @@ func unicodeFindFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Unicode::RFind", + Name: "unicode_rfind", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -100,7 +100,7 @@ func unicodeFindFuncs() []*catalog.Function { func unicodeSubstringFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::Substring", + Name: "unicode_substring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Uint64"}}, @@ -114,35 +114,35 @@ func unicodeSubstringFuncs() []*catalog.Function { func unicodeNormalizeFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::Normalize", + Name: "unicode_normalize", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::NormalizeNFD", + Name: "unicode_normalizenfd", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::NormalizeNFC", + Name: "unicode_normalizenfc", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::NormalizeNFKD", + Name: "unicode_normalizenfkd", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::NormalizeNFKC", + Name: "unicode_normalizenfkc", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, @@ -154,14 +154,14 @@ func unicodeNormalizeFuncs() []*catalog.Function { func unicodeTranslitFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::Translit", + Name: "unicode_translit", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::Translit", + Name: "unicode_translit", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -174,7 +174,7 @@ func unicodeTranslitFuncs() []*catalog.Function { func unicodeLevensteinFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::LevensteinDistance", + Name: "unicode_levensteindistance", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -187,14 +187,14 @@ func unicodeLevensteinFuncs() []*catalog.Function { func unicodeFoldFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::Fold", + Name: "unicode_fold", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::Fold", + Name: "unicode_fold", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -202,7 +202,7 @@ func unicodeFoldFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::Fold", + Name: "unicode_fold", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -211,7 +211,7 @@ func unicodeFoldFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::Fold", + Name: "unicode_fold", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -221,7 +221,7 @@ func unicodeFoldFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::Fold", + Name: "unicode_fold", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -232,7 +232,7 @@ func unicodeFoldFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::Fold", + Name: "unicode_fold", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -249,7 +249,7 @@ func unicodeFoldFuncs() []*catalog.Function { func unicodeReplaceFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::ReplaceAll", + Name: "unicode_replaceall", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -258,7 +258,7 @@ func unicodeReplaceFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::ReplaceFirst", + Name: "unicode_replacefirst", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -267,7 +267,7 @@ func unicodeReplaceFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::ReplaceLast", + Name: "unicode_replacelast", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -281,7 +281,7 @@ func unicodeReplaceFuncs() []*catalog.Function { func unicodeRemoveFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::RemoveAll", + Name: "unicode_removeall", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -289,7 +289,7 @@ func unicodeRemoveFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::RemoveFirst", + Name: "unicode_removefirst", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -297,7 +297,7 @@ func unicodeRemoveFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::RemoveLast", + Name: "unicode_removelast", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -310,14 +310,14 @@ func unicodeRemoveFuncs() []*catalog.Function { func unicodeCodePointFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::ToCodePointList", + Name: "unicode_tocodepointlist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Unicode::FromCodePointList", + Name: "unicode_fromcodepointlist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -329,7 +329,7 @@ func unicodeCodePointFuncs() []*catalog.Function { func unicodeReverseFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::Reverse", + Name: "unicode_reverse", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, @@ -341,21 +341,21 @@ func unicodeReverseFuncs() []*catalog.Function { func unicodeCaseFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::ToLower", + Name: "unicode_tolower", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::ToUpper", + Name: "unicode_toupper", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Utf8"}, }, { - Name: "Unicode::ToTitle", + Name: "unicode_totitle", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, @@ -367,7 +367,7 @@ func unicodeCaseFuncs() []*catalog.Function { func unicodeSplitJoinFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::SplitToList", + Name: "unicode_splittolist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -375,7 +375,7 @@ func unicodeSplitJoinFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Unicode::SplitToList", + Name: "unicode_splittolist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -384,7 +384,7 @@ func unicodeSplitJoinFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Unicode::SplitToList", + Name: "unicode_splittolist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -394,7 +394,7 @@ func unicodeSplitJoinFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Unicode::SplitToList", + Name: "unicode_splittolist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -405,7 +405,7 @@ func unicodeSplitJoinFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Unicode::JoinFromList", + Name: "unicode_joinfromlist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "Utf8"}}, @@ -418,14 +418,14 @@ func unicodeSplitJoinFuncs() []*catalog.Function { func unicodeToUint64Funcs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::ToUint64", + Name: "unicode_touint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Unicode::ToUint64", + Name: "unicode_touint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Uint16"}}, @@ -433,7 +433,7 @@ func unicodeToUint64Funcs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Unicode::TryToUint64", + Name: "unicode_trytouint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, @@ -441,7 +441,7 @@ func unicodeToUint64Funcs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Unicode::TryToUint64", + Name: "unicode_trytouint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Uint16"}}, @@ -455,7 +455,7 @@ func unicodeToUint64Funcs() []*catalog.Function { func unicodeStripFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::Strip", + Name: "unicode_strip", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, @@ -467,49 +467,49 @@ func unicodeStripFuncs() []*catalog.Function { func unicodeIsFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::IsAscii", + Name: "unicode_isascii", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Unicode::IsSpace", + Name: "unicode_isspace", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Unicode::IsUpper", + Name: "unicode_isupper", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Unicode::IsLower", + Name: "unicode_islower", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Unicode::IsAlpha", + Name: "unicode_isalpha", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Unicode::IsAlnum", + Name: "unicode_isalnum", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Unicode::IsHex", + Name: "unicode_ishex", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, }, @@ -521,7 +521,7 @@ func unicodeIsFuncs() []*catalog.Function { func unicodeIsUnicodeSetFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Unicode::IsUnicodeSet", + Name: "unicode_isunicodeset", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Utf8"}}, {Type: &ast.TypeName{Name: "Utf8"}}, diff --git a/internal/engine/ydb/lib/cpp/url.go b/internal/engine/ydb/lib/cpp/url.go index 151115a8f0..325952de74 100644 --- a/internal/engine/ydb/lib/cpp/url.go +++ b/internal/engine/ydb/lib/cpp/url.go @@ -23,7 +23,7 @@ func UrlFunctions() []*catalog.Function { func urlNormalizeFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Url::Normalize", + Name: "url_normalize", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -31,7 +31,7 @@ func urlNormalizeFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::NormalizeWithDefaultHttpScheme", + Name: "url_normalizewithdefaulthttpscheme", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -44,7 +44,7 @@ func urlNormalizeFuncs() []*catalog.Function { func urlEncodeDecodeFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Url::Encode", + Name: "url_encode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -52,7 +52,7 @@ func urlEncodeDecodeFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::Decode", + Name: "url_decode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -65,7 +65,7 @@ func urlEncodeDecodeFuncs() []*catalog.Function { func urlParseFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Url::Parse", + Name: "url_parse", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -77,14 +77,14 @@ func urlParseFuncs() []*catalog.Function { func urlGetFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Url::GetScheme", + Name: "url_getscheme", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "Url::GetHost", + Name: "url_gethost", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -92,7 +92,7 @@ func urlGetFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::GetHostPort", + Name: "url_gethostport", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -100,7 +100,7 @@ func urlGetFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::GetSchemeHost", + Name: "url_getschemehost", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -108,7 +108,7 @@ func urlGetFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::GetSchemeHostPort", + Name: "url_getschemehostport", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -116,7 +116,7 @@ func urlGetFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::GetPort", + Name: "url_getport", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -124,7 +124,7 @@ func urlGetFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::GetTail", + Name: "url_gettail", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -132,7 +132,7 @@ func urlGetFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::GetPath", + Name: "url_getpath", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -140,7 +140,7 @@ func urlGetFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::GetFragment", + Name: "url_getfragment", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -148,7 +148,7 @@ func urlGetFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::GetCGIParam", + Name: "url_getcgiparam", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -157,7 +157,7 @@ func urlGetFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::GetDomain", + Name: "url_getdomain", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Uint8"}}, @@ -171,42 +171,42 @@ func urlGetFuncs() []*catalog.Function { func urlDomainFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Url::GetTLD", + Name: "url_gettld", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "Url::IsKnownTLD", + Name: "url_isknowntld", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Url::IsWellKnownTLD", + Name: "url_iswellknowntld", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Url::GetDomainLevel", + Name: "url_getdomainlevel", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "Uint64"}, }, { - Name: "Url::GetSignificantDomain", + Name: "url_getsignificantdomain", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "Url::GetSignificantDomain", + Name: "url_getsignificantdomain", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -214,7 +214,7 @@ func urlDomainFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "Url::GetOwner", + Name: "url_getowner", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -226,7 +226,7 @@ func urlDomainFuncs() []*catalog.Function { func urlCutFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Url::CutScheme", + Name: "url_cutscheme", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -234,7 +234,7 @@ func urlCutFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::CutWWW", + Name: "url_cutwww", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -242,7 +242,7 @@ func urlCutFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::CutWWW2", + Name: "url_cutwww2", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -250,7 +250,7 @@ func urlCutFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::CutQueryStringAndFragment", + Name: "url_cutquerystringandfragment", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -262,7 +262,7 @@ func urlCutFuncs() []*catalog.Function { func urlPunycodeFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Url::HostNameToPunycode", + Name: "url_hostnametopunycode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -270,14 +270,14 @@ func urlPunycodeFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::ForceHostNameToPunycode", + Name: "url_forcehostnametopunycode", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "Url::PunycodeToHostName", + Name: "url_punycodetohostname", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -285,14 +285,14 @@ func urlPunycodeFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Url::ForcePunycodeToHostName", + Name: "url_forcepunycodetohostname", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "Url::CanBePunycodeHostName", + Name: "url_canbepunycodehostname", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -305,14 +305,14 @@ func urlQueryStringFuncs() []*catalog.Function { // fixme: rewrite with containers if possible return []*catalog.Function{ { - Name: "Url::QueryStringToList", + Name: "url_querystringtolist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Url::QueryStringToList", + Name: "url_querystringtolist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -320,7 +320,7 @@ func urlQueryStringFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Url::QueryStringToList", + Name: "url_querystringtolist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -329,7 +329,7 @@ func urlQueryStringFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Url::QueryStringToList", + Name: "url_querystringtolist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -339,7 +339,7 @@ func urlQueryStringFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Url::QueryStringToList", + Name: "url_querystringtolist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -350,14 +350,14 @@ func urlQueryStringFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Url::QueryStringToDict", + Name: "url_querystringtodict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Url::QueryStringToDict", + Name: "url_querystringtodict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -365,7 +365,7 @@ func urlQueryStringFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Url::QueryStringToDict", + Name: "url_querystringtodict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -374,7 +374,7 @@ func urlQueryStringFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Url::QueryStringToDict", + Name: "url_querystringtodict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -384,7 +384,7 @@ func urlQueryStringFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Url::QueryStringToDict", + Name: "url_querystringtodict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, {Type: &ast.TypeName{Name: "Bool"}}, @@ -395,14 +395,14 @@ func urlQueryStringFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Url::BuildQueryString", + Name: "url_buildquerystring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "String"}, }, { - Name: "Url::BuildQueryString", + Name: "url_buildquerystring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, diff --git a/internal/engine/ydb/lib/cpp/yson.go b/internal/engine/ydb/lib/cpp/yson.go index 78332e0f29..60897f9052 100644 --- a/internal/engine/ydb/lib/cpp/yson.go +++ b/internal/engine/ydb/lib/cpp/yson.go @@ -31,28 +31,28 @@ func YsonFunctions() []*catalog.Function { func ysonParseFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::Parse", + Name: "yson_parse", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Yson"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ParseJson", + Name: "yson_parsejson", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Json"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ParseJsonDecodeUtf8", + Name: "yson_parsejsondecodeutf8", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Json"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::Parse", + Name: "yson_parse", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -60,7 +60,7 @@ func ysonParseFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::ParseJson", + Name: "yson_parsejson", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -68,7 +68,7 @@ func ysonParseFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::ParseJsonDecodeUtf8", + Name: "yson_parsejsondecodeutf8", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "String"}}, }, @@ -81,7 +81,7 @@ func ysonParseFuncs() []*catalog.Function { func ysonFromFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::From", + Name: "yson_from", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -93,7 +93,7 @@ func ysonFromFuncs() []*catalog.Function { func ysonWithAttributesFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::WithAttributes", + Name: "yson_withattributes", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -107,7 +107,7 @@ func ysonWithAttributesFuncs() []*catalog.Function { func ysonEqualsFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::Equals", + Name: "yson_equals", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -120,7 +120,7 @@ func ysonEqualsFuncs() []*catalog.Function { func ysonGetHashFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::GetHash", + Name: "yson_gethash", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -132,56 +132,56 @@ func ysonGetHashFuncs() []*catalog.Function { func ysonIsFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::IsEntity", + Name: "yson_isentity", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Yson::IsString", + Name: "yson_isstring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Yson::IsDouble", + Name: "yson_isdouble", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Yson::IsUint64", + Name: "yson_isuint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Yson::IsInt64", + Name: "yson_isint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Yson::IsBool", + Name: "yson_isbool", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Yson::IsList", + Name: "yson_islist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Bool"}, }, { - Name: "Yson::IsDict", + Name: "yson_isdict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -193,7 +193,7 @@ func ysonIsFuncs() []*catalog.Function { func ysonGetLengthFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::GetLength", + Name: "yson_getlength", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -206,7 +206,7 @@ func ysonGetLengthFuncs() []*catalog.Function { func ysonConvertToFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::ConvertTo", + Name: "yson_convertto", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -214,7 +214,7 @@ func ysonConvertToFuncs() []*catalog.Function { ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ConvertToBool", + Name: "yson_converttobool", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -222,7 +222,7 @@ func ysonConvertToFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::ConvertToInt64", + Name: "yson_converttoint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -230,7 +230,7 @@ func ysonConvertToFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::ConvertToUint64", + Name: "yson_converttouint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -238,7 +238,7 @@ func ysonConvertToFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::ConvertToDouble", + Name: "yson_converttodouble", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -246,7 +246,7 @@ func ysonConvertToFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::ConvertToString", + Name: "yson_converttostring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -254,7 +254,7 @@ func ysonConvertToFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::ConvertToList", + Name: "yson_converttolist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -266,35 +266,35 @@ func ysonConvertToFuncs() []*catalog.Function { func ysonConvertToListFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::ConvertToBoolList", + Name: "yson_converttoboollist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ConvertToInt64List", + Name: "yson_converttoint64list", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ConvertToUint64List", + Name: "yson_converttouint64list", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ConvertToDoubleList", + Name: "yson_converttodoublelist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ConvertToStringList", + Name: "yson_converttostringlist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -306,42 +306,42 @@ func ysonConvertToListFuncs() []*catalog.Function { func ysonConvertToDictFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::ConvertToDict", + Name: "yson_converttodict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ConvertToBoolDict", + Name: "yson_converttobooldict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ConvertToInt64Dict", + Name: "yson_converttoint64dict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ConvertToUint64Dict", + Name: "yson_converttouint64dict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ConvertToDoubleDict", + Name: "yson_converttodoubledict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::ConvertToStringDict", + Name: "yson_converttostringdict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -353,7 +353,7 @@ func ysonConvertToDictFuncs() []*catalog.Function { func ysonContainsFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::Contains", + Name: "yson_contains", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -367,7 +367,7 @@ func ysonContainsFuncs() []*catalog.Function { func ysonLookupFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::Lookup", + Name: "yson_lookup", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -376,7 +376,7 @@ func ysonLookupFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::LookupBool", + Name: "yson_lookupbool", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -385,7 +385,7 @@ func ysonLookupFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::LookupInt64", + Name: "yson_lookupint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -394,7 +394,7 @@ func ysonLookupFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::LookupUint64", + Name: "yson_lookupuint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -403,7 +403,7 @@ func ysonLookupFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::LookupDouble", + Name: "yson_lookupdouble", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -412,7 +412,7 @@ func ysonLookupFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::LookupString", + Name: "yson_lookupstring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -421,7 +421,7 @@ func ysonLookupFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::LookupDict", + Name: "yson_lookupdict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -430,7 +430,7 @@ func ysonLookupFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::LookupList", + Name: "yson_lookuplist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -444,7 +444,7 @@ func ysonLookupFuncs() []*catalog.Function { func ysonYPathFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::YPath", + Name: "yson_ypath", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -453,7 +453,7 @@ func ysonYPathFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::YPathBool", + Name: "yson_ypathbool", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -462,7 +462,7 @@ func ysonYPathFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::YPathInt64", + Name: "yson_ypathint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -471,7 +471,7 @@ func ysonYPathFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::YPathUint64", + Name: "yson_ypathuint64", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -480,7 +480,7 @@ func ysonYPathFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::YPathDouble", + Name: "yson_ypathdouble", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -489,7 +489,7 @@ func ysonYPathFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::YPathString", + Name: "yson_ypathstring", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -498,7 +498,7 @@ func ysonYPathFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::YPathDict", + Name: "yson_ypathdict", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -507,7 +507,7 @@ func ysonYPathFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::YPathList", + Name: "yson_ypathlist", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "String"}}, @@ -521,7 +521,7 @@ func ysonYPathFuncs() []*catalog.Function { func ysonAttributesFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::Attributes", + Name: "yson_attributes", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -533,28 +533,28 @@ func ysonAttributesFuncs() []*catalog.Function { func ysonSerializeFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::Serialize", + Name: "yson_serialize", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Yson"}, }, { - Name: "Yson::SerializeText", + Name: "yson_serializetext", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Yson"}, }, { - Name: "Yson::SerializePretty", + Name: "yson_serializepretty", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, ReturnType: &ast.TypeName{Name: "Yson"}, }, { - Name: "Yson::SerializeJson", + Name: "yson_serializejson", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, }, @@ -562,7 +562,7 @@ func ysonSerializeFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::SerializeJson", + Name: "yson_serializejson", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -571,7 +571,7 @@ func ysonSerializeFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::SerializeJson", + Name: "yson_serializejson", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -581,7 +581,7 @@ func ysonSerializeFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::SerializeJson", + Name: "yson_serializejson", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -592,7 +592,7 @@ func ysonSerializeFuncs() []*catalog.Function { ReturnTypeNullable: true, }, { - Name: "Yson::SerializeJson", + Name: "yson_serializejson", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "any"}}, {Type: &ast.TypeName{Name: "any"}}, @@ -609,19 +609,19 @@ func ysonSerializeFuncs() []*catalog.Function { func ysonOptionsFuncs() []*catalog.Function { return []*catalog.Function{ { - Name: "Yson::Options", + Name: "yson_options", Args: []*catalog.Argument{}, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::Options", + Name: "yson_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, }, ReturnType: &ast.TypeName{Name: "any"}, }, { - Name: "Yson::Options", + Name: "yson_options", Args: []*catalog.Argument{ {Type: &ast.TypeName{Name: "Bool"}}, {Type: &ast.TypeName{Name: "Bool"}}, diff --git a/internal/engine/ydb/parse.go b/internal/engine/ydb/parse.go index 8fbdd81ebb..5d383958a1 100755 --- a/internal/engine/ydb/parse.go +++ b/internal/engine/ydb/parse.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io" + "strings" "github.com/antlr4-go/antlr/v4" "github.com/sqlc-dev/sqlc/internal/source" @@ -43,6 +44,9 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { return nil, err } content := string(blob) + if strings.TrimSpace(content) == "" { + return nil, nil + } input := antlr.NewInputStream(content) lexer := parser.NewYQLLexer(input) stream := antlr.NewCommonTokenStream(lexer, 0) @@ -69,11 +73,11 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { return nil, fmt.Errorf("expected ast.Node; got %T", out) } if _, ok := out.(*ast.TODO); ok { - loc = byteOffset(content, stmt.GetStop().GetStop() + 2) + loc = byteOffset(content, stmt.GetStop().GetStop()+2) continue } if out != nil { - len := byteOffset(content, stmt.GetStop().GetStop() + 1) - loc + len := byteOffset(content, stmt.GetStop().GetStop()+1) - loc stmts = append(stmts, ast.Statement{ Raw: &ast.RawStmt{ Stmt: out, @@ -81,7 +85,7 @@ func (p *Parser) Parse(r io.Reader) ([]ast.Statement, error) { StmtLen: len, }, }) - loc = byteOffset(content, stmt.GetStop().GetStop() + 2) + loc = byteOffset(content, stmt.GetStop().GetStop()+2) } } } diff --git a/internal/engine/ydb/stdlib.go b/internal/engine/ydb/stdlib.go index 69ef6b223e..8abf4c7f96 100644 --- a/internal/engine/ydb/stdlib.go +++ b/internal/engine/ydb/stdlib.go @@ -15,7 +15,6 @@ func defaultSchema(name string) *catalog.Schema { s.Funcs = append(s.Funcs, lib.AggregateFunctions()...) s.Funcs = append(s.Funcs, lib.WindowFunctions()...) s.Funcs = append(s.Funcs, lib.CppFunctions()...) - // TODO: add container functions if return s diff --git a/internal/engine/ydb/utils.go b/internal/engine/ydb/utils.go index 8f118df09b..c1f25fe610 100755 --- a/internal/engine/ydb/utils.go +++ b/internal/engine/ydb/utils.go @@ -295,3 +295,50 @@ func (c *cc) collectEqualityOps(ctx parser.ICond_exprContext) []antlr.TerminalNo } return ops } + +// parseStringLiteral parses a string literal from a YQL query and returns the value and whether it has a suffix. +// If a valid suffix is found, it is stripped and the content is returned. +// FIXME: rewrite this logic to correctly handle the type based on the suffix. +func parseStringLiteral(s string) (value string, hasSuffix bool) { + if len(s) < 2 { + return s, false + } + + quote := s[0] + if quote != '\'' && quote != '"' { + return s, false + } + + quotePos := -1 + for i := len(s) - 1; i >= 0; i-- { + if s[i] == quote { + quotePos = i + break + } + } + + if quotePos == -1 || quotePos == 0 { + return s, false + } + + content := s[1:quotePos] + + if quotePos < len(s)-1 { + suffix := s[quotePos+1:] + if isValidYDBStringSuffix(suffix) { + return content, true + } + } + + return content, false +} + +func isValidYDBStringSuffix(suffix string) bool { + switch suffix { + case "s", "S", "u", "U", "y", "Y", "j", "J", + "pt", "PT", "pb", "PB", "pv", "PV": + return true + default: + return false + } +} From 08424e0249d8a4a7839da467456d0538caaca4c5 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Mon, 27 Oct 2025 16:25:01 +0300 Subject: [PATCH 20/22] Resolved go.mod && go.sum --- go.sum | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/go.sum b/go.sum index 64b6dbd933..b826002fd7 100644 --- a/go.sum +++ b/go.sum @@ -296,6 +296,7 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM= golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o= golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -306,6 +307,10 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ= golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= From be13a379bc0da8ca9377d8ab5fde92578c30923e Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov Date: Mon, 27 Oct 2025 16:33:34 +0300 Subject: [PATCH 21/22] Fixed builtins test --- internal/endtoend/testdata/builtins/ydb/go/query.sql.go | 2 +- internal/endtoend/testdata/builtins/ydb/query.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/endtoend/testdata/builtins/ydb/go/query.sql.go b/internal/endtoend/testdata/builtins/ydb/go/query.sql.go index ccae911039..6a9f875214 100644 --- a/internal/endtoend/testdata/builtins/ydb/go/query.sql.go +++ b/internal/endtoend/testdata/builtins/ydb/go/query.sql.go @@ -674,7 +674,7 @@ func (q *Queries) FUnicodeFind(ctx context.Context) (*uint64, error) { } const fUnicodeGetlength = `-- name: FUnicodeGetlength :one -SELECT Unicode::Getlength("привет") +SELECT Unicode::Getlength("你好") ` func (q *Queries) FUnicodeGetlength(ctx context.Context) (uint64, error) { diff --git a/internal/endtoend/testdata/builtins/ydb/query.sql b/internal/endtoend/testdata/builtins/ydb/query.sql index afcdf1dbb1..fd41a31332 100644 --- a/internal/endtoend/testdata/builtins/ydb/query.sql +++ b/internal/endtoend/testdata/builtins/ydb/query.sql @@ -128,7 +128,7 @@ SELECT DateTime::Intervalfromdays(7); -- name: FUnicodeIsutf :one SELECT Unicode::Isutf("hello"); -- name: FUnicodeGetlength :one -SELECT Unicode::Getlength("привет"); +SELECT Unicode::Getlength("你好"); -- name: FUnicodeFind :one SELECT Unicode::Find("hello", "ll"); -- name: FUnicodeRfind :one From 683926c7dd455e2da253bc31758017037ee03121 Mon Sep 17 00:00:00 2001 From: Viktor Pentyukhov <150552906+1NepuNep1@users.noreply.github.com> Date: Tue, 28 Oct 2025 02:48:29 +0300 Subject: [PATCH 22/22] Added docs and rewrited examples for ydb (#17) * Added docs and rewrited examples for ydb --- docs/tutorials/getting-started-ydb.md | 234 +++++++++++++ examples/authors/ydb/db_test.go | 107 ++---- examples/authors/ydb/models.go | 2 +- examples/authors/ydb/query.sql | 17 +- examples/authors/ydb/query.sql.go | 46 ++- examples/authors/ydb/schema.sql | 6 +- examples/booktest/sqlc.json | 8 + examples/booktest/ydb/db.go | 26 ++ examples/booktest/ydb/db_test.go | 148 ++++++++ examples/booktest/ydb/models.go | 25 ++ examples/booktest/ydb/query.sql | 63 ++++ examples/booktest/ydb/query.sql.go | 327 ++++++++++++++++++ examples/booktest/ydb/schema.sql | 18 + examples/jets/sqlc.json | 8 + examples/jets/ydb/db.go | 26 ++ examples/jets/ydb/db_test.go | 73 ++++ examples/jets/ydb/models.go | 28 ++ examples/jets/ydb/query-building.sql | 12 + examples/jets/ydb/query-building.sql.go | 73 ++++ examples/jets/ydb/schema.sql | 30 ++ examples/ondeck/sqlc.json | 11 + examples/ondeck/ydb/city.sql.go | 126 +++++++ examples/ondeck/ydb/db.go | 26 ++ examples/ondeck/ydb/db_test.go | 130 +++++++ examples/ondeck/ydb/models.go | 26 ++ examples/ondeck/ydb/querier.go | 29 ++ examples/ondeck/ydb/query/city.sql | 27 ++ examples/ondeck/ydb/query/venue.sql | 48 +++ examples/ondeck/ydb/schema/0001_city.sql | 6 + examples/ondeck/ydb/schema/0002_venue.sql | 13 + .../ondeck/ydb/schema/0003_add_column.sql | 4 + examples/ondeck/ydb/venue.sql.go | 230 ++++++++++++ .../templates/ydb-go-sdk/interfaceCode.tmpl | 20 +- internal/codegen/golang/ydb_type.go | 2 +- internal/sqltest/local/ydb.go | 19 +- 35 files changed, 1870 insertions(+), 124 deletions(-) create mode 100644 docs/tutorials/getting-started-ydb.md create mode 100644 examples/booktest/ydb/db.go create mode 100644 examples/booktest/ydb/db_test.go create mode 100644 examples/booktest/ydb/models.go create mode 100644 examples/booktest/ydb/query.sql create mode 100644 examples/booktest/ydb/query.sql.go create mode 100644 examples/booktest/ydb/schema.sql create mode 100644 examples/jets/ydb/db.go create mode 100644 examples/jets/ydb/db_test.go create mode 100644 examples/jets/ydb/models.go create mode 100644 examples/jets/ydb/query-building.sql create mode 100644 examples/jets/ydb/query-building.sql.go create mode 100644 examples/jets/ydb/schema.sql create mode 100644 examples/ondeck/ydb/city.sql.go create mode 100644 examples/ondeck/ydb/db.go create mode 100644 examples/ondeck/ydb/db_test.go create mode 100644 examples/ondeck/ydb/models.go create mode 100644 examples/ondeck/ydb/querier.go create mode 100644 examples/ondeck/ydb/query/city.sql create mode 100644 examples/ondeck/ydb/query/venue.sql create mode 100644 examples/ondeck/ydb/schema/0001_city.sql create mode 100644 examples/ondeck/ydb/schema/0002_venue.sql create mode 100644 examples/ondeck/ydb/schema/0003_add_column.sql create mode 100644 examples/ondeck/ydb/venue.sql.go diff --git a/docs/tutorials/getting-started-ydb.md b/docs/tutorials/getting-started-ydb.md new file mode 100644 index 0000000000..a8fdf85377 --- /dev/null +++ b/docs/tutorials/getting-started-ydb.md @@ -0,0 +1,234 @@ +# Getting started with YDB + +This tutorial assumes that the latest version of sqlc is +[installed](../overview/install.md) and ready to use. + +We'll generate Go code here, but other +[language plugins](../reference/language-support.rst) are available. You'll +naturally need the Go toolchain if you want to build and run a program with the +code sqlc generates, but sqlc itself has no dependencies. + +At the end, you'll push your SQL queries to [sqlc +Cloud](https://dashboard.sqlc.dev/) for further insights and analysis. + +## Setting up + +Create a new directory called `sqlc-tutorial` and open it up. + +Initialize a new Go module named `tutorial.sqlc.dev/app`: + +```shell +go mod init tutorial.sqlc.dev/app +``` + +sqlc looks for either a `sqlc.(yaml|yml)` or `sqlc.json` file in the current +directory. In our new directory, create a file named `sqlc.yaml` with the +following contents: + +```yaml +version: "2" +sql: + - engine: "ydb" + queries: "query.sql" + schema: "schema.sql" + gen: + go: + package: "tutorial" + out: "tutorial" +``` + +## Schema and queries + +sqlc needs to know your database schema and queries in order to generate code. +In the same directory, create a file named `schema.sql` with the following +content: + +```sql +CREATE TABLE authors ( + id Serial, + name Text NOT NULL, + bio Text, + PRIMARY KEY (id) +); +``` + +Next, create a `query.sql` file with the following five queries: + +```sql +-- name: GetAuthor :one +SELECT * FROM authors +WHERE id = $id LIMIT 1; + +-- name: ListAuthors :many +SELECT * FROM authors +ORDER BY name; + +-- name: CreateOrUpdateAuthor :one +UPSERT INTO authors (name, bio) +VALUES ( + $name, $bio +) +RETURNING *; + +-- name: DeleteAuthor :exec +DELETE FROM authors WHERE id = $id; + +-- name: DropTable :exec +DROP TABLE IF EXISTS authors; +``` + +Note that YDB uses named parameters (`$id`, `$name`, `$bio`) rather than +positional parameters. + +## Generating code + +You are now ready to generate code. You shouldn't see any output when you run +the `generate` subcommand, unless something goes wrong: + +```shell +sqlc generate +``` + +You should now have a `tutorial` subdirectory with three files containing Go +source code. These files comprise a Go package named `tutorial`: + +``` +├── go.mod +├── query.sql +├── schema.sql +├── sqlc.yaml +└── tutorial + ├── db.go + ├── models.go + └── query.sql.go +``` + +## Using generated code + +You can use your newly-generated `tutorial` package from any Go program. +Create a file named `tutorial.go` and add the following contents: + +```go +package main + +import ( + "context" + "log" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/query" + + "tutorial.sqlc.dev/app/tutorial" +) + +func ptr(s string) *string { + return &s +} + +func run() error { + ctx := context.Background() + + // Create YDB connection + // Replace with your actual YDB endpoint + db, err := ydb.Open(ctx, "grpcs://localhost:2136/local") + if err != nil { + return err + } + defer db.Close(ctx) + + queries := tutorial.New(db.Query()) + + // list all authors + authors, err := queries.ListAuthors(ctx) + if err != nil { + return err + } + log.Println(authors) + + // create an author + insertedAuthor, err := queries.CreateOrUpdateAuthor(ctx, tutorial.CreateOrUpdateAuthorParams{ + Name: "Brian Kernighan", + Bio: ptr("Co-author of The C Programming Language and The Go Programming Language"), + }, query.WithIdempotent()) + if err != nil { + return err + } + log.Println(insertedAuthor) + + // get the author we just inserted + fetchedAuthor, err := queries.GetAuthor(ctx, insertedAuthor.ID) + if err != nil { + return err + } + log.Println(fetchedAuthor) + return nil +} + +func main() { + if err := run(); err != nil { + log.Fatal(err) + } +} +``` + +Before this code will compile you'll need to fetch the relevant YDB driver: + +```shell +go get github.com/ydb-platform/ydb-go-sdk/v3 +go build ./... +``` + +The program should compile without errors. To make that possible, sqlc generates +readable, **idiomatic** Go code that you otherwise would've had to write +yourself. Take a look in `tutorial/query.sql.go`. + +Of course for this program to run successfully you'll need +to compile after replacing the database connection parameters in the call to +`ydb.Open()` with the correct parameters for your database. And your +database must have the `authors` table as defined in `schema.sql`. + +You should now have a working program using sqlc's generated Go source code, +and hopefully can see how you'd use sqlc in your own real-world applications. + +## Query verification (Not supported for YDB yet) + +[sqlc Cloud](https://dashboard.sqlc.dev) provides additional verification, catching subtle bugs. To get started, create a +[dashboard account](https://dashboard.sqlc.dev). Once you've signed in, create a +project and generate an auth token. Add your project's ID to the `cloud` block +to your sqlc.yaml. + +```yaml +version: "2" +cloud: + # Replace with your project ID from the sqlc Cloud dashboard + project: "" +sql: + - engine: "ydb" + queries: "query.sql" + schema: "schema.sql" + gen: + go: + package: "tutorial" + out: "tutorial" +``` + +Replace `` with your project ID from the sqlc Cloud dashboard. It +will look something like `01HA8SZH31HKYE9RR3N3N3TSJM`. + +And finally, set the `SQLC_AUTH_TOKEN` environment variable: + +```shell +export SQLC_AUTH_TOKEN="" +``` + +```shell +$ sqlc push --tag tutorial +``` + +In the sidebar, go to the "Queries" section to see your published queries. Run +`verify` to ensure that previously published queries continue to work against +updated database schema. + +```shell +$ sqlc verify --against tutorial +``` diff --git a/examples/authors/ydb/db_test.go b/examples/authors/ydb/db_test.go index ab5324e76d..88ae04caec 100644 --- a/examples/authors/ydb/db_test.go +++ b/examples/authors/ydb/db_test.go @@ -1,3 +1,4 @@ + package authors import ( @@ -15,86 +16,38 @@ func ptr(s string) *string { func TestAuthors(t *testing.T) { ctx := context.Background() - db := local.YDB(t, []string{"schema.sql"}) defer db.Close(ctx) q := New(db.Query()) - t.Run("InsertAuthors", func(t *testing.T) { - authorsToInsert := []CreateOrUpdateAuthorParams{ - {P0: 1, P1: "Leo Tolstoy", P2: ptr("Russian writer, author of \"War and Peace\"")}, - {P0: 2, P1: "Alexander Pushkin", P2: ptr("Author of \"Eugene Onegin\"")}, - {P0: 3, P1: "Alexander Pushkin", P2: ptr("Russian poet, playwright, and prose writer")}, - {P0: 4, P1: "Fyodor Dostoevsky", P2: ptr("Author of \"Crime and Punishment\"")}, - {P0: 5, P1: "Nikolai Gogol", P2: ptr("Author of \"Dead Souls\"")}, - {P0: 6, P1: "Anton Chekhov", P2: nil}, - {P0: 7, P1: "Ivan Turgenev", P2: ptr("Author of \"Fathers and Sons\"")}, - {P0: 8, P1: "Mikhail Lermontov", P2: nil}, - {P0: 9, P1: "Daniil Kharms", P2: ptr("Absurdist, writer and poet")}, - {P0: 10, P1: "Maxim Gorky", P2: ptr("Author of \"At the Bottom\"")}, - {P0: 11, P1: "Vladimir Mayakovsky", P2: nil}, - {P0: 12, P1: "Sergei Yesenin", P2: ptr("Russian lyric poet")}, - {P0: 13, P1: "Boris Pasternak", P2: ptr("Author of \"Doctor Zhivago\"")}, - } - - for _, author := range authorsToInsert { - if err := q.CreateOrUpdateAuthor(ctx, author, query.WithIdempotent()); err != nil { - t.Fatalf("failed to insert author %q: %v", author.P1, err) - } - } - }) - - t.Run("ListAuthors", func(t *testing.T) { - authors, err := q.ListAuthors(ctx) - if err != nil { - t.Fatal(err) - } - if len(authors) == 0 { - t.Fatal("expected at least one author, got none") - } - t.Log("Authors:") - for _, a := range authors { - bio := "Null" - if a.Bio != nil { - bio = *a.Bio - } - t.Logf("- ID: %d | Name: %s | Bio: %s", a.ID, a.Name, bio) - } - }) - - t.Run("GetAuthor", func(t *testing.T) { - singleAuthor, err := q.GetAuthor(ctx, 10) - if err != nil { - t.Fatal(err) - } - bio := "Null" - if singleAuthor.Bio != nil { - bio = *singleAuthor.Bio - } - t.Logf("- ID: %d | Name: %s | Bio: %s", singleAuthor.ID, singleAuthor.Name, bio) - }) - - t.Run("Delete All Authors", func(t *testing.T) { - var i uint64 - for i = 1; i <= 13; i++ { - if err := q.DeleteAuthor(ctx, i, query.WithIdempotent()); err != nil { - t.Fatalf("failed to delete author: %v", err) - } - } - authors, err := q.ListAuthors(ctx) - if err != nil { - t.Fatal(err) - } - if len(authors) != 0 { - t.Fatalf("expected no authors, got %d", len(authors)) - } - }) - - t.Run("Drop Table Authors", func(t *testing.T) { - err := q.DropTable(ctx) - if err != nil { - t.Fatal(err) - } - }) + // list all authors + authors, err := q.ListAuthors(ctx) + if err != nil { + t.Fatal(err) + } + t.Log(authors) + + // create an author + insertedAuthor, err := q.CreateOrUpdateAuthor(ctx, CreateOrUpdateAuthorParams{ + Name: "Brian Kernighan", + Bio: ptr("Co-author of The C Programming Language and The Go Programming Language"), + }, query.WithIdempotent()) + if err != nil { + t.Fatal(err) + } + t.Log(insertedAuthor) + + // get the author we just inserted + fetchedAuthor, err := q.GetAuthor(ctx, insertedAuthor.ID) + if err != nil { + t.Fatal(err) + } + t.Log(fetchedAuthor) + + // drop table + err = q.DropTable(ctx) + if err != nil { + t.Fatal(err) + } } diff --git a/examples/authors/ydb/models.go b/examples/authors/ydb/models.go index 2806beacfe..a0c2e18920 100644 --- a/examples/authors/ydb/models.go +++ b/examples/authors/ydb/models.go @@ -5,7 +5,7 @@ package authors type Author struct { - ID uint64 `json:"id"` + ID int32 `json:"id"` Name string `json:"name"` Bio *string `json:"bio"` } diff --git a/examples/authors/ydb/query.sql b/examples/authors/ydb/query.sql index 804150615d..34ee633a17 100644 --- a/examples/authors/ydb/query.sql +++ b/examples/authors/ydb/query.sql @@ -1,15 +1,20 @@ -- name: GetAuthor :one SELECT * FROM authors -WHERE id = $p0 LIMIT 1; +WHERE id = $id LIMIT 1; -- name: ListAuthors :many -SELECT * FROM authors ORDER BY name; +SELECT * FROM authors +ORDER BY name; --- name: CreateOrUpdateAuthor :exec -UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2); +-- name: CreateOrUpdateAuthor :one +UPSERT INTO authors (name, bio) +VALUES ( + $name, $bio +) +RETURNING *; -- name: DeleteAuthor :exec -DELETE FROM authors WHERE id = $p0; +DELETE FROM authors WHERE id = $id; -- name: DropTable :exec -DROP TABLE IF EXISTS authors; \ No newline at end of file +DROP TABLE IF EXISTS authors; diff --git a/examples/authors/ydb/query.sql.go b/examples/authors/ydb/query.sql.go index 6d3c6743a9..e460675c92 100644 --- a/examples/authors/ydb/query.sql.go +++ b/examples/authors/ydb/query.sql.go @@ -13,37 +13,44 @@ import ( "github.com/ydb-platform/ydb-go-sdk/v3/query" ) -const createOrUpdateAuthor = `-- name: CreateOrUpdateAuthor :exec -UPSERT INTO authors (id, name, bio) VALUES ($p0, $p1, $p2) +const createOrUpdateAuthor = `-- name: CreateOrUpdateAuthor :one +UPSERT INTO authors (name, bio) +VALUES ( + $name, $bio +) +RETURNING id, name, bio ` type CreateOrUpdateAuthorParams struct { - P0 uint64 `json:"p0"` - P1 string `json:"p1"` - P2 *string `json:"p2"` + Name string `json:"name"` + Bio *string `json:"bio"` } -func (q *Queries) CreateOrUpdateAuthor(ctx context.Context, arg CreateOrUpdateAuthorParams, opts ...query.ExecuteOption) error { +func (q *Queries) CreateOrUpdateAuthor(ctx context.Context, arg CreateOrUpdateAuthorParams, opts ...query.ExecuteOption) (Author, error) { parameters := ydb.ParamsBuilder() - parameters = parameters.Param("$p0").Uint64(arg.P0) - parameters = parameters.Param("$p1").Text(arg.P1) - parameters = parameters.Param("$p2").BeginOptional().Text(arg.P2).EndOptional() - err := q.db.Exec(ctx, createOrUpdateAuthor, + parameters = parameters.Param("$name").Text(arg.Name) + parameters = parameters.Param("$bio").BeginOptional().Text(arg.Bio).EndOptional() + row, err := q.db.QueryRow(ctx, createOrUpdateAuthor, append(opts, query.WithParameters(parameters.Build()))..., ) + var i Author if err != nil { - return xerrors.WithStackTrace(err) + return i, xerrors.WithStackTrace(err) } - return nil + err = row.Scan(&i.ID, &i.Name, &i.Bio) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil } const deleteAuthor = `-- name: DeleteAuthor :exec -DELETE FROM authors WHERE id = $p0 +DELETE FROM authors WHERE id = $id ` -func (q *Queries) DeleteAuthor(ctx context.Context, p0 uint64, opts ...query.ExecuteOption) error { +func (q *Queries) DeleteAuthor(ctx context.Context, id int32, opts ...query.ExecuteOption) error { parameters := ydb.ParamsBuilder() - parameters = parameters.Param("$p0").Uint64(p0) + parameters = parameters.Param("$id").Int32(id) err := q.db.Exec(ctx, deleteAuthor, append(opts, query.WithParameters(parameters.Build()))..., ) @@ -67,12 +74,12 @@ func (q *Queries) DropTable(ctx context.Context, opts ...query.ExecuteOption) er const getAuthor = `-- name: GetAuthor :one SELECT id, name, bio FROM authors -WHERE id = $p0 LIMIT 1 +WHERE id = $id LIMIT 1 ` -func (q *Queries) GetAuthor(ctx context.Context, p0 uint64, opts ...query.ExecuteOption) (Author, error) { +func (q *Queries) GetAuthor(ctx context.Context, id int32, opts ...query.ExecuteOption) (Author, error) { parameters := ydb.ParamsBuilder() - parameters = parameters.Param("$p0").Uint64(p0) + parameters = parameters.Param("$id").Int32(id) row, err := q.db.QueryRow(ctx, getAuthor, append(opts, query.WithParameters(parameters.Build()))..., ) @@ -88,7 +95,8 @@ func (q *Queries) GetAuthor(ctx context.Context, p0 uint64, opts ...query.Execut } const listAuthors = `-- name: ListAuthors :many -SELECT id, name, bio FROM authors ORDER BY name +SELECT id, name, bio FROM authors +ORDER BY name ` func (q *Queries) ListAuthors(ctx context.Context, opts ...query.ExecuteOption) ([]Author, error) { diff --git a/examples/authors/ydb/schema.sql b/examples/authors/ydb/schema.sql index 5207fb3b1e..c25f40986e 100644 --- a/examples/authors/ydb/schema.sql +++ b/examples/authors/ydb/schema.sql @@ -1,6 +1,6 @@ CREATE TABLE authors ( - id Uint64, - name Utf8 NOT NULL, - bio Utf8, + id Serial, + name Text NOT NULL, + bio Text, PRIMARY KEY (id) ); diff --git a/examples/booktest/sqlc.json b/examples/booktest/sqlc.json index b0b0d71d01..7baeff68e7 100644 --- a/examples/booktest/sqlc.json +++ b/examples/booktest/sqlc.json @@ -46,6 +46,14 @@ "rules": [ "sqlc/db-prepare" ] + }, + { + "name": "booktest", + "path": "ydb", + "schema": "ydb/schema.sql", + "queries": "ydb/query.sql", + "engine": "ydb", + "sql_package": "ydb-go-sdk" } ] } diff --git a/examples/booktest/ydb/db.go b/examples/booktest/ydb/db.go new file mode 100644 index 0000000000..5de267426c --- /dev/null +++ b/examples/booktest/ydb/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package booktest + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/examples/booktest/ydb/db_test.go b/examples/booktest/ydb/db_test.go new file mode 100644 index 0000000000..bd4535e5ee --- /dev/null +++ b/examples/booktest/ydb/db_test.go @@ -0,0 +1,148 @@ +package booktest + +import ( + "context" + "testing" + "time" + + "github.com/sqlc-dev/sqlc/internal/sqltest/local" + _ "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const ( + BooksBookTypeFICTION string = "FICTION" + BooksBookTypeNONFICTION string = "NONFICTION" +) + +func TestBooks(t *testing.T) { + ctx := context.Background() + db := local.YDB(t, []string{"schema.sql"}) + defer db.Close(ctx) + + dq := New(db.Query()) + + // create an author + a, err := dq.CreateAuthor(ctx, "Unknown Master") + if err != nil { + t.Fatal(err) + } + + // save first book + now := time.Now() + _, err = dq.CreateBook(ctx, CreateBookParams{ + AuthorID: a.AuthorID, + Isbn: "1", + Title: "my book title", + BookType: BooksBookTypeFICTION, + Year: 2016, + Available: now, + Tag: "", + }, query.WithIdempotent()) + if err != nil { + t.Fatal(err) + } + + // save second book + b1, err := dq.CreateBook(ctx, CreateBookParams{ + AuthorID: a.AuthorID, + Isbn: "2", + Title: "the second book", + BookType: BooksBookTypeFICTION, + Year: 2016, + Available: now, + Tag: "unique", + }, query.WithIdempotent()) + if err != nil { + t.Fatal(err) + } + + // update the title and tags + err = dq.UpdateBook(ctx, UpdateBookParams{ + BookID: b1.BookID, + Title: "changed second title", + Tag: "disastor", + }, query.WithIdempotent()) + if err != nil { + t.Fatal(err) + } + + // save third book + _, err = dq.CreateBook(ctx, CreateBookParams{ + AuthorID: a.AuthorID, + Isbn: "3", + Title: "the third book", + BookType: BooksBookTypeFICTION, + Year: 2001, + Available: now, + Tag: "cool", + }, query.WithIdempotent()) + if err != nil { + t.Fatal(err) + } + + // save fourth book + b3, err := dq.CreateBook(ctx, CreateBookParams{ + AuthorID: a.AuthorID, + Isbn: "4", + Title: "4th place finisher", + BookType: BooksBookTypeFICTION, + Year: 2011, + Available: now, + Tag: "other", + }, query.WithIdempotent()) + if err != nil { + t.Fatal(err) + } + + // upsert, changing ISBN and title + err = dq.UpdateBookISBN(ctx, UpdateBookISBNParams{ + BookID: b3.BookID, + Isbn: "NEW ISBN", + Title: "never ever gonna finish, a quatrain", + Tag: "someother", + }, query.WithIdempotent()) + if err != nil { + t.Fatal(err) + } + + // retrieve first book + books0, err := dq.BooksByTitleYear(ctx, BooksByTitleYearParams{ + Title: "my book title", + Year: 2016, + }) + if err != nil { + t.Fatal(err) + } + for _, book := range books0 { + t.Logf("Book %d (%s): %s available: %s\n", book.BookID, book.BookType, book.Title, book.Available.Format(time.RFC822Z)) + author, err := dq.GetAuthor(ctx, book.AuthorID) + if err != nil { + t.Fatal(err) + } + t.Logf("Book %d author: %s\n", book.BookID, author.Name) + } + + // find a book with either "cool" or "other" or "someother" tag + t.Logf("---------\nTag search results:\n") + res, err := dq.BooksByTags(ctx, []string{"cool", "other", "someother"}) + if err != nil { + t.Fatal(err) + } + for _, ab := range res { + name := "" + if ab.Name != nil { + name = *ab.Name + } + t.Logf("Book %d: '%s', Author: '%s', ISBN: '%s' Tag: '%s'\n", ab.BookID, ab.Title, name, ab.Isbn, ab.Tag) + } + + // get book 4 and delete + b5, err := dq.GetBook(ctx, b3.BookID) + if err != nil { + t.Fatal(err) + } + if err := dq.DeleteBook(ctx, b5.BookID); err != nil { + t.Fatal(err) + } +} diff --git a/examples/booktest/ydb/models.go b/examples/booktest/ydb/models.go new file mode 100644 index 0000000000..d6d0804151 --- /dev/null +++ b/examples/booktest/ydb/models.go @@ -0,0 +1,25 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package booktest + +import ( + "time" +) + +type Author struct { + AuthorID int32 + Name string +} + +type Book struct { + BookID int32 + AuthorID int32 + Isbn string + BookType string + Title string + Year int32 + Available time.Time + Tag string +} diff --git a/examples/booktest/ydb/query.sql b/examples/booktest/ydb/query.sql new file mode 100644 index 0000000000..09a3338690 --- /dev/null +++ b/examples/booktest/ydb/query.sql @@ -0,0 +1,63 @@ +-- name: GetAuthor :one +SELECT * FROM authors +WHERE author_id = $author_id LIMIT 1; + +-- name: GetBook :one +SELECT * FROM books +WHERE book_id = $book_id LIMIT 1; + +-- name: DeleteBook :exec +DELETE FROM books +WHERE book_id = $book_id; + +-- name: BooksByTitleYear :many +SELECT * FROM books +WHERE title = $title AND year = $year; + +-- name: BooksByTags :many +SELECT + book_id, + title, + name, + isbn, + tag +FROM books +LEFT JOIN authors ON books.author_id = authors.author_id +WHERE tag IN sqlc.slice(tags); + +-- name: CreateAuthor :one +INSERT INTO authors (name) +VALUES ($name) +RETURNING *; + +-- name: CreateBook :one +INSERT INTO books ( + author_id, + isbn, + book_type, + title, + year, + available, + tag +) VALUES ( + $author_id, + $isbn, + $book_type, + $title, + $year, + $available, + $tag +) +RETURNING *; + +-- name: UpdateBook :exec +UPDATE books +SET title = $title, tag = $tag +WHERE book_id = $book_id; + +-- name: UpdateBookISBN :exec +UPDATE books +SET title = $title, tag = $tag, isbn = $isbn +WHERE book_id = $book_id; + + diff --git a/examples/booktest/ydb/query.sql.go b/examples/booktest/ydb/query.sql.go new file mode 100644 index 0000000000..cfd8da06ff --- /dev/null +++ b/examples/booktest/ydb/query.sql.go @@ -0,0 +1,327 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query.sql + +package booktest + +import ( + "context" + "time" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const booksByTags = `-- name: BooksByTags :many +SELECT + book_id, + title, + name, + isbn, + tag +FROM books +LEFT JOIN authors ON books.author_id = authors.author_id +WHERE tag IN $tags +` + +type BooksByTagsRow struct { + BookID int32 + Title string + Name *string + Isbn string + Tag string +} + +func (q *Queries) BooksByTags(ctx context.Context, tags []string, opts ...query.ExecuteOption) ([]BooksByTagsRow, error) { + parameters := ydb.ParamsBuilder() + var list = parameters.Param("$tags").BeginList() + for _, param := range tags { + list = list.Add().Text(param) + } + parameters = list.EndList() + result, err := q.db.QueryResultSet(ctx, booksByTags, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []BooksByTagsRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i BooksByTagsRow + if err := row.Scan( + &i.BookID, + &i.Title, + &i.Name, + &i.Isbn, + &i.Tag, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const booksByTitleYear = `-- name: BooksByTitleYear :many +SELECT book_id, author_id, isbn, book_type, title, year, available, tag FROM books +WHERE title = $title AND year = $year +` + +type BooksByTitleYearParams struct { + Title string + Year int32 +} + +func (q *Queries) BooksByTitleYear(ctx context.Context, arg BooksByTitleYearParams, opts ...query.ExecuteOption) ([]Book, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$title").Text(arg.Title) + parameters = parameters.Param("$year").Int32(arg.Year) + result, err := q.db.QueryResultSet(ctx, booksByTitleYear, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Book + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Book + if err := row.Scan( + &i.BookID, + &i.AuthorID, + &i.Isbn, + &i.BookType, + &i.Title, + &i.Year, + &i.Available, + &i.Tag, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const createAuthor = `-- name: CreateAuthor :one +INSERT INTO authors (name) +VALUES ($name) +RETURNING author_id, name +` + +func (q *Queries) CreateAuthor(ctx context.Context, name string, opts ...query.ExecuteOption) (Author, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").Text(name) + row, err := q.db.QueryRow(ctx, createAuthor, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i Author + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.AuthorID, &i.Name) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const createBook = `-- name: CreateBook :one +INSERT INTO books ( + author_id, + isbn, + book_type, + title, + year, + available, + tag +) VALUES ( + $author_id, + $isbn, + $book_type, + $title, + $year, + $available, + $tag +) +RETURNING book_id, author_id, isbn, book_type, title, year, available, tag +` + +type CreateBookParams struct { + AuthorID int32 + Isbn string + BookType string + Title string + Year int32 + Available time.Time + Tag string +} + +func (q *Queries) CreateBook(ctx context.Context, arg CreateBookParams, opts ...query.ExecuteOption) (Book, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$author_id").Int32(arg.AuthorID) + parameters = parameters.Param("$isbn").Text(arg.Isbn) + parameters = parameters.Param("$book_type").Text(arg.BookType) + parameters = parameters.Param("$title").Text(arg.Title) + parameters = parameters.Param("$year").Int32(arg.Year) + parameters = parameters.Param("$available").Timestamp(arg.Available) + parameters = parameters.Param("$tag").Text(arg.Tag) + row, err := q.db.QueryRow(ctx, createBook, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i Book + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan( + &i.BookID, + &i.AuthorID, + &i.Isbn, + &i.BookType, + &i.Title, + &i.Year, + &i.Available, + &i.Tag, + ) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const deleteBook = `-- name: DeleteBook :exec +DELETE FROM books +WHERE book_id = $book_id +` + +func (q *Queries) DeleteBook(ctx context.Context, bookID int32, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$book_id").Int32(bookID) + err := q.db.Exec(ctx, deleteBook, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} + +const getAuthor = `-- name: GetAuthor :one +SELECT author_id, name FROM authors +WHERE author_id = $author_id LIMIT 1 +` + +func (q *Queries) GetAuthor(ctx context.Context, authorID int32, opts ...query.ExecuteOption) (Author, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$author_id").Int32(authorID) + row, err := q.db.QueryRow(ctx, getAuthor, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i Author + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.AuthorID, &i.Name) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const getBook = `-- name: GetBook :one +SELECT book_id, author_id, isbn, book_type, title, year, available, tag FROM books +WHERE book_id = $book_id LIMIT 1 +` + +func (q *Queries) GetBook(ctx context.Context, bookID int32, opts ...query.ExecuteOption) (Book, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$book_id").Int32(bookID) + row, err := q.db.QueryRow(ctx, getBook, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i Book + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan( + &i.BookID, + &i.AuthorID, + &i.Isbn, + &i.BookType, + &i.Title, + &i.Year, + &i.Available, + &i.Tag, + ) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const updateBook = `-- name: UpdateBook :exec +UPDATE books +SET title = $title, tag = $tag +WHERE book_id = $book_id +` + +type UpdateBookParams struct { + Title string + Tag string + BookID int32 +} + +func (q *Queries) UpdateBook(ctx context.Context, arg UpdateBookParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$title").Text(arg.Title) + parameters = parameters.Param("$tag").Text(arg.Tag) + parameters = parameters.Param("$book_id").Int32(arg.BookID) + err := q.db.Exec(ctx, updateBook, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} + +const updateBookISBN = `-- name: UpdateBookISBN :exec +UPDATE books +SET title = $title, tag = $tag, isbn = $isbn +WHERE book_id = $book_id +` + +type UpdateBookISBNParams struct { + Title string + Tag string + Isbn string + BookID int32 +} + +func (q *Queries) UpdateBookISBN(ctx context.Context, arg UpdateBookISBNParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$title").Text(arg.Title) + parameters = parameters.Param("$tag").Text(arg.Tag) + parameters = parameters.Param("$isbn").Text(arg.Isbn) + parameters = parameters.Param("$book_id").Int32(arg.BookID) + err := q.db.Exec(ctx, updateBookISBN, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/examples/booktest/ydb/schema.sql b/examples/booktest/ydb/schema.sql new file mode 100644 index 0000000000..d5ea97972f --- /dev/null +++ b/examples/booktest/ydb/schema.sql @@ -0,0 +1,18 @@ +CREATE TABLE authors ( + author_id Serial, + name Text NOT NULL DEFAULT '', + PRIMARY KEY (author_id) +); + +CREATE TABLE books ( + book_id Serial, + author_id Int32 NOT NULL, + isbn Text NOT NULL DEFAULT '', + book_type Text NOT NULL DEFAULT 'FICTION', + title Text NOT NULL DEFAULT '', + year Int32 NOT NULL DEFAULT 2000, + available Timestamp NOT NULL, + tag Text NOT NULL DEFAULT '', + PRIMARY KEY (book_id) +); + diff --git a/examples/jets/sqlc.json b/examples/jets/sqlc.json index 8dfa0df777..1924af6fe0 100644 --- a/examples/jets/sqlc.json +++ b/examples/jets/sqlc.json @@ -20,6 +20,14 @@ "rules": [ "sqlc/db-prepare" ] + }, + { + "path": "ydb", + "name": "jets", + "schema": "ydb/schema.sql", + "queries": "ydb/query-building.sql", + "engine": "ydb", + "sql_package": "ydb-go-sdk" } ] } diff --git a/examples/jets/ydb/db.go b/examples/jets/ydb/db.go new file mode 100644 index 0000000000..c8f3a5ed08 --- /dev/null +++ b/examples/jets/ydb/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package jets + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/examples/jets/ydb/db_test.go b/examples/jets/ydb/db_test.go new file mode 100644 index 0000000000..3b7b03e3ac --- /dev/null +++ b/examples/jets/ydb/db_test.go @@ -0,0 +1,73 @@ +package jets + +import ( + "context" + "testing" + + "github.com/sqlc-dev/sqlc/internal/sqltest/local" + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +func TestJets(t *testing.T) { + ctx := context.Background() + db := local.YDB(t, []string{"schema.sql"}) + defer db.Close(ctx) + + q := New(db.Query()) + + // insert test data + pilots := []struct { + id int32 + name string + }{ + {1, "John Doe"}, + {2, "Jane Smith"}, + {3, "Bob Johnson"}, + } + + for _, p := range pilots { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int32(p.id) + parameters = parameters.Param("$name").Text(p.name) + err := db.Query().Exec(ctx, "UPSERT INTO pilots (id, name) VALUES ($id, $name)", + query.WithParameters(parameters.Build()), + ) + if err != nil { + t.Fatalf("failed to insert pilot: %v", err) + } + } + + // list all pilots + pilotsList, err := q.ListPilots(ctx) + if err != nil { + t.Fatal(err) + } + t.Log("Pilots:", pilotsList) + + // count pilots + count, err := q.CountPilots(ctx) + if err != nil { + t.Fatal(err) + } + t.Logf("Total pilots: %d", count) + + if count != 3 { + t.Errorf("expected 3 pilots, got %d", count) + } + + // delete a pilot + err = q.DeletePilot(ctx, 1) + if err != nil { + t.Fatal(err) + } + + // count after delete + count, err = q.CountPilots(ctx) + if err != nil { + t.Fatal(err) + } + if count != 2 { + t.Errorf("expected 2 pilots after delete, got %d", count) + } +} diff --git a/examples/jets/ydb/models.go b/examples/jets/ydb/models.go new file mode 100644 index 0000000000..166bf06f3d --- /dev/null +++ b/examples/jets/ydb/models.go @@ -0,0 +1,28 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package jets + +type Jet struct { + ID int32 + PilotID int32 + Age int32 + Name string + Color string +} + +type Language struct { + ID int32 + Language string +} + +type Pilot struct { + ID int32 + Name string +} + +type PilotLanguage struct { + PilotID int32 + LanguageID int32 +} diff --git a/examples/jets/ydb/query-building.sql b/examples/jets/ydb/query-building.sql new file mode 100644 index 0000000000..07f2ad23ec --- /dev/null +++ b/examples/jets/ydb/query-building.sql @@ -0,0 +1,12 @@ +-- name: CountPilots :one +SELECT COUNT(*) FROM pilots; + +-- name: ListPilots :many +SELECT * FROM pilots LIMIT 5; + +-- name: DeletePilot :exec +DELETE FROM pilots WHERE id = $id; + + + + diff --git a/examples/jets/ydb/query-building.sql.go b/examples/jets/ydb/query-building.sql.go new file mode 100644 index 0000000000..5ec73a4edf --- /dev/null +++ b/examples/jets/ydb/query-building.sql.go @@ -0,0 +1,73 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: query-building.sql + +package jets + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const countPilots = `-- name: CountPilots :one +SELECT COUNT(*) FROM pilots +` + +func (q *Queries) CountPilots(ctx context.Context, opts ...query.ExecuteOption) (uint64, error) { + row, err := q.db.QueryRow(ctx, countPilots, opts...) + var count uint64 + if err != nil { + return count, xerrors.WithStackTrace(err) + } + err = row.Scan(&count) + if err != nil { + return count, xerrors.WithStackTrace(err) + } + return count, nil +} + +const deletePilot = `-- name: DeletePilot :exec +DELETE FROM pilots WHERE id = $id +` + +func (q *Queries) DeletePilot(ctx context.Context, id int32, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$id").Int32(id) + err := q.db.Exec(ctx, deletePilot, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} + +const listPilots = `-- name: ListPilots :many +SELECT id, name FROM pilots LIMIT 5 +` + +func (q *Queries) ListPilots(ctx context.Context, opts ...query.ExecuteOption) ([]Pilot, error) { + result, err := q.db.QueryResultSet(ctx, listPilots, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Pilot + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Pilot + if err := row.Scan(&i.ID, &i.Name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/examples/jets/ydb/schema.sql b/examples/jets/ydb/schema.sql new file mode 100644 index 0000000000..bb256e5d5f --- /dev/null +++ b/examples/jets/ydb/schema.sql @@ -0,0 +1,30 @@ +CREATE TABLE pilots ( + id Int32 NOT NULL, + name Text NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE jets ( + id Int32 NOT NULL, + pilot_id Int32 NOT NULL, + age Int32 NOT NULL, + name Text NOT NULL, + color Text NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE languages ( + id Int32 NOT NULL, + language Text NOT NULL, + PRIMARY KEY (id) +); + +CREATE TABLE pilot_languages ( + pilot_id Int32 NOT NULL, + language_id Int32 NOT NULL, + PRIMARY KEY (pilot_id, language_id) +); + + + + diff --git a/examples/ondeck/sqlc.json b/examples/ondeck/sqlc.json index 7b97328b3f..a39c743a0c 100644 --- a/examples/ondeck/sqlc.json +++ b/examples/ondeck/sqlc.json @@ -55,6 +55,17 @@ "emit_json_tags": true, "emit_prepared_queries": true, "emit_interface": true + }, + { + "path": "ydb", + "name": "ondeck", + "schema": "ydb/schema", + "queries": "ydb/query", + "engine": "ydb", + "sql_package": "ydb-go-sdk", + "emit_json_tags": true, + "emit_prepared_queries": true, + "emit_interface": true } ] } diff --git a/examples/ondeck/ydb/city.sql.go b/examples/ondeck/ydb/city.sql.go new file mode 100644 index 0000000000..e9078dad6f --- /dev/null +++ b/examples/ondeck/ydb/city.sql.go @@ -0,0 +1,126 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: city.sql + +package ondeck + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const createCity = `-- name: CreateCity :one +INSERT INTO city ( + name, + slug +) VALUES ( + $name, + $slug +) RETURNING slug, name +` + +type CreateCityParams struct { + Name string `json:"name"` + Slug string `json:"slug"` +} + +// Create a new city. The slug must be unique. +// This is the second line of the comment +// This is the third line + +func (q *Queries) CreateCity(ctx context.Context, arg CreateCityParams, opts ...query.ExecuteOption) (City, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").Text(arg.Name) + parameters = parameters.Param("$slug").Text(arg.Slug) + row, err := q.db.QueryRow(ctx, createCity, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i City + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.Slug, &i.Name) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const getCity = `-- name: GetCity :one +SELECT slug, name +FROM city +WHERE slug = $slug +` + +func (q *Queries) GetCity(ctx context.Context, slug string, opts ...query.ExecuteOption) (City, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$slug").Text(slug) + row, err := q.db.QueryRow(ctx, getCity, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i City + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan(&i.Slug, &i.Name) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const listCities = `-- name: ListCities :many +SELECT slug, name +FROM city +ORDER BY name +` + +func (q *Queries) ListCities(ctx context.Context, opts ...query.ExecuteOption) ([]City, error) { + result, err := q.db.QueryResultSet(ctx, listCities, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []City + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i City + if err := row.Scan(&i.Slug, &i.Name); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const updateCityName = `-- name: UpdateCityName :exec +UPDATE city +SET name = $name +WHERE slug = $slug +` + +type UpdateCityNameParams struct { + Name string `json:"name"` + Slug string `json:"slug"` +} + +func (q *Queries) UpdateCityName(ctx context.Context, arg UpdateCityNameParams, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").Text(arg.Name) + parameters = parameters.Param("$slug").Text(arg.Slug) + err := q.db.Exec(ctx, updateCityName, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} diff --git a/examples/ondeck/ydb/db.go b/examples/ondeck/ydb/db.go new file mode 100644 index 0000000000..7102987eee --- /dev/null +++ b/examples/ondeck/ydb/db.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package ondeck + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type DBTX interface { + Exec(ctx context.Context, sql string, opts ...query.ExecuteOption) error + Query(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Result, error) + QueryResultSet(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.ClosableResultSet, error) + QueryRow(ctx context.Context, sql string, opts ...query.ExecuteOption) (query.Row, error) +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} diff --git a/examples/ondeck/ydb/db_test.go b/examples/ondeck/ydb/db_test.go new file mode 100644 index 0000000000..24c34dadcb --- /dev/null +++ b/examples/ondeck/ydb/db_test.go @@ -0,0 +1,130 @@ +//go:build examples + +package ondeck + +import ( + "context" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/sqlc-dev/sqlc/internal/sqltest/local" + _ "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +func runOnDeckQueries(t *testing.T, q *Queries) { + ctx := context.Background() + + city, err := q.CreateCity(ctx, CreateCityParams{ + Slug: "san-francisco", + Name: "San Francisco", + }, query.WithIdempotent()) + if err != nil { + t.Fatal(err) + } + + tags := "rock, punk" + venueID, err := q.CreateVenue(ctx, CreateVenueParams{ + Slug: "the-fillmore", + Name: "The Fillmore", + City: city.Slug, + SpotifyPlaylist: "spotify:uri", + Status: "op!en", + Tags: &tags, + }, query.WithIdempotent()) + if err != nil { + t.Fatal(err) + } + + venue, err := q.GetVenue(ctx, GetVenueParams{ + Slug: "the-fillmore", + City: city.Slug, + }) + if err != nil { + t.Fatal(err) + } + + if diff := cmp.Diff(venue.ID, venueID); diff != "" { + t.Errorf("venue ID mismatch:\n%s", diff) + } + + { + actual, err := q.GetCity(ctx, city.Slug) + if err != nil { + t.Error(err) + } + if diff := cmp.Diff(actual, city); diff != "" { + t.Errorf("get city mismatch:\n%s", diff) + } + } + + { + actual, err := q.VenueCountByCity(ctx) + if err != nil { + t.Error(err) + } + if diff := cmp.Diff(actual, []VenueCountByCityRow{ + {city.Slug, uint64(1)}, + }); diff != "" { + t.Errorf("venue count mismatch:\n%s", diff) + } + } + + { + actual, err := q.ListCities(ctx) + if err != nil { + t.Error(err) + } + if diff := cmp.Diff(actual, []City{city}); diff != "" { + t.Errorf("list city mismatch:\n%s", diff) + } + } + + { + actual, err := q.ListVenues(ctx, city.Slug) + if err != nil { + t.Error(err) + } + if diff := cmp.Diff(actual, []Venue{venue}); diff != "" { + t.Errorf("list venue mismatch:\n%s", diff) + } + } + + { + err := q.UpdateCityName(ctx, UpdateCityNameParams{ + Slug: city.Slug, + Name: "SF", + }, query.WithIdempotent()) + if err != nil { + t.Error(err) + } + } + + { + id, err := q.UpdateVenueName(ctx, UpdateVenueNameParams{ + Slug: venue.Slug, + Name: "Fillmore", + }, query.WithIdempotent()) + if err != nil { + t.Error(err) + } + if diff := cmp.Diff(id, venue.ID); diff != "" { + t.Errorf("update venue mismatch:\n%s", diff) + } + } + + { + err := q.DeleteVenue(ctx, venue.Slug) + if err != nil { + t.Error(err) + } + } +} + +func TestQueries(t *testing.T) { + ctx := context.Background() + db := local.YDB(t, []string{"schema"}) + defer db.Close(ctx) + + runOnDeckQueries(t, New(db.Query())) +} diff --git a/examples/ondeck/ydb/models.go b/examples/ondeck/ydb/models.go new file mode 100644 index 0000000000..2d0202f1fa --- /dev/null +++ b/examples/ondeck/ydb/models.go @@ -0,0 +1,26 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package ondeck + +import ( + "time" +) + +type City struct { + Slug string `json:"slug"` + Name string `json:"name"` +} + +type Venue struct { + ID int32 `json:"id"` + Status string `json:"status"` + Slug string `json:"slug"` + Name string `json:"name"` + City string `json:"city"` + SpotifyPlaylist string `json:"spotify_playlist"` + SongkickID *string `json:"songkick_id"` + Tags *string `json:"tags"` + CreatedAt *time.Time `json:"created_at"` +} diff --git a/examples/ondeck/ydb/querier.go b/examples/ondeck/ydb/querier.go new file mode 100644 index 0000000000..28b34ed8ac --- /dev/null +++ b/examples/ondeck/ydb/querier.go @@ -0,0 +1,29 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 + +package ondeck + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +type Querier interface { + // Create a new city. The slug must be unique. + // This is the second line of the comment + // This is the third line + CreateCity(ctx context.Context, arg CreateCityParams, opts ...query.ExecuteOption) (City, error) + CreateVenue(ctx context.Context, arg CreateVenueParams, opts ...query.ExecuteOption) (int32, error) + DeleteVenue(ctx context.Context, slug string, opts ...query.ExecuteOption) error + GetCity(ctx context.Context, slug string, opts ...query.ExecuteOption) (City, error) + GetVenue(ctx context.Context, arg GetVenueParams, opts ...query.ExecuteOption) (Venue, error) + ListCities(ctx context.Context, opts ...query.ExecuteOption) ([]City, error) + ListVenues(ctx context.Context, city string, opts ...query.ExecuteOption) ([]Venue, error) + UpdateCityName(ctx context.Context, arg UpdateCityNameParams, opts ...query.ExecuteOption) error + UpdateVenueName(ctx context.Context, arg UpdateVenueNameParams, opts ...query.ExecuteOption) (int32, error) + VenueCountByCity(ctx context.Context, opts ...query.ExecuteOption) ([]VenueCountByCityRow, error) +} + +var _ Querier = (*Queries)(nil) diff --git a/examples/ondeck/ydb/query/city.sql b/examples/ondeck/ydb/query/city.sql new file mode 100644 index 0000000000..7d5ddb169f --- /dev/null +++ b/examples/ondeck/ydb/query/city.sql @@ -0,0 +1,27 @@ +-- name: ListCities :many +SELECT * +FROM city +ORDER BY name; + +-- name: GetCity :one +SELECT * +FROM city +WHERE slug = $slug; + +-- name: CreateCity :one +-- Create a new city. The slug must be unique. +-- This is the second line of the comment +-- This is the third line +INSERT INTO city ( + name, + slug +) VALUES ( + $name, + $slug +) RETURNING *; + +-- name: UpdateCityName :exec +UPDATE city +SET name = $name +WHERE slug = $slug; + diff --git a/examples/ondeck/ydb/query/venue.sql b/examples/ondeck/ydb/query/venue.sql new file mode 100644 index 0000000000..4eec18d349 --- /dev/null +++ b/examples/ondeck/ydb/query/venue.sql @@ -0,0 +1,48 @@ +-- name: ListVenues :many +SELECT * +FROM venue +WHERE city = $city +ORDER BY name; + +-- name: DeleteVenue :exec +DELETE FROM venue +WHERE slug = $slug AND slug = $slug; + +-- name: GetVenue :one +SELECT * +FROM venue +WHERE slug = $slug AND city = $city; + +-- name: CreateVenue :one +INSERT INTO venue ( + slug, + name, + city, + created_at, + spotify_playlist, + status, + tags +) VALUES ( + $slug, + $name, + $city, + CurrentUtcTimestamp(), + $spotify_playlist, + $status, + $tags +) RETURNING id; + +-- name: UpdateVenueName :one +UPDATE venue +SET name = $name +WHERE slug = $slug +RETURNING id; + +-- name: VenueCountByCity :many +SELECT + city, + count(*) as count +FROM venue +GROUP BY city +ORDER BY city; + diff --git a/examples/ondeck/ydb/schema/0001_city.sql b/examples/ondeck/ydb/schema/0001_city.sql new file mode 100644 index 0000000000..d0941ef052 --- /dev/null +++ b/examples/ondeck/ydb/schema/0001_city.sql @@ -0,0 +1,6 @@ +CREATE TABLE city ( + slug Text NOT NULL, + name Text NOT NULL, + PRIMARY KEY (slug) +); + diff --git a/examples/ondeck/ydb/schema/0002_venue.sql b/examples/ondeck/ydb/schema/0002_venue.sql new file mode 100644 index 0000000000..f6296c9099 --- /dev/null +++ b/examples/ondeck/ydb/schema/0002_venue.sql @@ -0,0 +1,13 @@ +CREATE TABLE venues ( + id Serial NOT NULL, + dropped Text, + status Text NOT NULL, + slug Text NOT NULL, + name Text NOT NULL, + city Text NOT NULL, + spotify_playlist Text NOT NULL, + songkick_id Text, + tags Text, + PRIMARY KEY (id) +); + diff --git a/examples/ondeck/ydb/schema/0003_add_column.sql b/examples/ondeck/ydb/schema/0003_add_column.sql new file mode 100644 index 0000000000..d0a954e008 --- /dev/null +++ b/examples/ondeck/ydb/schema/0003_add_column.sql @@ -0,0 +1,4 @@ +ALTER TABLE venues RENAME TO venue; +ALTER TABLE venue DROP COLUMN dropped; +ALTER TABLE venue ADD COLUMN created_at Timestamp; + diff --git a/examples/ondeck/ydb/venue.sql.go b/examples/ondeck/ydb/venue.sql.go new file mode 100644 index 0000000000..b191518591 --- /dev/null +++ b/examples/ondeck/ydb/venue.sql.go @@ -0,0 +1,230 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.30.0 +// source: venue.sql + +package ondeck + +import ( + "context" + + "github.com/ydb-platform/ydb-go-sdk/v3" + "github.com/ydb-platform/ydb-go-sdk/v3/pkg/xerrors" + "github.com/ydb-platform/ydb-go-sdk/v3/query" +) + +const createVenue = `-- name: CreateVenue :one +INSERT INTO venue ( + slug, + name, + city, + created_at, + spotify_playlist, + status, + tags +) VALUES ( + $slug, + $name, + $city, + CurrentUtcTimestamp(), + $spotify_playlist, + $status, + $tags +) RETURNING id +` + +type CreateVenueParams struct { + Slug string `json:"slug"` + Name string `json:"name"` + City string `json:"city"` + SpotifyPlaylist string `json:"spotify_playlist"` + Status string `json:"status"` + Tags *string `json:"tags"` +} + +func (q *Queries) CreateVenue(ctx context.Context, arg CreateVenueParams, opts ...query.ExecuteOption) (int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$slug").Text(arg.Slug) + parameters = parameters.Param("$name").Text(arg.Name) + parameters = parameters.Param("$city").Text(arg.City) + parameters = parameters.Param("$spotify_playlist").Text(arg.SpotifyPlaylist) + parameters = parameters.Param("$status").Text(arg.Status) + parameters = parameters.Param("$tags").BeginOptional().Text(arg.Tags).EndOptional() + row, err := q.db.QueryRow(ctx, createVenue, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var id int32 + if err != nil { + return id, xerrors.WithStackTrace(err) + } + err = row.Scan(&id) + if err != nil { + return id, xerrors.WithStackTrace(err) + } + return id, nil +} + +const deleteVenue = `-- name: DeleteVenue :exec +DELETE FROM venue +WHERE slug = $slug AND slug = $slug +` + +func (q *Queries) DeleteVenue(ctx context.Context, slug string, opts ...query.ExecuteOption) error { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$slug").Text(slug) + err := q.db.Exec(ctx, deleteVenue, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return xerrors.WithStackTrace(err) + } + return nil +} + +const getVenue = `-- name: GetVenue :one +SELECT id, status, slug, name, city, spotify_playlist, songkick_id, tags, created_at +FROM venue +WHERE slug = $slug AND city = $city +` + +type GetVenueParams struct { + Slug string `json:"slug"` + City string `json:"city"` +} + +func (q *Queries) GetVenue(ctx context.Context, arg GetVenueParams, opts ...query.ExecuteOption) (Venue, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$slug").Text(arg.Slug) + parameters = parameters.Param("$city").Text(arg.City) + row, err := q.db.QueryRow(ctx, getVenue, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var i Venue + if err != nil { + return i, xerrors.WithStackTrace(err) + } + err = row.Scan( + &i.ID, + &i.Status, + &i.Slug, + &i.Name, + &i.City, + &i.SpotifyPlaylist, + &i.SongkickID, + &i.Tags, + &i.CreatedAt, + ) + if err != nil { + return i, xerrors.WithStackTrace(err) + } + return i, nil +} + +const listVenues = `-- name: ListVenues :many +SELECT id, status, slug, name, city, spotify_playlist, songkick_id, tags, created_at +FROM venue +WHERE city = $city +ORDER BY name +` + +func (q *Queries) ListVenues(ctx context.Context, city string, opts ...query.ExecuteOption) ([]Venue, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$city").Text(city) + result, err := q.db.QueryResultSet(ctx, listVenues, + append(opts, query.WithParameters(parameters.Build()))..., + ) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []Venue + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i Venue + if err := row.Scan( + &i.ID, + &i.Status, + &i.Slug, + &i.Name, + &i.City, + &i.SpotifyPlaylist, + &i.SongkickID, + &i.Tags, + &i.CreatedAt, + ); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} + +const updateVenueName = `-- name: UpdateVenueName :one +UPDATE venue +SET name = $name +WHERE slug = $slug +RETURNING id +` + +type UpdateVenueNameParams struct { + Name string `json:"name"` + Slug string `json:"slug"` +} + +func (q *Queries) UpdateVenueName(ctx context.Context, arg UpdateVenueNameParams, opts ...query.ExecuteOption) (int32, error) { + parameters := ydb.ParamsBuilder() + parameters = parameters.Param("$name").Text(arg.Name) + parameters = parameters.Param("$slug").Text(arg.Slug) + row, err := q.db.QueryRow(ctx, updateVenueName, + append(opts, query.WithParameters(parameters.Build()))..., + ) + var id int32 + if err != nil { + return id, xerrors.WithStackTrace(err) + } + err = row.Scan(&id) + if err != nil { + return id, xerrors.WithStackTrace(err) + } + return id, nil +} + +const venueCountByCity = `-- name: VenueCountByCity :many +SELECT + city, + count(*) as count +FROM venue +GROUP BY city +ORDER BY city +` + +type VenueCountByCityRow struct { + City string `json:"city"` + Count uint64 `json:"count"` +} + +func (q *Queries) VenueCountByCity(ctx context.Context, opts ...query.ExecuteOption) ([]VenueCountByCityRow, error) { + result, err := q.db.QueryResultSet(ctx, venueCountByCity, opts...) + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var items []VenueCountByCityRow + for row, err := range result.Rows(ctx) { + if err != nil { + return nil, xerrors.WithStackTrace(err) + } + var i VenueCountByCityRow + if err := row.Scan(&i.City, &i.Count); err != nil { + return nil, xerrors.WithStackTrace(err) + } + items = append(items, i) + } + if err := result.Close(ctx); err != nil { + return nil, xerrors.WithStackTrace(err) + } + return items, nil +} diff --git a/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl b/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl index 9ed0dd1bc3..f9c06cc705 100644 --- a/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl +++ b/internal/codegen/golang/templates/ydb-go-sdk/interfaceCode.tmpl @@ -3,17 +3,17 @@ {{- $dbtxParam := .EmitMethodsWithDBArgument -}} {{- range .GoQueries}} {{- if and (eq .Cmd ":one") ($dbtxParam) }} - {{- range .Comments}}//{{.}} - {{- end}} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ({{.Ret.DefineType}}, error) {{- else if eq .Cmd ":one"}} - {{- range .Comments}}//{{.}} - {{- end}} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ({{.Ret.DefineType}}, error) {{- end}} {{- if and (eq .Cmd ":many") ($dbtxParam) }} - {{- range .Comments}}//{{.}} - {{- end}} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) {{- else if eq .Cmd ":many"}} {{range .Comments}}//{{.}} @@ -21,12 +21,12 @@ {{.MethodName}}(ctx context.Context, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) ([]{{.Ret.DefineType}}, error) {{- end}} {{- if and (eq .Cmd ":exec") ($dbtxParam) }} - {{- range .Comments}}//{{.}} - {{- end}} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, db DBTX, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) error {{- else if eq .Cmd ":exec"}} - {{- range .Comments}}//{{.}} - {{- end}} + {{range .Comments}}//{{.}} + {{end -}} {{.MethodName}}(ctx context.Context, {{if not .Arg.IsEmpty}}{{.Arg.Pair}}, {{end}}opts ...query.ExecuteOption) error {{- end}} {{- end}} diff --git a/internal/codegen/golang/ydb_type.go b/internal/codegen/golang/ydb_type.go index 572f79f334..0192b80e52 100644 --- a/internal/codegen/golang/ydb_type.go +++ b/internal/codegen/golang/ydb_type.go @@ -32,7 +32,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col // return "sql.NullBool" return "*bool" - case "int8": + case "int8", "tinyint": if notNull { return "int8" } diff --git a/internal/sqltest/local/ydb.go b/internal/sqltest/local/ydb.go index e3e51e3716..b5dde93315 100644 --- a/internal/sqltest/local/ydb.go +++ b/internal/sqltest/local/ydb.go @@ -5,6 +5,7 @@ import ( "fmt" "math/rand" "os" + "strings" "testing" "time" @@ -57,10 +58,7 @@ func link_YDB(t *testing.T, migrations []string, rw bool, tls bool) *ydb.Driver connectionString = fmt.Sprintf("grpc://%s%s", dbuiri, baseDB) } - db, err := ydb.Open(ctx, connectionString, - ydb.WithInsecure(), - ydb.WithDiscoveryInterval(time.Hour), - ) + db, err := ydb.Open(ctx, connectionString) if err != nil { t.Fatalf("failed to open YDB connection: %s", err) } @@ -77,9 +75,16 @@ func link_YDB(t *testing.T, migrations []string, rw bool, tls bool) *ydb.Driver } stmt := migrate.RemoveRollbackStatements(string(blob)) - err = db.Query().Exec(ctx, stmt, query.WithTxControl(query.EmptyTxControl())) - if err != nil { - t.Fatalf("failed to apply migration: %s\nSQL: %s", err, stmt) + statements := strings.Split(stmt, ";") + for _, singleStmt := range statements { + singleStmt = strings.TrimSpace(singleStmt) + if singleStmt == "" { + continue + } + err = db.Query().Exec(ctx, singleStmt, query.WithTxControl(query.EmptyTxControl())) + if err != nil { + t.Fatalf("failed to apply migration: %s\nSQL: %s", err, singleStmt) + } } }