Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F13810233
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
View Options
diff --git a/query/builder.go b/query/builder.go
new file mode 100644
index 0000000..01916f6
--- /dev/null
+++ b/query/builder.go
@@ -0,0 +1,92 @@
+// Package query assists in building SQL queries.
+package query
+
+import (
+ "database/sql"
+)
+
+type Update struct {
+ Updates, Conditions string
+ Params []interface{}
+
+ sep string
+}
+
+func NewUpdate() *Update {
+ return &Update{}
+}
+
+func (u *Update) Set(v, property string) *Update {
+ if v != "" {
+ u.Updates += u.sep + property + " = ?"
+ u.sep = ", "
+ u.Params = append(u.Params, v)
+ }
+ return u
+}
+
+func (u *Update) SetBytes(v []byte, property string) *Update {
+ if len(v) > 0 {
+ u.Updates += u.sep + property + " = ?"
+ u.sep = ", "
+ u.Params = append(u.Params, v)
+ }
+ return u
+}
+
+func (u *Update) SetStringPtr(v *string, property string) *Update {
+ if v != nil {
+ u.Updates += u.sep + property + " = ?"
+ u.sep = ", "
+ u.Params = append(u.Params, v)
+ }
+ return u
+}
+
+func (u *Update) SetIntPtr(v *int, property string) *Update {
+ if v != nil {
+ u.Updates += u.sep + property + " = ?"
+ u.sep = ", "
+ u.Params = append(u.Params, v)
+ }
+ return u
+}
+
+func (u *Update) SetBoolPtr(v *bool, property string) *Update {
+ if v != nil {
+ u.Updates += u.sep + property + " = ?"
+ u.sep = ", "
+ u.Params = append(u.Params, v)
+ }
+ return u
+}
+
+func (u *Update) SetNullBool(v *sql.NullBool, property string) *Update {
+ if v != nil {
+ u.Updates += u.sep + property + " = ?"
+ u.sep = ", "
+ u.Params = append(u.Params, v)
+ }
+ return u
+}
+
+func (u *Update) SetNullString(v *sql.NullString, property string) *Update {
+ if v != nil {
+ u.Updates += u.sep + property + " = ?"
+ u.sep = ", "
+ u.Params = append(u.Params, v)
+ }
+ return u
+}
+
+func (u *Update) Append(v interface{}) {
+ u.Params = append(u.Params, v)
+}
+
+func (u *Update) Where(condition string, params ...interface{}) *Update {
+ u.Conditions = condition
+ for _, p := range params {
+ u.Append(p)
+ }
+ return u
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Wed, Feb 11, 8:45 PM (15 h, 28 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3624905
Attached To
rWC Write.as Web Core
Event Timeline
Log In to Comment