-
Notifications
You must be signed in to change notification settings - Fork 47
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
SQL library code #18
Comments
I don’t have any concerns and I don’t care about attribution. It brought me joy to randomly stumble upon some code I wrote a while ago in a new context 😀 Using template strings to prevent SQL injection while also providing a good DX is a great idea and I’m happy to see you using it! If you popularize the idea, I’ll be super excited. I hope my comment didn’t sound salty, my intention was to raise my hand and give you a high five. |
While we’re here, though, since I use
I also only care about Postgres which is a different goal then what you have. |
✋ high five to you too 😄 Glad to hear you're also happy, I was just slightly concerned you might have been pissed about me just copy-pasting bits of your code. People differ on what they're happy with in that area. The babel plugin for minification is interesting, and definitely not on my radar. I'm definitely interested in what we can do to improve error messages/improve the debugging experience. Most of atdatabases/packages/pg/src/index.ts Lines 77 to 108 in e30c559
I've been thinking a lot about trying to generate types from SQL queries. pg-schema contains some of the initial work I've done on making it easy to introspect the postgres schema. The challenges with generating the types from queries are:
My current thinking is to generate types for each table, and help people use things like |
For Postgres introspection in https://yarn.pm/postgraphile here’s the ~250 line query I wrote for introspection: Along with a companion class for easily accessing the catalog in JS: (I’m linking to v3 since that’s when I stopped maintaining PostGraphile, cc @benjie who’s been doing an incredible job ever since! 😀) I started writing a typed query builder for Postgres with the built-in ability to add privacy constraints https://gist.github.com/calebmer/99127fee6eb645587d8efee69f0b09db I ended up ditching that for a I think you’re right that building a properly typed Diesel for Rust is really my inspiration for this. The dream is that a sufficiently powerful compiler can remove the abstraction levels of a query builder and leave you with an artifact that’s really close to SQL. Rust is probably a lot closer in that respect. |
I'm not anywhere near as much of a type ninja as @calebmer; but feel free to ask me any questions I might be able to help with. I've been considering building a query builder on top of |
I think I'll go down the path of being able to generate types for some growing subset of sql statements. I think falling back to un-typed SQL from typed SQL is friendlier than falling back to un-typed SQL from our own DSL style API. I think a library that understood/validated/added types for basic |
I've got a primitive SQL parser just about working: #20 Next steps:
|
Hi @calebmer - I can't keep track of a discussion in a large commit, so if you want to discuss it, let's talk here.
Regarding the source of the code, the initial version is loosely based on the pg-sql implementation. I'd be happy to provide some sort of attribution if you'd like? I put this implementation into this code base for a few reasons though:
$1
style placeholder syntax)sql.raw
had a value that was more obviously dangerous.Regarding the symbols in pg-sql2, this library uses
instanceof
, which is equivalently secure - you can't create an instance ofSQLQuery
viaJSON.parse
.Let me know if you have any other concerns/if you want specific attribution.
The text was updated successfully, but these errors were encountered: