3 ms·
I swear to god I'm going to write a SQL library some day that doesn't take strings as arguments. Although LINQ kinda already does what I'm thinking about, so ma
by hinkley 3y ago
I swear to god I'm going to write a SQL library some day that doesn't take strings as arguments. Although LINQ kinda already does what I'm thinking about, so maybe I just wait for someone to port it.
- intrasight 3y agoThe updated SqlQuery function of .NET 8 is pretty cool. It takes a string but safely interpolates the parameters. https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-8.0/whatsnew https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-cor... https://timdeschryver.dev/blog/you-can-now-return-unmapped-types-from-raw-sql-select-statements-with-entity-framework-8 https://timdeschryver.dev/blog/you-can-now-return-unmapped-t... "With the new SqlQuery method, you can now write your own SQL queries and map the result to any type that you want. This is useful for tasks that are not directly related to the day-to-day business of your application. For example, this can be used to import data, migrate data, or to retrieve data from a legacy system."
- throwaway2990 3y agoSooo it’s dapper with string interpolation override to make queries parameterized so you don’t need to manually put the parameters on as 2nd arguments?
- intrasight 3y agoIt's not just interpolation. The interpolation handler rewrites the query and makes it safe from SQL injection. There's an add-on to Dapper that does similar: https://github.com/mishael-o/Dapper.SimpleSqlBuilder https://github.com/mishael-o/Dapper.SimpleSqlBuilder
- useerup 3y ago> Sooo it’s dapper with string interpolation override to make queries parameterized so you don’t need to manually put the parameters on as 2nd arguments? Pretty much. C# does some really cool innovations around string interpolation which proves very useful for logging, SQL query etc. You can create your own string interpolation handler, which is what the new SQL query does and what several log libraries do. So basically you can use interpolation safely and remain assured that you do not introduce SQL injection errors. Also, this way string interpolation does not prevent query plan caching, as normal string interpolation would do.
- mkleczek 3y agoNot sure what language you are talking about. For Java there is an awesome https://www.jooq.org/doc/3.19/manual-single-page/ https://www.jooq.org/doc/3.19/manual-single-page/ Having said that: I stopped using it as writing plain SQL seems much more effective.
- jokab 3y agoIf you are fine with search and replace to refactor your code then ok.
- funcDropShadow 3y agoOr you could use an IDE that supports refactoring SQL, like Intellij IDEA.
- nhumrich 3y agoYou can do it in typescript/es6 using tagged template literals. I have done it before and it was awesome. Seriously wish more languages supported custom variable interpolation for it.
- missingdays 3y agoExposed exists
- codethief 3y agoPersonally, I really hope that https://github.com/PRQL/prql https://github.com/PRQL/prql will see some language support (similarly to JSX/TSX).
- JoelSanchez 3y agohttps://github.com/seancorfield/honeysql https://github.com/seancorfield/honeysql