Fancy Syntax
To avoid creating intermediate containers here and there, use Nim's dup
macro to create mutable objects on the fly:
import sugar
For example, here's how you insert ten rows without having to create ten stale objects:
for i in 1..10:
discard newUser($i & "@example.com").dup:
dbConn.insert
echo()
INSERT INTO "User" (email) VALUES(?) <- @['1@example.com'] INSERT INTO "User" (email) VALUES(?) <- @['2@example.com'] INSERT INTO "User" (email) VALUES(?) <- @['3@example.com'] INSERT INTO "User" (email) VALUES(?) <- @['4@example.com'] INSERT INTO "User" (email) VALUES(?) <- @['5@example.com'] INSERT INTO "User" (email) VALUES(?) <- @['6@example.com'] INSERT INTO "User" (email) VALUES(?) <- @['7@example.com'] INSERT INTO "User" (email) VALUES(?) <- @['8@example.com'] INSERT INTO "User" (email) VALUES(?) <- @['9@example.com'] INSERT INTO "User" (email) VALUES(?) <- @['10@example.com']
dup
lets you call multiple procs, which gives a pleasant interface for row filter and bulk manipulation:
discard @[newUser()].dup:
dbConn.select("email LIKE ?", "_@example.com")
dbConn.delete
echo()
SELECT "User".email, "User".id FROM "User" WHERE email LIKE ? <- ['_@example.com'] DELETE FROM "User" WHERE id = 1 DELETE FROM "User" WHERE id = 2 DELETE FROM "User" WHERE id = 3 DELETE FROM "User" WHERE id = 4 DELETE FROM "User" WHERE id = 5 DELETE FROM "User" WHERE id = 6 DELETE FROM "User" WHERE id = 7 DELETE FROM "User" WHERE id = 8 DELETE FROM "User" WHERE id = 9