Giter Site home page Giter Site logo

mintonmu / pg_parse Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paupino/pg_parse

0.0 0.0 0.0 205 KB

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

Rust 98.06% PLpgSQL 1.94%

pg_parse's Introduction

pg_parse โ€ƒ Build Status Latest Version Docs Badge

PostgreSQL parser for Rust that uses the actual PostgreSQL server source to parse SQL queries and return the internal PostgreSQL parse tree.

Getting started

Add the following to your Cargo.toml

[dependencies]
pg_parse = "0.8"

Example: Parsing a query

use pg_parse::ast::Node;

let result = pg_parse::parse("SELECT * FROM contacts");
assert!(result.is_ok());
let result = result.unwrap();
assert!(matches!(*&result[0], Node::SelectStmt(_)));

// We can also convert back to a string
assert_eq!(result[0].to_string(), "SELECT * FROM contacts");

What's the difference between pg_parse and pg_query.rs?

The pganalyze organization will maintain the official implementation called pg_query.rs. This closely resembles the name of the C library also published by the team (libpg_query). This implementation will use the protobuf interface introduced with version 13 of libpg_query.

This library similarly consumes libpg_query however utilizes the older JSON interface to manage parsing. The intention of this library is to maintain a dependency "light" implementation with serde being the only required runtime dependency. While this was originally called pg_query.rs it makes sense to decouple itself from the official naming convention and go on it's own. Hence pg_parse.

So which one should you use? You probably want to use the official pg_query.rs library as that will continue to be kept closely up to date with libpg_query updates. This library will continue to be maintained however may not be as up to date as the official implementation.

Credits

A huge thank you to Lukas Fittl for all of his amazing work creating libpg_query.

pg_parse's People

Contributors

paupino avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.