(provider: 'sqlite' | 'postgresql', dbName: string)
| 89 | }); |
| 90 | |
| 91 | async function createClient(provider: 'sqlite' | 'postgresql', dbName: string) { |
| 92 | const _schema = clone(schema); |
| 93 | let dialect: Dialect; |
| 94 | if (provider === 'sqlite') { |
| 95 | (_schema as any).provider.type = 'sqlite'; |
| 96 | dialect = new BunSqliteDialect({ |
| 97 | database: new Database(':memory:'), |
| 98 | }); |
| 99 | } else { |
| 100 | (_schema as any).provider.type = 'postgresql'; |
| 101 | const pgClient = new Client({ |
| 102 | connectionString: TEST_PG_URL, |
| 103 | }); |
| 104 | await pgClient.connect(); |
| 105 | await pgClient.query(`DROP DATABASE IF EXISTS "${dbName}"`); |
| 106 | await pgClient.query(`CREATE DATABASE "${dbName}"`); |
| 107 | await pgClient.end(); |
| 108 | dialect = new PostgresDialect({ |
| 109 | pool: new Pool({ |
| 110 | connectionString: `${TEST_PG_URL}/${dbName}`, |
| 111 | }), |
| 112 | }); |
| 113 | } |
| 114 | |
| 115 | const db = new ZenStackClient(_schema, { dialect }); |
| 116 | await db.$pushSchema(); |
| 117 | return db; |
| 118 | } |
no test coverage detected