Comments (1)
I think this is specific to SQLite, because we use Database.all
to run the underlying query and that API only supports passing a single query.
Overall this is pretty inconsistent between databases though. I'm starting to think the best option would be to have an API in @databases/sql
that you can call to split multiple statements into an Array (i.e. SQLQuery[]
). We could then make a breaking change to @databases/pg
and possibly @databases/mysql
so that the interface becomes overloaded like:
interface Queryable {
/**
* Accepts an SQLQuery with a single statement, and errors if there are multiple statements in one query
*/
query(q: SQLQuery): Promise<any[]>
/**
* Accepts an array of SQLQueries with one statement each, and returns an array where each
* element represents the results of one statement.
*
* If you pass it an empty array it returns an empty array without any call to the database.
* If you pass it an array with only one statement, it returns an array of length 1 containing
* an array of the results to the statement.
*/
query(q: SQLQuery[]): Promise<any[][]>
}
We would then extend SQLQuery
with:
interface SQLQuery {
// Split this query into an array where each item in the array is one statement.
// If this query is an empty string, or only contains comments, a string of length 0 is returned.
split(): SQLQuery[]
// ...existing methods & properties...
}
The breaking change here is that currently we allow you to pass multiple statements in one go to query
in Postgres. If you do that, we run all statements, and return the results of the last statement.
Decisions / Questions
- Is it a good idea to require the caller of the API to be explicit about when a query has multiple statements? The problem with supporting this implicitly, is that it can be easy to have code that breaks when there is only one query or where there are 0 queries. We could keep the postgres behaviour for
query
(i.e. if there are multiple queries, just return the value from the last query). - What happens when a query fails? If this API is used outside of a transaction, we could implicitly create a transaction for just these queries, this might be the safest thing to do. SQLite's .exec function just runs them one at a time and stops at the first error, but this feels pretty dangerous.
from atdatabases.
Related Issues (20)
- [Inquiry]: Supported SQLite connection protocols HOT 1
- documentation on insert ID HOT 2
- Dynamically choosing a schema in Postgres queries HOT 1
- [pg-migrations] CockroachDB SQL version parsing HOT 1
- Postgres: pg-typed: support for arrays
- pg - optional id for `generated always as identity`
- pg: Cannot interpolate values into Postgres 14-style JSON queries
- Mysql: where in expression?
- Unable to compile typescript targeting ESNext with ES Module HOT 1
- Pg queryNodeStream ignoring batchSize and highWaterMark HOT 2
- [Postgres] Support bigIntMode for pg-schema-cli, pg-schema-print-types
- sqlite and multiple processes HOT 1
- split-sql-query breaks a trigger into multiple queries HOT 4
- Event Handlers: does not support promises HOT 2
- Request for Generic Type Support in 'Queryable.query' HOT 1
- Add support for `stream` parameter for PostgreSQL and MySQL HOT 1
- Dates and Timestamps retrieved from Postgres are offset incorrectly based on the local time zone
- Support for PostgreSQL partitioned tables
- removed cuid dependency as it's deprecated HOT 2
- Question: Capability of browser and esm HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atdatabases.