Getting Started
Install
- TypeScript
- Python
npm install @csdb/typescript
pip install csdb
The Python package is not implemented yet. This command reserves the intended installation shape.
Create A Database In Memory
- TypeScript
- Python
import { CSDBDatabase } from "@csdb/typescript";
const db = CSDBDatabase.parse(`--- csdb
format: CSDB
version: 1
name: demo
tables:
- notes
--- table:notes:schema
name: notes
columns:
id: text
body: text
required:
- id
primary_key:
columns: [id]
--- table:notes:data
id,body
n_001,hello
`);
from csdb import CSDBDatabase
db = CSDBDatabase.parse("""--- csdb
format: CSDB
version: 1
name: demo
tables:
- notes
--- table:notes:schema
name: notes
columns:
id: text
body: text
required:
- id
primary_key:
columns: [id]
--- table:notes:data
id,body
n_001,hello
""")
Insert And Query Rows
- TypeScript
- Python
- SQL
db.table("notes").insert({ id: "n_002", body: "from the fluent API" });
db.table("notes").insert({ id: "n_003", body: null });
const notes = db.table("notes")
.where("body", "!=", null)
.orderBy("id")
.all();
db.table("notes").insert({"id": "n_002", "body": "from the fluent API"})
db.table("notes").insert({"id": "n_003", "body": None})
notes = (
db.table("notes")
.where("body", "!=", None)
.order_by("id")
.all()
)
INSERT INTO notes (id, body)
VALUES ('n_002', 'from SQL');
INSERT INTO notes (id, body)
VALUES ('n_003', NULL);
SELECT *
FROM notes
WHERE body IS NOT NULL
ORDER BY id ASC;
Optional non-primary-key columns accept null. In CSV, unquoted empty fields
represent null, while quoted empty strings remain empty strings.
Save A File
- TypeScript
- Python
import { saveCSDB } from "@csdb/typescript";
await saveCSDB(db, "demo.csdb", { machineIndexes: "omit" });
from csdb import save_csdb
save_csdb(db, "demo.csdb", machine_indexes="omit")
What To Read Next
- Overview explains the document model.
- Database API shows table creation, validation, and serialization.
- TableQuery API covers the fluent table API.