Earlier quoted context omitted.
> If developers aren't reading the docs to learn about prepared statements, why would they do so for some DSL developed using tag strings? Because you've deprecated the "bare string" interface so they can't use that anymore, or it's hidden deep into the utility modules.
But you could do that already, could you not? Django does. Its just not really SQL anymore then. Someone else also pointed out that you could just do this with functions. It seems like a very fancy way of avoiding using (). I don't know, maybe show me how that would solve the issue of unsafe SQL and I'd be more easily convinced.
This already exists in the Javascript ecosystem:
sql`select * from users where id = ${id}`
Turns into: { query: 'select * from users where id = $1', values: [id] }
So if you tried an injection like this: sql`select * from users ${'where id = 3'}`
It turns into an invalid statement since "where id = 3" cannot exist as a parameterized value for the same reason this doesn't work: { query: 'select * from users $1', values: ['where id = 3'] }
Where you go from here is to offer a query(statement) function that requires the use of the tag string so that you can't accidentally pass in a normal string-interpolated string.Examples:
- slonik: https://github.com/gajus/slonik?tab=readme-ov-file#protectin...
- postgres.js: https://github.com/porsager/postgres?tab=readme-ov-file#quer...