fromDatabase() — drizzle-orm Function Reference
Architecture documentation for the fromDatabase() function in gelSerializer.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 4e4d6d58_9452_ce92_00b8_77a3b8ffd541["fromDatabase()"] 33990744_4141_72e3_2ae9_3c695bf71d75["gelSerializer.ts"] 4e4d6d58_9452_ce92_00b8_77a3b8ffd541 -->|defined in| 33990744_4141_72e3_2ae9_3c695bf71d75 1a73d5cc_f857_ab73_baab_da75d15f06f3["getColumnsInfoQuery()"] 4e4d6d58_9452_ce92_00b8_77a3b8ffd541 -->|calls| 1a73d5cc_f857_ab73_baab_da75d15f06f3 b6d9c437_c4d6_d6c1_d2eb_613b745761cd["defaultForColumn()"] 4e4d6d58_9452_ce92_00b8_77a3b8ffd541 -->|calls| b6d9c437_c4d6_d6c1_d2eb_613b745761cd 6342c0f6_3fba_20d2_10c6_c4e192f835a0["trimChar()"] 4e4d6d58_9452_ce92_00b8_77a3b8ffd541 -->|calls| 6342c0f6_3fba_20d2_10c6_c4e192f835a0 68a39adf_55ab_d2a7_4618_b0046b1fac37["stringFromDatabaseIdentityProperty()"] 4e4d6d58_9452_ce92_00b8_77a3b8ffd541 -->|calls| 68a39adf_55ab_d2a7_4618_b0046b1fac37 style 4e4d6d58_9452_ce92_00b8_77a3b8ffd541 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/serializer/gelSerializer.ts lines 954–1535
export const fromDatabase = async (
db: DB,
tablesFilter: (table: string) => boolean = () => true,
schemaFilters: string[],
entities?: {
roles: boolean | {
provider?: string | undefined;
include?: string[] | undefined;
exclude?: string[] | undefined;
};
},
progressCallback?: (
stage: IntrospectStage,
count: number,
status: IntrospectStatus,
) => void,
tsSchema?: GelSchemaInternal,
): Promise<GelSchemaInternal> => {
const result: Record<string, Table> = {};
// const views: Record<string, View> = {};
const policies: Record<string, Policy> = {};
const internals: GelKitInternals = { tables: {} };
const where = schemaFilters.map((t) => `n.nspname = '${t}'`).join(' or ');
const allTables = await db.query<{ table_schema: string; table_name: string; type: string; rls_enabled: boolean }>(
`SELECT
n.nspname::text AS table_schema,
c.relname::text AS table_name,
CASE
WHEN c.relkind = 'r' THEN 'table'
WHEN c.relkind = 'v' THEN 'view'
WHEN c.relkind = 'm' THEN 'materialized_view'
END AS type,
c.relrowsecurity AS rls_enabled
FROM
pg_catalog.pg_class c
JOIN
pg_catalog.pg_namespace n ON n.oid::text = c.relnamespace::text
WHERE
c.relkind IN ('r', 'v', 'm')
${where === '' ? '' : ` AND ${where}`};`,
);
const schemas = new Set(allTables.map((it) => it.table_schema));
const allSchemas = await db.query<{
table_schema: string;
}>(`select s.nspname::text as table_schema
from pg_catalog.pg_namespace s
join pg_catalog.pg_user u on u.usesysid::text = s.nspowner::text
where nspname not in ('information_schema', 'pg_catalog', 'public')
and nspname::text not like 'pg_toast%'
and nspname::text not like 'pg_temp_%'
order by 1;`);
allSchemas.forEach((item) => {
if (schemaFilters.includes(item.table_schema)) {
schemas.add(item.table_schema);
}
});
let columnsCount = 0;
let indexesCount = 0;
let foreignKeysCount = 0;
let tableCount = 0;
const sequencesToReturn: Record<string, Sequence> = {};
const all = allTables
.filter((it) => it.type === 'table')
.map((row) => {
return new Promise(async (res, rej) => {
const tableName = row.table_name as string;
if (!tablesFilter(tableName)) return res('');
tableCount += 1;
const tableSchema = row.table_schema;
try {
const columnToReturn: Record<string, Column> = {};
const indexToReturn: Record<string, Index> = {};
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does fromDatabase() do?
fromDatabase() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/serializer/gelSerializer.ts.
Where is fromDatabase() defined?
fromDatabase() is defined in drizzle-kit/src/serializer/gelSerializer.ts at line 954.
What does fromDatabase() call?
fromDatabase() calls 4 function(s): defaultForColumn, getColumnsInfoQuery, stringFromDatabaseIdentityProperty, trimChar.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free