(sql: string)
| 31 | } |
| 32 | |
| 33 | exec(sql: string) { |
| 34 | this.statements.push(sql) |
| 35 | const statement = sql.replace(/\s+/g, " ").trim() |
| 36 | if (transactionSql.test(statement)) { |
| 37 | throw new Error(`Unsupported transaction SQL: ${statement}`) |
| 38 | } |
| 39 | const create = /^CREATE TABLE (\w+)/i.exec(statement) |
| 40 | if (create !== null) { |
| 41 | this.tables.set(create[1], []) |
| 42 | return new FakeCursor([]) |
| 43 | } |
| 44 | const insert = /^INSERT INTO (\w+) \(name\) VALUES \('([^']*)'\)$/i.exec(statement) |
| 45 | if (insert !== null) { |
| 46 | const rows = this.tables.get(insert[1])! |
| 47 | rows.push({ id: rows.length + 1, name: insert[2] }) |
| 48 | return new FakeCursor([]) |
| 49 | } |
| 50 | const select = /^SELECT \* FROM (\w+)$/i.exec(statement) |
| 51 | if (select !== null) { |
| 52 | return new FakeCursor(this.tables.get(select[1]) ?? [], ["id", "name"]) |
| 53 | } |
| 54 | return new FakeCursor([]) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | class FakeDurableObjectStorage { |
no test coverage detected