prax-sqlite
SQLite query engine for Prax ORM.
Overview
prax-sqlite provides an async SQLite backend using tokio-rusqlite.
Features
- Async query execution with Tokio
- Connection pooling with reuse optimization
- WAL mode support for concurrent reads
- In-memory database support (see caveat below)
- Transaction support
In-memory caveat: every connection opened for
sqlite::memory:is its own isolated database, so an in-memory pool isolates every statement on its own database. Usetransaction()to pin one connection, or a tempfile/shared-cache URI, for multi-statement workflows.
Usage
use PraxClient;
use ;
// File-based database
let pool = builder
.url
.build
.await?;
let engine = new;
// In-memory database (see caveat above)
let pool = builder
.url
.build
.await?;
let engine = new;
// Execute queries through Prax client
let client = new;
let users = client.user.find_many.exec.await?;
Performance
SQLite operations are highly optimized:
- ~145ns connection acquisition (with pooling)
- WAL mode for concurrent read/write
Vector Support (LLM / RAG)
Enable the vector feature to get typed vector columns, HNSW indexing,
and top-k similarity search backed by sqlite-vector-rs.
[]
= { = "0.7", = ["vector"] }
When the feature is enabled, every new connection opened by SqlitePool
auto-registers the extension, so vector_from_json, vector_distance,
and the vector virtual table module are available without extra setup.
Schema
model Document {
id Int @id @auto
title String
content String
embedding Vector @dim(1536) @vectorType("float4") @metric("cosine") @index(hnsw)
}
prax migrate emits:
(
"id" INTEGER PRIMARY KEY,
"title" TEXT NOT NULL,
"content" TEXT NOT NULL
);
CREATE VIRTUAL TABLE "documents_vectors" USING vector(
rowid_column='document_id',
embedding='float4[1536] cosine hnsw'
);
Similarity search
use *;
let embedding = new?;
let sql = new
.query_embedding
.metric
.limit
.to_sql?;
Hybrid (vector + fts5) search via RRF
let sql = new
.vector_table
.rowid_column
.vector_column
.fts_table
.query_embedding
.query_text
.vector_weight
.text_weight
.limit
.to_sql?;
See examples/vector_rag.rs for an end-to-end sample.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.