nmongo
MongoDB Integration
MongoDB driver with pooling, CRUD, aggregations, indexes, transactions, GridFS, and change streams.
- Connection pooling
- BSON CRUD
- Aggregation pipelines
- Change streams
SQLite Integration
Databases
nsqlite opens a .db file relative to your working directory and gives you SQL without running a separate server. Good for local tools, tests, and small services that don't need Postgres.
WAL mode is on by default so readers don't block writers as much. Migrations match the npg pattern, and batch inserts wrap many rows in one transaction to cut overhead.
Import
import "nsqlite" |
Quick start
import "nsqlite" |
|
let db = nsqlite.open("app.db") |
db.exec("CREATE TABLE IF NOT EXISTS logs (id INTEGER PRIMARY KEY, msg TEXT)") |
db.insert("logs", { msg: "server started" }) |
High-level overview of what nsqlite is for.
Write-Ahead Logging enabled when you open a database, better concurrent reads and safer crash recovery.
Same numbered up/down migration files as npg, so one project can swap SQLite locally and Postgres in prod.
Bind parameters to a compiled statement for repeated queries without string concatenation.
Explicit begin/commit/rollback when several statements need to succeed or fail together.
Insert many rows inside a single transaction, much faster than committing after every row.
Run blocking disk I/O on a worker thread and poll completion from Niao code.
39 functions and methods in nsqlite. Grouped by category from the standard library docs.
| Signature | Description |
|---|---|
| nsqlite.open(path) | Open or create a DB in cwd when `path` is relative; use `:memory:` for RAM |
| nsqlite.open_abs(path) | Open with no cwd join |
| nsqlite.close(conn) | Close connection and invalidate handles |
| nsqlite.path(conn) | Resolved path (`":memory:"` for in-memory) |
| nsqlite.configure(conn, opts) | Pragmas: `wal`, `synchronous`, `cache_size`, `mmap_size`, `foreign_keys` |
| nsqlite.last_insert_rowid(conn) | Rowid after last `INSERT` |
| nsqlite.changes(conn) | Rows changed by last statement |
| Signature | Description |
|---|---|
| nsqlite.exec(conn, sql, params?) | Run DDL/DML without a result set |
| nsqlite.exec_many(conn, sql_list) | Run multiple statements in one transaction |
| nsqlite.migrate(conn, migrations) | Apply `{version, sql}` objects in order; tracks `_nsqlite_schema_version` |
| nsqlite.table_exists(conn, name) | Returns bool |
| nsqlite.list_tables(conn) | Table names (excludes `sqlite_*`) |
| nsqlite.table_info(conn, table) | Column metadata: `name`, `type`, `notnull`, `pk`, `default` |
| nsqlite.list_indexes(conn, table?) | Index metadata |
| Signature | Description |
|---|---|
| nsqlite.query(conn, sql, params?, format?) | All rows; `format` is `"object"` (default) or `"array"` |
| nsqlite.query_row(conn, sql, params?) | First row object or `nil` |
| nsqlite.query_value(conn, sql, params?) | First column of first row |
| nsqlite.query_column(conn, sql, params?) | First column of all rows |
| Signature | Description |
|---|---|
| nsqlite.prepare(conn, sql) | Statement handle |
| nsqlite.bind(stmt, index, value) | Positional bind (1-based) |
| nsqlite.bind_named(stmt, name, value) | Named bind (`:name`) |
| nsqlite.stmt_exec(stmt) | Execute without rows |
| nsqlite.stmt_query(stmt, format?) | Execute with rows |
| nsqlite.stmt_reset(stmt) | Clear bindings |
| nsqlite.finalize(stmt) | Free statement |
| Signature | Description |
|---|---|
| nsqlite.begin(conn, mode?) | `"deferred"` (default), `"immediate"`, `"exclusive"` |
| nsqlite.commit(conn) | Commit |
| nsqlite.rollback(conn) | Rollback |
| Signature | Description |
|---|---|
| nsqlite.batch(conn, sql, rows) | `executemany` with array of param arrays |
| nsqlite.insert(conn, table, data) | Insert from object `{col: val, …}` |
| Signature | Description |
|---|---|
| nsqlite.backup(dest, src) | Online backup between open connections |
| nsqlite.vacuum(conn) | `VACUUM` |
| nsqlite.version() | SQLite library version string |
| Signature | Description |
|---|---|
| nsqlite_async_exec(conn, sql) | Background DDL/DML |
| nsqlite_async_query(conn, sql, params?, format?) | Background read |
| nsqlite_task_done(id) | Poll completion |
| nsqlite_task_wait(id) | Block until done |
| nsqlite_task_result(id) | Result or error value |
| nsqlite_task_cancel(id) | Cancel pending task |
More from Databases.
MongoDB Integration
MongoDB driver with pooling, CRUD, aggregations, indexes, transactions, GridFS, and change streams.
PostgreSQL Integration
PostgreSQL driver with connection pooling, migrations, prepared statements, LISTEN/NOTIFY, and COPY bulk load.