-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add batch query interface #38
Conversation
Signed-off-by: Alex Chi <iskyzh@gmail.com>
I think we also need to support something like: const { txn, stmt, sql } = neon(env.NEON_DB_URL);
await txn([
stmt`SELECT ${1}::int AS int`,
"SELECT 1"
], /* ...options */) ...? |
wonder if it is possible to introduce only one new thing instead of two, e.g. make it possible to write: const { txn, sql } = neon(env.NEON_DB_URL);
await txn([
sql`SELECT ${1}::int AS int`,
sql`SELECT ${"hello"} AS str`
], /* ...options */) Right away I don't have any good idea how to implement that except accessing some global state to detect txn context (which would be a mess to recover from errors). |
Of course this is possible by attaching a property to the function object and then extract it. But I feel it would be too tricky for users to understand what's happening...? |
the way to do that, |
Agree with Stas that it would be good to be able to use the same Also: we need a way to specify the transaction isolation level. |
For me less imports is less burden to understand what each thing does. And
ah, right. forgot that it is async function
good point. Also there is |
I just realized that JavaScript promise is different from Rust futures. That is to say, once the promise object is created, the runtime will execute it in the background. Therefore, attaching properties to the promise does not look like a good idea... It seems that we can create a deferred promise as in https://masteringjs.io/tutorials/fundamentals/promise-create#:~:text=JavaScript%20promises%20are%20%22hot%22%20in,a%20new%20promise%20every%20time. but this will cause problems for error reporting. |
I took a stab at this in #39 The api looks like: const sql = neon(...);
const results = await sql.transaction([
sql`SELECT ${1}::int AS int`,
sql`SELECT ${"hello"} AS str`
], /* options */); Which (I think) achieves all the goals stated above. It's not a breaking change because the single queries worked as before! |
We will retrieve `neon-batch-isolation-level` and `neon-batch-read-only` from the http header, which sets the txn properties. neondatabase/serverless#38 (comment) --------- Signed-off-by: Alex Chi Z <chi@neon.tech>
This is a very early draft of non-interactive txn batch query interface and might need some refactor before merging.
neondatabase/neon#4703
TL;DR, we added a new interface:
meanwhile, we are also compatible with the original way of handling a query:
several challenges of the current architecture:
any
a lot.