good morning!!!!

Skip to content
Snippets Groups Projects
Commit 2f75506e authored by José Carlos Nieto's avatar José Carlos Nieto
Browse files

db.Cond{} accepts more than one key:value under conjunction.

parent 7849a922
Branches
Tags
No related merge requests found
...@@ -104,9 +104,9 @@ func compileStatement(where db.Cond) bson.M { ...@@ -104,9 +104,9 @@ func compileStatement(where db.Cond) bson.M {
for key, val := range where { for key, val := range where {
key = strings.Trim(key, " ") key = strings.Trim(key, " ")
chunks := strings.Split(key, " ") chunks := strings.SplitN(key, " ", 2)
if len(chunks) >= 2 { if len(chunks) > 1 {
op := "" op := ""
switch chunks[1] { switch chunks[1] {
case ">": case ">":
......
...@@ -208,23 +208,37 @@ func (self *Table) compileConditions(term interface{}) (string, db.SqlArgs) { ...@@ -208,23 +208,37 @@ func (self *Table) compileConditions(term interface{}) (string, db.SqlArgs) {
*/ */
func (self *Table) compileStatement(where db.Cond) (string, []string) { func (self *Table) compileStatement(where db.Cond) (string, []string) {
for key, val := range where { str := make([]string, len(where))
arg := make([]string, len(where))
i := 0
for key, _ := range where {
key = strings.Trim(key, " ") key = strings.Trim(key, " ")
chunks := strings.Split(key, " ") chunks := strings.SplitN(key, " ", 2)
strval := toInternal(val) op := "="
if len(chunks) >= 2 { if len(chunks) > 1 {
return fmt.Sprintf("%s %s ?", chunks[0], chunks[1]), []string{strval} op = chunks[1]
} else {
return fmt.Sprintf("%s = ?", chunks[0]), []string{strval}
} }
str[i] = fmt.Sprintf("%s %s ?", chunks[0], op)
arg[i] = toInternal(where[key])
i++
} }
switch len(str) {
case 1:
return str[0], arg
case 0:
return "", []string{} return "", []string{}
} }
return "(" + strings.Join(str, " AND ") + ")", arg
}
/* /*
Deletes all the rows in the table. Deletes all the rows in the table.
*/ */
......
...@@ -231,23 +231,37 @@ func (self *Table) compileConditions(term interface{}) (string, db.SqlArgs) { ...@@ -231,23 +231,37 @@ func (self *Table) compileConditions(term interface{}) (string, db.SqlArgs) {
*/ */
func (self *Table) compileStatement(where db.Cond) (string, []string) { func (self *Table) compileStatement(where db.Cond) (string, []string) {
for key, val := range where { str := make([]string, len(where))
arg := make([]string, len(where))
i := 0
for key, _ := range where {
key = strings.Trim(key, " ") key = strings.Trim(key, " ")
chunks := strings.Split(key, " ") chunks := strings.SplitN(key, " ", 2)
strval := toInternal(val) op := "="
if len(chunks) >= 2 { if len(chunks) > 1 {
return fmt.Sprintf("%s %s ?", chunks[0], chunks[1]), []string{strval} op = chunks[1]
} else {
return fmt.Sprintf("%s = ?", chunks[0]), []string{strval}
} }
str[i] = fmt.Sprintf("%s %s ?", chunks[0], op)
arg[i] = toInternal(where[key])
i++
} }
switch len(str) {
case 1:
return str[0], arg
case 0:
return "", []string{} return "", []string{}
} }
return "(" + strings.Join(str, " AND ") + ")", arg
}
/* /*
Deletes all the rows in the table. Deletes all the rows in the table.
*/ */
......
...@@ -209,22 +209,37 @@ func (self *Table) compileConditions(term interface{}) (string, db.SqlArgs) { ...@@ -209,22 +209,37 @@ func (self *Table) compileConditions(term interface{}) (string, db.SqlArgs) {
*/ */
func (self *Table) compileStatement(where db.Cond) (string, []string) { func (self *Table) compileStatement(where db.Cond) (string, []string) {
for key, val := range where { str := make([]string, len(where))
arg := make([]string, len(where))
i := 0
for key, _ := range where {
key = strings.Trim(key, " ") key = strings.Trim(key, " ")
chunks := strings.Split(key, " ") chunks := strings.SplitN(key, " ", 2)
strval := toInternal(val) op := "="
if len(chunks) >= 2 { if len(chunks) > 1 {
return fmt.Sprintf("%s %s ?", chunks[0], chunks[1]), []string{strval} op = chunks[1]
} else {
return fmt.Sprintf("%s = ?", chunks[0]), []string{strval}
} }
str[i] = fmt.Sprintf("%s %s ?", chunks[0], op)
arg[i] = toInternal(where[key])
i++
} }
switch len(str) {
case 1:
return str[0], arg
case 0:
return "", []string{} return "", []string{}
} }
return "(" + strings.Join(str, " AND ") + ")", arg
}
/* /*
Deletes all the rows in the table. Deletes all the rows in the table.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment