Open Jarred-Sumner opened 1 week ago
Can this be an import from bun:postgres
to be more clear?
import { sql } from 'bun:postgres';
const [{ x }] = await sql`select 1 as x`;
console.log({ x });
Use .iterate() to run a query and incrementally return results. This is useful for large result sets that you want to process one row at a time without loading all the results into memory.
Support this method in Postgres client, please.
What's the reason for a import { sql } from ...
instead of matching the SQLite setup and just swapping it to bun:postgres
I'd like to see some features such as flexible prepared statements and Pool as both exist on libs such as Postgres.js and Node-PG.
This is personal but the prepared statements on pg
lib feel quite easy to use, but no hard feelings or anything really:
sql(
'INSERT INTO photos(user_id, photo_url) VALUES ($1, $2)',
['1', 'example.com']
)
/**
* Alternatively you could also accept an object as a param
* which could have more metadata to improve tracing later on:
*/
sql({
name: 'add-photo',
text: 'INSERT INTO photos(user_id, photo_url) VALUES ($1, $2)',
values: ['1', 'example.com'],
})
It can be a future enhancement tho.
Bun.sql
is Bun's builtin postgres client, currently only available on canary builds of Bun.sqlite and other database protocols will be added sometime after it ships.
Minimum necessary to unflag for Bun v1.2:
sql(array)
inINSERT INTO
queriessslmode=require
Feature complete:
COPY
protocolPoint
& other geo-related typesNice to have:
--sql-preconnect
CLI flag to start connecting to DB before code loadssql.begin(callback)
API for transactionssql.array(array)
for various operations involving arrays