sqlite
| Kind | ffi-c |
|---|---|
| Capabilities | ffi file |
| Categories | database ffi |
| Keywords | sqlite database sql ffi bindings |
SQLite bindings for Kit
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
dev/chinook.kit | Development script for chinook |
dev/northwind.kit | Development script for northwind |
dev/repl.kit | Development script for repl |
examples/basic.kit | Basic usage example |
examples/chinook.kit | Example: chinook |
examples/northwind.kit | Example: northwind |
examples/sqlite.kit | Example: sqlite |
kit.toml | Package manifest with metadata and dependencies |
src/sqlite.kit | SQLite Bindings for Kit |
tests/sqlite.test.kit | Tests for sqlite |
Dependencies
No Kit package dependencies.
Related Packages
- kit-query - Fluent SQL query builder for Kit
Installation
kit add gitlab.com/kit-lang/packages/kit-sqlite.gitUsage
import Kit.Sqlite as SQLite
main = fn(-env: Env) =>
# Connect to an in-memory database
db = SQLite.connect ":memory:"
defer SQLite.close db
# Create a table
SQLite.execute db.handle "CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER)"
# Insert data
SQLite.execute db.handle "INSERT INTO users (name, age) VALUES ('Alice', 30)"
SQLite.execute db.handle "INSERT INTO users (name, age) VALUES ('Bob', 25)"
SQLite.execute db.handle "INSERT INTO users (name, age) VALUES ('Charlie', 35)"
# Query with the high-level API
match db.query "SELECT id, name, age FROM users"
| Success rows -> println "Got ${List.length rows} rows"
| Error msg -> println "Query failed: ${msg}"
mainREPL Preloaders
Pre-built REPL helpers for interactive exploration with famous sample databases:
kit repl --preload dev/repl.kit # Generic in-memory database (users, posts)
kit repl --preload dev/chinook.kit # Chinook music store (artists, albums, tracks)
kit repl --preload dev/northwind.kit # Northwind traders (products, orders, customers)Each preloader creates an in-memory database with sample data and provides helper functions for common queries. Type the preloader's suggested commands to get started.
Development
Running Examples
Run examples with the interpreter:
kit run examples/basic.kitCompile examples to a native binary:
kit build examples/basic.kit && ./basicRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis installs the package to ~/.kit/packages/@kit/sqlite/, making it available for import as Kit.Sqlite in other projects.
License
This package is released under the MIT License - see LICENSE for details.
SQLite is in the public domain.
Exported Functions & Types
sqlite-ok
SQLite operation completed successfully.
sqlite-row
SQLite query returned a row.
sqlite-done
SQLite query completed with no more rows.
sqlite-type-int
SQLite column type for integer values.
sqlite-type-float
SQLite column type for floating point values.
sqlite-type-text
SQLite column type for text strings.
sqlite-type-blob
SQLite column type for binary blob data.
sqlite-type-null
SQLite column type for NULL values.
SQLiteError
SQLite error type for typed error handling. Variants distinguish between different failure modes.
Variants
SQLiteOpenError {message}SQLitePrepareError {message}SQLiteQueryError {message}SQLiteExecError {message}SQLiteBindError {message}connect
Open a SQLite database connection and return a connection object with query/execute methods. Returns a connection record with query/execute methods.
String -> {handle: Ptr, driver: String, query: String -> Result List SQLiteError, execute: String -> Result Int SQLiteError}
db = SQLite.connect "example.sqlite"
result = db.query "SELECT * FROM users"
query
Execute a query and return all rows as a list of records with column names as keys. Each row is a Record with column names as keys. NULL values are represented as None, non-null values as Some value. Text values matching ISO8601 format (YYYY-MM-DD or YYYY-MM-DD HH:MM:SS) are automatically converted to DateTime.
Ptr -> NonEmptyString -> Result List SQLiteError
query-maps
Execute a query and return all rows as a list of maps with column names as keys. Each row is a Map with column names as keys. NULL values are represented as None, non-null values as Some value.
Ptr -> NonEmptyString -> Result List SQLiteError
query-raw
Execute a query and return all rows as a list of vectors in column order. Each row is a vector [col0, col1, col2, ...] in column order. This is more efficient than maps when you know the column order.
Ptr -> NonEmptyString -> Result List SQLiteError
execute
Execute a SQL statement (INSERT, UPDATE, DELETE, CREATE, etc.) and return affected row count. Returns number of affected rows on success, or error.
Ptr -> NonEmptyString -> Result Int SQLiteError