SQLite database access for Harding.
This library packages both:
- native Nim bindings using
db_connector/db_sqlite - Harding classes under
lib/sqlite/
It mirrors the packaging style of harding-mysql, but uses SQLite's local-file and in-memory database model.
From a Harding checkout:
./harding lib install sqlite
nimble hardingIf you cloned this library manually into external/sqlite, create the local metadata file first:
cp external/sqlite/.harding-lib.json.disabled external/sqlite/.harding-lib.json
nimble discover
nimble hardingRun the in-memory demo:
./harding external/sqlite/examples/smoke.hrdExpected output is similar to:
Connected to SQLite
2
2
Grace => 1337
Ada => 1200
From a Harding checkout with this repo at external/sqlite:
cp external/sqlite/.harding-lib.json.disabled external/sqlite/.harding-lib.json
nimble discover
nimble harding
nim c -r --nimcache:nimcache/sqlite-lib-tests -o:external/sqlite/tests/sqlite_lib_tests -d:harding_sqlite external/sqlite/tests/test_sqlite.nimThe tests use SQLite's :memory: database, so no database server or fixture cleanup is required.
conn := SqliteConnection open: ":memory:".
conn execute: "CREATE TABLE players (name TEXT, score INTEGER)".
conn execute: "INSERT INTO players (name, score) VALUES ('Ada', 1200)".
conn execute: "INSERT INTO players (name, score) VALUES ('Grace', 1337)".
result := conn query: "SELECT name, score FROM players ORDER BY score DESC".
row := result next.
((row at: 0) , " => " , (row at: 1)) println.
row := result next.
((row at: 0) , " => " , (row at: 1)) println.
result close.
conn close.