3 ms·
Show HN: Better-SQL - Generate sql query from syntax like GraphQL and EdgeDB
- aabbcc1241 4y agoInspired by the query language of EdgeDB and GraphQL, I created a npm package that can generate sql query from a more concise syntax. Some key features: * select with nested syntax and auto generate join-table statements * auto add table name to each column It comes with a "typescript-playground-style" online demo so you can try it without any setup ;)
- verdverm 4y agoWhy is this better? Is conciseness always preferred? Is it better or preferable to have a shared syntax that works across languages and tools? Most importantly, what are the consequences of creating a custom language that only works in a narrow situation?
- aabbcc1241 4y agoThis tool output plain SQL, so it can work with the rest of tools built around the ordinary SQL.
- verdverm 4y agoIf I use Go, how is this going to work? The main point is that developers don't want to learn a bespoke language tied to a single tool. SQL relates to the underlying math and is known by many many people, even non-developers.
- aabbcc1241 4y agoThere could be equivalent converter in go, or you can copy the generated sql from the playground to go source code. This this tool becomes dev-time only. One of the design goal for this language is to enable developers that are not familiar with sql to get into work that involves database with less effort. This tool is like syntax sugar on the select part, the where, order by, groups by, having are the same as standard sql (except they can be distributed with corresponding table select, and they can appear in any order, which should be easier to dev with)
- aabbcc1241 4y agoThis language is inspired from query language used in EdgeDB, which is a standalone database program. Instead this language is converted into plain SQL, so it can work with any existing SQL databases, including mysql, postgres, mssql, sqlite, e.t.c. The handy part of this language is it allows selecting columns from multiple tables using nested syntax without writing join table statements explicitly.
- gavinray 4y agoI like it! One problem you will run into is putting a LIMIT on relationship queries You can't use a limit for this select post [ id title # Can't generate simple LIMIT here user { nickname } limit 2 ] limit 5
- aabbcc1241 4y agoIt doesn't make sense to put two limit here, it's essential a single select query with join table. If you mean use sub-query. You may write something like below select post [ id title user { nickname } ] limit 5 where user_id in ( select user [ id ] order by created_at desc limit 2 ) Thanks for your interest, welcome more questions and ideas :)