Files And Serialization
Open File
Open and parse a CSDB file.
- TypeScript
import { openCSDB } from "@csvdatabase/csdb";
const db = await openCSDB("payroll.csdb");
JSON clients name a server-managed database in every command envelope. The server resolves that logical identifier inside its configured data directory and opens the file; clients cannot supply filesystem paths.
Save File
Serialize and save a CSDB file. The TypeScript writer uses a temporary file and rename for safer replacement.
- TypeScript
import { saveCSDB } from "@csvdatabase/csdb";
await saveCSDB(db, "payroll.csdb", { machineIndexes: "auto" });
The JSON server automatically saves each successful mutation atomically. It does not expose a command that writes to a client-selected path.
Parse Text
Parse text into a database.
- TypeScript
import { parseCSDB } from "@csvdatabase/csdb";
const db = parseCSDB(text);
Serialize Text
Serialize a database to CSDB text.
- TypeScript
- JSON
import { serializeCSDB } from "@csvdatabase/csdb";
const text = serializeCSDB(db);
{
"database": "payroll",
"command": { "kind": "serialize" }
}
The serialized CSDB document is returned as result.text.
Configure Parsing And Serialization
Parsing supports validation control:
- TypeScript
CSDBDatabase.parse(text, { validate: false });
Serialization supports machine index control:
- TypeScript
- JSON
db.toString({ machineIndexes: "omit" });
db.toString({ machineIndexes: "auto" });
{
"database": "payroll",
"command": {
"kind": "serialize",
"options": { "machineIndexes": "auto" }
}
}