oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.36k stars 2.78k forks source link

`Bun.sql` tracking issue (Postgres client) #15088

Open Jarred-Sumner opened 1 week ago

Jarred-Sumner commented 1 week ago

Bun.sql is Bun's builtin postgres client, currently only available on canary builds of Bun.

import { sql } from 'bun';

const [{x}] = await sql`select 1 as x`;
console.log({x});

sqlite and other database protocols will be added sometime after it ships.

Minimum necessary to unflag for Bun v1.2:

Feature complete:

Nice to have:

aquapi commented 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 });
truongan07 commented 1 week ago

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.

versecafe commented 1 week ago

What's the reason for a import { sql } from ... instead of matching the SQLite setup and just swapping it to bun:postgres

rafaell-lycan commented 1 week ago

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.