Giter Club home page Giter Club logo

postgresqlparser's Introduction

PostgreSQLParser Build Status

A parser for PostgreSQL written in Pharo using PetitParser.

For now, the focus is made on PL/pgSQL source code.

Install

Metacello new
	baseline: 'PostgreSQLParser';
	repository: 'github://juliendelplanque/PostgreSQLParser/src';
	load

Groups

You can use the groups defined in the baseline to install only what you need. The following groups are available:

  • parser : Only the tokenizer and the grammar.
  • parser-tests : parser and its unit tests.
  • ast : Only the Abstract Syntactic Tree model.
  • ast-builder : ast + the object that builds the AST from the source code (also requires parser).
  • ast-builder-tests : ast-builder + its unit tests.
  • visitors : ast + default visitors of the AST.
  • core : parser + ast + ast-builder.
  • core-tests : core + all unit tests associated.
  • future : Experimental code of this project, do not use this in production.
  • dev : Everything you need to help in this project development loads future group as well.

Let's say you only need the ast group, the following code will load this specific group:

Metacello new
	baseline: 'PostgreSQLParser';
	repository: 'github://juliendelplanque/PostgreSQLParser/src';
	load: 'ast'

Use it as a dependency

To use this project as a dependency, add the following code in your baseline:

[...]
spec baseline: 'PostgreSQLParser' with: [ 
	spec
		repository: 'github://juliendelplanque/PostgreSQLParser/src' ]
[...]

Usage

The complexity of the parsing process is hidden (for users) behind a facade: PostgreSQLParser class. The class-side methods provide a simple API to parse SQL code and get an AST as return.

For example:

ast := PostgreSQLParser parseSelectQuery: 'SELECT person.id, person.name, person.city_id 
FROM person, city
WHERE person.city_id = city.id
LIMIT 10'. "Mind that there is not trailing ';' because this is part of statement's grammar not query grammar."

"... process the AST... "

There other methods work similarly:

  • PostgreSQLParser class>>#parseUpdateQuery:
  • PostgreSQLParser class>>#parseCRUDQuery:
  • PostgreSQLParser class>>#parseDeleteQuery:
  • PostgreSQLParser class>>#parseInsertQuery:
  • PostgreSQLParser class>>#parseSelectQuery:
  • PostgreSQLParser class>>#parseStoredProcedureBody:

postgresqlparser's People

Contributors

deem0n avatar juliendelplanque avatar larcheveque avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

postgresqlparser's Issues

Create groups in baseline

  • parser : Only PostgreSQL-Parser
  • parser-tests : parser + tests
  • ast : Only PostgreSQL-AST
  • ast-builder : parser + ast + PostgreSQL-ASTBuilder
  • ast-tests : ast-builder + tests
  • visitors : PostgreSQL-ASTVisitors
  • core : ast-builder + visitors
  • core-tests : core + ast-tests + parser-tests
  • all : All packages except PostgreSQL-DevTools
  • dev : all + PostgreSQL-DevTools

This issue requires issue #32 to be solved.

Finish implementation of #fromItems

[ LATERAL ] ROWS FROM( function_name ( [ argument [, ...] ] ) [ AS ( column_definition [, ...] ) ] [, ...] )
                [ WITH ORDINALITY ] [ [ AS ] alias [ ( column_alias [, ...] ) ] ]

construct is not implemented. For now we can work without that anyway.

String concatenation without operator

It looks like the following is valid PL/pgSQL:

EXECUTE format('SELECT count(*) FROM %I '
   'WHERE inserted_by = $1 AND inserted <= $2', tabname)
   INTO c
   USING checked_user, checked_date;

Finish #conflictTarget1

Trying to make the parser work without this part of the grammar completely written because it is unclear what has to be parsed.

SELECT INTO alternative construct

It seems that SELECT INTO table * ... is a valid construct (apparently not documented in postgresql doc.

The parser should handle that.

Fix issue with EXTRACT()

It can not be parsed for now because it takes an argument of the form x FROM y e.g. EXTRACT(DAY FROM origine)

Put tests into separated packages

Since there is huge number of unit tests, we may want to load the project without them.

An update of the baseline will be needed.

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.