()
| 65 | } |
| 66 | |
| 67 | execute(): { success: true; results: Row[]; meta: { changes: number; duration: number } } { |
| 68 | this.d1.onStatement?.(this.sql); |
| 69 | const stmt = this.d1.db.prepare(this.sql); |
| 70 | const params = this.params.map(bindable) as never[]; |
| 71 | if (/^\s*(SELECT|WITH)\b/i.test(this.sql)) { |
| 72 | return { success: true, results: stmt.all(...params) as Row[], meta: { changes: 0, duration: this.d1.statementMs } }; |
| 73 | } |
| 74 | const info = stmt.run(...params); |
| 75 | return { success: true, results: [], meta: { changes: Number(info.changes), duration: this.d1.statementMs } }; |
| 76 | } |
| 77 | |
| 78 | async first<T>(): Promise<T | null> { |
| 79 | return (this.execute().results[0] as T | undefined) ?? null; |
no test coverage detected