Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions internal/cmd/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,39 @@ func pluginCodegen(s config.Codegen) *plugin.Codegen {

func pluginPythonCode(s config.SQLPython) *plugin.PythonCode {
return &plugin.PythonCode{
Out: s.Out,
Package: s.Package,
EmitExactTableNames: s.EmitExactTableNames,
EmitSyncQuerier: s.EmitSyncQuerier,
EmitAsyncQuerier: s.EmitAsyncQuerier,
EmitPydanticModels: s.EmitPydanticModels,
Out: s.Out,
Package: s.Package,
EmitExactTableNames: s.EmitExactTableNames,
EmitSyncQuerier: s.EmitSyncQuerier,
EmitAsyncQuerier: s.EmitAsyncQuerier,
EmitPydanticModels: s.EmitPydanticModels,
InflectionExcludeTableNames: s.InflectionExcludeTableNames,
}
}

func pluginGoCode(s config.SQLGo) *plugin.GoCode {
return &plugin.GoCode{
EmitInterface: s.EmitInterface,
EmitJsonTags: s.EmitJSONTags,
EmitDbTags: s.EmitDBTags,
EmitPreparedQueries: s.EmitPreparedQueries,
EmitExactTableNames: s.EmitExactTableNames,
EmitEmptySlices: s.EmitEmptySlices,
EmitExportedQueries: s.EmitExportedQueries,
EmitResultStructPointers: s.EmitResultStructPointers,
EmitParamsStructPointers: s.EmitParamsStructPointers,
EmitMethodsWithDbArgument: s.EmitMethodsWithDBArgument,
EmitEnumValidMethod: s.EmitEnumValidMethod,
EmitAllEnumValues: s.EmitAllEnumValues,
JsonTagsCaseStyle: s.JSONTagsCaseStyle,
Package: s.Package,
Out: s.Out,
SqlPackage: s.SQLPackage,
OutputDbFileName: s.OutputDBFileName,
OutputModelsFileName: s.OutputModelsFileName,
OutputQuerierFileName: s.OutputQuerierFileName,
OutputFilesSuffix: s.OutputFilesSuffix,
EmitInterface: s.EmitInterface,
EmitJsonTags: s.EmitJSONTags,
EmitDbTags: s.EmitDBTags,
EmitPreparedQueries: s.EmitPreparedQueries,
EmitExactTableNames: s.EmitExactTableNames,
EmitEmptySlices: s.EmitEmptySlices,
EmitExportedQueries: s.EmitExportedQueries,
EmitResultStructPointers: s.EmitResultStructPointers,
EmitParamsStructPointers: s.EmitParamsStructPointers,
EmitMethodsWithDbArgument: s.EmitMethodsWithDBArgument,
EmitEnumValidMethod: s.EmitEnumValidMethod,
EmitAllEnumValues: s.EmitAllEnumValues,
JsonTagsCaseStyle: s.JSONTagsCaseStyle,
Package: s.Package,
Out: s.Out,
SqlPackage: s.SQLPackage,
OutputDbFileName: s.OutputDBFileName,
OutputModelsFileName: s.OutputModelsFileName,
OutputQuerierFileName: s.OutputQuerierFileName,
OutputFilesSuffix: s.OutputFilesSuffix,
InflectionExcludeTableNames: s.InflectionExcludeTableNames,
}
}

Expand All @@ -136,9 +138,10 @@ func pluginPythonType(pt config.PythonType) *plugin.PythonType {

func pluginKotlinCode(s config.SQLKotlin) *plugin.KotlinCode {
return &plugin.KotlinCode{
Out: s.Out,
Package: s.Package,
EmitExactTableNames: s.EmitExactTableNames,
Out: s.Out,
Package: s.Package,
EmitExactTableNames: s.EmitExactTableNames,
InflectionExcludeTableNames: s.InflectionExcludeTableNames,
}
}

Expand Down
5 changes: 4 additions & 1 deletion internal/codegen/golang/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ func buildStructs(req *plugin.CodeGenRequest) []Struct {
}
structName := tableName
if !req.Settings.Go.EmitExactTableNames {
structName = inflection.Singular(structName)
structName = inflection.Singular(inflection.SingularParams{
Name: structName,
Exclusions: req.Settings.Go.InflectionExcludeTableNames,
})
}
s := Struct{
Table: plugin.Identifier{Schema: schema.Name, Name: table.Rel.Name},
Expand Down
5 changes: 4 additions & 1 deletion internal/codegen/kotlin/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ func buildDataClasses(req *plugin.CodeGenRequest) []Struct {
}
structName := dataClassName(tableName, req.Settings)
if !req.Settings.Kotlin.EmitExactTableNames {
structName = inflection.Singular(structName)
structName = inflection.Singular(inflection.SingularParams{
Name: structName,
Exclusions: req.Settings.Kotlin.InflectionExcludeTableNames,
})
}
s := Struct{
Table: plugin.Identifier{Schema: schema.Name, Name: table.Rel.Name},
Expand Down
5 changes: 4 additions & 1 deletion internal/codegen/python/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ func buildModels(req *plugin.CodeGenRequest) []Struct {
}
structName := tableName
if !req.Settings.Python.EmitExactTableNames {
structName = inflection.Singular(structName)
structName = inflection.Singular(inflection.SingularParams{
Name: structName,
Exclusions: req.Settings.Python.InflectionExcludeTableNames,
})
}
s := Struct{
Table: plugin.Identifier{Schema: schema.Name, Name: table.Rel.Name},
Expand Down
67 changes: 35 additions & 32 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,44 +131,47 @@ type SQLGen struct {
}

type SQLGo struct {
EmitInterface bool `json:"emit_interface" yaml:"emit_interface"`
EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags"`
EmitDBTags bool `json:"emit_db_tags" yaml:"emit_db_tags"`
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
EmitEmptySlices bool `json:"emit_empty_slices,omitempty" yaml:"emit_empty_slices"`
EmitExportedQueries bool `json:"emit_exported_queries" yaml:"emit_exported_queries"`
EmitResultStructPointers bool `json:"emit_result_struct_pointers" yaml:"emit_result_struct_pointers"`
EmitParamsStructPointers bool `json:"emit_params_struct_pointers" yaml:"emit_params_struct_pointers"`
EmitMethodsWithDBArgument bool `json:"emit_methods_with_db_argument,omitempty" yaml:"emit_methods_with_db_argument"`
EmitEnumValidMethod bool `json:"emit_enum_valid_method,omitempty" yaml:"emit_enum_valid_method"`
EmitAllEnumValues bool `json:"emit_all_enum_values,omitempty" yaml:"emit_all_enum_values"`
JSONTagsCaseStyle string `json:"json_tags_case_style,omitempty" yaml:"json_tags_case_style"`
Package string `json:"package" yaml:"package"`
Out string `json:"out" yaml:"out"`
Overrides []Override `json:"overrides,omitempty" yaml:"overrides"`
Rename map[string]string `json:"rename,omitempty" yaml:"rename"`
SQLPackage string `json:"sql_package" yaml:"sql_package"`
OutputDBFileName string `json:"output_db_file_name,omitempty" yaml:"output_db_file_name"`
OutputModelsFileName string `json:"output_models_file_name,omitempty" yaml:"output_models_file_name"`
OutputQuerierFileName string `json:"output_querier_file_name,omitempty" yaml:"output_querier_file_name"`
OutputFilesSuffix string `json:"output_files_suffix,omitempty" yaml:"output_files_suffix"`
EmitInterface bool `json:"emit_interface" yaml:"emit_interface"`
EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags"`
EmitDBTags bool `json:"emit_db_tags" yaml:"emit_db_tags"`
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
EmitEmptySlices bool `json:"emit_empty_slices,omitempty" yaml:"emit_empty_slices"`
EmitExportedQueries bool `json:"emit_exported_queries" yaml:"emit_exported_queries"`
EmitResultStructPointers bool `json:"emit_result_struct_pointers" yaml:"emit_result_struct_pointers"`
EmitParamsStructPointers bool `json:"emit_params_struct_pointers" yaml:"emit_params_struct_pointers"`
EmitMethodsWithDBArgument bool `json:"emit_methods_with_db_argument,omitempty" yaml:"emit_methods_with_db_argument"`
EmitEnumValidMethod bool `json:"emit_enum_valid_method,omitempty" yaml:"emit_enum_valid_method"`
EmitAllEnumValues bool `json:"emit_all_enum_values,omitempty" yaml:"emit_all_enum_values"`
JSONTagsCaseStyle string `json:"json_tags_case_style,omitempty" yaml:"json_tags_case_style"`
Package string `json:"package" yaml:"package"`
Out string `json:"out" yaml:"out"`
Overrides []Override `json:"overrides,omitempty" yaml:"overrides"`
Rename map[string]string `json:"rename,omitempty" yaml:"rename"`
SQLPackage string `json:"sql_package" yaml:"sql_package"`
OutputDBFileName string `json:"output_db_file_name,omitempty" yaml:"output_db_file_name"`
OutputModelsFileName string `json:"output_models_file_name,omitempty" yaml:"output_models_file_name"`
OutputQuerierFileName string `json:"output_querier_file_name,omitempty" yaml:"output_querier_file_name"`
OutputFilesSuffix string `json:"output_files_suffix,omitempty" yaml:"output_files_suffix"`
InflectionExcludeTableNames []string `json:"inflection_exclude_table_names,omitempty" yaml:"inflection_exclude_table_names"`
}

type SQLKotlin struct {
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
Package string `json:"package" yaml:"package"`
Out string `json:"out" yaml:"out"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
Package string `json:"package" yaml:"package"`
Out string `json:"out" yaml:"out"`
InflectionExcludeTableNames []string `json:"inflection_exclude_table_names,omitempty" yaml:"inflection_exclude_table_names"`
}

type SQLPython struct {
EmitExactTableNames bool `json:"emit_exact_table_names" yaml:"emit_exact_table_names"`
EmitSyncQuerier bool `json:"emit_sync_querier" yaml:"emit_sync_querier"`
EmitAsyncQuerier bool `json:"emit_async_querier" yaml:"emit_async_querier"`
Package string `json:"package" yaml:"package"`
Out string `json:"out" yaml:"out"`
Overrides []Override `json:"overrides,omitempty" yaml:"overrides"`
EmitPydanticModels bool `json:"emit_pydantic_models,omitempty" yaml:"emit_pydantic_models"`
EmitExactTableNames bool `json:"emit_exact_table_names" yaml:"emit_exact_table_names"`
EmitSyncQuerier bool `json:"emit_sync_querier" yaml:"emit_sync_querier"`
EmitAsyncQuerier bool `json:"emit_async_querier" yaml:"emit_async_querier"`
Package string `json:"package" yaml:"package"`
Out string `json:"out" yaml:"out"`
Overrides []Override `json:"overrides,omitempty" yaml:"overrides"`
EmitPydanticModels bool `json:"emit_pydantic_models,omitempty" yaml:"emit_pydantic_models"`
InflectionExcludeTableNames []string `json:"inflection_exclude_table_names,omitempty" yaml:"inflection_exclude_table_names"`
}

type SQLJSON struct {
Expand Down
94 changes: 48 additions & 46 deletions internal/config/v_one.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,32 @@ type V1GenerateSettings struct {
}

type v1PackageSettings struct {
Name string `json:"name" yaml:"name"`
Engine Engine `json:"engine,omitempty" yaml:"engine"`
Path string `json:"path" yaml:"path"`
Schema Paths `json:"schema" yaml:"schema"`
Queries Paths `json:"queries" yaml:"queries"`
EmitInterface bool `json:"emit_interface" yaml:"emit_interface"`
EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags"`
EmitDBTags bool `json:"emit_db_tags" yaml:"emit_db_tags"`
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
EmitEmptySlices bool `json:"emit_empty_slices,omitempty" yaml:"emit_empty_slices"`
EmitExportedQueries bool `json:"emit_exported_queries,omitempty" yaml:"emit_exported_queries"`
EmitResultStructPointers bool `json:"emit_result_struct_pointers" yaml:"emit_result_struct_pointers"`
EmitParamsStructPointers bool `json:"emit_params_struct_pointers" yaml:"emit_params_struct_pointers"`
EmitMethodsWithDBArgument bool `json:"emit_methods_with_db_argument" yaml:"emit_methods_with_db_argument"`
EmitEnumValidMethod bool `json:"emit_enum_valid_method,omitempty" yaml:"emit_enum_valid_method"`
EmitAllEnumValues bool `json:"emit_all_enum_values,omitempty" yaml:"emit_all_enum_values"`
JSONTagsCaseStyle string `json:"json_tags_case_style,omitempty" yaml:"json_tags_case_style"`
SQLPackage string `json:"sql_package" yaml:"sql_package"`
Overrides []Override `json:"overrides" yaml:"overrides"`
OutputDBFileName string `json:"output_db_file_name,omitempty" yaml:"output_db_file_name"`
OutputModelsFileName string `json:"output_models_file_name,omitempty" yaml:"output_models_file_name"`
OutputQuerierFileName string `json:"output_querier_file_name,omitempty" yaml:"output_querier_file_name"`
OutputFilesSuffix string `json:"output_files_suffix,omitempty" yaml:"output_files_suffix"`
StrictFunctionChecks bool `json:"strict_function_checks" yaml:"strict_function_checks"`
Name string `json:"name" yaml:"name"`
Engine Engine `json:"engine,omitempty" yaml:"engine"`
Path string `json:"path" yaml:"path"`
Schema Paths `json:"schema" yaml:"schema"`
Queries Paths `json:"queries" yaml:"queries"`
EmitInterface bool `json:"emit_interface" yaml:"emit_interface"`
EmitJSONTags bool `json:"emit_json_tags" yaml:"emit_json_tags"`
EmitDBTags bool `json:"emit_db_tags" yaml:"emit_db_tags"`
EmitPreparedQueries bool `json:"emit_prepared_queries" yaml:"emit_prepared_queries"`
EmitExactTableNames bool `json:"emit_exact_table_names,omitempty" yaml:"emit_exact_table_names"`
EmitEmptySlices bool `json:"emit_empty_slices,omitempty" yaml:"emit_empty_slices"`
EmitExportedQueries bool `json:"emit_exported_queries,omitempty" yaml:"emit_exported_queries"`
EmitResultStructPointers bool `json:"emit_result_struct_pointers" yaml:"emit_result_struct_pointers"`
EmitParamsStructPointers bool `json:"emit_params_struct_pointers" yaml:"emit_params_struct_pointers"`
EmitMethodsWithDBArgument bool `json:"emit_methods_with_db_argument" yaml:"emit_methods_with_db_argument"`
EmitEnumValidMethod bool `json:"emit_enum_valid_method,omitempty" yaml:"emit_enum_valid_method"`
EmitAllEnumValues bool `json:"emit_all_enum_values,omitempty" yaml:"emit_all_enum_values"`
JSONTagsCaseStyle string `json:"json_tags_case_style,omitempty" yaml:"json_tags_case_style"`
SQLPackage string `json:"sql_package" yaml:"sql_package"`
Overrides []Override `json:"overrides" yaml:"overrides"`
OutputDBFileName string `json:"output_db_file_name,omitempty" yaml:"output_db_file_name"`
OutputModelsFileName string `json:"output_models_file_name,omitempty" yaml:"output_models_file_name"`
OutputQuerierFileName string `json:"output_querier_file_name,omitempty" yaml:"output_querier_file_name"`
OutputFilesSuffix string `json:"output_files_suffix,omitempty" yaml:"output_files_suffix"`
StrictFunctionChecks bool `json:"strict_function_checks" yaml:"strict_function_checks"`
InflectionExcludeTableNames []string `json:"inflection_exclude_table_names,omitempty" yaml:"inflection_exclude_table_names"`
}

func v1ParseConfig(rd io.Reader) (Config, error) {
Expand Down Expand Up @@ -118,27 +119,28 @@ func (c *V1GenerateSettings) Translate() Config {
Queries: pkg.Queries,
Gen: SQLGen{
Go: &SQLGo{
EmitInterface: pkg.EmitInterface,
EmitJSONTags: pkg.EmitJSONTags,
EmitDBTags: pkg.EmitDBTags,
EmitPreparedQueries: pkg.EmitPreparedQueries,
EmitExactTableNames: pkg.EmitExactTableNames,
EmitEmptySlices: pkg.EmitEmptySlices,
EmitExportedQueries: pkg.EmitExportedQueries,
EmitResultStructPointers: pkg.EmitResultStructPointers,
EmitParamsStructPointers: pkg.EmitParamsStructPointers,
EmitMethodsWithDBArgument: pkg.EmitMethodsWithDBArgument,
EmitEnumValidMethod: pkg.EmitEnumValidMethod,
EmitAllEnumValues: pkg.EmitAllEnumValues,
Package: pkg.Name,
Out: pkg.Path,
SQLPackage: pkg.SQLPackage,
Overrides: pkg.Overrides,
JSONTagsCaseStyle: pkg.JSONTagsCaseStyle,
OutputDBFileName: pkg.OutputDBFileName,
OutputModelsFileName: pkg.OutputModelsFileName,
OutputQuerierFileName: pkg.OutputQuerierFileName,
OutputFilesSuffix: pkg.OutputFilesSuffix,
EmitInterface: pkg.EmitInterface,
EmitJSONTags: pkg.EmitJSONTags,
EmitDBTags: pkg.EmitDBTags,
EmitPreparedQueries: pkg.EmitPreparedQueries,
EmitExactTableNames: pkg.EmitExactTableNames,
EmitEmptySlices: pkg.EmitEmptySlices,
EmitExportedQueries: pkg.EmitExportedQueries,
EmitResultStructPointers: pkg.EmitResultStructPointers,
EmitParamsStructPointers: pkg.EmitParamsStructPointers,
EmitMethodsWithDBArgument: pkg.EmitMethodsWithDBArgument,
EmitEnumValidMethod: pkg.EmitEnumValidMethod,
EmitAllEnumValues: pkg.EmitAllEnumValues,
Package: pkg.Name,
Out: pkg.Path,
SQLPackage: pkg.SQLPackage,
Overrides: pkg.Overrides,
JSONTagsCaseStyle: pkg.JSONTagsCaseStyle,
OutputDBFileName: pkg.OutputDBFileName,
OutputModelsFileName: pkg.OutputModelsFileName,
OutputQuerierFileName: pkg.OutputQuerierFileName,
OutputFilesSuffix: pkg.OutputFilesSuffix,
InflectionExcludeTableNames: pkg.InflectionExcludeTableNames,
},
},
StrictFunctionChecks: pkg.StrictFunctionChecks,
Expand Down
9 changes: 6 additions & 3 deletions internal/endtoend/testdata/codegen_json/gen/codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
"emit_async_querier": false,
"package": "",
"out": "",
"emit_pydantic_models": false
"emit_pydantic_models": false,
"inflection_exclude_table_names": []
},
"kotlin": {
"emit_exact_table_names": false,
"package": "",
"out": ""
"out": "",
"inflection_exclude_table_names": []
},
"go": {
"emit_interface": false,
Expand All @@ -48,7 +50,8 @@
"output_querier_file_name": "",
"output_files_suffix": "",
"emit_enum_valid_method": false,
"emit_all_enum_values": false
"emit_all_enum_values": false,
"inflection_exclude_table_names": []
},
"json": {
"out": "gen",
Expand Down
Loading