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

Function drizzle

drizzle-orm/src/node-postgres/driver.ts:91–140  ·  view source on GitHub ↗
(
	...params:
		| [
			TClient | string,
		]
		| [
			TClient | string,
			DrizzleConfig<TSchema>,
		]
		| [
			& DrizzleConfig<TSchema>
			& ({
				client: TClient;
			} | {
				connection: string | PoolConfig;
			}),
		]
)

Source from the content-addressed store, hash-verified

89}
90
91export function drizzle<
92 TSchema extends Record<string, unknown> = Record<string, never>,
93 TClient extends NodePgClient = Pool,
94>(
95 ...params:
96 | [
97 TClient | string,
98 ]
99 | [
100 TClient | string,
101 DrizzleConfig<TSchema>,
102 ]
103 | [
104 & DrizzleConfig<TSchema>
105 & ({
106 client: TClient;
107 } | {
108 connection: string | PoolConfig;
109 }),
110 ]
111): NodePgDatabase<TSchema> & {
112 $client: NodePgClient extends TClient ? Pool : TClient;
113} {
114 if (typeof params[0] === 'string') {
115 const instance = new pg.Pool({
116 connectionString: params[0],
117 });
118
119 return construct(instance, params[1] as DrizzleConfig<TSchema> | undefined) as any;
120 }
121
122 if (isConfig(params[0])) {
123 const { connection, client, ...drizzleConfig } = params[0] as (
124 & ({ connection?: PoolConfig | string; client?: TClient })
125 & DrizzleConfig<TSchema>
126 );
127
128 if (client) return construct(client, drizzleConfig);
129
130 const instance = typeof connection === 'string'
131 ? new pg.Pool({
132 connectionString: connection,
133 })
134 : new pg.Pool(connection!);
135
136 return construct(instance, drizzleConfig) as any;
137 }
138
139 return construct(params[0] as TClient, params[1] as DrizzleConfig<TSchema> | undefined) as any;
140}
141
142export namespace drizzle {
143 export function mock<TSchema extends Record<string, unknown> = Record<string, never>>(

Callers 11

node-pg.test.mjsFile · 0.90
pg.test.tsFile · 0.90
pg.test.tsFile · 0.90
pg-custom.test.tsFile · 0.90
pg.test.tsFile · 0.90
pg.test.tsFile · 0.90
pgTest.tsFile · 0.90

Calls 2

isConfigFunction · 0.90
constructFunction · 0.70

Tested by

no test coverage detected