A fork of db_sqlite, Nim's standard library higher level SQLite database wrapper. Warning: work in progress, API is a subject of change.
- Binding
?
parameters is done with native SQlitesqlite3_bind_*
functions instead of stringifying and then escaping every parameter. As a result:- In addition to
?
, the?NNN
syntax is supported. See sqlite3_varparam. - Inserting binary blobs is handled in a proper way. See Nim#5768.
- It is possible to insert the
NULL
value.
- In addition to
- No more empty strings as a default placeholder value.
Empty string,
NULL
, and an absence of a row are distinguished.
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()
Initial PostgreSQL support is provided. It is not complete yet.
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
.