Skip to content

Commit 326c694

Browse files
Detect =LEN 6 TYPE INDEX ROWID CHANGES TOTAL_CHANGES FINALIZED:
Will provide metadata to statements that are the result of an insert, update or delete statement.
1 parent 853b31c commit 326c694

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/gateway/gateway.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,23 @@ async function queryAsync(connection: SQLiteCloudBunConnection, apiRequest: SqlA
257257
const rowset = result
258258
const data = apiRequest.row === 'dictionary' ? rowset : rowset.map(rowsetRow => rowsetRow.getData()) // rows as arrays by default
259259
return { data, metadata: rowset.metadata }
260+
} else {
261+
// detect that this array was sent in response to an insert, update or delete statement and will add special
262+
// metadata so it's easier for clients to extract useful information like the number of rows
263+
// affected by the statement. in the future, the server may produce a typed rowset instead
264+
if (Array.isArray(result) && result.length === 6) {
265+
const lowerSql = apiRequest.sql.toLocaleLowerCase()
266+
if (lowerSql.includes('insert ') || lowerSql.includes('update ') || lowerSql.includes('delete ')) {
267+
const metadata = {
268+
version: 1,
269+
numberOfRows: 1,
270+
numberOfColumns: 6,
271+
// https://github.com/sqlitecloud/sdk/blob/master/PROTOCOL.md#sqlite-statements
272+
columns: [{ name: 'TYPE' }, { name: 'INDEX' }, { name: 'ROWID' }, { name: 'CHANGES' }, { name: 'TOTAL_CHANGES' }, { name: 'FINALIZED' }]
273+
}
274+
return { data: [result], metadata }
275+
}
276+
}
260277
}
261278
}
262279
} catch (error) {

0 commit comments

Comments
 (0)