Skip to content
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

upgraded pg_query #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ This is based on the output of [libpg_query](https://github.com/lfittl/libpg_que

All credit for the hard problems goes to [Lukas Fittl](https://github.com/lfittl).

## How to re-buid

```sh
git clone -b 10-latest git://github.com/lfittl/libpg_query
cd libpg_query
make
```

Then get the `.a` file and drop it in the folder in this repo.

## Installation

```sh
npm install pg-query-native
npm install pg-query-native-latest
```

### Documentation
Expand Down
15 changes: 11 additions & 4 deletions libpg_query/include/pg_query.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ typedef struct {
char* filename; // source of exception (e.g. parse.l)
int lineno; // source of exception (e.g. 104)
int cursorpos; // char in query at which exception occurred
char* context; // additional context (optional)
char* context; // additional context (optional, can be NULL)
} PgQueryError;

typedef struct {
Expand All @@ -17,8 +17,7 @@ typedef struct {
} PgQueryParseResult;

typedef struct {
char* plpgsql_func;
char* stderr_buffer;
char* plpgsql_funcs;
PgQueryError* error;
} PgQueryPlpgsqlParseResult;

Expand All @@ -37,7 +36,6 @@ typedef struct {
extern "C" {
#endif

void pg_query_init(void);
PgQueryNormalizeResult pg_query_normalize(const char* input);
PgQueryParseResult pg_query_parse(const char* input);
PgQueryPlpgsqlParseResult pg_query_parse_plpgsql(const char* input);
Expand All @@ -49,6 +47,15 @@ void pg_query_free_parse_result(PgQueryParseResult result);
void pg_query_free_plpgsql_parse_result(PgQueryPlpgsqlParseResult result);
void pg_query_free_fingerprint_result(PgQueryFingerprintResult result);

// Postgres version information
#define PG_VERSION "10.0"
#define PG_MAJORVERSION "10"
#define PG_VERSION_NUM 100000

// Deprecated APIs below

void pg_query_init(void); // Deprecated as of 9.5-1.4.1, this is now run automatically as needed

#ifdef __cplusplus
}
#endif
Expand Down
Binary file modified libpg_query/linux/libpg_query.a
Binary file not shown.
Binary file modified libpg_query/osx/libpg_query.a
Binary file not shown.
6 changes: 3 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ var assert = require('assert');

describe('pg-query', function() {
it('should parse a query', function() {
assert.equal(typeof query.parse('select 1').query[0].SelectStmt, 'object');
assert.equal(typeof query.parse('select 1').query[0].RawStmt.stmt.SelectStmt, 'object');
});

it('should parse a null', function() {
assert(query.parse("select null").query[0].SelectStmt.targetList[0].ResTarget.val.A_Const.val.Null);
assert(query.parse("select null").query[0].RawStmt.stmt.SelectStmt.targetList[0].ResTarget.val.A_Const.val.Null);
});

it('should parse an empty string', function() {
assert(query.parse("select ''").query[0].SelectStmt.targetList[0].ResTarget.val.A_Const.val.String.str === '');
assert(query.parse("select ''").query[0].RawStmt.stmt.SelectStmt.targetList[0].ResTarget.val.A_Const.val.String.str === '');
});

it('should not parse a bogus query', function() {
Expand Down