postguard
postguard copied to clipboard
Questions? Feedback?
Add your feedback as a comment to this issue π
Just wanted to say that this looks awesome. Not sure we will use it given its early stage though.
Hi, this project looks amazing. Is it possible to use this for validating plain SQL and not postgres sql?
Is it possible to use this for validating plain SQL and not postgres sql?
Since Postgres' SQL dialect is just a superset of "vanilla" SQL, there should be no problem validating that π
I guess the only risk would be to use something too fancy that postgres/postguard understand and accept, but your non-postgres database (sqlite for instance) does not.
This looks super cool. The thing that would make it perfect, from my point of view, would be if you could point it at an actual postgres schema definition (i.e. a directory containing .sql files) as the source of truth for the database, rather than defining it with defineTable. How much of a leap would that be?
@gregplaysguitar Yeah, that would be great! Shouldn't be too hard either, now as I think about itβ¦
Just not sure if I will have time to work on it anytime soon. I've been sick for the last week and a half and stuff is already piling up π
@andywer do you have any pointers as to where to start with that? I'd love to help out, although I don't have much free time either...
@gregplaysguitar You can have a look at:
parseTableDefinition()insrc/babel/parse-table-definition.ts: It takes a piece of source code parsed by Babel and returns aTableSchemasrc/postgres/parse-pg-query.ts: Here you can see how SQL queries are parsed usingpg-query-parser(not super intuitive)
I think the best way to get started with the pg-query-parser package is to write a tiny test script that parses a simple SQL query and prints the parsed AST. Then play around with the input query a little bit and check out the resulting output.
Great, thanks! Iβve been wanting to dig into pg query parsing for another project too so keen to have a look at this. Iβll let you know how I go!
Can it validate queries at runtime? @andywer
No, it's build-time-only π @LifeIsStrange
that's unfortunate :) I have a use case where users write SQL queries on a web frontend and it would be nice to check the syntax validity on the client instead of doing roundtrips to the server. The only solution I've found is https://github.com/paxdei/GWTJSqlParser but it is a bit obscure haha