NIAOJoin Beta
Ecosystem

nsqlite

available

SQLite Integration

Databases

Overview

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.

  • WAL mode
  • Schema migrations
  • Prepared statements
  • Batch inserts

Import

import
import "nsqlite"

Quick start

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" })

Capabilities

High-level overview of what nsqlite is for.

WAL mode defaults

Write-Ahead Logging enabled when you open a database, better concurrent reads and safer crash recovery.

Schema migrations

Same numbered up/down migration files as npg, so one project can swap SQLite locally and Postgres in prod.

Prepared statements

Bind parameters to a compiled statement for repeated queries without string concatenation.

Transactions

Explicit begin/commit/rollback when several statements need to succeed or fail together.

Batch inserts

Insert many rows inside a single transaction, much faster than committing after every row.

Async queries

Run blocking disk I/O on a worker thread and poll completion from Niao code.

API reference

39 functions and methods in nsqlite. Grouped by category from the standard library docs.

Connection

SignatureDescription
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

Schema & migrations

SignatureDescription
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

Queries

SignatureDescription
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

Prepared statements

SignatureDescription
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

Transactions

SignatureDescription
nsqlite.begin(conn, mode?)`"deferred"` (default), `"immediate"`, `"exclusive"`
nsqlite.commit(conn)Commit
nsqlite.rollback(conn)Rollback

Batch & helpers

SignatureDescription
nsqlite.batch(conn, sql, rows)`executemany` with array of param arrays
nsqlite.insert(conn, table, data)Insert from object `{col: val, …}`

Backup & utilities

SignatureDescription
nsqlite.backup(dest, src)Online backup between open connections
nsqlite.vacuum(conn)`VACUUM`
nsqlite.version()SQLite library version string

Async

SignatureDescription
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

Notes

  • ncl can read query results straight into a DataFrame and write frames back to tables.

Related libraries

More from Databases.

available

nmongo

MongoDB Integration

MongoDB driver with pooling, CRUD, aggregations, indexes, transactions, GridFS, and change streams.

  • Connection pooling
  • BSON CRUD
  • Aggregation pipelines
  • Change streams
Read more
available

npg

PostgreSQL Integration

PostgreSQL driver with connection pooling, migrations, prepared statements, LISTEN/NOTIFY, and COPY bulk load.

  • r2d2 pool
  • Schema migrations
  • Prepared statements
  • LISTEN/NOTIFY
Read more