Skip to content
Merged
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ WASM_OUT_DIR := wasm
WASM_OUT_NAME := libpg-query
WASM_MODULE_NAME := PgQueryModule
LIBPG_QUERY_REPO := https://github.com/pganalyze/libpg_query.git
LIBPG_QUERY_TAG := 15-4.2.4
LIBPG_QUERY_TAG := 17-6.1.0

CACHE_DIR := .cache

OS ?= $(shell uname -s)
Expand Down
4 changes: 2 additions & 2 deletions docker/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ docker run \
# build inside the docker image

```sh
branch=15-latest
branch=17-6.1.0
mkdir git_clone_dir && cd git_clone_dir
git clone -b $branch --single-branch https://github.com/launchql/libpg-query-node
cd libpg-query-node/
Expand All @@ -40,7 +40,7 @@ npm publish
to build manually using `libpg_query`

```sh
branch=15-latest
branch=17-6.1.0
mkdir git_clone_dir && cd git_clone_dir
git clone -b $branch --single-branch https://github.com/pganalyze/libpg_query.git
cd libpg_query/
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libpg-query",
"version": "15.2.0-rc.deparse.3",
"version": "17.1.0",
"description": "The real PostgreSQL query parser",
"homepage": "https://github.com/launchql/libpg-query-node",
"main": "index.js",
Expand Down Expand Up @@ -31,7 +31,7 @@
}
},
"scripts": {
"protogen": "node ./script/protogen.js 15-4.2.4",
"protogen": "node ./script/protogen.js 17-6.1.0",
"clean": "rimraf build",
"configure": "node-pre-gyp configure",
"install": "node-pre-gyp install --fallback-to-build --loglevel verbose",
Expand Down Expand Up @@ -66,7 +66,7 @@
"@emnapi/runtime": "^0.43.1",
"@launchql/protobufjs": "7.2.6",
"@mapbox/node-pre-gyp": "^1.0.8",
"@pgsql/types": "^15.0.1",
"@pgsql/types": "^17.0.0",
"node-addon-api": "^7.0.0",
"node-gyp": "^10.0.1"
},
Expand Down
106,031 changes: 58,785 additions & 47,246 deletions proto.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions script/buildAddon.bat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@echo off

set commit=db39825bc7c1ddd45962ec6a626d740b7f8f027a
set branch=15-latest
set commit=1c1a32ed2f4c7799830d50bf4cb159222aafec48
set branch=17-6.1.0

setlocal enabledelayedexpansion

Expand Down
4 changes: 2 additions & 2 deletions script/buildAddon.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

# Set the desired commit hash and branch
commit=db39825bc7c1ddd45962ec6a626d740b7f8f027a
branch=15-latest
commit=1c1a32ed2f4c7799830d50bf4cb159222aafec48
branch=17-6.1.0

# Remember current directory and create a new, unique, temporary directory
rDIR=$(pwd)
Expand Down
35 changes: 35 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,41 @@ describe("Queries", () => {
expect(deparsed).to.eq(`INSERT INTO people (name, age) VALUES ('John', 28), ('Jane', 22)`)
});

it("sync function should return a same SQL (update)", async () => {
const testQuery = "UPDATE people SET age = age + 1 WHERE name = 'John';";
const parsed = query.parseQuerySync(testQuery);
const deparsed = query.deparseSync(parsed);
expect(deparsed).to.eq("UPDATE people SET age = age + 1 WHERE name = 'John'");
});

it("sync function should return a same SQL (join and where)", async () => {
const testQuery = "select a.id, b.name from table_a a join table_b b on a.id = b.a_id where b.status = 'active';";
const parsed = query.parseQuerySync(testQuery);
const deparsed = query.deparseSync(parsed);
expect(deparsed).to.eq("SELECT a.id, b.name FROM table_a a JOIN table_b b ON a.id = b.a_id WHERE b.status = 'active'");
});

it("sync function should return a same SQL (CTE)", async () => {
const testQuery = "with recent as (select * from people where age > 30) select name from recent;";
const parsed = query.parseQuerySync(testQuery);
const deparsed = query.deparseSync(parsed);
expect(deparsed).to.eq("WITH recent AS (SELECT * FROM people WHERE age > 30) SELECT name FROM recent");
});

it("sync function should return a same SQL (create table)", async () => {
const testQuery = `CREATE TABLE orders (
id serial PRIMARY KEY,
user_id integer NOT NULL,
total numeric(10,2) DEFAULT 0.00,
ordered_at timestamp with time zone DEFAULT now(),
description text,
CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
);`;
const parsed = query.parseQuerySync(testQuery);
const deparsed = query.deparseSync(parsed);
expect(deparsed).to.eq(`CREATE TABLE orders (id serial PRIMARY KEY, user_id int NOT NULL, total numeric(10, 2) DEFAULT 0.00, ordered_at timestamp with time zone DEFAULT now(), description text, CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE)`);
});

it("should reject on bogus input", async () => {
return query.deparse({stmts: [{}]}).then(
() => {
Expand Down
Loading