Skip to content

[sqlite] Implement streaming queries #11243

@douglascayers

Description

@douglascayers

Feature Description

For SQLite, I'd like to stream back rows from a query rather than retrieve all of them at once. This feature is implemented for other databases, and I've used it successfully with Postgres.

Currently, if you try to stream a query with SQLite, TypeORM throws the error Stream is not supported by sqlite driver.

https://github.com/typeorm/typeorm/blob/master/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts#L170-L177

I reviewed the git history of the AbstractSqliteQueryRunner.ts file, and it seems that this method was stubbed out ~8 years ago and possibly never revisted. I searched the issues to see if this had been addressed before, but I did not find any related issues or PRs.

The Solution

From what I can tell from the other *QueryRunner.ts files, I believe we need to use SQLite's Statement#get method to retrieve one row at a time, and stream them back via a Readable implementation.

For inspiration, I found https://gist.github.com/rmela/a3bed669ad6194fb2d9670789541b0c7 which provides an example of wrapping SQLite's Statement#get method in a Readable. Locally, I've reproduced a proof of concept and feel (naively?) confident moving forward to try and implement it in TypeORM.

Considered Alternatives

The only alternative I'm aware of is to perform a regular query, but that would return all the rows at once into memory, which is what I want to avoid.

Additional Context

No response

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, and I know how to start.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions