(
credentials: PostgresCredentials | {
driver: 'pglite';
client: PGlite;
},
pgSchema: Record<string, Record<string, AnyPgTable>>,
relations: Record<string, Relations>,
schemaFiles?: SchemaFile[],
casing?: CasingType,
)
| 277 | }; |
| 278 | |
| 279 | export const drizzleForPostgres = async ( |
| 280 | credentials: PostgresCredentials | { |
| 281 | driver: 'pglite'; |
| 282 | client: PGlite; |
| 283 | }, |
| 284 | pgSchema: Record<string, Record<string, AnyPgTable>>, |
| 285 | relations: Record<string, Relations>, |
| 286 | schemaFiles?: SchemaFile[], |
| 287 | casing?: CasingType, |
| 288 | ): Promise<Setup> => { |
| 289 | const { preparePostgresDB } = await import('../cli/connections'); |
| 290 | const db = await preparePostgresDB(credentials); |
| 291 | const customDefaults = getCustomDefaults(pgSchema, casing); |
| 292 | |
| 293 | let dbUrl: string; |
| 294 | |
| 295 | if ('driver' in credentials) { |
| 296 | const { driver } = credentials; |
| 297 | if (driver === 'aws-data-api') { |
| 298 | dbUrl = `aws-data-api://${credentials.database}/${credentials.secretArn}/${credentials.resourceArn}`; |
| 299 | } else if (driver === 'pglite') { |
| 300 | dbUrl = 'client' in credentials ? credentials.client.dataDir || 'pglite://custom-client' : credentials.url; |
| 301 | } else { |
| 302 | assertUnreachable(driver); |
| 303 | } |
| 304 | } else if ('url' in credentials) { |
| 305 | dbUrl = credentials.url; |
| 306 | } else { |
| 307 | dbUrl = |
| 308 | `postgresql://${credentials.user}:${credentials.password}@${credentials.host}:${credentials.port}/${credentials.database}`; |
| 309 | } |
| 310 | |
| 311 | const dbHash = createHash('sha256').update(dbUrl).digest('hex'); |
| 312 | |
| 313 | return { |
| 314 | dbHash, |
| 315 | dialect: 'postgresql', |
| 316 | driver: 'driver' in credentials ? credentials.driver : undefined, |
| 317 | packageName: db.packageName, |
| 318 | proxy: db.proxy, |
| 319 | transactionProxy: db.transactionProxy, |
| 320 | customDefaults, |
| 321 | schema: pgSchema, |
| 322 | relations, |
| 323 | schemaFiles, |
| 324 | casing, |
| 325 | }; |
| 326 | }; |
| 327 | |
| 328 | export const drizzleForMySQL = async ( |
| 329 | credentials: MysqlCredentials, |
no test coverage detected