4 ms·
From foo where bar yield baz; is always how I think about SQL and wish I could write it
by nattaylor 7y ago
From foo where bar yield baz; is always how I think about SQL and wish I could write it
- mhd 7y agoI'm still surprised that there's no common ratfor/coffeescript/SCSS for SQL.
- losvedir 7y agoI've thought about that before, too. One of the issues with a light syntax helper atop SQL is that SQL is often used as snippets in other languages or with SQL tools, etc. It seems hard to shim a layer in there. However, I think what would make a ton of sense is a coffeescript-esque PL/pgSQL, complete with runtime. Basically an easier to use psql shell (or equivalent for another DB). Postgres is incredibly powerful, and I feel like could be a much more useful interactive tool for loading up CSVs, doing some querying, modifying, etc, with a little friendlier or more programmer-familiar environment.
- mhd 7y agoIt would get complicated in code if you're constructing your statement from bits and pieces, as the preprocessor would have no way of forming a complete syntax tree out of it, of course. I'm picturing something closer to "emmet"[1], where you write some shorthand and this gets expanded to proper SQL in line. So our imaginary sql-script would never see the light of git, most of the time you'd use it through an IDE plugin or vim's "!" filter (although you could have it available as a function at runtime and actually save the simplified code). Actual database access at this stage would be good, I wouldn't mind e.g. globbing column names or excluding some ("sel *-[{created,updated}_at]")... But you're right, for something like psql this would make good sense, too. And after you've played arond with it, you can paste the proper SQL wherever you needed it, too. [1]: https://docs.emmet.io/ https://docs.emmet.io/
- fiddlerwoaroof 7y agoThere are s-expression syntaxes in various lisps. True hard problem is designing an alternate syntax that still gives you access to all the features of your database.