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

fix(sql) fix fragments containing fragments + concat syntax for parameters #17273

Merged
merged 7 commits into from
Feb 12, 2025

Conversation

cirospaciari
Copy link
Member

What does this PR do?

Fix: #17215

The following query should work:

await sql`CREATE TABLE IF NOT EXISTS alerts (id int, hotel_id int, created_at timestamp)`;
await sql`INSERT INTO alerts VALUES (1, 1, '2024-01-01 10:00:00')`;
await sql`INSERT INTO alerts VALUES (2, 1, '2024-01-02 10:00:00')`;
await sql`INSERT INTO alerts VALUES (3, 2, '2024-01-03 10:00:00')`;

// fragment containing another scape fragment for the field name
const orderBy = (field_name: string) => sql`ORDER BY ${sql(field_name)} DESC`;

// dynamic information
const sortBy = { should_sort: true, field: "created_at" };
const user = { hotel_id: 1 };

// query containing the fragments
const results = await sql`
SELECT alerts.*
FROM alerts
WHERE alerts.hotel_id = ${user.hotel_id} 
${sortBy.should_sort ? orderBy(sortBy.field) : sql``}`;
console.log(results);
  • Documentation or TypeScript types (it's okay to leave the rest blank in this case)
  • Code changes

How did you verify your code works?

@robobun
Copy link

robobun commented Feb 12, 2025

Updated 7:41 PM PT - Feb 11th, 2025

@cirospaciari, your commit 1a89431 has 5 failures in Build #11481:


🧪   try this PR locally:

bunx bun-pr 17273

@cirospaciari cirospaciari marked this pull request as ready for review February 12, 2025 02:39
@Jarred-Sumner Jarred-Sumner merged commit 1bb1f59 into main Feb 12, 2025
54 of 69 checks passed
@Jarred-Sumner Jarred-Sumner deleted the ciro/fix-fragments branch February 12, 2025 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

injecting postgresQueryBuilder interperted as values this is critical
3 participants