Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Latest commit

 

History

98 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Skulite

High-level SQLite bindings for Nim.

Examples

Basic example

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!

Storing a hash table as JSON using jsony

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.

Notes

  • -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.

See also

About

SQLite bindings for Nim

Topics

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages