(provider: string, databaseUrl: string, outputPath: string)
| 199 | } |
| 200 | |
| 201 | async function createDialect(provider: string, databaseUrl: string, outputPath: string) { |
| 202 | switch (provider) { |
| 203 | case 'sqlite': { |
| 204 | let SQLite: typeof BetterSqlite3; |
| 205 | try { |
| 206 | SQLite = (await import('better-sqlite3')).default; |
| 207 | } catch { |
| 208 | throw new CliError( |
| 209 | `Package "better-sqlite3" is required for SQLite support. Please install it with: npm install better-sqlite3`, |
| 210 | ); |
| 211 | } |
| 212 | let resolvedUrl = databaseUrl.trim(); |
| 213 | if (resolvedUrl.startsWith('file:')) { |
| 214 | const filePath = resolvedUrl.substring('file:'.length); |
| 215 | if (!path.isAbsolute(filePath)) { |
| 216 | resolvedUrl = path.join(outputPath, filePath); |
| 217 | } |
| 218 | } |
| 219 | console.log(colors.gray(`Connecting to SQLite database at: ${resolvedUrl}`)); |
| 220 | return new SqliteDialect({ |
| 221 | database: new SQLite(resolvedUrl), |
| 222 | }); |
| 223 | } |
| 224 | case 'postgresql': { |
| 225 | let PgPool: typeof PgPoolType; |
| 226 | try { |
| 227 | PgPool = (await import('pg')).Pool; |
| 228 | } catch { |
| 229 | throw new CliError( |
| 230 | `Package "pg" is required for PostgreSQL support. Please install it with: npm install pg`, |
| 231 | ); |
| 232 | } |
| 233 | console.log(colors.gray(`Connecting to PostgreSQL database at: ${redactDatabaseUrl(databaseUrl)}`)); |
| 234 | return new PostgresDialect({ |
| 235 | pool: new PgPool({ |
| 236 | connectionString: databaseUrl, |
| 237 | }), |
| 238 | }); |
| 239 | } |
| 240 | case 'mysql': { |
| 241 | let createMysqlPool: typeof MysqlCreatePool; |
| 242 | try { |
| 243 | createMysqlPool = (await import('mysql2')).createPool; |
| 244 | } catch { |
| 245 | throw new CliError( |
| 246 | `Package "mysql2" is required for MySQL support. Please install it with: npm install mysql2`, |
| 247 | ); |
| 248 | } |
| 249 | console.log(colors.gray(`Connecting to MySQL database at: ${redactDatabaseUrl(databaseUrl)}`)); |
| 250 | return new MysqlDialect({ |
| 251 | pool: createMysqlPool(databaseUrl), |
| 252 | }); |
| 253 | } |
| 254 | default: |
| 255 | throw new CliError(`Unsupported database provider: ${provider}`); |
| 256 | } |
| 257 | } |
| 258 |
no test coverage detected