| 134 | } |
| 135 | |
| 136 | export class PrismaD1WorkerAdapter extends D1WorkerQueryable<StdClient> implements SqlDriverAdapter { |
| 137 | readonly tags = { |
| 138 | error: red('prisma:error'), |
| 139 | warn: yellow('prisma:warn'), |
| 140 | info: cyan('prisma:info'), |
| 141 | query: blue('prisma:query'), |
| 142 | } |
| 143 | |
| 144 | alreadyWarned = new Set() |
| 145 | |
| 146 | constructor( |
| 147 | client: StdClient, |
| 148 | private readonly release?: () => Promise<void>, |
| 149 | ) { |
| 150 | super(client) |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * This will warn once per transaction |
| 155 | * e.g. the following two explicit transactions |
| 156 | * will only trigger _two_ warnings |
| 157 | * |
| 158 | * ```ts |
| 159 | * await prisma.$transaction([ ...queries ]) |
| 160 | * await prisma.$transaction([ ...moreQueries ]) |
| 161 | * ``` |
| 162 | */ |
| 163 | private warnOnce = (key: string, message: string, ...args: unknown[]) => { |
| 164 | if (!this.alreadyWarned.has(key)) { |
| 165 | this.alreadyWarned.add(key) |
| 166 | console.info(`${this.tags.warn} ${message}`, ...args) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | async executeScript(script: string): Promise<void> { |
| 171 | try { |
| 172 | await this.client.exec(script) |
| 173 | } catch (error) { |
| 174 | onError(error as Error) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | getConnectionInfo(): ConnectionInfo { |
| 179 | return { |
| 180 | maxBindValues: MAX_BIND_VALUES, |
| 181 | supportsRelationJoins: false, |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | async startTransaction(isolationLevel?: IsolationLevel): Promise<Transaction> { |
| 186 | if (isolationLevel && isolationLevel !== 'SERIALIZABLE') { |
| 187 | throw new DriverAdapterError({ |
| 188 | kind: 'InvalidIsolationLevel', |
| 189 | level: isolationLevel, |
| 190 | }) |
| 191 | } |
| 192 | |
| 193 | this.warnOnce( |