(url: string, supportedFactories: Factory[] = defaultFactories)
| 4 | import type { SqlDriverAdapter, SqlDriverAdapterFactory, Transaction } from '@prisma/driver-adapter-utils' |
| 5 | |
| 6 | export function createAdapter(url: string, supportedFactories: Factory[] = defaultFactories): SqlDriverAdapterFactory { |
| 7 | const allSupportedProtocols = supportedFactories.flatMap((factory) => factory.protocols) |
| 8 | for (const factory of supportedFactories) { |
| 9 | if (factory.protocols.some((protocol) => url.startsWith(`${protocol}://`))) { |
| 10 | return wrapFactory(allSupportedProtocols, factory.create(url)) |
| 11 | } |
| 12 | } |
| 13 | let urlObj: URL |
| 14 | try { |
| 15 | urlObj = new URL(url) |
| 16 | } catch { |
| 17 | throw new Error('Invalid database URL') |
| 18 | } |
| 19 | throw new Error(`Unsupported protocol in database URL: ${urlObj.protocol}`) |
| 20 | } |
| 21 | |
| 22 | type Factory = { |
| 23 | protocols: string[] |
no test coverage detected