Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
7240b27214 | |||
f37d867e32 | |||
5e75cc7b83 | |||
76340ab008 |
@ -932,7 +932,6 @@ func (c *compilerContext) renderNestedWhere(ex *qcode.Exp, ti *DBTableInfo) erro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println(">", ex)
|
|
||||||
io.WriteString(c.w, `)`)
|
io.WriteString(c.w, `)`)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/gobuffalo/flect"
|
"github.com/gobuffalo/flect"
|
||||||
"github.com/jackc/pgx/v4/pgxpool"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type DBSchema struct {
|
type DBSchema struct {
|
||||||
@ -51,8 +50,7 @@ type DBRel struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDBSchema(db *pgxpool.Pool,
|
func NewDBSchema(info *DBInfo, aliases map[string][]string) (*DBSchema, error) {
|
||||||
info *DBInfo, aliases map[string][]string) (*DBSchema, error) {
|
|
||||||
|
|
||||||
schema := &DBSchema{
|
schema := &DBSchema{
|
||||||
t: make(map[string]*DBTableInfo),
|
t: make(map[string]*DBTableInfo),
|
||||||
@ -322,8 +320,21 @@ func (s *DBSchema) SetRel(child, parent string, rel *DBRel) error {
|
|||||||
func (s *DBSchema) GetRel(child, parent string) (*DBRel, error) {
|
func (s *DBSchema) GetRel(child, parent string) (*DBRel, error) {
|
||||||
rel, ok := s.rm[child][parent]
|
rel, ok := s.rm[child][parent]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("unknown relationship '%s' -> '%s'",
|
// No relationship found so this time fetch the table info
|
||||||
child, parent)
|
// and try again in case child or parent was an alias
|
||||||
|
ct, err := s.GetTable(child)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pt, err := s.GetTable(parent)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
rel, ok = s.rm[ct.Name][pt.Name]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unknown relationship '%s' -> '%s'",
|
||||||
|
child, parent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return rel, nil
|
return rel, nil
|
||||||
}
|
}
|
||||||
|
@ -33,11 +33,7 @@ func argMap(ctx context.Context, vars []byte) func(w io.Writer, tag string) (int
|
|||||||
return 0, errors.New("query requires variable $user_role")
|
return 0, errors.New("query requires variable $user_role")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("1>", tag)
|
|
||||||
fmt.Println("2>", string(vars))
|
|
||||||
|
|
||||||
fields := jsn.Get(vars, [][]byte{[]byte(tag)})
|
fields := jsn.Get(vars, [][]byte{[]byte(tag)})
|
||||||
fmt.Println("2.1>", fields)
|
|
||||||
|
|
||||||
if len(fields) == 0 {
|
if len(fields) == 0 {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
@ -47,8 +43,6 @@ func argMap(ctx context.Context, vars []byte) func(w io.Writer, tag string) (int
|
|||||||
fields[0].Value = v[1 : len(v)-1]
|
fields[0].Value = v[1 : len(v)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("3>", string(fields[0].Value))
|
|
||||||
|
|
||||||
return w.Write(escQuote(fields[0].Value))
|
return w.Write(escQuote(fields[0].Value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ func initCompilers(c *config) (*qcode.Compiler, *psql.Compiler, error) {
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
schema, err = psql.NewDBSchema(db, di, c.getAliasMap())
|
schema, err = psql.NewDBSchema(di, c.getAliasMap())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user