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
ADDED DROP/ALTER USER/GROUP
  • Loading branch information
1NepuNep1 authored and Viktor Pentyukhov committed Sep 3, 2025
commit e687cf6d78ab4d61d5ff0788c46869c76719b259
122 changes: 122 additions & 0 deletions internal/engine/ydb/catalog_tests/alter_group_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
153 changes: 153 additions & 0 deletions internal/engine/ydb/catalog_tests/alter_user_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
87 changes: 87 additions & 0 deletions internal/engine/ydb/catalog_tests/drop_role_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}
Loading