Skip to content

Commit

Permalink
fixup! Return row counts for SQL ingestion (storage.sql.ingest()).
Browse files Browse the repository at this point in the history
  • Loading branch information
smerritt committed Apr 29, 2024
1 parent 9e1f75e commit f583865
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/workerd/api/sql-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async function test(storage) {
// Ingest any complete statements and snip those chars off the buffer
let result = sql.ingest(buffer);
buffer = result.remainder;
totalRowsWritten += result.meta.rowsWritten;
totalRowsWritten += result.rowsWritten;

// Simulate awaiting next chunk
await scheduler.wait(1)
Expand Down
9 changes: 2 additions & 7 deletions src/workerd/api/sql.c++
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,9 @@ SqlStorage::IngestResult::IngestResult(kj::String remainder, uint64_t rowsRead,

kj::StringPtr SqlStorage::IngestResult::getRemainder() { return remainder; }

jsg::Ref<SqlStorage::IngestResult::Meta> SqlStorage::IngestResult::getMeta() { return jsg::alloc<Meta>(rowsRead, rowsWritten); }
double SqlStorage::IngestResult::getRowsRead() { return rowsRead; }


SqlStorage::IngestResult::Meta::Meta(uint64_t rowsRead, uint64_t rowsWritten) : rowsRead(rowsRead), rowsWritten(rowsWritten) {}

double SqlStorage::IngestResult::Meta::getRowsRead() { return rowsRead; }

double SqlStorage::IngestResult::Meta::getRowsWritten() { return rowsWritten; }
double SqlStorage::IngestResult::getRowsWritten() { return rowsWritten; }


} // namespace workerd::api
25 changes: 4 additions & 21 deletions src/workerd/api/sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,48 +254,31 @@ class SqlStorage::Statement final: public jsg::Object {

class SqlStorage::IngestResult final : public jsg::Object {
public:
class Meta;

IngestResult(kj::String remainder, uint64_t rowsRead, uint64_t rowsWritten);

JSG_RESOURCE_TYPE(IngestResult) {
JSG_READONLY_PROTOTYPE_PROPERTY(meta, getMeta);
JSG_READONLY_PROTOTYPE_PROPERTY(remainder, getRemainder);
JSG_NESTED_TYPE(Meta);
}

jsg::Ref<Meta> getMeta();
kj::StringPtr getRemainder();

private:
kj::String remainder;
uint64_t rowsRead;
uint64_t rowsWritten;
};

class SqlStorage::IngestResult::Meta final : public jsg::Object {
public:
Meta(uint64_t rowsRead, uint64_t rowsWritten);

JSG_RESOURCE_TYPE(Meta) {
JSG_READONLY_PROTOTYPE_PROPERTY(rowsRead, getRowsRead);
JSG_READONLY_PROTOTYPE_PROPERTY(rowsWritten, getRowsWritten);
JSG_READONLY_PROTOTYPE_PROPERTY(remainder, getRemainder);
}

kj::StringPtr getRemainder();
double getRowsRead();
double getRowsWritten();

private:
kj::String remainder;
uint64_t rowsRead;
uint64_t rowsWritten;
};


#define EW_SQL_ISOLATE_TYPES \
api::SqlStorage, \
api::SqlStorage::Statement, \
api::SqlStorage::Cursor, \
api::SqlStorage::IngestResult, \
api::SqlStorage::IngestResult::Meta, \
api::SqlStorage::Cursor::RowIterator, \
api::SqlStorage::Cursor::RowIterator::Next, \
api::SqlStorage::Cursor::RawIterator, \
Expand Down

0 comments on commit f583865

Please sign in to comment.