bun-query-builder 0.1.25 → 0.1.27
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.
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/introspect-db.d.ts +32 -0
- package/dist/actions/migrate-rollback.d.ts +14 -0
- package/dist/bin/cli.js +862 -216
- package/dist/client.d.ts +40 -10
- package/dist/config.d.ts +1 -15
- package/dist/db.d.ts +54 -0
- package/dist/orm.d.ts +30 -1
- package/dist/relation-utils.d.ts +27 -0
- package/dist/schema.d.ts +65 -3
- package/dist/src/index.js +858 -215
- package/dist/type-inference.d.ts +40 -0
- package/dist/types.d.ts +21 -0
- package/package.json +1 -1
package/dist/actions/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export { explain } from './explain';
|
|
|
9
9
|
export { file } from './file';
|
|
10
10
|
export { inspectTable, tableInfo } from './inspect';
|
|
11
11
|
export { introspect } from './introspect';
|
|
12
|
+
export { generateModelSource, introspectDatabase, modelNameForTable, sqlTypeToAttr } from './introspect-db';
|
|
12
13
|
export { makeModel } from './make-model';
|
|
13
14
|
export { executeMigration, generateMigration, resetDatabase } from './migrate';
|
|
14
15
|
export { migrateGenerate } from './migrate-generate';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Map a raw SQL column type to a model attribute type. */
|
|
2
|
+
export declare function sqlTypeToAttr(sqlType: string): AttrType;
|
|
3
|
+
/** PascalCase, singular model name for a table (`blog_posts` -> `BlogPost`). */
|
|
4
|
+
export declare function modelNameForTable(table: string): string;
|
|
5
|
+
/** Generate `defineModel(...)` source for one introspected table. */
|
|
6
|
+
export declare function generateModelSource(table: string, columns: IntrospectedColumn[]): string;
|
|
7
|
+
/**
|
|
8
|
+
* Introspect the configured live database and return a generated model per
|
|
9
|
+
* table. Pass `tables` to limit the set.
|
|
10
|
+
*/
|
|
11
|
+
export declare function introspectDatabase(opts?: { tables?: string[] }): Promise<IntrospectedModel[]>;
|
|
12
|
+
/**
|
|
13
|
+
* Reverse introspection (stacksjs/bun-query-builder#1047): read a LIVE database
|
|
14
|
+
* and emit `defineModel(...)` source, so an existing schema can be adopted
|
|
15
|
+
* without hand-writing models. Complements the forward `introspect(dir)` which
|
|
16
|
+
* loads models and prints the inferred schema.
|
|
17
|
+
*/
|
|
18
|
+
export declare interface IntrospectedColumn {
|
|
19
|
+
name: string
|
|
20
|
+
sqlType: string
|
|
21
|
+
nullable: boolean
|
|
22
|
+
isPrimaryKey: boolean
|
|
23
|
+
}
|
|
24
|
+
export declare interface IntrospectedModel {
|
|
25
|
+
table: string
|
|
26
|
+
modelName: string
|
|
27
|
+
primaryKey: string
|
|
28
|
+
columns: IntrospectedColumn[]
|
|
29
|
+
source: string
|
|
30
|
+
}
|
|
31
|
+
/** The attribute `type` we map a raw SQL column type to. */
|
|
32
|
+
export type AttrType = 'string' | 'number' | 'boolean' | 'datetime' | 'json';
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split a SQL script into individual statements, ignoring `;` inside single
|
|
3
|
+
* quotes or `--` line comments. Good enough for our generated DDL.
|
|
4
|
+
*/
|
|
5
|
+
export declare function splitSqlStatements(sql: string): string[];
|
|
6
|
+
/**
|
|
7
|
+
* Derive reverse ("down") DDL from a forward migration's SQL, so a rollback can
|
|
8
|
+
* actually undo schema changes (stacksjs/bun-query-builder#1048). Inverts the
|
|
9
|
+
* statements our generator emits — CREATE TABLE, ALTER TABLE ADD COLUMN, CREATE
|
|
10
|
+
* [UNIQUE] INDEX — in reverse order. Statements it can't safely invert (data
|
|
11
|
+
* changes, complex alters) are skipped; the caller reports them.
|
|
12
|
+
*/
|
|
13
|
+
export declare function deriveDownStatements(forwardSql: string, dialect?: string): { down: string[], skipped: string[] };
|
|
1
14
|
/**
|
|
2
15
|
* Rollback migrations
|
|
3
16
|
*
|
|
@@ -10,4 +23,5 @@
|
|
|
10
23
|
export declare function migrateRollback(options?: RollbackOptions): Promise<void>;
|
|
11
24
|
export declare interface RollbackOptions {
|
|
12
25
|
steps?: number
|
|
26
|
+
reverseSchema?: boolean
|
|
13
27
|
}
|