https://github.com/GULPF/tiny_sqlite
A thin SQLite wrapper for Nim
https://github.com/GULPF/tiny_sqlite
nim sql sqlite3
Last synced: 25 days ago
JSON representation
A thin SQLite wrapper for Nim
- Host: GitHub
- URL: https://github.com/GULPF/tiny_sqlite
- Owner: GULPF
- License: mit
- Created: 2019-01-04T23:29:13.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-07-10T14:47:26.000Z (almost 2 years ago)
- Last Synced: 2025-03-23T18:50:56.325Z (about 1 month ago)
- Topics: nim, sql, sqlite3
- Language: Nim
- Size: 115 KB
- Stars: 71
- Watchers: 9
- Forks: 13
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nim - tiny_sqlite - Very lightweight and safe SQLite library. (Data / Database)
README
# tiny_sqlite 
`tiny_sqlite` is a comparatively thin wrapper for the SQLite database library. It differs from the standard library module `std/db_sqlite` in several ways:
- `tiny_sqlite` represents database values with a typesafe case object called `DbValue` instead of treating every value as a string, which among other things means that SQLite `NULL` values can be properly supported.
- `tiny_sqlite` is not designed as a generic database API, only SQLite will ever be supported. The database modules in the standard library are built with replaceability in mind so that the code might work with several different database engines just by replacing an import. This is not the case for `tiny_sqlite`.
- `tiny_sqlite` is safe. Unlike `std/db_sqlite` the raw SQLite handles are not used directly to prevent use-after-free bugs triggering undefined behavior.
## Installation
`tiny_sqlite` is available on Nimble:
```
nimble install tiny_sqlite
```## Usage
```nim
import tiny_sqlite, std / optionslet db = openDatabase(":memory:")
db.execScript("""
CREATE TABLE Person(
name TEXT,
age INTEGER
);INSERT INTO
Person(name, age)
VALUES
("John Doe", 47);
""")db.exec("INSERT INTO Person VALUES(?, ?)", "Jane Doe", nil)
for row in db.iterate("SELECT name, age FROM Person"):
let (name, age) = row.unpack((string, Option[int]))
echo name, " ", age# Output:
# John Doe Some(47)
# Jane Doe None[int]
```## Documentation
- [Documentation available here](https://gulpf.github.io/tiny_sqlite/tiny_sqlite.html).