rawsql-ts
Version:
High-performance SQL parser and AST analyzer written in TypeScript. Provides fast parsing and advanced transformation capabilities.
61 lines (60 loc) • 2.07 kB
TypeScript
import { CommonTable } from '../models/Clause';
/** Describes a single column in a fixture used for query rewriting. */
export interface FixtureColumnDefinition {
name: string;
typeName?: string;
defaultValue?: string;
}
/** Defines the data required to represent a fixture table as a CTE. */
export interface FixtureTableDefinition {
tableName: string;
columns: FixtureColumnDefinition[];
rows: (string | number | bigint | Buffer | null)[][];
}
export declare class FixtureCteBuilder {
/**
* Creates fixture definitions from a SQL string containing DDL (CREATE TABLE) and INSERT statements.
*
* @param sql The SQL string containing DDL and INSERTs.
* @returns An array of FixtureTableDefinition objects.
*/
static fromSQL(sql: string): FixtureTableDefinition[];
/**
* Converts JSON fixture definitions to FixtureTableDefinition format.
* Accepts an object where keys are table names and values contain columns and rows.
*
* @param jsonDefinitions Object with table definitions
* @returns Array of FixtureTableDefinition
*
* @example
* ```typescript
* const json = {
* users: {
* columns: [
* { name: 'id', type: 'integer' },
* { name: 'name', type: 'text' }
* ],
* rows: [
* { id: 1, name: 'Alice' },
* { id: 2, name: 'Bob' }
* ]
* }
* };
* const fixtures = FixtureCteBuilder.fromJSON(json);
* ```
*/
static fromJSON(jsonDefinitions: Record<string, {
columns: Array<{
name: string;
type?: string;
default?: string;
}>;
rows?: Array<Record<string, any>>;
}>): FixtureTableDefinition[];
/** Builds CommonTable representations for the provided fixtures. */
static buildFixtures(fixtures: FixtureTableDefinition[]): CommonTable[];
private static buildFixture;
private static buildSelectQuery;
private static buildSelectRow;
private static createLiteralValue;
}