fromDatabase() — drizzle-orm Function Reference
Architecture documentation for the fromDatabase() function in sqliteSerializer.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 31460848_0b68_376e_2389_5130b321a073["fromDatabase()"] 8e6879a2_2b61_04aa_8765_25bc6cfe77be["sqliteSerializer.ts"] 31460848_0b68_376e_2389_5130b321a073 -->|defined in| 8e6879a2_2b61_04aa_8765_25bc6cfe77be 7c863cc4_5d6c_f72d_cf36_6aa755ac2321["sqliteIntrospect()"] 7c863cc4_5d6c_f72d_cf36_6aa755ac2321 -->|calls| 31460848_0b68_376e_2389_5130b321a073 5f4d3311_e879_6740_786e_659afa534b5a["sqlitePushIntrospect()"] 5f4d3311_e879_6740_786e_659afa534b5a -->|calls| 31460848_0b68_376e_2389_5130b321a073 42d6e07a_a947_fc7c_de6f_f734dcbaccfd["filterIgnoredTablesByField()"] 31460848_0b68_376e_2389_5130b321a073 -->|calls| 42d6e07a_a947_fc7c_de6f_f734dcbaccfd 90cd491b_3549_815a_97cb_c14bb692e41d["extractGeneratedColumns()"] 31460848_0b68_376e_2389_5130b321a073 -->|calls| 90cd491b_3549_815a_97cb_c14bb692e41d 282d78ed_ea0e_1e4d_d10d_b7b8473abb46["mapSqlToSqliteType()"] 31460848_0b68_376e_2389_5130b321a073 -->|calls| 282d78ed_ea0e_1e4d_d10d_b7b8473abb46 style 31460848_0b68_376e_2389_5130b321a073 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/serializer/sqliteSerializer.ts lines 510–953
export const fromDatabase = async (
db: SQLiteDB,
tablesFilter: (table: string) => boolean = (table) => true,
progressCallback?: (
stage: IntrospectStage,
count: number,
status: IntrospectStatus,
) => void,
): Promise<SQLiteSchemaInternal> => {
const result: Record<string, Table> = {};
const resultViews: Record<string, View> = {};
const columns = await db.query<{
tableName: string;
columnName: string;
columnType: string;
notNull: number;
defaultValue: string;
pk: number;
seq: number;
hidden: number;
sql: string;
type: 'view' | 'table';
}>(`SELECT
m.name as "tableName",
p.name as "columnName",
p.type as "columnType",
p."notnull" as "notNull",
p.dflt_value as "defaultValue",
p.pk as pk,
p.hidden as hidden,
m.sql,
m.type as type
FROM sqlite_master AS m
JOIN pragma_table_xinfo(m.name) AS p
WHERE (m.type = 'table' OR m.type = 'view')
AND ${filterIgnoredTablesByField('m.tbl_name')};`);
const tablesWithSeq: string[] = [];
const seq = await db.query<{
name: string;
}>(`SELECT
*
FROM sqlite_master
WHERE sql GLOB '*[ *' || CHAR(9) || CHAR(10) || CHAR(13) || ']AUTOINCREMENT[^'']*'
AND ${filterIgnoredTablesByField('tbl_name')};`);
for (const s of seq) {
tablesWithSeq.push(s.name);
}
let columnsCount = 0;
let tablesCount = new Set();
let indexesCount = 0;
let foreignKeysCount = 0;
let checksCount = 0;
let viewsCount = 0;
// append primaryKeys by table
const tableToPk: { [tname: string]: string[] } = {};
let tableToGeneratedColumnsInfo: Record<
string,
Record<string, ColumnInfo>
> = {};
for (const column of columns) {
if (!tablesFilter(column.tableName)) continue;
// TODO
if (column.type !== 'view') {
columnsCount += 1;
}
if (progressCallback) {
progressCallback('columns', columnsCount, 'fetching');
}
const tableName = column.tableName;
tablesCount.add(tableName);
if (progressCallback) {
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does fromDatabase() do?
fromDatabase() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/serializer/sqliteSerializer.ts.
Where is fromDatabase() defined?
fromDatabase() is defined in drizzle-kit/src/serializer/sqliteSerializer.ts at line 510.
What does fromDatabase() call?
fromDatabase() calls 3 function(s): extractGeneratedColumns, filterIgnoredTablesByField, mapSqlToSqliteType.
What calls fromDatabase()?
fromDatabase() is called by 2 function(s): sqliteIntrospect, sqlitePushIntrospect.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free