MCPcopy
hub / github.com/drizzle-team/drizzle-orm / prepareLibSQLRecreateTable

Function prepareLibSQLRecreateTable

drizzle-kit/src/statementCombiner.ts:10–41  ·  view source on GitHub ↗
(
	table: SQLiteSchemaSquashed['tables'][keyof SQLiteSchemaSquashed['tables']],
	action?: 'push',
)

Source from the content-addressed store, hash-verified

8import { SQLiteSchemaSquashed, SQLiteSquasher } from './serializer/sqliteSchema';
9
10export const prepareLibSQLRecreateTable = (
11 table: SQLiteSchemaSquashed['tables'][keyof SQLiteSchemaSquashed['tables']],
12 action?: 'push',
13): (JsonRecreateTableStatement | JsonCreateIndexStatement)[] => {
14 const { name, columns, uniqueConstraints, indexes, checkConstraints } = table;
15
16 const composites: string[][] = Object.values(table.compositePrimaryKeys).map(
17 (it) => SQLiteSquasher.unsquashPK(it),
18 );
19
20 const references: string[] = Object.values(table.foreignKeys);
21 const fks = references.map((it) =>
22 action === 'push' ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it)
23 );
24
25 const statements: (JsonRecreateTableStatement | JsonCreateIndexStatement)[] = [
26 {
27 type: 'recreate_table',
28 tableName: name,
29 columns: Object.values(columns),
30 compositePKs: composites,
31 referenceData: fks,
32 uniqueConstraints: Object.values(uniqueConstraints),
33 checkConstraints: Object.values(checkConstraints),
34 },
35 ];
36
37 if (Object.keys(indexes).length) {
38 statements.push(...prepareCreateIndexesJson(name, '', indexes));
39 }
40 return statements;
41};
42
43export const prepareSQLiteRecreateTable = (
44 table: SQLiteSchemaSquashed['tables'][keyof SQLiteSchemaSquashed['tables']],

Callers 1

libSQLCombineStatementsFunction · 0.85

Calls 2

prepareCreateIndexesJsonFunction · 0.90
valuesMethod · 0.45

Tested by

no test coverage detected