3 ms·
Just to add a thought: really what I would like to have is a language that has native support for SQL. (I mean, I also want a better alternative to SQL, but the
by dgellow 6y ago
Just to add a thought: really what I would like to have is a language that has native support for SQL. (I mean, I also want a better alternative to SQL, but the post author is right that it is the standard we currently have and it will not disappear or be replaced soon)
That sounds absurd, but my dream would be to write Go (just my personal favorite), then whenever I want to interact with the DB I can directly write actual SQL, not as a string, but as an actual valid expression. I have zero idea how that would work in practice but that’s the dev experience I would love to have. SQL as a DSL, written in my go file, without the need to change context, with syntax highlighting, type check, linting, etc.
Instead of having SQL as a second-class language it could be first class and that would be fantastic.
Not that something like this will ever happen, I’m well aware that standard SQL isn’t an actual thing in the real world and all the other issues around that idea, but I would LOVE this!
- et1337 6y agoLINQ from .NET was pretty close to this. You could write a variant of SQL directly inline with your C#. I think technically there was also an ORM layer (Entity Framework) but for the most part it was just a query builder.
- teh_klev 6y agoLINQ is still very much alive and well. I think you're thinking of LINQ to SQL which was an ORM in its own right. Then along came entity framework which also supports LINQ querying syntax (or you can use expressions).
- davidspiess 6y agoSQLC could be a good fit. It generates type-safe Go code from SQL. https://github.com/kyleconroy/sqlc https://github.com/kyleconroy/sqlc
- dgellow 6y agoWow, that's interesting. Thanks for sharing, I will look into it!
- Hir0ki 6y agoTheir is actually a programing language that has this feature. It's called ABAP[1] and it has build in SQL Support with OpenSQL[2]. OpenSQL is just a SQL dialect which is translated to the equivalent SQL needed for the DB specific underlying DB. Sadly ABAP is a proprietary programming language only available on the SAP Netweaver stack. [1] https://en.wikipedia.org/wiki/ABAP https://en.wikipedia.org/wiki/ABAP [2] https://help.sap.com/viewer/fe24b0146c551014891ad42d6b2789e5/7.02.22/en-US/fceb3969358411d1829f0000e829fbfe.html https://help.sap.com/viewer/fe24b0146c551014891ad42d6b2789e5...
- dgellow 6y agoThanks, I never heard of this. That looks like a weird mix between COBOL and SQL?!
- BiteCode_dev 6y agoThis is why good ORM like SQLAlchemy actually are split in 2 parts: the declarative layer, and the core layer. The declarative layer gives you the handy ORM syntax for simple operations. The core layer is lower level, and allows to composes all possible SQL operations you can dream, but from the comfort of your programming language, including typing, completion, and so on. Does something like that exist for Go ? I don't know the golang ecosystem very well.
- dgellow 6y agoMy dream is to write actual SQL in the middle of my code, as a valid syntax and first-class construct. As I said, that's not really a realistic goal. Do you have some examples of SQLAlchemy core layer you're talking about, just to have an idea of what you have in mind?
- squaresmile 6y agoI couldn't find exactly an only Core example that you are looking for in the examples folder [0] so here is a more complicated tutorial query [1] and here's how I use Core in my project [2] (mostly short select statements so not really a comprehensive demonstration of SQLAlchemy Core's capabilities). [0] https://github.com/sqlalchemy/sqlalchemy/tree/master/examples https://github.com/sqlalchemy/sqlalchemy/tree/master/example... [1] https://docs.sqlalchemy.org/en/14/core/tutorial.html#common-table-expressions-cte https://docs.sqlalchemy.org/en/14/core/tutorial.html#common-... [2] https://github.com/atlasacademy/fgo-game-data-api/tree/master/app/db/helpers https://github.com/atlasacademy/fgo-game-data-api/tree/maste...
- dgellow 6y agoThank you :)
- lelanthran 6y ago> My dream is to write actual SQL in the middle of my code, as a valid syntax and first-class construct. As I said, that's not really a realistic goal. Sure, it is. See how regexes in some languages are first class datatypes, so you can have a regex literal in your code (with backreferences too, I believe). There is no good reason that SQL statements can't also be a datatype, with SQL literals in the code like the way regexes do. I'm imagining something like this: sql_t stmt = /SELECT #1, #2 FROM #3, #4 WHERE #3.#1 = #4.#2/; sql_res_t res_cursor = sql_exec (stmt, t1_col1, t2_col2, T1, T2); The stmt above is not a string, hence is part of the AST and can be checked at compile time. The execution might be a problem (returned columns have to be checked too).
- thewakalix 6y agoUr/Web has something like this (example: http://www.impredicative.com/ur/demo/sql.ur.html http://www.impredicative.com/ur/demo/sql.ur.html).