Skip to content

Commit

Permalink
removed - unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Jun 23, 2023
1 parent f63a422 commit a961d5d
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 2,122 deletions.
62 changes: 41 additions & 21 deletions cmd/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/viant/datly/view"
"github.com/viant/parsly"
"github.com/viant/sqlparser"
qexpr "github.com/viant/sqlparser/expr"
"github.com/viant/sqlparser/node"
"github.com/viant/sqlparser/query"
sio "github.com/viant/sqlx/io"
"github.com/viant/sqlx/metadata/sink"
Expand Down Expand Up @@ -1474,28 +1476,7 @@ func (s *Builder) prepareRuleIfNeeded(ctx context.Context, SQL []byte) (string,
return "", err
}
SQL, err = s.fs.DownloadWithURL(ctx, s.Options.Generate.DSQLLocation())

return string(SQL), err
//
//
//dsql, err := template.GenerateDSQL()
//fmt.Printf("dsql: %v %v\n", dsql, err)
//state := template.GenerateState("")
//fmt.Printf("state %v\n", state)
//
//entity, err := template.GenerateEntity(ctx, "", nil)
//fmt.Printf("entity %s %v\n", entity, err)

switch strings.ToLower(s.options.PrepareRule) {
case PreparePost:
return s.preparePostRule(context.Background(), routeBuilder, SQL)
case PreparePatch:
return s.preparePatchRule(context.Background(), routeBuilder, SQL)
case PreparePut:
return s.preparePutRule(context.Background(), routeBuilder, SQL)
default:
return "", fmt.Errorf("unsupported prepare rule type")
}
}

func (s *Builder) loadGoType(resource *view.Resource, typeSrc *option.TypeSrcConfig) error {
Expand Down Expand Up @@ -2250,3 +2231,42 @@ func stringifyAst(expr ast.Expr, builder *strings.Builder) error {
}
return nil
}

func extractRelationAliases(join *query.Join) (string, string) {
relAlias := ""
refAlias := ""
sqlparser.Traverse(join.On, func(n node.Node) bool {
switch actual := n.(type) {
case *qexpr.Binary:
if xSel, ok := actual.X.(*qexpr.Selector); ok {

if xSel.Name == join.Alias {

refAlias = xSel.Name
} else if relAlias == "" {
relAlias = xSel.Name
}
}
if ySel, ok := actual.Y.(*qexpr.Selector); ok {
if ySel.Name == join.Alias {
refAlias = ySel.Name
} else if relAlias == "" {
relAlias = ySel.Name
}
}
return true
}
return true
})
return relAlias, refAlias
}

func (c *ViewConfig) IsToMany() bool {
if c.parent == nil {
return c.outputConfig.IsMany()
}
if c.parent.IsToMany() {
return true
}
return false
}
27 changes: 27 additions & 0 deletions cmd/configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bytes"
"context"
"database/sql"
"fmt"
"github.com/viant/datly/cmd/option"
"github.com/viant/datly/config"
Expand All @@ -15,6 +16,9 @@ import (
"github.com/viant/sqlparser/expr"
"github.com/viant/sqlparser/node"
"github.com/viant/sqlparser/query"
"github.com/viant/sqlx/metadata"
"github.com/viant/sqlx/metadata/info"
"github.com/viant/sqlx/metadata/sink"
rdata "github.com/viant/toolbox/data"
expr2 "github.com/viant/velty/ast/expr"
"net/http"
Expand Down Expand Up @@ -595,3 +599,26 @@ outer:
}
return builder.String()
}

func readForeignKeys(ctx context.Context, db *sql.DB, tableName string) ([]sink.Key, error) {
if tableName == "" {
return nil, nil
}
meta := metadata.New()
var keys []sink.Key
if err := meta.Info(ctx, db, info.KindForeignKeys, &keys); err != nil {
return nil, err
}

return filterKeys(keys, tableName), nil
}

func filterKeys(keys []sink.Key, tableName string) []sink.Key {
var tableKeys []sink.Key
for i, aKey := range keys {
if aKey.Table == tableName {
tableKeys = append(tableKeys, keys[i])
}
}
return tableKeys
}
Loading

0 comments on commit a961d5d

Please sign in to comment.