import { SchemaJson, Table, Column, Variable, Expr } from "./types"; type ColumnMap = { [columnId: string]: Column; }; /** Abstracted schema for a database. Immutable. * Stores tables with columns (possibly in nested sections). * See types.ts for more info. * * Also contains any variables and their values. * * Variables can be either bound or unbound. If they are bound, it means that they currently have a value within the schema. * If they are unbound, then the expression cannot be compiled, but can still be validated. */ export default class Schema { tables: Table[]; /** Map of table.id to table */ tableMap: { [tableId: string]: Table; }; /** Map of "" to map of { "" to column } */ columnMaps: { [tableId: string]: ColumnMap; }; /** Variables in the schema */ variables: Variable[]; /** Values of variables */ variableValues: { [variableId: string]: Expr; }; constructor(schemaJson?: SchemaJson, variables?: Variable[], variableValues?: { [variableId: string]: Expr; }); /** Add a single variable, replacing any existing one with the same id */ addVariable(variable: Variable, value?: Expr): Schema; /** Add variables, replacing any existing ones with the same id */ addVariables(variables: Variable[], variableValues: { [variableId: string]: Expr; }): Schema; private indexTable; getTables(): Table[]; getTable(tableId: string): Table | null; getColumn(tableId: string, columnId: string): Column | null; /** Gets the columns in order, flattened out from sections */ getColumns(tableId: string): Column[]; getVariables(): Variable[]; getVariableValues(): { [variableId: string]: Expr; }; /** Add table with id, name, desc, primaryKey, ordering (column with natural order) and contents (array of columns/sections) * Will replace table if already exists. * schemas are immutable, so returns a fresh copy */ addTable(table: Table): Schema; toJSON(): SchemaJson; } export {};