import { Datasource } from "./types.js"; //#region src/shared/datasources/to-sql.d.ts /** * Takes a datasource and converts it to an equivalent SQL table creation statement(s). * Take into account: * - $.id: the name of the table * - $.schema: the schema of the datasource (a JSON schema of type "object", each property becomes a column) * - $.indexes: the indexes defined on the datasource * - $.foreignKeys: the foreign keys defined on the datasource * * Note: $.schema is defined as TAny in the type, but in practice it will always be a TObject */ declare function datasourceToSQL(datasource: Datasource): string; /** * The SQL migration removing a datasource: its full-text index tables, then its table. Generated * when a site's datasource file is deleted (pre-commit hook, `upstart-delete-datasource`). */ declare function datasourceDropSQL(datasource: Datasource): string; /** * Generates a SQL migration from one datasource version to another. * * Simple changes (handled via ALTER TABLE): * - ADD new columns (optional, nullable, or NOT NULL with a default value) * - DROP columns (no indexes/FKs on them) * - ADD new indexes (regular, unique, fulltext) * - DROP indexes * * Complex changes (handled via table recreation — create new table, copy data, drop old, rename): * - CHANGE column types (with smart CAST expressions) * - MAKE column required / optional (optional→required fills NULLs with a fallback value) * - ADD new NOT NULL column without a default (fills existing rows with a type-appropriate fallback) * - REMOVE foreign keys * * @param from - The current datasource schema * @param to - The target datasource schema * @returns SQL migration statements, or empty string if no changes * @throws Error if the table IDs don't match */ declare function generateMigration(from: Datasource, to: Datasource): string | null; /** * Generates SQL INSERT statements from the examples in a datasource schema. * * @param datasource - The datasource containing examples in $.schema via .meta({ examples: [...] }) * @returns SQL INSERT statements for all examples, or empty string if no examples */ declare function datasourceExamplestoSQL(datasource: Datasource): string | null; /** * Generates SQL INSERT statements from real datasource items fetched from the API. * Each item's `data` JSONB field is spread into the table columns. */ declare function datasourceItemsToSQL(datasource: Datasource, items: Array<{ id: string; data: Record; createdAt?: string | null; updatedAt?: string | null; }>): string | null; /** * Reorders the given array of sqlite statements to ensure that tables are created * before they are referenced by foreign keys. * @param statements array of sqlite statements string like "CREATE TABLE IF NOT EXISTS ..." * @todo Implement proper reordering of statements to handle foreign key dependencies * @returns */ declare function reorderStatements(statements: string[]): string[]; //#endregion export { datasourceDropSQL, datasourceExamplestoSQL, datasourceItemsToSQL, datasourceToSQL, generateMigration, reorderStatements }; //# sourceMappingURL=to-sql.d.ts.map