High-level SQLite bindings for Nim.
import pkg/skulite
let db = openDatabase(":memory:")
db.exec "CREATE TABLE IF NOT EXISTS greeting(words TEXT) STRICT"
db.exec "INSERT INTO greeting (words) VALUES (?),(?)", ("Hello,", "World!")
for word in db.query("SELECT words FROM greeting", string):
echo word
# Hello,
# World!
import pkg/[skulite, jsony], std/tables
proc bindParam*(stmt: Statement; index: Positive32; val: SomeTable) {.inline.} =
bindParam(stmt, index, toJson(val))
proc getColumn*[K,V](stmt: Statement; index: Natural32; T: typedesc[SomeTable[K,V]]): T {.inline.} =
fromJson(getColumn(stmt, index, string), T)
let db = openDatabase(":memory:")
db.exec "CREATE TABLE IF NOT EXISTS projects(metadata TEXT) STRICT"
let proj = {"name": "skulite", "language": "nim", "license": "blessing"}.toTable
db.exec "INSERT INTO projects (metadata) VALUES (?)", proj
echo "name: ", db.query("SELECT metadata FROM projects", Table[string, string])["name"]
echo "lang: ", db.query("SELECT json_extract(metadata, '$.language') FROM projects", string)
# name: skulite
# lang: nim
† See all bindParam
and getColumn
implementations in stmtops.nim.
-d:staticSqlite
: Build and link SQlite statically, enabled by default on Windows.- There are more options related to compiling SQLite in the header of sqlite3.nim.
-d:checkSqliteUsage
: Check if you're misusing the SQLite API, enabled by default for debug builds.