Skip to content
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

postgres: Feature request: Support creating SQL fragments using tagged literal #415

Open
jonasb opened this issue Oct 4, 2023 · 0 comments

Comments

@jonasb
Copy link

jonasb commented Oct 4, 2023

I've opened a PR (#395) to add another tagged literal, called fragment. When you create a fragment it can be used in a sql tagged literal.

Example usage:

const sharedValues = fragment`${123}, ${'admin'}`;
await sql`INSERT INTO users (id, credits, role) VALUES (1, ${sharedValues}), (2, ${sharedValues})`;
const column = isFoo ? fragment`foo` : fragment`bar`;
const filter = fragment`${column} = ${123}`;
return sql`SELECT ${column} FROM table WHERE ${filter}`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants