Home

Awesome

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:

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: