-
Notifications
You must be signed in to change notification settings - Fork 663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling parser with backtick #1512
base: v5
Are you sure you want to change the base?
Conversation
Ahhhh - Javascript. The language that keeps surprising. Never seen the
notation before, but after a bit of googleling I realised that you want to use alasql as a tagFunction for a template string I like the idea, even if im not sure its smart that its meant to return a string. But... Currently alasql is sync, and one way you can make it async is by providing an array as the first parameter
I cant see how I can seperate the two situations (one using it as tagFunction and the other providing an array as parameter)- so for now I will reject the PR. If you have a good idea let me know and we can talk about how we do it. |
Actually, I just saw that tagFunctions are called with a But now I also understand that we will have to merge any merge fields (like Hmm. Still thinking about this - but reopening... |
d813fd3
to
be6cca0
Compare
Still thinking about how best to use this interesting feature. |
i think this would be a cool addition to alasql I'm just imagining being able to do things like: sql`SELECT * FROM ${table} ORDER BY ${fieldName} ${direction}`
sql`SELECT author FROM books WHERE name = ${book} AND author = ${author}` |
I really enjoy the convenience of this approach as well. However, we should be explicit about its usage. Consider this example: let orderBy = `ORDER BY x desc, y asc`
alasql`
SELECT author
FROM ${items}
WHERE
AND type = ${type}_v2
AND name = ${item}
${orderBy}
`
It seems we have a pattern where values surrounded by whitespace are to be converted into parameters. However, there are exceptions like
If we choose A, I propose we use a let orderBy = `ORDER BY x desc, y asc`
alasql`
SELECT author
FROM :${items}
WHERE
AND type = ${type}_v2
AND name = :${item}
${orderBy}
` Alternatively, if we opt for B, we could introduce a let orderBy = `ORDER BY x desc, y asc`
alasql`
SELECT author
FROM ${items}
WHERE
AND type = ${type}_v2
AND name = ${item}
~${orderBy}
` I have a preference for option B as it defaults to performance and things will break during development until people discuver why (although it might clash with the intuitive use of template strings). Thoughts? Suggestions? |
I made the logic for converting scenario B. Its currently only in a testfile. Im still not convinced that its smart to default to parameters. Also: wondering if we should throw if people seek to inline objects or arrays. Is there any use for this at all? |
No description provided.