Skip to content

Commit a5616ba

Browse files
authored
Merge pull request #72 from launchql/15-deparse
15 deparse
2 parents 1f95e07 + 85e453e commit a5616ba

File tree

23 files changed

+102696
-340
lines changed

23 files changed

+102696
-340
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Build and Publish Dry Run libpq-query no windows 🏗
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
make-release-candidate:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout Repository 📥
11+
uses: actions/checkout@v4
12+
13+
- name: Setup Node.js 🌐
14+
uses: actions/setup-node@v4
15+
with:
16+
node-version: '20.x'
17+
cache: 'yarn'
18+
19+
build-artifacts:
20+
needs: make-release-candidate
21+
runs-on: ${{ matrix.os }}
22+
strategy:
23+
matrix:
24+
os: [macos-latest, ubuntu-latest]
25+
steps:
26+
- name: Checkout Repository 📥
27+
uses: actions/checkout@v4
28+
29+
- name: Setup Node.js 🌐
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: '20.x'
33+
cache: 'yarn'
34+
35+
- name: Install and Build 📦
36+
run: |
37+
yarn
38+
yarn binary:build
39+
40+
- name: Save Artifacts For Supabase CDN 🏗
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: build-supabase-artifact-${{ matrix.os }}
44+
path: './build/stage/libpg-query-node/'
45+
46+
- name: Save Artifacts For NPM 🏗
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: build-npm-artifact-${{ matrix.os }}
50+
path: |
51+
${{ matrix.os == 'macos-latest' && './libpg_query/osx/libpg_query.a' ||
52+
matrix.os == 'ubuntu-latest' && './libpg_query/linux/libpg_query.a' }}
53+
54+
build-wasm:
55+
needs: build-artifacts
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Checkout Repository 📥
59+
uses: actions/checkout@v4
60+
61+
- name: Setup Node.js 🌐
62+
uses: actions/setup-node@v4
63+
with:
64+
node-version: '20.x'
65+
cache: 'yarn'
66+
67+
- name: Install and Build 🚀
68+
run: |
69+
yarn
70+
71+
- name: Install Emscripten ✍🏻
72+
run: |
73+
sudo apt-get update
74+
sudo apt-get install cmake python3 python3-pip
75+
git clone --branch 3.1.59 --depth 1 https://github.com/emscripten-core/emsdk.git
76+
cd emsdk
77+
./emsdk install 3.1.59
78+
./emsdk activate 3.1.59
79+
source ./emsdk_env.sh
80+
81+
- name: Build with Emscripten 🏗
82+
run: |
83+
source ./emsdk/emsdk_env.sh
84+
emmake make
85+
emmake make build
86+
87+
- name: Archive production artifacts 🏛
88+
uses: actions/upload-artifact@v4
89+
with:
90+
name: wasm-artifacts
91+
path: wasm
92+
93+
prepare-and-publish:
94+
needs: build-wasm
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Checkout Repository 📥
98+
uses: actions/checkout@v4
99+
100+
- name: Get Artifacts 📚
101+
uses: actions/download-artifact@v4
102+
with:
103+
path: downloaded-artifacts
104+
105+
- name: Prepare artifacts 📦
106+
run: |
107+
find ./downloaded-artifacts/
108+
cp ./downloaded-artifacts/build-npm-artifact-ubuntu-latest/libpg_query.a ./libpg_query/linux/libpg_query.a
109+
cp ./downloaded-artifacts/build-npm-artifact-macos-latest/libpg_query.a ./libpg_query/osx/libpg_query.a
110+
cp ./downloaded-artifacts/wasm-artifacts/libpg-query.js ./wasm/libpg-query.js
111+
cp ./downloaded-artifacts/wasm-artifacts/libpg-query.wasm ./wasm/libpg-query.wasm
112+
rm -rf ./downloaded-artifacts
113+
114+
# - name: Setup AWS CLI
115+
# run: sudo apt-get update && sudo apt-get install awscli -y
116+
117+
# - name: Configure AWS Credentials
118+
# uses: aws-actions/configure-aws-credentials@v4
119+
# with:
120+
# aws-access-key-id: ${{ secrets.SUPABASE_AWS_KEY }}
121+
# aws-secret-access-key: ${{ secrets.SUPABASE_AWS_SECRET }}
122+
# aws-region: us-east-1
123+
124+
# - name: List Bucket Contents
125+
# run: aws s3 ls s3://supabase-public-artifacts-bucket/
126+
127+
# - name: Publish to NPM 🚀
128+
# run: |
129+
# npm publish
130+
# env:
131+
# NODE_AUTH_TOKEN: ${{secrets.NPM_API_KEY}}
Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build Supabase Artifacts 🏗
1+
name: Build Supabase Artifacts Linux 🏗
22

33
on:
44
workflow_dispatch:
@@ -8,7 +8,7 @@ jobs:
88
runs-on: ${{ matrix.os }}
99
strategy:
1010
matrix:
11-
os: [windows-latest, macos-latest, ubuntu-latest]
11+
os: [macos-latest, ubuntu-latest]
1212
steps:
1313
- name: Checkout Repository 📥
1414
uses: actions/checkout@v4
@@ -19,35 +19,25 @@ jobs:
1919
node-version: '20.x'
2020
cache: 'yarn'
2121

22-
- name: Install Dependencies 🧶
22+
- name: Configure AWS CLI for Supabase
23+
env:
24+
AWS_ACCESS_KEY_ID: ${{ secrets.SUPABASE_AWS_KEY }}
25+
AWS_SECRET_ACCESS_KEY: ${{ secrets.SUPABASE_AWS_SECRET }}
26+
AWS_EC2_METADATA_DISABLED: true
27+
run: |
28+
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile supabase-dev
29+
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile supabase-dev
30+
aws configure set region us-east-1 --profile supabase-dev
31+
32+
- name: Install and Build Dependencies 🧶
2333
run: |
2434
yarn
2535
yarn binary:build
2636
27-
- name: Save Artifacts For Supabase CDN 🏗
28-
uses: actions/upload-artifact@v4
29-
with:
30-
name: build-supabase-artifact-${{ matrix.os }}
31-
path: './build/stage/libpg-query-node/'
32-
33-
prepare-and-publish:
34-
needs: build-matrix
35-
runs-on: ubuntu-latest
36-
steps:
37-
- name: Checkout Repository 📥
38-
uses: actions/checkout@v4
39-
40-
- name: Get Artifacts 📖
41-
uses: actions/download-artifact@v4
42-
with:
43-
path: downloaded-artifacts
44-
45-
- name: Prepare artifacts 📦
46-
run: |
47-
find ./downloaded-artifacts
37+
- name: Publish binary
38+
env:
39+
AWS_ACCESS_KEY_ID: ${{ secrets.SUPABASE_ACCESS_KEY_ID }}
40+
AWS_SECRET_ACCESS_KEY: ${{ secrets.SUPABASE_SECRET_ACCESS_KEY }}
41+
AWS_REGION: 'us-east-1'
42+
run: yarn binary:publish
4843

49-
# - name: Publish to NPM 🚀
50-
# run: |
51-
# # Assuming you've set up your package.json and .npmrc correctly
52-
# npm publish
53-
# env:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ libs/
44
npm-debug.log
55
libpg_query/**/*.a
66
libpg_query/**/*.h
7+
libpg_query/**/*.proto
78
wasm/libpg-query.js
89
*.wasm
910
.cache

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/run-tests-win.yml">
1919
<img height="20" src="https://github.com/launchql/libpg-query-node/actions/workflows/run-tests-win.yml/badge.svg" />
2020
</a>
21-
2221
</p>
2322

2423
The real PostgreSQL parser, exposed for nodejs.

index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export function parseQuery(sql: string): Promise<ParseResult>;
33
export function parsePlPgSQL(funcsSql: string): Promise<any>;
44
export function parseQuerySync(sql: string): ParseResult;
55
export function parsePlPgSQLSync(funcsSql: string): any;
6+
export function deparse(parseTree: any): Promise<string>;
7+
export function deparseSync(parseTree: any): any;
68
export function fingerprint(sql: string): Promise<string>;
79
export function fingerprintSync(sql: string): string;
810
export * from '@pgsql/types';

index.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const PgQuery = require('./build/Release/queryparser.node');
1+
const PgQuery = require('./build/Release/queryparser');
2+
const { pg_query } = require('./proto');
3+
24

35
module.exports = {
46
parseQuery(query) {
@@ -9,6 +11,16 @@ module.exports = {
911
});
1012
},
1113

14+
deparse(parseTree) {
15+
const msg = pg_query.ParseResult.fromObject(parseTree);
16+
const data = pg_query.ParseResult.encode(msg).finish();
17+
return new Promise((resolve, reject) => {
18+
PgQuery.deparseAsync(data, (err, result) => {
19+
err ? reject(err) : resolve(result);
20+
});
21+
});
22+
},
23+
1224
parsePlPgSQL(query) {
1325
return new Promise((resolve, reject) => {
1426
PgQuery.parsePlPgSQLAsync(query, (err, result) => {
@@ -21,6 +33,12 @@ module.exports = {
2133
return JSON.parse(PgQuery.parseQuerySync(query));
2234
},
2335

36+
deparseSync(parseTree) {
37+
const msg = pg_query.ParseResult.fromObject(parseTree);
38+
const data = pg_query.ParseResult.encode(msg).finish();
39+
return PgQuery.deparseSync(data);
40+
},
41+
2442
parsePlPgSQLSync(query) {
2543
return JSON.parse(PgQuery.parsePlPgSQLSync(query));
2644
},

libpg_query/protobuf/.gitkeep

Whitespace-only changes.

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "libpg-query",
3-
"version": "15.2.0",
3+
"version": "15.2.0-rc.deparse.3",
44
"description": "The real PostgreSQL query parser",
55
"homepage": "https://github.com/launchql/libpg-query-node",
66
"main": "index.js",
@@ -12,6 +12,7 @@
1212
"binding.gyp",
1313
"index.js",
1414
"index.d.ts",
15+
"proto.js",
1516
"libpg_query/*",
1617
"script/*",
1718
"src/*",
@@ -30,6 +31,7 @@
3031
}
3132
},
3233
"scripts": {
34+
"protogen": "node ./script/protogen.js 15-4.2.4",
3335
"clean": "rimraf build",
3436
"configure": "node-pre-gyp configure",
3537
"install": "node-pre-gyp install --fallback-to-build --loglevel verbose",
@@ -51,7 +53,9 @@
5153
"url": "git://github.com/launchql/libpg-query-node.git"
5254
},
5355
"devDependencies": {
56+
"@launchql/proto-cli": "1.25.0",
5457
"@yamlize/cli": "^0.8.0",
58+
"aws-sdk": "2.1691.0",
5559
"chai": "^3.5.0",
5660
"emnapi": "^0.43.1",
5761
"lodash": "^4.17.15",
@@ -60,6 +64,7 @@
6064
},
6165
"dependencies": {
6266
"@emnapi/runtime": "^0.43.1",
67+
"@launchql/protobufjs": "7.2.6",
6368
"@mapbox/node-pre-gyp": "^1.0.8",
6469
"@pgsql/types": "^15.0.1",
6570
"node-addon-api": "^7.0.0",
@@ -77,7 +82,10 @@
7782
"binary": {
7883
"module_name": "queryparser",
7984
"module_path": "./build/Release/",
80-
"host": "https://supabase-public-artifacts-bucket.s3.amazonaws.com",
81-
"remote_path": "./libpg-query-node/"
85+
"host": "https://gnbyoxcowpfpalflhptv.supabase.co/storage/v1/s3",
86+
"remote_path": "./libpg-query-node/",
87+
"bucket": "public-artifacts",
88+
"region": "us-east-1",
89+
"s3ForcePathStyle": true
8290
}
8391
}

0 commit comments

Comments
 (0)