ndb.nim
ndb.nim copied to clipboard
A db_sqlite fork with a proper typing
ndb/sqlite
A fork of db_sqlite, Nim's standard library higher level SQLite database wrapper. Warning: work in progress, API is a subject of change.
Features
- Binding
?parameters is done with native SQlitesqlite3_bind_*functions instead of stringifying and then escaping every parameter. As a result:- In addition to
?, the?NNNsyntax is supported. See sqlite3_varparam. - Inserting binary blobs is handled in a proper way. See Nim#5768.
- It is possible to insert the
NULLvalue.
- In addition to
- No more empty strings as a default placeholder value.
Empty string,
NULL, and an absence of a row are distinguished.
Example
import ndb/sqlite
let db = open(":memory:", "", "", "")
# Insert NULL
db.exec(sql"CREATE TABLE foo (a, b)")
db.exec(sql"INSERT INTO foo VALUES (?, ?)", 1, DbNull())
# Insert binary blob
db.exec(sql"CREATE TABLE blobs (a BLOB)")
db.exec(sql"INSERT INTO blobs VALUES (?)", DbBlob "\x00\x01\x02\x03")
let blobValue = db.getAllRows(sql"SELECT * FROM BLOBS")[0][0].b
db.close()
ndb/postgres
Initial PostgreSQL support is provided. It is not complete yet.
Roadmap
This approach can be extended to other db_* modules in a consistent way:
db_mysql: usemysql_stmt_bind_param, see Nim#5884.db_odbc: useSQLBindParameter.