Skip to content
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ node_js:
- "0.12"
- "4"
- "5"
- "10"
- "12"
addons:
apt:
sources:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ 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
## How to re-build

```sh
git clone -b 10-latest git://github.com/lfittl/libpg_query
git clone -b 13-latest-develop git://github.com/lfittl/libpg_query
cd libpg_query
make
```
Expand Down
66 changes: 62 additions & 4 deletions libpg_query/include/pg_query.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef PG_QUERY_H
#define PG_QUERY_H

#include <stdint.h>

typedef struct {
char* message; // exception message
char* funcname; // source function of exception (e.g. SearchSysCache)
Expand All @@ -10,19 +12,54 @@ typedef struct {
char* context; // additional context (optional, can be NULL)
} PgQueryError;

typedef struct {
unsigned int len;
char* data;
} PgQueryProtobuf;

typedef struct {
PgQueryProtobuf pbuf;
char* stderr_buffer;
PgQueryError* error;
} PgQueryScanResult;

typedef struct {
char* parse_tree;
char* stderr_buffer;
PgQueryError* error;
} PgQueryParseResult;

typedef struct {
PgQueryProtobuf parse_tree;
char* stderr_buffer;
PgQueryError* error;
} PgQueryProtobufParseResult;

typedef struct {
int stmt_location;
int stmt_len;
} PgQuerySplitStmt;

typedef struct {
PgQuerySplitStmt **stmts;
int n_stmts;
char* stderr_buffer;
PgQueryError* error;
} PgQuerySplitResult;

typedef struct {
char* query;
PgQueryError* error;
} PgQueryDeparseResult;

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

typedef struct {
char* hexdigest;
uint64_t fingerprint;
char* fingerprint_str;
char* stderr_buffer;
PgQueryError* error;
} PgQueryFingerprintResult;
Expand All @@ -37,20 +74,41 @@ extern "C" {
#endif

PgQueryNormalizeResult pg_query_normalize(const char* input);
PgQueryScanResult pg_query_scan(const char* input);
PgQueryParseResult pg_query_parse(const char* input);
PgQueryProtobufParseResult pg_query_parse_protobuf(const char* input);
PgQueryPlpgsqlParseResult pg_query_parse_plpgsql(const char* input);

PgQueryFingerprintResult pg_query_fingerprint(const char* input);

// Use pg_query_split_with_scanner when you need to split statements that may
// contain parse errors, otherwise pg_query_split_with_parser is recommended
// for improved accuracy due the parser adding additional token handling.
//
// Note that we try to support special cases like comments, strings containing
// ";" on both, as well as oddities like "CREATE RULE .. (SELECT 1; SELECT 2);"
// which is treated as as single statement.
PgQuerySplitResult pg_query_split_with_scanner(const char *input);
PgQuerySplitResult pg_query_split_with_parser(const char *input);

PgQueryDeparseResult pg_query_deparse_protobuf(PgQueryProtobuf parse_tree);

void pg_query_free_normalize_result(PgQueryNormalizeResult result);
void pg_query_free_scan_result(PgQueryScanResult result);
void pg_query_free_parse_result(PgQueryParseResult result);
void pg_query_free_split_result(PgQuerySplitResult result);
void pg_query_free_deparse_result(PgQueryDeparseResult result);
void pg_query_free_protobuf_parse_result(PgQueryProtobufParseResult result);
void pg_query_free_plpgsql_parse_result(PgQueryPlpgsqlParseResult result);
void pg_query_free_fingerprint_result(PgQueryFingerprintResult result);

// Optional, cleans up the top-level memory context (automatically done for threads that exit)
void pg_query_exit(void);

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

// Deprecated APIs below

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.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pg-query-native",
"version": "1.1.0",
"name": "@pyramation/pg-query-native",
"version": "1.1.0-v12",
"description": "The real PostgreSQL query parser",
"homepage": "http://github.com/zhm/node-pg-query-native",
"main": "index.js",
Expand All @@ -10,11 +10,11 @@
"rebuild": "./node_modules/node-gyp/bin/node-gyp.js configure rebuild",
"test": "mocha"
},
"author": "Zac McCormick <zac.mccormick@gmail.com> (http://github.com/zhm)",
"author": "Dan Lynch <pyramation@gmail.com> (http://github.com/pyramation)",
"license": "BSD",
"repository": {
"type": "git",
"url": "git://github.com/zhm/node-pg-query-native.git"
"url": "git://github.com/pyramation/node-pg-query-native.git"
},
"devDependencies": {
"mocha": "^2.5.3"
Expand Down
Loading