Skip to main content

CSDBDatabase

CSDBDatabase wraps a parsed document and exposes table access, SQL execution, validation, and serialization.

Create Database Object

new CSDBDatabase(document: CSDBDocument)

Parse Text

Parse CSDB text into a database.

const db = CSDBDatabase.parse(text, { validate: true });

Start Table Query

Start a fluent query for a table.

const query = db.table("workers");

Query Table

Query a table with the fluent API or SQL.

const rows = db.table("workers")
.where("email", "=", "ada@example.com")
.select(["id"])
.all();

Visit TableQuery for the full table query API.

Query SQL

Run SQL text through the database API.

const rows = db.sql(
"SELECT id, email FROM workers WHERE email = ?",
["ada@example.com"]
);

Execute Plan

Execute a query plan directly.

const rows = db.execute({
kind: "select",
table: "workers",
columns: "*",
joins: [],
orderBy: [],
output: "objects"
});

Create Table

Create a table from a TableSchema.

db.createTable({
name: "tags",
columns: { label: "text" },
required: ["label"],
primary_key: { columns: ["label"] }
});

Drop Table

Drop a table by name.

db.dropTable("tags");

Validate Database

Validate metadata, schema references, rows, constraints, uniqueness, and foreign keys.

db.validate();

Serialize Database

Serialize the document.

const text = db.toString({ machineIndexes: "omit" });