Skip to content
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

fix: Modify func prefix #46

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions internal/arcgen/lang/go/generate_orm_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const (
receiverName = "_orm"
queryerContextVarName = "dbtx"
queryerContextTypeName = "DBTX"
readOneFuncPrefix = "Get"
readManyFuncPrefix = "List"
)

func fprintORMCommon(osFile osFile, buf buffer, arcSrcSetSlice ARCSourceSetSlice, crudFiles []string) error {
Expand Down
22 changes: 11 additions & 11 deletions internal/arcgen/lang/go/generate_orm_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
columnNames := tableInfo.Columns.ColumnNames()
pks := tableInfo.Columns.PrimaryKeys()

// const Find{StructName}ByPKQuery = `SELECT {column_name1}, {column_name2} FROM {table_name} WHERE {pk1} = ? [AND ...]`
// const Get{StructName}ByPKQuery = `SELECT {column_name1}, {column_name2} FROM {table_name} WHERE {pk1} = ? [AND ...]`
//
// func (q *query) Find{StructName}ByPK(ctx context.Context, queryer QueryerContext, pk1 pk1type, ...) ({Struct}, error) {
// row := queryer.QueryRowContext(ctx, Find{StructName}Query, pk1, ...)
// func (q *query) Get{StructName}ByPK(ctx context.Context, queryer QueryerContext, pk1 pk1type, ...) ({Struct}, error) {
// row := queryer.QueryRowContext(ctx, Get{StructName}Query, pk1, ...)
// var s {Struct}
// if err := row.Scan(
// &s.{ColumnName1},
Expand All @@ -32,7 +32,7 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
// }
// return &s, nil
// }
byPKFuncName := "Find" + structName + "ByPK"
byPKFuncName := readOneFuncPrefix + structName + "ByPK"
byPKQueryName := byPKFuncName + "Query"
astFile.Decls = append(astFile.Decls,
&ast.GenDecl{
Expand Down Expand Up @@ -79,7 +79,7 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
}},
},
Body: &ast.BlockStmt{
// row, err := queryer.QueryRowContext(ctx, Find{StructName}Query, pk1, ...)
// row, err := queryer.QueryRowContext(ctx, Get{StructName}Query, pk1, ...)
List: []ast.Stmt{
&ast.ExprStmt{
// LoggerFromContext(ctx).Debug(queryName)
Expand Down Expand Up @@ -165,10 +165,10 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {

hasOneColumnsByTag := tableInfo.HasOneTagColumnsByTag()
for _, hasOneTag := range tableInfo.HasOneTags {
// const Find{StructName}By{FieldName}Query = `SELECT {column_name1}, {column_name2} FROM {table_name} WHERE {column} = ? [AND ...]`
// const Get{StructName}By{FieldName}Query = `SELECT {column_name1}, {column_name2} FROM {table_name} WHERE {column} = ? [AND ...]`
//
// func (q *queryer) Find{StructName}ByColumn1[AndColumn2](ctx context.Context, queryer QueryerContext, {ColumnName} {ColumnType} [, {Column2Name} {Column2Type}]) ({Struct}Slice, error) {
// row := queryer.QueryRowContext(ctx, Find{StructName}Query, {ColumnName}, {Column2Name})
// func (q *queryer) Get{StructName}ByColumn1[AndColumn2](ctx context.Context, queryer QueryerContext, {ColumnName} {ColumnType} [, {Column2Name} {Column2Type}]) ({Struct}Slice, error) {
// row := queryer.QueryRowContext(ctx, Get{StructName}Query, {ColumnName}, {Column2Name})
// var s {Struct}
// if err := row.Scan(
// &s.{ColumnName1},
Expand All @@ -178,7 +178,7 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
// }
// return &s, nil
// }
byHasOneTagFuncName := "Find" + structName + "By" + hasOneTag
byHasOneTagFuncName := readOneFuncPrefix + structName + "By" + hasOneTag
byHasOneTagQueryName := byHasOneTagFuncName + "Query"
hasOneColumns := hasOneColumnsByTag[hasOneTag]
astFile.Decls = append(astFile.Decls,
Expand Down Expand Up @@ -226,7 +226,7 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
}},
},
Body: &ast.BlockStmt{
// row, err := queryer.QueryRowContext(ctx, Find{StructName}Query, column1, ...)
// row, err := queryer.QueryRowContext(ctx, Get{StructName}Query, column1, ...)
List: []ast.Stmt{
&ast.ExprStmt{
// LoggerFromContext(ctx).Debug(queryName)
Expand Down Expand Up @@ -343,7 +343,7 @@ func generateREADContent(astFile *ast.File, arcSrcSet *ARCSourceSet) {
if sliceSuffix := config.GoSliceTypeSuffix(); sliceSuffix != "" {
structSliceType = importName + "." + structName + sliceSuffix
}
byHasOneTagFuncName := "List" + structName + "By" + hasManyTag
byHasOneTagFuncName := readManyFuncPrefix + structName + "By" + hasManyTag
byHasOneTagQueryName := byHasOneTagFuncName + "Query"
hasManyColumns := hasManyColumnsByTag[hasManyTag]
astFile.Decls = append(astFile.Decls,
Expand Down
7 changes: 6 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"context"
"encoding/json"
"os"
"sync"

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

remainingArgs, err = cmd.Parse(contexts.OSArgs(ctx))
osArgs := contexts.OSArgs(ctx)
if len(osArgs) == 0 {
osArgs = os.Args
}
remainingArgs, err = cmd.Parse(osArgs)
if err != nil {
return nil, nil, errorz.Errorf("cmd.Parse: %w", err)
}
Expand Down
Loading