Skip to content

Commit

Permalink
Merge pull request #31 from viant/handler_gen
Browse files Browse the repository at this point in the history
work in progress - abstracted out plugin info/artifact
  • Loading branch information
adranwit authored Jun 23, 2023
2 parents 0305678 + 3e20750 commit b368b33
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
19 changes: 19 additions & 0 deletions cmd/datly/datly.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ func main() {
log.Fatal(err)
}
}()

os.Args = []string{
"",
"gen",
"-o=patch",
"-g=campaign",
"-p=/Users/awitas/go/src/github.com/viant/datly/poc",
"-s=/Users/awitas/go/src/github.com/viant/datly/poc/dsql/campaign/init/campaign_patch.sql",
"-c=ci_ads|mysql|root:dev@tcp(127.0.0.1:3306)/ci_ads?parseTime=true",

/*
"",
"dsql",
"-p=/Users/awitas/go/src/github.com/viant/datly/poc",
"-s=/Users/awitas/go/src/github.com/viant/datly/poc/dsql/campaign/campaign_patch.sql",
"-c=ci_ads|mysql|root:dev@tcp(127.0.0.1:3306)/ci_ads?parseTime=true",
*/

}
server, err := cmd.New(Version, os.Args[1:], &ConsoleWriter{})
if err != nil {
log.Fatal(err)
Expand Down
9 changes: 8 additions & 1 deletion internal/codegen/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,17 @@ func NewSpec(ctx context.Context, db *sql.DB, table, SQL string) (*Spec, error)
}

func isAuxiliary(SQL string) bool {
SQL = strings.Trim(strings.TrimSpace(SQL), "()")
SQL = strings.TrimSpace(SQL)

if SQL == "" {
return false
}
if SQL[0] == '(' {
SQL = SQL[1:]
}
if SQL[len(SQL)-1] == '(' {
SQL = SQL[:len(SQL)-2]
}
query, _ := sqlparser.ParseQuery(SQL)
if query == nil {
return true
Expand Down
3 changes: 3 additions & 0 deletions internal/codegen/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ func (t *Tags) buildRelation(info *Spec, relation *Relation) {
if join == nil {
return
}
if relation.KeyField == nil {
return
}
datlyTag := TagValue{}
datlyTag.Append(fmt.Sprintf("ralName=%s", join.Alias))
datlyTag.Append(fmt.Sprintf("relColumn=%s", relation.ParentField.Column.Name))
Expand Down
2 changes: 1 addition & 1 deletion internal/codegen/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (t *Template) modifyRecords(options *Options, structPathPrefix string, spec
recordPath := t.RecordName(spec.Type.Name)
forEach := ast.NewForEach(ast.NewIdent(recordPath), ast.NewIdent(structPath), ast.Block{})

if rel != nil {
if rel != nil && rel.KeyField != nil {
parentSelector := structPathPrefix + "." + rel.ParentField.Name
holder := recordPath + "." + rel.KeyField.Name
assignKey := ast.NewAssign(ast.NewIdent(holder), ast.NewIdent(parentSelector))
Expand Down

0 comments on commit b368b33

Please sign in to comment.