Skip to content
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

feat(sqlite) add support sqlc functions #2274

Merged
merged 7 commits into from
Jun 6, 2023

Conversation

hakobera
Copy link
Contributor

@hakobera hakobera commented May 8, 2023

This pull request add support sqlc functions below to SQLite.

  • sqlc.arg() & @<variable> notation
  • sqlc.narg()
  • sqlc.embed()
  • sqlc.slice()

I know we already have similar PR #2157 by @aloisbarreras and #2259 by @orisano .
Both are introducing new syntax like sqlc_arg() as alternative of sqlc.arg() because of current SQLite parser's limitation.
It works but I prefer to use same syntax for all supported engines to keep consistency, so I modified SQLite parser to accept sqlc. schema notation.

Fixes #1881 #1962.

@hakobera hakobera force-pushed the feat-sqlite-sqlc-functions branch from fdd53b6 to 05a9379 Compare May 8, 2023 15:16
@hakobera hakobera force-pushed the feat-sqlite-sqlc-functions branch from 05a9379 to 44c3ec7 Compare May 8, 2023 15:18
@@ -325,6 +354,10 @@ func (c *cc) convertMultiSelect_stmtContext(n *parser.Select_stmtContext) ast.No
}
}

func (c *cc) convertExprListContext(n *parser.Expr_listContext) ast.Node {
return c.convertExprLists(n.AllExpr())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are returning a nested "ast.List" here, but an un-nested "ast.List" would be correct.

Suggested change
return c.convertExprLists(n.AllExpr())
return c.convertExprLists(n.AllExpr()).Items[0]

Copy link
Contributor Author

@hakobera hakobera May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orisano Thank you for pointing out. I checked SQLite SQL syntax and confirmed parser.Expr_listContext should return ast.List. I thought I can reuse c.convertExprLists() but it's specialized for values for selectStatement.

https://www.sqlite.org/syntax/expr.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 2adb18f

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hakobera thanks!

@kyleconroy
Copy link
Collaborator

10/10, no notes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sqlc.narg does not work for sqlite3
3 participants