Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 98d50a6

Browse files
authored
fix: Modify func prefix (#46)
2 parents 503e364 + 6814f85 commit 98d50a6

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

internal/arcgen/lang/go/generate_orm_common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const (
2121
receiverName = "_orm"
2222
queryerContextVarName = "dbtx"
2323
queryerContextTypeName = "DBTX"
24+
readOneFuncPrefix = "Get"
25+
readManyFuncPrefix = "List"
2426
)
2527

2628
func fprintORMCommon(osFile osFile, buf buffer, arcSrcSetSlice ARCSourceSetSlice, crudFiles []string) error {

internal/arcgen/lang/go/generate_orm_read.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
1919
columnNames := tableInfo.Columns.ColumnNames()
2020
pks := tableInfo.Columns.PrimaryKeys()
2121

22-
// const Find{StructName}ByPKQuery = `SELECT {column_name1}, {column_name2} FROM {table_name} WHERE {pk1} = ? [AND ...]`
22+
// const Get{StructName}ByPKQuery = `SELECT {column_name1}, {column_name2} FROM {table_name} WHERE {pk1} = ? [AND ...]`
2323
//
24-
// func (q *query) Find{StructName}ByPK(ctx context.Context, queryer QueryerContext, pk1 pk1type, ...) ({Struct}, error) {
25-
// row := queryer.QueryRowContext(ctx, Find{StructName}Query, pk1, ...)
24+
// func (q *query) Get{StructName}ByPK(ctx context.Context, queryer QueryerContext, pk1 pk1type, ...) ({Struct}, error) {
25+
// row := queryer.QueryRowContext(ctx, Get{StructName}Query, pk1, ...)
2626
// var s {Struct}
2727
// if err := row.Scan(
2828
// &s.{ColumnName1},
@@ -32,7 +32,7 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
3232
// }
3333
// return &s, nil
3434
// }
35-
byPKFuncName := "Find" + structName + "ByPK"
35+
byPKFuncName := readOneFuncPrefix + structName + "ByPK"
3636
byPKQueryName := byPKFuncName + "Query"
3737
astFile.Decls = append(astFile.Decls,
3838
&ast.GenDecl{
@@ -79,7 +79,7 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
7979
}},
8080
},
8181
Body: &ast.BlockStmt{
82-
// row, err := queryer.QueryRowContext(ctx, Find{StructName}Query, pk1, ...)
82+
// row, err := queryer.QueryRowContext(ctx, Get{StructName}Query, pk1, ...)
8383
List: []ast.Stmt{
8484
&ast.ExprStmt{
8585
// LoggerFromContext(ctx).Debug(queryName)
@@ -165,10 +165,10 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
165165

166166
hasOneColumnsByTag := tableInfo.HasOneTagColumnsByTag()
167167
for _, hasOneTag := range tableInfo.HasOneTags {
168-
// const Find{StructName}By{FieldName}Query = `SELECT {column_name1}, {column_name2} FROM {table_name} WHERE {column} = ? [AND ...]`
168+
// const Get{StructName}By{FieldName}Query = `SELECT {column_name1}, {column_name2} FROM {table_name} WHERE {column} = ? [AND ...]`
169169
//
170-
// func (q *queryer) Find{StructName}ByColumn1[AndColumn2](ctx context.Context, queryer QueryerContext, {ColumnName} {ColumnType} [, {Column2Name} {Column2Type}]) ({Struct}Slice, error) {
171-
// row := queryer.QueryRowContext(ctx, Find{StructName}Query, {ColumnName}, {Column2Name})
170+
// func (q *queryer) Get{StructName}ByColumn1[AndColumn2](ctx context.Context, queryer QueryerContext, {ColumnName} {ColumnType} [, {Column2Name} {Column2Type}]) ({Struct}Slice, error) {
171+
// row := queryer.QueryRowContext(ctx, Get{StructName}Query, {ColumnName}, {Column2Name})
172172
// var s {Struct}
173173
// if err := row.Scan(
174174
// &s.{ColumnName1},
@@ -178,7 +178,7 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
178178
// }
179179
// return &s, nil
180180
// }
181-
byHasOneTagFuncName := "Find" + structName + "By" + hasOneTag
181+
byHasOneTagFuncName := readOneFuncPrefix + structName + "By" + hasOneTag
182182
byHasOneTagQueryName := byHasOneTagFuncName + "Query"
183183
hasOneColumns := hasOneColumnsByTag[hasOneTag]
184184
astFile.Decls = append(astFile.Decls,
@@ -226,7 +226,7 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
226226
}},
227227
},
228228
Body: &ast.BlockStmt{
229-
// row, err := queryer.QueryRowContext(ctx, Find{StructName}Query, column1, ...)
229+
// row, err := queryer.QueryRowContext(ctx, Get{StructName}Query, column1, ...)
230230
List: []ast.Stmt{
231231
&ast.ExprStmt{
232232
// LoggerFromContext(ctx).Debug(queryName)
@@ -343,7 +343,7 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
343343
if sliceSuffix := config.GoSliceTypeSuffix(); sliceSuffix != "" {
344344
structSliceType = importName + "." + structName + sliceSuffix
345345
}
346-
byHasOneTagFuncName := "List" + structName + "By" + hasManyTag
346+
byHasOneTagFuncName := readManyFuncPrefix + structName + "By" + hasManyTag
347347
byHasOneTagQueryName := byHasOneTagFuncName + "Query"
348348
hasManyColumns := hasManyColumnsByTag[hasManyTag]
349349
astFile.Decls = append(astFile.Decls,

internal/config/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package config
33
import (
44
"context"
55
"encoding/json"
6+
"os"
67
"sync"
78

89
errorz "github.com/kunitsucom/util.go/errors"
@@ -179,7 +180,11 @@ func load(ctx context.Context) (cfg *config, remainingArgs []string, err error)
179180
},
180181
}
181182

182-
remainingArgs, err = cmd.Parse(contexts.OSArgs(ctx))
183+
osArgs := contexts.OSArgs(ctx)
184+
if len(osArgs) == 0 {
185+
osArgs = os.Args
186+
}
187+
remainingArgs, err = cmd.Parse(osArgs)
183188
if err != nil {
184189
return nil, nil, errorz.Errorf("cmd.Parse: %w", err)
185190
}

0 commit comments

Comments
 (0)