prql
prql copied to clipboard
prql-js syntax suggestion/sugar
It sounds very exciting that you are revamping the outdated SQL language with a pipeline-based approach. Perhaps at the beginning of the project, there is still an opportunity to incorporate modern syntax into the language. I have two suggestions:
First is the
const sql = compile(`from employees | select first_name`);
instead of the
const sql = prql`from employees | select first_name`;
use, which immediately shows what it is about.
The second is that expressions can be formatted much better with line breaks:
const sql = prql`
from employees
select first_name
`;
Thanks for the issue @BCsabaEngine .
First is the
const sql = compile(`from employees | select first_name`);instead of theconst sql = prql`from employees | select first_name`;use, which immediately shows what it is about.
My JS is very weak, so I'll let others respond. Generally I would have defaulted to prql.compile, rather than just prql, so we mirror the function names across language bindings as much as possible.
The second is that expressions can be formatted much better with line breaks:
const sql = prql` from employees select first_name `;
For sure, we'd gladly take a PR showing the multiline query; it's shown in the readme in a single line for brevity; I can see why that's less clarifying for those who are new to PRQL.
The first is easy to implement in the project, when used with template literal: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
For 2nd, I will commit a PR.
Thx!
Super, thanks!
CC @aljazerzen on the names for the public API
Well, it's a convention to use verbs for function names, because functions do things. I think compile is a good description of what it's doing.
If I'm correct, we can implement this template function as a simple wrapper function to compile. It can be named prql as suggested, because it does resemble a language annotation.
import { prql, compile } from 'prql-js';
const sql = prql`
from employees
select first_name
`;
https://github.com/PRQL/prql/pull/1432