Skip to content

API Reference

DirSQL

Import

python
from dirsql import DirSQL
rust
use dirsql_sdk::DirSQL;
typescript
import { DirSQL } from 'dirsql';

Constructor

python
DirSQL(root: str, *, tables: list[Table], ignore: list[str] | None = None)
rust
DirSQL::new(root: &str, tables: Vec<Table>) -> Result<DirSQL>
typescript
new DirSQL(root: string, options: { tables: Table[], ignore?: string[] })

Creates an in-memory SQLite index over the given directory. In Python, the constructor starts scanning in a background thread and returns immediately. Call await db.ready() before querying. In Rust, the constructor scans synchronously. In TypeScript, scanning starts immediately.

Parameters:

  • root -- Path to the directory to index.
  • tables -- List of Table definitions. Each defines a SQLite table, a glob pattern, and an extract function.
  • ignore -- Optional list of glob patterns. Files matching any ignore pattern are skipped regardless of table globs.

Methods

ready

python
await db.ready() -> None
rust
db.ready().await -> Result<()>
typescript
await db.ready  // awaitable property

Wait for the initial scan to complete. Re-raises any exception from the scan. Safe to call multiple times.

query

python
await db.query(sql: str) -> list[dict]
rust
db.query(sql: &str) -> Result<Vec<HashMap<String, Value>>>
typescript
await db.query(sql: string): Promise<Record<string, unknown>[]>

Execute a SQL query against the in-memory database. Returns results keyed by column name. Internal tracking columns (_dirsql_file_path, _dirsql_row_index) are excluded from results.

watch

python
async for event in db.watch():  # AsyncIterator[RowEvent]
    ...
rust
let mut stream = db.watch();  // impl Stream<Item = RowEvent>
while let Some(event) = stream.next().await { ... }
typescript
for await (const event of db.watch()) {  // AsyncIterable<RowEvent>
    ...
}

Returns an async iterable of RowEvent objects. The file watcher starts automatically on first iteration. The iterator never terminates on its own.

from_config

python
DirSQL.from_config(path: str) -> DirSQL
rust
DirSQL::from_config(path: &str) -> Result<DirSQL>

Create a DirSQL instance from a .dirsql.toml config file. In Python, returns immediately and scans in the background -- call await db.ready() before querying.


Table

Import

python
from dirsql import Table
rust
use dirsql_sdk::Table;
typescript
import { Table } from 'dirsql';

Constructor

python
Table(*, ddl: str, glob: str, extract: Callable[[str, str], list[dict]])
rust
Table::new(ddl: &str, glob: &str, extract: fn(&str, &str) -> Vec<Value>)
typescript
new Table({ ddl: string, glob: string, extract: (path: string, content: string) => Record<string, unknown>[] })

Defines a mapping from files to SQLite table rows.

Parameters:

  • ddl -- A CREATE TABLE statement. The table name is parsed from this DDL.
  • glob -- A glob pattern matched against file paths relative to the root directory.
  • extract -- A callable (path, content) -> list[dict]. Receives the relative file path and file content as strings. Returns a list of dicts/maps mapping column names to values. Return an empty list to skip a file.

Attributes:

  • ddl -- The DDL string (read-only).
  • glob -- The glob pattern (read-only).

RowEvent

Import

python
from dirsql import RowEvent
rust
use dirsql_sdk::RowEvent;
typescript
import { RowEvent } from 'dirsql';

Emitted by the watch stream. Represents a change to a row in the database caused by a filesystem event.

Attributes:

AttributePythonRustTypeScript
Table nametable: strtable: Stringtable: string
Actionaction: straction: Actionaction: string
Current/new rowrow: dict | Nonerow: Option<HashMap>row?: Record
Previous rowold_row: dict | Noneold_row: Option<HashMap>oldRow?: Record
Error messageerror: str | Noneerror: Option<String>error?: string
File pathfile_path: str | Nonefile_path: Option<String>filePath?: string

Action values: "insert", "update", "delete", "error".

Released under the MIT License.