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

Function construct

drizzle-orm/src/pglite/driver.ts:49–96  ·  view source on GitHub ↗
(
	client: PgliteClient,
	config: DrizzleConfig<TSchema> = {},
)

Source from the content-addressed store, hash-verified

47}
48
49function construct<TSchema extends Record<string, unknown> = Record<string, never>>(
50 client: PgliteClient,
51 config: DrizzleConfig<TSchema> = {},
52): PgliteDatabase<TSchema> & {
53 $client: PgliteClient;
54} {
55 const dialect = new PgDialect({ casing: config.casing });
56 let logger;
57 if (config.logger === true) {
58 logger = new DefaultLogger();
59 } else if (config.logger !== false) {
60 logger = config.logger;
61 }
62
63 let schema: RelationalSchemaConfig<TablesRelationalConfig> | undefined;
64 if (config.schema) {
65 const tablesConfig = extractTablesRelationalConfig(
66 config.schema,
67 createTableRelationsHelpers,
68 );
69 schema = {
70 fullSchema: config.schema,
71 schema: tablesConfig.tables,
72 tableNamesMap: tablesConfig.tableNamesMap,
73 };
74 }
75
76 const driver = new PgliteDriver(client, dialect, { logger, cache: config.cache });
77 const session = driver.createSession(schema);
78 const db = new PgliteDatabase(dialect, session, schema as any) as PgliteDatabase<TSchema>;
79 (<any> db).$client = client;
80 (<any> db).$cache = config.cache;
81 if ((<any> db).$cache) {
82 (<any> db).$cache['invalidate'] = config.cache?.onMutate;
83 }
84 // (<any> db).$cache = { invalidate: (<any> config).cache?.onMutate };
85 // if (config.cache) {
86 // for (
87 // const key of Object.getOwnPropertyNames(Object.getPrototypeOf(config.cache)).filter((key) =>
88 // key !== 'constructor'
89 // )
90 // ) {
91 // (<any> db).$cache[key as keyof typeof config.cache] = (<any> config).cache[key];
92 // }
93 // }
94
95 return db as any;
96}
97
98export function drizzle<
99 TSchema extends Record<string, unknown> = Record<string, never>,

Callers 2

drizzleFunction · 0.70
mockFunction · 0.70

Calls 2

createSessionMethod · 0.95

Tested by

no test coverage detected