| 69 | ]; |
| 70 | |
| 71 | class WAEQueryable implements QueryableBaseDriver { |
| 72 | constructor( |
| 73 | protected accountId: string, |
| 74 | protected token: string |
| 75 | ) {} |
| 76 | |
| 77 | async query(stmt: string): Promise<DatabaseResultSet> { |
| 78 | const r = await fetch("/proxy/wae", { |
| 79 | method: "POST", |
| 80 | headers: { |
| 81 | "Content-Type": "text/plain", |
| 82 | Authorization: "Bearer " + this.token, |
| 83 | "x-account-id": this.accountId, |
| 84 | }, |
| 85 | body: stmt, |
| 86 | }); |
| 87 | |
| 88 | const json: CloudflareWAEResponse = await r.json(); |
| 89 | |
| 90 | if (json.error) { |
| 91 | throw new Error(json.error); |
| 92 | } |
| 93 | |
| 94 | return { |
| 95 | rows: json.data, |
| 96 | headers: json.meta.map( |
| 97 | (m) => |
| 98 | ({ |
| 99 | name: m.name, |
| 100 | displayName: m.name, |
| 101 | originalType: m.type, |
| 102 | type: |
| 103 | { |
| 104 | UInt32: ColumnType.INTEGER, |
| 105 | String: ColumnType.TEXT, |
| 106 | Float64: ColumnType.REAL, |
| 107 | DateTime: ColumnType.TEXT, |
| 108 | }[m.type] ?? ColumnType.TEXT, |
| 109 | }) as ColumnHeader |
| 110 | ), |
| 111 | stat: { |
| 112 | rowsAffected: 0, |
| 113 | rowsRead: 0, |
| 114 | rowsWritten: 0, |
| 115 | queryDurationMs: 0, |
| 116 | }, |
| 117 | }; |
| 118 | } |
| 119 | |
| 120 | async transaction(stmt: string[]): Promise<DatabaseResultSet[]> { |
| 121 | return Promise.all(stmt.map((s) => this.query(s))); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | export default class CloudflareWAEDriver extends PostgresLikeDriver { |
| 126 | getFlags(): DriverFlags { |
nothing calls this directly
no outgoing calls
no test coverage detected