prql icon indicating copy to clipboard operation
prql copied to clipboard

prql-js syntax suggestion/sugar

Open BCsabaEngine opened this issue 2 years ago • 1 comments

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
`;

BCsabaEngine avatar Dec 30 '22 16:12 BCsabaEngine

Thanks for the issue @BCsabaEngine .

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.

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.

max-sixty avatar Dec 30 '22 22:12 max-sixty

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!

BCsabaEngine avatar Jan 01 '23 20:01 BCsabaEngine

Super, thanks!

CC @aljazerzen on the names for the public API

max-sixty avatar Jan 01 '23 20:01 max-sixty

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
`;

aljazerzen avatar Jan 01 '23 21:01 aljazerzen

https://github.com/PRQL/prql/pull/1432

BCsabaEngine avatar Jan 04 '23 12:01 BCsabaEngine