From 5eb8e965367ee50542de1e9895ec25a81e4bc390 Mon Sep 17 00:00:00 2001 From: Murali1459 Date: Sat, 27 Sep 2025 22:35:44 +0530 Subject: [PATCH 1/4] added support for query_parameter_limit --- internal/codegen/queries.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/internal/codegen/queries.go b/internal/codegen/queries.go index f0d0205..c5ad50f 100644 --- a/internal/codegen/queries.go +++ b/internal/codegen/queries.go @@ -14,6 +14,10 @@ func resultRecordName(q core.Query) string { return strcase.ToCamel(q.MethodName) + "Row" } +func queryInputName(q core.Query) string { + return strcase.ToCamel(q.MethodName) + "QueryInput" +} + func createEmbeddedModel(sb *IndentStringBuilder, prefix, suffix string, identLevel, paramIdx int, r core.QueryReturn, embeddedModels core.EmbeddedModels) int { modelName := *r.EmbeddedModel model := embeddedModels[modelName] @@ -247,10 +251,37 @@ func BuildQueriesFile(engine string, config core.Config, queryFilename string, q methodBody.WriteIndentedString(2, "var stmt = conn.prepareStatement("+q.MethodName+");\n") } + queryInput := "" + + // input method for query params limit + if len(q.Args) > config.QueryParameterLimit { + queryInput = queryInputName(q) + + body.WriteString("\n") + body.WriteIndentedString(1, "public record "+queryInput+"(\n") + for i, arg := range q.Args { + imps, err := body.writeParameter(arg.JavaType, arg.Name, nonNullAnnotation, nullableAnnotation) + if err != nil { + return "", nil, err + } + if imps != nil { + imports = append(imports, imps...) + } + + if i != len(q.Args)-1 { + body.WriteString(",\n") + } + } + body.WriteString("\n") + body.WriteIndentedString(1, ") {}\n") + } + // write the method signature body.WriteString("\n") body.WriteIndentedString(1, fmt.Sprintf("public %s %s(", returnType, q.MethodName)) - if len(q.Args) > 0 { + if len(q.Args) > config.QueryParameterLimit { + body.WriteString(fmt.Sprintf("%s %sinput) throws SQLException{\n", queryInput, queryInput)) + } else if len(q.Args) > 0 { body.WriteString("\n") for i, arg := range q.Args { From 0e4b2b99edba8dfdb8b3efba54d4e277a7424227 Mon Sep 17 00:00:00 2001 From: Murali1459 Date: Sat, 27 Sep 2025 22:39:19 +0530 Subject: [PATCH 2/4] added default behaviour for backward compatibility --- internal/codegen/queries.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/codegen/queries.go b/internal/codegen/queries.go index c5ad50f..0a242d0 100644 --- a/internal/codegen/queries.go +++ b/internal/codegen/queries.go @@ -254,7 +254,7 @@ func BuildQueriesFile(engine string, config core.Config, queryFilename string, q queryInput := "" // input method for query params limit - if len(q.Args) > config.QueryParameterLimit { + if len(q.Args) > config.QueryParameterLimit && config.QueryParameterLimit != 0 { queryInput = queryInputName(q) body.WriteString("\n") @@ -279,7 +279,7 @@ func BuildQueriesFile(engine string, config core.Config, queryFilename string, q // write the method signature body.WriteString("\n") body.WriteIndentedString(1, fmt.Sprintf("public %s %s(", returnType, q.MethodName)) - if len(q.Args) > config.QueryParameterLimit { + if len(q.Args) > config.QueryParameterLimit && config.QueryParameterLimit != 0 { body.WriteString(fmt.Sprintf("%s %sinput) throws SQLException{\n", queryInput, queryInput)) } else if len(q.Args) > 0 { body.WriteString("\n") From d6f57de0fc7792cbb469a65eb3176cc9b160cb71 Mon Sep 17 00:00:00 2001 From: Murali1459 Date: Sat, 11 Oct 2025 23:37:09 +0530 Subject: [PATCH 3/4] Adding Comments --- internal/codegen/queries.go | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/internal/codegen/queries.go b/internal/codegen/queries.go index 0a242d0..3080742 100644 --- a/internal/codegen/queries.go +++ b/internal/codegen/queries.go @@ -253,8 +253,9 @@ func BuildQueriesFile(engine string, config core.Config, queryFilename string, q queryInput := "" + useInputRecord := config.QueryParameterLimit != 0 && len(q.Args) >= config.QueryParameterLimit // input method for query params limit - if len(q.Args) > config.QueryParameterLimit && config.QueryParameterLimit != 0 { + if useInputRecord { queryInput = queryInputName(q) body.WriteString("\n") @@ -279,22 +280,29 @@ func BuildQueriesFile(engine string, config core.Config, queryFilename string, q // write the method signature body.WriteString("\n") body.WriteIndentedString(1, fmt.Sprintf("public %s %s(", returnType, q.MethodName)) - if len(q.Args) > config.QueryParameterLimit && config.QueryParameterLimit != 0 { - body.WriteString(fmt.Sprintf("%s %sinput) throws SQLException{\n", queryInput, queryInput)) - } else if len(q.Args) > 0 { + + if len(q.Args) > 0 { body.WriteString("\n") - for i, arg := range q.Args { - imps, err := body.writeParameter(arg.JavaType, arg.Name, nonNullAnnotation, nullableAnnotation) - if err != nil { - return "", nil, err - } - if imps != nil { - imports = append(imports, imps...) - } + if useInputRecord { + body.WriteIndentedString(2, fmt.Sprintf("%s input", queryInput)) + } - if i != len(q.Args)-1 { - body.WriteString(",\n") + for i, arg := range q.Args { + if useInputRecord { + arg.Name = "input." + arg.Name + } else { + imps, err := body.writeParameter(arg.JavaType, arg.Name, nonNullAnnotation, nullableAnnotation) + if err != nil { + return "", nil, err + } + if imps != nil { + imports = append(imports, imps...) + } + + if i != len(q.Args)-1 { + body.WriteString(",\n") + } } methodBody.WriteIndentedString(2, arg.BindStmt(engine)+"\n") From 064b8f4c8e530cee62f977a5f5b39e2d7e2fdf1f Mon Sep 17 00:00:00 2001 From: Murali1459 Date: Sun, 12 Oct 2025 00:36:44 +0530 Subject: [PATCH 4/4] Updated README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4374918..5b9689c 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ A WASM plugin for SQLC allowing the generation of Java code. | `package` | string | yes | The name of the package where the generated files will be located. | | `emit_exact_table_names` | boolean | no | Whether table names will not be forced to singular form when generating the models. Defaults to `false`. | | `inflection_exclude_table_names` | []string | no | Table names to be excluded from being forced into singular form when generating the models. | -| `query_parameter_limit` | integer | no | not yet implemented | +| `query_parameter_limit` | integer | no | The max number of query parameters allowed before automatically generating a data model for method input. | | `indent_char` | string | no | The character to use to indent the code. Defaults to space `" "`. | | `chars_per_indent_level` | integer | no | The number of characters per indent level. Defaults to `4`. | | `nullable_annotation` | string | no | The full import path for the nullable annotation to use. Defaults to `org.jspecify.annotations.Nullable`. Set to empty string to disable. |