-
Notifications
You must be signed in to change notification settings - Fork 879
Dynamic Queries #2859
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
base: main
Are you sure you want to change the base?
Dynamic Queries #2859
Changes from all commits
34c1a54
6361797
5d171a0
7fe2794
f755265
e38b8b9
411b4e4
6bdd617
8161e09
a49ab13
0cc6a67
720ffda
3bfe6a4
b055f28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,14 +128,16 @@ func (v QueryValue) Params() string { | |
} | ||
var out []string | ||
if v.Struct == nil { | ||
if !v.Column.IsSqlcSlice && strings.HasPrefix(v.Typ, "[]") && v.Typ != "[]byte" && !v.SQLDriver.IsPGX() { | ||
if v.Column.IsSqlcDynamic { | ||
} else if !v.Column.IsSqlcSlice && strings.HasPrefix(v.Typ, "[]") && v.Typ != "[]byte" && !v.SQLDriver.IsPGX() { | ||
out = append(out, "pq.Array("+escape(v.Name)+")") | ||
} else { | ||
out = append(out, escape(v.Name)) | ||
} | ||
} else { | ||
for _, f := range v.Struct.Fields { | ||
if !f.HasSqlcSlice() && strings.HasPrefix(f.Type, "[]") && f.Type != "[]byte" && !v.SQLDriver.IsPGX() { | ||
if f.HasSqlcDynamic() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @ovadbar there is no logic inside this condition. May be it is not required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I have should have written it as the following. The code is needed
|
||
} else if !f.HasSqlcSlice() && strings.HasPrefix(f.Type, "[]") && f.Type != "[]byte" && !v.SQLDriver.IsPGX() { | ||
out = append(out, "pq.Array("+escape(v.VariableForField(f))+")") | ||
} else { | ||
out = append(out, escape(v.VariableForField(f))) | ||
|
@@ -188,6 +190,32 @@ func (v QueryValue) HasSqlcSlices() bool { | |
} | ||
return false | ||
} | ||
func (v QueryValue) HasSqlcDynamic() bool { | ||
if v.Struct == nil { | ||
if v.Column != nil && v.Column.IsSqlcDynamic { | ||
return true | ||
} | ||
return false | ||
} | ||
for _, v := range v.Struct.Fields { | ||
if v.Column.IsSqlcDynamic { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
func (v QueryValue) SqlcDynamic() int { | ||
var count int = 1 | ||
if v.Struct == nil { | ||
return 1 | ||
} | ||
for _, v := range v.Struct.Fields { | ||
if !v.Column.IsSqlcDynamic { | ||
count++ | ||
} | ||
} | ||
return count | ||
} | ||
|
||
func (v QueryValue) Scan() string { | ||
var out []string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure how to add these values without putting them here. So while it does work it is kind of a hack.