adelsz / pgtyped

pgTyped - Typesafe SQL in TypeScript
https://pgtyped.dev
MIT License
2.91k stars 94 forks source link

feature request: add ability to use globally replace strings #560

Open otan opened 8 months ago

otan commented 8 months ago

Apologies if this is already implemented, can't seem to find it.

Is your feature request related to a problem? Please describe. Let's say I have a users table with fields name, email, dob.

I want to avoid using SELECT * for whatever reason, but in general I always want to select the name, email, dob column. This generally results in multiple "repeated" params, like so:

/* @name getUser */
SELECT name, email, dob FROM users WHERE name = 'xxx';

/* @name listUsers */
SELECT name, email, dob FROM users;

/* @name upsertUsers */
INSERT INTO users (...) VALUES (...) ON CONFLICT DO NOTHING RETURNING name, email, dob;

I'd prefer if I only had to define that once

Describe the solution you'd like I'd like to able to define some sort of "global param", e.g.

/* @global user name, email, dob */

/* @name getUser */
SELECT @global:user FROM users WHERE name = 'xxx';

/* @name listUsers */
SELECT @global:user FROM users;

/* @name upsertUsers */
INSERT INTO users (...) VALUES (...) ON CONFLICT DO NOTHING RETURNING @global:user;

To avoid having to repeat this.