Skip to content

Commit

Permalink
Merge pull request #134 from itsumura-h/feature/raw_sql_param
Browse files Browse the repository at this point in the history
use placeholder for raw query
  • Loading branch information
itsumura-h authored Mar 4, 2021
2 parents a51dfa3 + 1ff188d commit 007c227
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion allographer.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.15.0"
version = "0.15.1"
author = "Hidenobu Itsumura @dumblepytech1 as 'medy'"
description = "A Nim query builder library inspired by Laravel/PHP and Orator/Python"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions documents/query_builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,8 @@ SELECT ProductName
echo rdb().raw(sql).getRaw()
```
```nim
let sql = "UPDATE users SET name='John' where id = 1"
rdb().raw(sql).exec()
let sql = "UPDATE users SET name='John' where id = ?"
rdb().raw(sql, "1").exec()
```

## Aggregates
Expand Down
7 changes: 7 additions & 0 deletions tests/test_query.nim
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,10 @@ suite "select":
test "delete with where":
rdb().table("users").where("name", "=", "user2").delete()
check rdb().table("users").find(2).isSome == false

test "raw query":
let sql = "SELECT * FROM users WHERE id = ?"
var res = rdb().raw(sql, "1").getRaw()
rdb().raw(sql, "1").exec()
echo res
check res[0]["name"].getStr == "user1"
2 changes: 1 addition & 1 deletion tests/test_query_return_type.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ suite "return with type fail":
check r.len == 0
check r == newSeq[Typ](0)
test "getRaw":
var r = rdb().raw("select * from users where id > 10").getRaw(Typ)
var r = rdb().raw("select * from users where id > ?", "10").getRaw(Typ)
check r.len == 0
check r == newSeq[Typ](0)
test "first":
Expand Down

0 comments on commit 007c227

Please sign in to comment.