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

Function drizzle

drizzle-orm/src/postgres-js/driver.ts:70–118  ·  view source on GitHub ↗
(
	...params: [
		TClient | string,
	] | [
		TClient | string,
		DrizzleConfig<TSchema>,
	] | [
		(
			& DrizzleConfig<TSchema>
			& ({
				connection: string | ({ url?: string } & Options<Record<string, PostgresType>>);
			} | {
				client: TClient;
			})
		),
	]
)

Source from the content-addressed store, hash-verified

68}
69
70export function drizzle<
71 TSchema extends Record<string, unknown> = Record<string, never>,
72 TClient extends Sql = Sql,
73>(
74 ...params: [
75 TClient | string,
76 ] | [
77 TClient | string,
78 DrizzleConfig<TSchema>,
79 ] | [
80 (
81 & DrizzleConfig<TSchema>
82 & ({
83 connection: string | ({ url?: string } & Options<Record<string, PostgresType>>);
84 } | {
85 client: TClient;
86 })
87 ),
88 ]
89): PostgresJsDatabase<TSchema> & {
90 $client: TClient;
91} {
92 if (typeof params[0] === 'string') {
93 const instance = pgClient(params[0] as string);
94
95 return construct(instance, params[1]) as any;
96 }
97
98 if (isConfig(params[0])) {
99 const { connection, client, ...drizzleConfig } = params[0] as {
100 connection?: { url?: string } & Options<Record<string, PostgresType>>;
101 client?: TClient;
102 } & DrizzleConfig<TSchema>;
103
104 if (client) return construct(client, drizzleConfig) as any;
105
106 if (typeof connection === 'object' && connection.url !== undefined) {
107 const { url, ...config } = connection;
108
109 const instance = pgClient(url, config);
110 return construct(instance, drizzleConfig) as any;
111 }
112
113 const instance = pgClient(connection);
114 return construct(instance, drizzleConfig) as any;
115 }
116
117 return construct(params[0] as TClient, params[1] as DrizzleConfig<TSchema> | undefined) as any;
118}
119
120export namespace drizzle {
121 export function mock<TSchema extends Record<string, unknown> = Record<string, never>>(

Callers 7

postgres.test.tsFile · 0.90
postgres.test.tsFile · 0.90

Calls 2

isConfigFunction · 0.90
constructFunction · 0.70

Tested by

no test coverage detected