(sql: string)
| 111 | } |
| 112 | |
| 113 | function createStatement(sql: string) { |
| 114 | const normalized = sql.replace(/\s+/g, ' ').trim() |
| 115 | return { |
| 116 | get: (...params: unknown[]) => getFakeStatementRow(normalized, params), |
| 117 | all: (...params: unknown[]) => { |
| 118 | if (normalized.startsWith('PRAGMA table_info')) return [] |
| 119 | if (normalized.includes('SELECT cwd FROM projects')) return [] |
| 120 | if (normalized.includes('FROM artifact_versions WHERE artifact_id = ?')) { |
| 121 | return fakeState.versions |
| 122 | .filter((row) => row.artifactId === params[0]) |
| 123 | .sort((a, b) => b.version - a.version) |
| 124 | .map(mapVersion) |
| 125 | } |
| 126 | if (normalized.includes('FROM artifacts WHERE conversation_id = ?')) { |
| 127 | return [...fakeState.artifacts.values()] |
| 128 | .filter((row) => row.conversationId === params[0]) |
| 129 | .map(mapArtifact) |
| 130 | } |
| 131 | if (normalized.includes('FROM artifacts ORDER BY')) { |
| 132 | return [...fakeState.artifacts.values()].map(mapArtifact) |
| 133 | } |
| 134 | return [] |
| 135 | }, |
| 136 | run: (...params: unknown[]) => { |
| 137 | if (normalized.startsWith('INSERT INTO artifacts')) { |
| 138 | insertFakeArtifact(params) |
| 139 | } |
| 140 | if (normalized.startsWith('INSERT INTO artifact_versions')) { |
| 141 | insertFakeArtifactVersion(params) |
| 142 | } |
| 143 | if (normalized.startsWith('UPDATE artifacts SET content = ?')) { |
| 144 | updateFakeArtifact(params) |
| 145 | } |
| 146 | if (normalized.startsWith('DELETE FROM artifacts WHERE conversation_id = ?')) { |
| 147 | deleteFakeArtifactsForConversation(params[0]) |
| 148 | } |
| 149 | return { changes: 1 } |
| 150 | }, |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | vi.mock('better-sqlite3', () => ({ |
| 155 | default: class FakeDatabase { |
no test coverage detected