@inflector/optima 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,40 @@
1
+ import type { Infer } from "./schema";
2
+ import type { Extension, OptimaTable, Where } from "./table";
3
+ export type Prettify<T> = {
4
+ [K in keyof T]: T[K];
5
+ } & {};
6
+ export type SetFlag<State, Key extends keyof State> = {
7
+ [P in keyof State]: P extends Key ? true : State[P];
8
+ };
9
+ export type MapToFalse<T> = {
10
+ [K in keyof T]: false;
11
+ };
12
+ export type InitialState<T> = {
13
+ [K in keyof T]: false;
14
+ } & {
15
+ extended: false;
16
+ };
17
+ export type QueryMethods<TDef extends Record<string, any>> = {
18
+ limit: [n: number];
19
+ offset: [n: number];
20
+ orderBy: [col: keyof TDef | Array<keyof TDef>, dir?: "ASC" | "DESC"];
21
+ where: [w: Where<Infer<TDef>>];
22
+ };
23
+ export type QueryOneMethods<TDef extends Record<string, any>> = {
24
+ where: [w: Where<Infer<TDef>>];
25
+ };
26
+ export type FluentQueryBuilder<TDef extends Record<string, any>, Result, State extends Record<keyof QueryMethods<TDef> | "extended", boolean>> = {
27
+ [K in keyof QueryMethods<TDef> as State[K] extends true ? never : K]: (...args: QueryMethods<TDef>[K]) => FluentQueryBuilder<TDef, Result, SetFlag<State, K>>;
28
+ } & {
29
+ [K in "extend" as State["extended"] extends true ? never : K]: <ExtTable extends OptimaTable<any>>(table: ExtTable) => FluentQueryBuilder<TDef, Prettify<Result & Extension<TDef, ExtTable>>, SetFlag<State, "extended">>;
30
+ } & PromiseLike<Result[]>;
31
+ export type FluentQueryBuilderOne<TDef extends Record<string, any>, Result, State extends Record<keyof QueryOneMethods<TDef> | "extended", boolean>> = {
32
+ [K in keyof QueryOneMethods<TDef> as State[K] extends true ? never : K]: (...args: QueryOneMethods<TDef>[K]) => FluentQueryBuilderOne<TDef, Result, SetFlag<State, K>>;
33
+ } & {
34
+ [K in "extend" as State["extended"] extends true ? never : K]: <ExtTable extends OptimaTable<any>>(table: ExtTable) => FluentQueryBuilderOne<TDef, Prettify<Result & Extension<TDef, ExtTable>>, SetFlag<State, "extended">>;
35
+ } & PromiseLike<Result | undefined>;
36
+ export declare const createProxyHandler: (table: OptimaTable<any>, config: any, isSingleResult: boolean) => {
37
+ get(target: any, prop: string | symbol): (...args: any[]) => any;
38
+ };
39
+ export declare function createQueryBuilder<TDef extends Record<string, any>, Result>(table: OptimaTable<TDef>, initialConfig?: any): FluentQueryBuilder<TDef, Result, InitialState<QueryMethods<TDef>>>;
40
+ export declare function createQueryBuilderOne<TDef extends Record<string, any>, Result>(table: OptimaTable<TDef>, initialConfig?: any): FluentQueryBuilderOne<TDef, Result, InitialState<QueryOneMethods<TDef>>>;
@@ -0,0 +1,64 @@
1
+ // --- Implementation ---
2
+ export const createProxyHandler = (table, config, isSingleResult) => {
3
+ return {
4
+ get(target, prop) {
5
+ // 1. Handle Promise Execution (.then)
6
+ if (prop === "then") {
7
+ return async (resolve, reject) => {
8
+ const tableAny = table;
9
+ try {
10
+ const { sql } = tableAny.BuildSelect(tableAny["Name"], config);
11
+ const rawResult = await (await tableAny.Connection.run(sql)).getRowObjects();
12
+ const formatted = tableAny.FormatOut(rawResult);
13
+ if (isSingleResult) {
14
+ const val = formatted.length > 0 ? formatted[0] : undefined;
15
+ resolve(val);
16
+ }
17
+ else {
18
+ resolve(formatted);
19
+ }
20
+ }
21
+ catch (e) {
22
+ reject(e);
23
+ }
24
+ };
25
+ }
26
+ // 2. Handle 'extend'
27
+ if (prop === "extend") {
28
+ return (extTable) => {
29
+ config.extend = config.extend || [];
30
+ // Optional Runtime Safety: Prevent adding the exact same table instance twice
31
+ // (Even though types now prevent calling extend() twice on the same chain)
32
+ if (!config.extend.includes(extTable)) {
33
+ config.extend.push(extTable);
34
+ }
35
+ return new Proxy(target, createProxyHandler(table, config, isSingleResult));
36
+ };
37
+ }
38
+ // 3. Handle Standard Schema Methods
39
+ return (...args) => {
40
+ if (args.length === 1) {
41
+ config[prop] = args[0];
42
+ }
43
+ else if (args.length > 1) {
44
+ config[prop] = args;
45
+ }
46
+ else {
47
+ config[prop] = true;
48
+ }
49
+ return new Proxy(target, createProxyHandler(table, config, isSingleResult));
50
+ };
51
+ },
52
+ };
53
+ };
54
+ // --- Factory Functions ---
55
+ export function createQueryBuilder(table, initialConfig = {}) {
56
+ const dummyState = {};
57
+ // The InitialState type ensures 'extended' starts as false
58
+ return new Proxy(dummyState, createProxyHandler(table, initialConfig, false));
59
+ }
60
+ export function createQueryBuilderOne(table, initialConfig = {}) {
61
+ const config = { ...initialConfig, limit: 1 };
62
+ const dummyState = {};
63
+ return new Proxy(dummyState, createProxyHandler(table, config, true));
64
+ }
@@ -0,0 +1,32 @@
1
+ import { DuckDBConnection, DuckDBInstance } from "@duckdb/node-api";
2
+ import { OptimaTable } from "./table";
3
+ type DBRow = Record<string, unknown>;
4
+ type SchemaConfig = Record<string, any>;
5
+ export declare class OptimaDB<T extends Record<string, OptimaTable>> {
6
+ private instance;
7
+ private connection;
8
+ Tables: T;
9
+ constructor(instance: DuckDBInstance, connection: DuckDBConnection, tables: T);
10
+ /**
11
+ * Initializes the database, connects, detects schema changes,
12
+ * runs migrations, and returns the DB instance.
13
+ */
14
+ static Open<TSchema extends SchemaConfig>(name: string, schema: TSchema, options?: {
15
+ MemoryLimit?: string;
16
+ ThreadCount?: number;
17
+ }): Promise<OptimaDB<{
18
+ [K in keyof TSchema]: OptimaTable<TSchema[K]>;
19
+ }>>;
20
+ /**
21
+ * Executes a raw SQL query and returns rows as objects.
22
+ */
23
+ execute(sql: string): Promise<DBRow[]>;
24
+ getTables(): Promise<string[]>;
25
+ getDiskSize(): Promise<unknown>;
26
+ /**
27
+ * Runs a function within a transaction.
28
+ * Re-throws error after rollback so caller handles logic failure.
29
+ */
30
+ transaction<R>(fn: () => Promise<R>): Promise<R>;
31
+ }
32
+ export {};
@@ -0,0 +1,240 @@
1
+ import { DuckDBInstance } from "@duckdb/node-api";
2
+ import { OptimaTable } from "./table";
3
+ export class OptimaDB {
4
+ constructor(instance, connection, tables) {
5
+ this.instance = instance;
6
+ this.connection = connection;
7
+ this.Tables = tables;
8
+ }
9
+ /**
10
+ * Initializes the database, connects, detects schema changes,
11
+ * runs migrations, and returns the DB instance.
12
+ */
13
+ static async Open(name = ":memory:", schema, options) {
14
+ const instance = await DuckDBInstance.create(name);
15
+ const connection = await instance.connect();
16
+ // 1. Apply Options
17
+ if (options?.MemoryLimit) {
18
+ await connection.run(`SET memory_limit = '${options.MemoryLimit}';`);
19
+ }
20
+ if (options?.ThreadCount) {
21
+ await connection.run(`SET threads = ${options.ThreadCount};`);
22
+ }
23
+ // 2. Auto-Migration
24
+ const existingTables = await (await connection.run(`SELECT * from duckdb_tables`)).getRowObjects();
25
+ const cleanSchema = SchemaMigrator.transformSchema(schema);
26
+ const migrationSQL = SchemaMigrator.generateSQL(existingTables, cleanSchema);
27
+ if (migrationSQL.length > 0) {
28
+ console.log(`[OptimaDB] Applying ${migrationSQL.length} migrations...`);
29
+ // Run migrations in a transaction to ensure safety
30
+ await connection.run("BEGIN TRANSACTION;");
31
+ try {
32
+ for (const sql of migrationSQL) {
33
+ await connection.run(sql);
34
+ }
35
+ await connection.run("COMMIT;");
36
+ }
37
+ catch (err) {
38
+ await connection.run("ROLLBACK;");
39
+ console.error("[OptimaDB] Migration failed, rolling back.", err);
40
+ throw err;
41
+ }
42
+ }
43
+ // 3. Initialize Table Wrappers
44
+ const tables = {};
45
+ for (const key of Object.keys(schema)) {
46
+ tables[key] = await OptimaTable.create(key, schema[key], connection);
47
+ }
48
+ return new OptimaDB(instance, connection, tables);
49
+ }
50
+ /**
51
+ * Executes a raw SQL query and returns rows as objects.
52
+ */
53
+ async execute(sql) {
54
+ return (await this.connection.run(sql)).getRowObjects();
55
+ }
56
+ async getTables() {
57
+ const result = await this.execute("PRAGMA show_tables;");
58
+ return result.map((t) => t.name);
59
+ }
60
+ async getDiskSize() {
61
+ const result = await this.execute("PRAGMA database_size;");
62
+ return result[0];
63
+ }
64
+ /**
65
+ * Runs a function within a transaction.
66
+ * Re-throws error after rollback so caller handles logic failure.
67
+ */
68
+ async transaction(fn) {
69
+ await this.connection.run("BEGIN TRANSACTION;");
70
+ try {
71
+ const result = await fn();
72
+ await this.connection.run("COMMIT;");
73
+ return result;
74
+ }
75
+ catch (e) {
76
+ await this.connection.run("ROLLBACK;");
77
+ throw e;
78
+ }
79
+ }
80
+ }
81
+ /**
82
+ * ------------------------------------------------------------------
83
+ * INTERNAL MIGRATION LOGIC
84
+ * Encapsulated to keep the main class clean.
85
+ * ------------------------------------------------------------------
86
+ */
87
+ class SchemaMigrator {
88
+ /**
89
+ * Transforms the complex Module/ColumnImpl schema into a simple config object.
90
+ */
91
+ static transformSchema(schemaObject) {
92
+ const cleanSchema = {};
93
+ for (const [tableName, tableDef] of Object.entries(schemaObject)) {
94
+ if (typeof tableDef !== "object" || tableDef === null)
95
+ continue;
96
+ const realTableName = tableDef.__tableName || tableName;
97
+ cleanSchema[realTableName] = {};
98
+ for (const [colName, colImpl] of Object.entries(tableDef)) {
99
+ if (colName.startsWith("__"))
100
+ continue; // Skip metadata
101
+ // @ts-ignore - Assuming colImpl structure based on input
102
+ if (colImpl?.config) {
103
+ // @ts-ignore
104
+ const config = { ...colImpl.config };
105
+ // Handle STRUCT merging
106
+ if (config.SQlType === "STRUCT" && config.STRUCTType) {
107
+ config.SQlType = config.STRUCTType;
108
+ }
109
+ cleanSchema[realTableName][colName] = config;
110
+ }
111
+ }
112
+ }
113
+ return cleanSchema;
114
+ }
115
+ /**
116
+ * Generates SQL statements to migrate DB from Current -> Desired state.
117
+ */
118
+ static generateSQL(existingTablesRaw, desiredSchema) {
119
+ const currentSchema = this.parseDuckDBTableSQL(existingTablesRaw);
120
+ const steps = [];
121
+ for (const [tableName, fields] of Object.entries(desiredSchema)) {
122
+ // 1. CREATE TABLE
123
+ if (!currentSchema[tableName]) {
124
+ const fieldDefs = Object.entries(fields).map(([colName, config]) => {
125
+ let def = `"${colName}" ${config.SQlType}`;
126
+ if (config.primaryKey)
127
+ def += " PRIMARY KEY";
128
+ if (config.notnull)
129
+ def += " NOT NULL";
130
+ return def;
131
+ });
132
+ steps.push(`CREATE TABLE ${tableName} (${fieldDefs.join(", ")});`);
133
+ continue;
134
+ }
135
+ const currentTableCols = currentSchema[tableName];
136
+ for (const [colName, config] of Object.entries(fields)) {
137
+ // 2. ADD COLUMN
138
+ if (!currentTableCols[colName]) {
139
+ let def = `${config.SQlType}`;
140
+ // If adding NOT NULL to existing table, we need a default value
141
+ if (config.notnull) {
142
+ def += ` DEFAULT ${this.getDefaultValueForType(config.SQlType)}`;
143
+ }
144
+ steps.push(`ALTER TABLE ${tableName} ADD COLUMN "${colName}" ${def};`);
145
+ // Enforce strict constraint after adding (if supported by version, else implied by definition)
146
+ if (config.notnull) {
147
+ steps.push(`ALTER TABLE ${tableName} ALTER "${colName}" SET NOT NULL;`);
148
+ }
149
+ continue;
150
+ }
151
+ // 3. ALTER COLUMN (Type or Constraints)
152
+ const currentCol = currentTableCols[colName];
153
+ const normCurrentType = currentCol.type.replace(/\s+/g, "").toUpperCase();
154
+ const normNewType = config.SQlType.replace(/\s+/g, "").toUpperCase();
155
+ // 3a. Type Mismatch
156
+ // We skip complex struct comparison here to avoid false positives on spacing
157
+ if (normCurrentType !== normNewType && !normNewType.startsWith("STRUCT")) {
158
+ steps.push(`ALTER TABLE ${tableName} ALTER "${colName}" TYPE ${config.SQlType};`);
159
+ }
160
+ // 3b. Not Null Mismatch
161
+ const desiredNotNull = !!config.notnull;
162
+ if (desiredNotNull !== currentCol.isNotNull) {
163
+ if (desiredNotNull) {
164
+ steps.push(`ALTER TABLE ${tableName} ALTER "${colName}" SET NOT NULL;`);
165
+ }
166
+ else {
167
+ steps.push(`ALTER TABLE ${tableName} ALTER "${colName}" DROP NOT NULL;`);
168
+ }
169
+ }
170
+ }
171
+ }
172
+ return steps;
173
+ }
174
+ /**
175
+ * Parses raw "CREATE TABLE" SQL from DuckDB into a usable map.
176
+ */
177
+ static parseDuckDBTableSQL(existingTables) {
178
+ const schemaMap = {};
179
+ existingTables.forEach((table) => {
180
+ const match = table.sql.match(/CREATE TABLE "?\w+"?\s*\((.*)\);/s);
181
+ if (!match)
182
+ return;
183
+ const columnBody = match[1];
184
+ const columns = {};
185
+ let depth = 0;
186
+ let currentChunk = "";
187
+ for (let i = 0; i < columnBody.length; i++) {
188
+ const char = columnBody[i];
189
+ if (char === "(")
190
+ depth++;
191
+ if (char === ")")
192
+ depth--;
193
+ if (char === "," && depth === 0) {
194
+ this.processColumnLine(currentChunk, columns);
195
+ currentChunk = "";
196
+ }
197
+ else {
198
+ currentChunk += char;
199
+ }
200
+ }
201
+ if (currentChunk.trim())
202
+ this.processColumnLine(currentChunk, columns);
203
+ schemaMap[table.table_name] = columns;
204
+ });
205
+ return schemaMap;
206
+ }
207
+ static processColumnLine(line, columnMap) {
208
+ const parts = line.trim().match(/^("?[\w]+"?)\s+(.*)$/);
209
+ if (!parts)
210
+ return;
211
+ const name = parts[1]?.replace(/"/g, "");
212
+ const definition = parts[2];
213
+ const upDef = definition?.toUpperCase();
214
+ let type = definition?.split(" ")[0];
215
+ if (upDef?.startsWith("STRUCT")) {
216
+ type = definition; // Simplification: capture full struct definition
217
+ }
218
+ if (name !== undefined) {
219
+ columnMap[name] = {
220
+ type: type,
221
+ isNotNull: upDef?.includes("NOT NULL") ?? false,
222
+ isPrimaryKey: upDef?.includes("PRIMARY KEY") ?? false,
223
+ };
224
+ }
225
+ }
226
+ /**
227
+ * Returns a safe default value for a given SQL type.
228
+ * Required when adding NOT NULL columns to existing tables.
229
+ */
230
+ static getDefaultValueForType(type) {
231
+ const t = type.toUpperCase();
232
+ if (t.includes("INT") || t.includes("FLOAT") || t.includes("DECIMAL") || t.includes("DOUBLE"))
233
+ return "0";
234
+ if (t.includes("BOOL"))
235
+ return "FALSE";
236
+ if (t.includes("STRUCT") || t.includes("MAP") || t.includes("LIST"))
237
+ return "NULL"; // Complex types usually default to NULL
238
+ return "''"; // VARCHAR, TEXT, etc.
239
+ }
240
+ }
@@ -0,0 +1,13 @@
1
+ export type SetFlag<State, Key extends keyof State> = {
2
+ [P in keyof State]: P extends Key ? true : State[P];
3
+ };
4
+ type MapToFalse<T> = {
5
+ [K in keyof T]: false;
6
+ };
7
+ type FluentStep<Schema, State extends {
8
+ [K in keyof Schema]: boolean | unknown;
9
+ }, Result> = {
10
+ [K in keyof Schema as State[K] extends true ? never : K]: Schema[K] extends boolean ? () => FluentStep<Schema, SetFlag<State, K>, Result> : Schema[K] extends any[] ? (...args: Schema[K]) => FluentStep<Schema, SetFlag<State, K>, Result> : (arg: Schema[K]) => FluentStep<Schema, SetFlag<State, K>, Result>;
11
+ } & PromiseLike<Result>;
12
+ export declare function createFluentBuilder<Schema, R = Schema>(onBuild?: (data: Schema) => R | Promise<R>): FluentStep<Schema, MapToFalse<Schema>, R>;
13
+ export {};
package/dist/fluent.js ADDED
@@ -0,0 +1,29 @@
1
+ export function createFluentBuilder(onBuild) {
2
+ const data = {};
3
+ const handler = {
4
+ get(target, prop) {
5
+ if (prop === "then") {
6
+ return (resolve, reject) => {
7
+ const result = onBuild ? onBuild(target) : target;
8
+ Promise.resolve(result).then(resolve, reject);
9
+ };
10
+ }
11
+ return (...args) => {
12
+ // 1. No Args -> True (Flag)
13
+ if (args.length === 0) {
14
+ target[prop] = true;
15
+ }
16
+ // 2. One Arg -> Store value
17
+ else if (args.length === 1) {
18
+ target[prop] = args[0];
19
+ }
20
+ // 3. Multiple Args -> Store as Array/Tuple
21
+ else {
22
+ target[prop] = args;
23
+ }
24
+ return new Proxy(target, handler);
25
+ };
26
+ },
27
+ };
28
+ return new Proxy(data, handler);
29
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./database";
2
+ export * from "./schema";
3
+ export { eq, ne, gt, gte, lt, lte, inOp, notIn, between, notBetween, is, isNot, like, notLike, startsWith, endsWith, contains, regexp, notRegexp, cond, type ConditionBuilder } from "./table";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./database";
2
+ export * from "./schema";
3
+ export { eq, ne, gt, gte, lt, lte, inOp, notIn, between, notBetween, is, isNot, like, notLike, startsWith, endsWith, contains, regexp, notRegexp, cond } from "./table";
@@ -0,0 +1,85 @@
1
+ import * as z from "zod";
2
+ type SetFlag<C extends ColumnConfig, K extends keyof ColumnConfig> = Omit<C, K> & {
3
+ [P in K]: true;
4
+ };
5
+ export type Prettify<T> = {
6
+ [K in keyof T]: T[K];
7
+ } & {};
8
+ export type Restrict<K extends keyof ColumnConfig> = {
9
+ [P in keyof ColumnConfig]: P extends K ? true : false;
10
+ };
11
+ export type One<T> = T & {
12
+ readonly __refKind: "one";
13
+ };
14
+ export type Many<T> = T & {
15
+ readonly __refKind: "many";
16
+ };
17
+ export declare const refHelpers: {
18
+ one: <T>(ref: T) => One<T>;
19
+ many: <T>(ref: T) => Many<T>;
20
+ };
21
+ export type InferColumnType<T> = T extends ColumnBuilder<infer U, any, any> ? U : never;
22
+ export type Infer<T extends Record<string, any>> = Prettify<{
23
+ [K in keyof T as K extends `__${string}` ? never : T[K] extends ColumnBuilder<any, infer C, any> ? C["notnull"] extends true ? K : never : never]: T[K] extends ColumnBuilder<infer U, any, any> ? U : never;
24
+ } & // 2. Handle Optional Keys (notnull: false)
25
+ {
26
+ [K in keyof T as K extends `__${string}` ? never : T[K] extends ColumnBuilder<any, infer C, any> ? C["notnull"] extends true ? never : K : never]: T[K] extends ColumnBuilder<infer U, any, any> ? U | null : never;
27
+ }>;
28
+ export type InferAdd<T extends Record<string, any>> = Prettify<{
29
+ [K in keyof T as K extends `__${string}` ? never : T[K] extends ColumnBuilder<any, infer C, any> ? C["notnull"] extends true ? K : never : never]: T[K] extends ColumnBuilder<infer U, any, any> ? U : never;
30
+ } & // 2. Handle Optional Keys (notnull: false)
31
+ {
32
+ [K in keyof T as K extends `__${string}` ? never : T[K] extends ColumnBuilder<any, infer C, any> ? C["notnull"] extends true ? never : K : never]?: T[K] extends ColumnBuilder<infer U, any, any> ? U | null : never;
33
+ }>;
34
+ export type ColumnConfig = {
35
+ SQlType: boolean;
36
+ primaryKey: boolean;
37
+ notnull: boolean;
38
+ unique: boolean;
39
+ default: boolean;
40
+ defaultNow: boolean;
41
+ reference: boolean;
42
+ validate: boolean;
43
+ transform: boolean;
44
+ deprecated: boolean;
45
+ STRUCTType: boolean;
46
+ };
47
+ export type ColumnBuilder<Type, Config extends ColumnConfig, RefSchema = never> = {
48
+ [K in keyof ColumnConfig as K extends "STRUCTType" ? never : Config[K] extends true ? never : K]: K extends "SQlType" ? (val: string) => ColumnBuilder<Type, SetFlag<Config, "SQlType">, RefSchema> : K extends "primaryKey" ? () => ColumnBuilder<Type, SetFlag<Config, "primaryKey">, RefSchema> : K extends "notnull" ? () => ColumnBuilder<Type, SetFlag<Config, "notnull">, RefSchema> : K extends "unique" ? () => ColumnBuilder<Type, SetFlag<Config, "unique">, RefSchema> : K extends "default" ? (val: Type | (() => Type)) => ColumnBuilder<Type, SetFlag<Config, "default">, RefSchema> : K extends "defaultNow" ? () => ColumnBuilder<Type, SetFlag<Config, "defaultNow">, RefSchema> : K extends "reference" ? <TRef>(ref: (helpers: typeof refHelpers) => TRef) => ColumnBuilder<Type, SetFlag<Config, "reference">, TRef> : K extends "validate" ? (fn: (val: Type) => boolean) => ColumnBuilder<Type, SetFlag<Config, "validate">, RefSchema> : K extends "transform" ? (fn: (val: Type) => Type) => ColumnBuilder<Type, SetFlag<Config, "transform">, RefSchema> : K extends "deprecated" ? () => ColumnBuilder<Type, SetFlag<Config, "deprecated">, RefSchema> : never;
49
+ };
50
+ export declare const Int: () => ColumnBuilder<number, SetFlag<Restrict<"defaultNow">, "SQlType">, never>;
51
+ export declare const BigInt: () => ColumnBuilder<bigint, SetFlag<Restrict<"defaultNow">, "SQlType">, never>;
52
+ export declare const Float: () => ColumnBuilder<number, SetFlag<Restrict<"defaultNow">, "SQlType">, never>;
53
+ export declare const Boolean: () => ColumnBuilder<boolean, SetFlag<Restrict<"primaryKey" | "unique" | "defaultNow">, "SQlType">, never>;
54
+ export declare const Text: () => ColumnBuilder<string, SetFlag<Restrict<"defaultNow">, "SQlType">, never>;
55
+ export declare const Uuid: () => ColumnBuilder<string, SetFlag<Restrict<"defaultNow">, "SQlType">, never>;
56
+ export declare const DateType: () => ColumnBuilder<Date, SetFlag<Restrict<"default">, "SQlType">, never>;
57
+ export declare const Timestamp: () => ColumnBuilder<Date, SetFlag<Restrict<"default">, "SQlType">, never>;
58
+ export declare const Enum: <T extends string | number>(vals: readonly T[]) => ColumnBuilder<T, SetFlag<SetFlag<Restrict<"defaultNow">, "validate">, "SQlType">, never>;
59
+ export * from "zod";
60
+ export declare const Json: <T extends z.ZodRawShape>(obj: T) => ColumnBuilder<z.core.$InferObjectOutput<T, {}>, SetFlag<Restrict<"primaryKey" | "unique" | "defaultNow">, "SQlType">, never>;
61
+ export declare const Array: <T extends z.ZodTypeAny>(schema: T) => ColumnBuilder<z.core.output<T>[], SetFlag<Restrict<"primaryKey" | "unique" | "defaultNow">, "SQlType">, never>;
62
+ export declare const Email: () => ColumnBuilder<string, SetFlag<SetFlag<Restrict<"defaultNow">, "SQlType">, "validate">, never>;
63
+ export declare const Slug: () => ColumnBuilder<string, SetFlag<SetFlag<Restrict<"defaultNow">, "SQlType">, "validate">, never>;
64
+ export declare const Color: () => ColumnBuilder<string, SetFlag<SetFlag<Restrict<"defaultNow">, "SQlType">, "validate">, never>;
65
+ export declare const Bytes: () => ColumnBuilder<Uint8Array<ArrayBufferLike>, SetFlag<Restrict<"primaryKey" | "defaultNow">, "SQlType">, never>;
66
+ export declare const Password: () => ColumnBuilder<string, SetFlag<Restrict<"primaryKey" | "unique" | "defaultNow">, "SQlType">, never>;
67
+ export declare const GeoPoint: () => ColumnBuilder<{
68
+ latitude: number;
69
+ longitude: number;
70
+ }, SetFlag<Restrict<"primaryKey" | "defaultNow">, "SQlType">, never>;
71
+ export declare const GeoArea: () => ColumnBuilder<{
72
+ latitude: number;
73
+ longitude: number;
74
+ radius: number;
75
+ }, SetFlag<Restrict<"primaryKey" | "defaultNow">, "SQlType">, never>;
76
+ export declare const Table: <Name extends string, T extends Record<string, ColumnBuilder<any, any>>>(name: Name, fields: T) => T & {
77
+ __tableName: Name;
78
+ };
79
+ export declare class SQLBuilder {
80
+ static BuildField(name: string, f: ColumnBuilder<any, any>): {
81
+ sql: string;
82
+ ref: boolean;
83
+ };
84
+ static BuildTable(name: string, t: Record<string, any>): string;
85
+ }