| 1209 | } |
| 1210 | |
| 1211 | function normalizeRunResult(result: unknown): { changes: number; lastInsertRowid: number } { |
| 1212 | if (!result) return { changes: 0, lastInsertRowid: 0 }; |
| 1213 | |
| 1214 | if (typeof result === 'object' && !Array.isArray(result)) { |
| 1215 | const row = result as Record<string, unknown>; |
| 1216 | if ('changes' in row || 'lastInsertRowid' in row) { |
| 1217 | return { |
| 1218 | changes: Number(row.changes || 0), |
| 1219 | lastInsertRowid: Number(row.lastInsertRowid || 0), |
| 1220 | }; |
| 1221 | } |
| 1222 | if ('affectedRows' in row || 'insertId' in row) { |
| 1223 | return { |
| 1224 | changes: Number(row.affectedRows || 0), |
| 1225 | lastInsertRowid: Number(row.insertId || 0), |
| 1226 | }; |
| 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | if (Array.isArray(result) && result.length > 0) { |
| 1231 | const first = result[0] as Record<string, unknown>; |
| 1232 | if (first && typeof first === 'object') { |
| 1233 | if ('changes' in first || 'lastInsertRowid' in first) { |
| 1234 | return { |
| 1235 | changes: Number(first.changes || 0), |
| 1236 | lastInsertRowid: Number(first.lastInsertRowid || 0), |
| 1237 | }; |
| 1238 | } |
| 1239 | if ('affectedRows' in first || 'insertId' in first) { |
| 1240 | return { |
| 1241 | changes: Number(first.affectedRows || 0), |
| 1242 | lastInsertRowid: Number(first.insertId || 0), |
| 1243 | }; |
| 1244 | } |
| 1245 | if ('rowCount' in first) { |
| 1246 | return { |
| 1247 | changes: Number(first.rowCount || 0), |
| 1248 | lastInsertRowid: 0, |
| 1249 | }; |
| 1250 | } |
| 1251 | } |
| 1252 | } |
| 1253 | |
| 1254 | return { changes: 0, lastInsertRowid: 0 }; |
| 1255 | } |
| 1256 | |
| 1257 | const wrappedObjects = new WeakMap<object, unknown>(); |
| 1258 | |