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

Function drizzle

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

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 NeonClient = Pool,
94>(
95 ...params: [
96 TClient | string,
97 ] | [
98 TClient | string,
99 DrizzleConfig<TSchema>,
100 ] | [
101 (
102 & DrizzleConfig<TSchema>
103 & ({
104 connection: string | PoolConfig;
105 } | {
106 client: TClient;
107 })
108 & {
109 ws?: any;
110 }
111 ),
112 ]
113): NeonDatabase<TSchema> & {
114 $client: NeonClient extends TClient ? Pool : TClient;
115} {
116 if (typeof params[0] === 'string') {
117 const instance = new Pool({
118 connectionString: params[0],
119 });
120
121 return construct(instance, params[1]) as any;
122 }
123
124 if (isConfig(params[0])) {
125 const { connection, client, ws, ...drizzleConfig } = params[0] as {
126 connection?: PoolConfig | string;
127 ws?: any;
128 client?: TClient;
129 } & DrizzleConfig<TSchema>;
130
131 if (ws) {
132 neonConfig.webSocketConstructor = ws;
133 }
134
135 if (client) return construct(client, drizzleConfig);
136
137 const instance = typeof connection === 'string'
138 ? new Pool({
139 connectionString: connection,
140 })
141 : new Pool(connection);
142
143 return construct(instance, drizzleConfig) as any;
144 }
145
146 return construct(params[0] as TClient, params[1] as DrizzleConfig<TSchema> | undefined) as any;
147}
148

Callers 2

neon-ws.test.mjsFile · 0.90

Calls 2

isConfigFunction · 0.90
constructFunction · 0.70

Tested by

no test coverage detected