paupino / pg_parse Goto Github PK
View Code? Open in Web Editor NEWPostgreSQL parser for Rust that uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parse tree.
License: MIT License
PostgreSQL parser for Rust that uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parse tree.
License: MIT License
There may be a way to reduce dependencies further as well as reduce layers of complexity, by extrapolating the pg source directly. This could perhaps leverage the ruby script that libpg_query already uses.
For example queries with lists of values like INSERT INTO contacts.person(name, ssn) VALUES ($1, $2)
, parse()
fails with an error of:
unknown variant `List`, expected one of <every variant of Node>
As far as I can tell, this is a consequence of treating every List
as an Option<Vec<Node>>
, which works most of the time, but not in this specific case of parsing lists of params in ResTarget
nodes.
I've included a hacky fix on my fork of pg_query.rs
that special-cases List
and creates a List
struct
with an items
field, similar to how List
is handled in the go
library, and creates a separate List
variant of Node
. This solves the issue for the test case above.
If this โ๏ธ approach is acceptable, let me know and I'll put together a PR. A downside to this approach is the split treatment of List
across the codebase: in most cases, it becomes an Option<Vec<Node>>
(see the other existing parsing tests), but not in the case of e.g. VALUES
lists. This doesn't bother me too much for my particular use-case, but would be surprising from someone used to the go
implementation's approach of using List
everywhere instead of Node[]
. A different implementation might be to use a separate List
type like the one I've hacked into the build script, but implement IntoIterator
and ExactSizedIterator
and friends to make working with List
exactly like working with Vec<Node>
for backwards-compatibility.
Thanks for creating this crate, and let me know how you'd like to proceed!
Implement version-sync to ensure versions in docs match published crate versions.
In theory this would probably need to be implemented directly in Rust through traits. It's worthwhile exploring the idea to see how difficult it'd be.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.