ndb

A db_sqlite fork with a proper typing

Readme

ndb/sqlite

A fork of db_sqlite, Nim's standard library higher level SQLite database wrapper. Latest supported Nim version is 0.19. Documentation

Warning: work in progress, API is a subject of change.

Features

  • Binding ? parameters is done with native SQlite sqlite3_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.
  • 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()

Roadmap

This approach can be extended to other db_* modules in a consistent way:

Need help? Read Nimble
Author:
xzfc
Available versions:
License: MIT

Project website Docs Hosted docs