Skip to content
Commit Detail

Commit 479edba

Author
Samuel Merritt <smerritt@cloudflare.com> 2024-04-25 15:07:38 -0700
Parents
cdb18b7
Tree
c04c016
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.rowsRead == 0
  result.rowsWritten == 1

This 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.statementsExecuted" without breaking any existing users.

[1] This is a terrible understatement.

Files changed

5 files changed~5 modified