You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Return row counts for SQL ingestion (storage.sql.ingest()).
D1 bills based on rows read and written, but sql.ingest() didn't
return those. Now it does.
This required changing the return type of sql.ingest(), but it's an
experimental API so that should be okay.
let sqlCode = "INSERT INTO tbl (col) VALUES (123); INSERT I";
let result = sql.ingest(sqlCode);
Old:
result == " INSERT I"
New:
result.remainder == " INSERT I"
result.meta.rowsRead == 0
result.meta.rowsWritten == 1
This "meta" attribute also gives us a convenient spot to stick
additional information. For example, if we wanted to count how many
SQL statements ingest() executed, we could easily add
"result.meta.statementsExecuted" without breaking any existing users.
Implementation-wise, there might be an optimization opportunity around
SqlStorage::IngestResult::getMeta(). Right now, it allocates a new
Meta every time it's called, so if you do the obvious thing like so:
totalRead += result.meta.rowsRead
totalWritten += result.meta.rowsWritten
totalRedFish += result.meta.redFish // and so on
then that might end up allocating and discarding multiple Meta
objects, and some caching could fix that. On the other hand, I'm not
very familiar[1] with JSG internals, so maybe that's already happening
somehow. I have no idea.
[1] This is a terrible understatement.
0 commit comments