From 9df3929fc7424a9c3d4e870c8eb6d1501c1a13cc Mon Sep 17 00:00:00 2001 From: wener Date: Thu, 10 Oct 2024 10:39:46 +0800 Subject: [PATCH] feat: expose createMigrationBuilder to allow using this lib as sql builder --- src/index.ts | 1 + src/migrationBuilder.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/index.ts b/src/index.ts index 3003a19d..f47efd40 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export { Migration } from './migration'; +export { createMigrationBuilder } from './migrationBuilder'; export type { CreateCast, CreateCastFn, diff --git a/src/migrationBuilder.ts b/src/migrationBuilder.ts index a23fd4f9..1be7be0b 100644 --- a/src/migrationBuilder.ts +++ b/src/migrationBuilder.ts @@ -531,3 +531,29 @@ export default class MigrationBuilderImpl implements MigrationBuilder { return this._REVERSE_MODE ? [...this._steps].reverse() : this._steps; } } + +export function createMigrationBuilder({ + db, + typeShorthands, + shouldDecamelize, + logger, +}: { + db?: DB; + typeShorthands: ColumnDefinitions | undefined; + shouldDecamelize: boolean; + logger: Logger; +}): MigrationBuilderImpl { + return new MigrationBuilderImpl( + db || { + select: () => { + throw new Error('Not implemented'); + }, + query: () => { + throw new Error('Not implemented'); + }, + }, + typeShorthands, + shouldDecamelize, + logger + ); +}