-
Notifications
You must be signed in to change notification settings - Fork 1
Made new params building logic & got rid off .Query handle #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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)) | ||||||
|
||||||
| panic(fmt.Sprintf("unknown YDB column type for param %s (goType=%s)", name, goType)) | |
| panic(fmt.Sprintf("unknown YDB column type for param %s (goType=%s, columnType=%s)", name, goType, sdk.DataType(field.Column.Type))) |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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" | ||||
|
|
||||
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TODO comment should specify which types need to be supported or reference an issue. An empty return value could lead to the panic in YDBParamsBuilder without clear indication of what's missing.