Skip to content

Commit 653ef30

Browse files
committed
allow multipe where statement in update
1 parent 3ba3bb2 commit 653ef30

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

sqlbuilder.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Package
22

3-
version = "1.1.3"
3+
version = "1.1.4"
44
author = "ThomasTJdev"
55
description = "SQL builder"
66
license = "MIT"

src/sqlbuilderpkg/utils_private.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ proc formatWhereParams*(v: string): string =
7474
#
7575
# Does the data have a `=` sign?
7676
#
77-
if fieldSplit.len() == 2:
77+
if fieldSplit.len() >= 2:
7878
#
7979
# If the data is only having equal but no value, insert a `?` sign
8080
#

tests/update/test_update.nim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,36 @@ suite "update - queries":
8484

8585

8686

87+
test "update value where x IS NULL":
88+
let q = sqlUpdate(
89+
"table",
90+
["name", "age"],
91+
["id =", "info IS NULL"],
92+
)
93+
check querycompare(q, sql("UPDATE table SET name = ?, age = ? WHERE id = ? AND info IS NULL"))
94+
95+
96+
97+
test "update value where x OR y IS NULL":
98+
let q = sqlUpdate(
99+
"table",
100+
["name", "age"],
101+
["id =", "(info IS NULL OR notty IS NULL)"],
102+
)
103+
check querycompare(q, sql("UPDATE table SET name = ?, age = ? WHERE id = ? AND (info IS NULL OR notty IS NULL)"))
104+
105+
106+
107+
test "update value where x IS NULL OR y IS FALSE":
108+
let q = sqlUpdate(
109+
"table",
110+
["name", "age"],
111+
["id =", "(info IS NULL OR notty IS FALSE)"],
112+
)
113+
check querycompare(q, sql("UPDATE table SET name = ?, age = ? WHERE id = ? AND (info IS NULL OR notty IS FALSE)"))
114+
115+
116+
87117
test "update value with spaces":
88118
let q = sqlUpdate(
89119
"table",

0 commit comments

Comments
 (0)