Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e949b19
Initial YDB support: SELECT logic, some convert tests, and YDB engine…
1NepuNep1 Apr 22, 2025
4e46daa
Added almost full INSERT support and basic DELETE (without ON) support
1NepuNep1 Apr 26, 2025
3a4f818
Added UPDATE and DELETE full logic. Updated examples in example/authors
1NepuNep1 Apr 28, 2025
e980d19
Added some examples and README for demo
1NepuNep1 Apr 28, 2025
3013c84
Supported some more YQL constructions:
1NepuNep1 May 17, 2025
e687cf6
ADDED DROP/ALTER USER/GROUP
1NepuNep1 May 19, 2025
0293f6a
Added Funcs support!
1NepuNep1 May 20, 2025
fc8c932
Added examples for funcs codegen
1NepuNep1 May 21, 2025
d0e1550
Upgraded jwt to 4.5.2
1NepuNep1 May 27, 2025
0b1752a
First ydb-go-sdk generation version (See #4) (#6)
1NepuNep1 Sep 2, 2025
4eb8ff5
Bump sqlc version in examples/authors/ydb to v1.30.0
Sep 3, 2025
14b60c5
Rewrited comments and testdata to eng
Sep 3, 2025
f2d7aea
Expanding YQL Syntax support in sqlc engine (Refactored SELECT (Suppo…
1NepuNep1 Sep 8, 2025
296cca7
Made new params building logic & got rid off .Query handle (#11)
1NepuNep1 Sep 9, 2025
1379e43
Rewrited convert to Visitor Interface from ANTLR4 + fixed some types …
1NepuNep1 Sep 23, 2025
a680b1b
Massive Optional + Functions update (#13)
1NepuNep1 Sep 26, 2025
a69429c
Added simple types in param builder and ydbType (#14)
1NepuNep1 Oct 8, 2025
816eda8
Ydb-go-sdk codegen: Containers support in ydb.ParamsBuilder() (#15)
1NepuNep1 Oct 9, 2025
2eaa5d0
Tests: Added a lot of ydb e2e tests + some engine and types fixes
1NepuNep1 Oct 27, 2025
bde9d5e
Merge branch 'main' into ydb
1NepuNep1 Oct 27, 2025
08424e0
Resolved go.mod && go.sum
1NepuNep1 Oct 27, 2025
be13a37
Fixed builtins test
1NepuNep1 Oct 27, 2025
683926c
Added docs and rewrited examples for ydb (#17)
1NepuNep1 Oct 27, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
1NepuNep1 authored and Viktor Pentyukhov committed Sep 3, 2025
commit 0b1752a833ddc0131dfd2ae07c0d7889c11acf16
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

1 change: 1 addition & 0 deletions examples/authors/sqlc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sql:
package: authors
out: ydb
emit_json_tags: true
sql_package: ydb-go-sdk


rules:
Expand Down
17 changes: 6 additions & 11 deletions examples/authors/ydb/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 13 additions & 82 deletions examples/authors/ydb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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{
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
})
}
29 changes: 6 additions & 23 deletions examples/authors/ydb/query.sql
Original file line number Diff line number Diff line change
@@ -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;
Loading
Loading