getSchema

The getSchema method reads the database's tables, with their columns, primary keys, and indexes, as the engine's catalog holds them.

getSchema(): Promise<Schema>
returnsPromise<Schema>

A Promise resolving to the Schema.

Tables and each table's indexes are in name order, and columns and key columns are in the order the table declares them. Call it outside a transaction.

Example

import {create} from 'tinyjoin';

const db = await create();
await db.exec(`
  CREATE TABLE tasks (id TEXT PRIMARY KEY, done BOOLEAN NOT NULL DEFAULT false);
  CREATE INDEX tasks_done ON tasks (done);
`);
const {tables} = await db.getSchema();
console.log(tables[0].columns[1]);
// -> {name: 'done', type: 'boolean', nullable: false, default: false}
await db.close();