Skip to content

Commit 71de72f

Browse files
committed
Endtoend tests: bunch of ydb e2e tests + some engine and types fixes
1 parent 816eda8 commit 71de72f

File tree

229 files changed

+6105
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+6105
-37
lines changed

internal/codegen/golang/gen.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum,
218218
}
219219
}
220220

221+
isYDBEngine := func() bool { return options.Engine == "ydb" }
222+
221223
funcMap := template.FuncMap{
222224
"lowerTitle": sdk.LowerTitle,
223225
"comment": sdk.DoubleSlashComment,
@@ -232,6 +234,7 @@ func generate(req *plugin.GenerateRequest, options *opts.Options, enums []Enum,
232234
"emitPreparedQueries": tctx.codegenEmitPreparedQueries,
233235
"queryMethod": tctx.codegenQueryMethod,
234236
"queryRetval": tctx.codegenQueryRetval,
237+
"isYDBEngine": isYDBEngine,
235238
}
236239

237240
tmpl := template.Must(

internal/codegen/golang/imports.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ func buildImports(options *opts.Options, queries []Query, uses func(string) bool
232232
if uses("pgvector.Vector") && !overrideVector {
233233
pkg[ImportSpec{Path: "github.com/pgvector/pgvector-go"}] = struct{}{}
234234
}
235+
_, overrideDecimal := overrideTypes["types.Decimal"]
236+
if uses("types.Decimal") && !overrideDecimal {
237+
pkg[ImportSpec{Path: "github.com/ydb-platform/ydb-go-sdk/v3/table/types"}] = struct{}{}
238+
}
235239

236240
// Custom imports
237241
for _, override := range options.Overrides {
@@ -404,7 +408,7 @@ func (i *importer) queryImports(filename string) fileImports {
404408
}
405409

406410
sqlpkg := parseDriver(i.Options.SqlPackage)
407-
if sqlcSliceScan() && !sqlpkg.IsPGX() && !sqlpkg.IsYDBGoSDK() {
411+
if sqlcSliceScan() && !sqlpkg.IsPGX() && !sqlpkg.IsYDBGoSDK() && i.Options.Engine != "ydb" {
408412
std["strings"] = struct{}{}
409413
}
410414
if sliceScan() && !sqlpkg.IsPGX() && !sqlpkg.IsYDBGoSDK() {

internal/codegen/golang/opts/options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type Options struct {
4747
Initialisms *[]string `json:"initialisms,omitempty" yaml:"initialisms"`
4848

4949
InitialismsMap map[string]struct{} `json:"-" yaml:"-"`
50+
Engine string `json:"-" yaml:"-"`
5051
}
5152

5253
type GlobalOptions struct {
@@ -72,6 +73,11 @@ func Parse(req *plugin.GenerateRequest) (*Options, error) {
7273
}
7374
maps.Copy(options.Rename, global.Rename)
7475
}
76+
77+
if req.Settings != nil {
78+
options.Engine = req.Settings.Engine
79+
}
80+
7581
return options, nil
7682
}
7783

internal/codegen/golang/query.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func ydbBuilderMethodForColumnType(dbType string) string {
307307
return "Int32"
308308
case "uint16":
309309
return "Uint16"
310-
case "int16", "smallserial","serial2":
310+
case "int16", "smallserial", "serial2":
311311
return "Int16"
312312
case "uint8":
313313
return "Uint8"
@@ -342,8 +342,18 @@ func ydbBuilderMethodForColumnType(dbType string) string {
342342
case "yson":
343343
return "YSON"
344344

345+
case "integer": // LIMIT/OFFSET parameters support
346+
return "Uint64"
347+
348+
case "Integer": // Invalid YDB type - fallback to Uint64
349+
return "Uint64"
350+
345351
//TODO: support other types
346352
default:
353+
// Check for decimal types
354+
if strings.HasPrefix(baseType, "decimal") {
355+
return "Decimal"
356+
}
347357
return ""
348358
}
349359
}
@@ -405,6 +415,21 @@ func (v QueryValue) YDBParamsBuilder() string {
405415
isPtr := strings.HasPrefix(goType, "*")
406416
isArray := field.Column.IsArray || field.Column.IsSqlcSlice
407417

418+
if method == "Decimal" {
419+
if isArray {
420+
lines = append(lines, fmt.Sprintf("\tvar list = parameters.Param(%s).BeginList()", paramName))
421+
lines = append(lines, fmt.Sprintf("\tfor _, param := range %s {", variable))
422+
lines = append(lines, "\t\tlist = list.Add().Decimal(param.Bytes, param.Precision, param.Scale)")
423+
lines = append(lines, "\t}")
424+
lines = append(lines, "\tparameters = list.EndList()")
425+
} else if isPtr {
426+
lines = append(lines, fmt.Sprintf("\tparameters = parameters.Param(%s).BeginOptional().Decimal(&%s.Bytes, %s.Precision, %s.Scale).EndOptional()", paramName, variable, variable, variable))
427+
} else {
428+
lines = append(lines, fmt.Sprintf("\tparameters = parameters.Param(%s).Decimal(%s.Bytes, %s.Precision, %s.Scale)", paramName, variable, variable, variable))
429+
}
430+
return true
431+
}
432+
408433
if isArray {
409434
lines = append(lines, fmt.Sprintf("\tvar list = parameters.Param(%s).BeginList()", paramName))
410435
lines = append(lines, fmt.Sprintf("\tfor _, param := range %s {", variable))

internal/codegen/golang/templates/stdlib/queryCode.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (q *Queries) {{.MethodName}}(ctx context.Context, {{ dbarg }} {{.Arg.Pair}}
125125
{{end}}
126126

127127
{{define "queryCodeStdExec"}}
128-
{{- if .Arg.HasSqlcSlices }}
128+
{{- if and (not isYDBEngine) .Arg.HasSqlcSlices }}
129129
query := {{.ConstantName}}
130130
var queryParams []interface{}
131131
{{- if .Arg.Struct }}

internal/codegen/golang/ydb_type.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col
163163
}
164164
return "*string"
165165

166-
case "date", "date32", "datetime", "timestamp", "tzdate", "tztimestamp", "tzdatetime":
166+
case "date", "date32", "datetime", "timestamp", "tzdate", "tztimestamp", "tzdatetime", "datetime64", "timestamp64", "tzdate32", "tzdatetime64", "tztimestamp64":
167167
if notNull {
168168
return "time.Time"
169169
}
@@ -172,6 +172,15 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col
172172
}
173173
return "*time.Time"
174174

175+
case "interval", "interval64":
176+
if notNull {
177+
return "time.Duration"
178+
}
179+
if emitPointersForNull {
180+
return "*time.Duration"
181+
}
182+
return "*time.Duration"
183+
175184
case "uuid":
176185
if notNull {
177186
return "uuid.UUID"
@@ -197,7 +206,28 @@ func YDBType(req *plugin.GenerateRequest, options *opts.Options, col *plugin.Col
197206
case "any":
198207
return "interface{}"
199208

209+
case "integer":
210+
// integer type is used for LIMIT/OFFSET parameters - use uint64 for semantic correctness
211+
if notNull {
212+
return "uint64"
213+
}
214+
if emitPointersForNull {
215+
return "*uint64"
216+
}
217+
return "*uint64"
218+
200219
default:
220+
if strings.HasPrefix(columnType, "decimal") {
221+
if notNull {
222+
return "types.Decimal"
223+
}
224+
225+
if emitPointersForNull {
226+
return "*types.Decimal"
227+
}
228+
return "*types.Decimal"
229+
}
230+
201231
if debug.Active {
202232
log.Printf("unknown YDB type: %s\n", columnType)
203233
}

internal/endtoend/testdata/alias/ydb/stdlib/go/db.go

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/alias/ydb/stdlib/go/models.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/endtoend/testdata/alias/ydb/stdlib/go/query.sql.go

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- name: AliasBar :one
2+
SELECT * FROM bar
3+
WHERE b.id = $p0;

0 commit comments

Comments
 (0)