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

Function fromDatabase

drizzle-kit/src/serializer/sqliteSerializer.ts:510–953  ·  view source on GitHub ↗
(
	db: SQLiteDB,
	tablesFilter: (table: string) => boolean = (table) => true,
	progressCallback?: (
		stage: IntrospectStage,
		count: number,
		status: IntrospectStatus,
	) => void,
)

Source from the content-addressed store, hash-verified

508}
509
510export const fromDatabase = async (
511 db: SQLiteDB,
512 tablesFilter: (table: string) => boolean = (table) => true,
513 progressCallback?: (
514 stage: IntrospectStage,
515 count: number,
516 status: IntrospectStatus,
517 ) => void,
518): Promise<SQLiteSchemaInternal> => {
519 const result: Record<string, Table> = {};
520 const resultViews: Record<string, View> = {};
521
522 const columns = await db.query<{
523 tableName: string;
524 columnName: string;
525 columnType: string;
526 notNull: number;
527 defaultValue: string;
528 pk: number;
529 seq: number;
530 hidden: number;
531 sql: string;
532 type: 'view' | 'table';
533 }>(`SELECT
534 m.name as "tableName",
535 p.name as "columnName",
536 p.type as "columnType",
537 p."notnull" as "notNull",
538 p.dflt_value as "defaultValue",
539 p.pk as pk,
540 p.hidden as hidden,
541 m.sql,
542 m.type as type
543 FROM sqlite_master AS m
544 JOIN pragma_table_xinfo(m.name) AS p
545 WHERE (m.type = 'table' OR m.type = 'view')
546 AND ${filterIgnoredTablesByField('m.tbl_name')};`);
547
548 const tablesWithSeq: string[] = [];
549
550 const seq = await db.query<{
551 name: string;
552 }>(`SELECT
553 *
554 FROM sqlite_master
555 WHERE sql GLOB '*[ *' || CHAR(9) || CHAR(10) || CHAR(13) || ']AUTOINCREMENT[^'']*'
556 AND ${filterIgnoredTablesByField('tbl_name')};`);
557
558 for (const s of seq) {
559 tablesWithSeq.push(s.name);
560 }
561
562 let columnsCount = 0;
563 let tablesCount = new Set();
564 let indexesCount = 0;
565 let foreignKeysCount = 0;
566 let checksCount = 0;
567 let viewsCount = 0;

Callers 4

sqliteIntrospectFunction · 0.90
sqlitePushIntrospectFunction · 0.90
diffTestSchemasPushFunction · 0.90
introspectPgToFileFunction · 0.90

Calls 5

extractGeneratedColumnsFunction · 0.85
mapSqlToSqliteTypeFunction · 0.85
queryMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected