Skip to content

Commit

Permalink
Merge pull request #72 from launchql/15-deparse
Browse files Browse the repository at this point in the history
15 deparse
  • Loading branch information
pyramation authored Sep 24, 2024
2 parents 1f95e07 + 85e453e commit a5616ba
Show file tree
Hide file tree
Showing 23 changed files with 102,696 additions and 340 deletions.
131 changes: 131 additions & 0 deletions .github/workflows/build-dry-run-no-win.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Build and Publish Dry Run libpq-query no windows 🏗

on:
workflow_dispatch:

jobs:
make-release-candidate:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository 📥
uses: actions/checkout@v4

- name: Setup Node.js 🌐
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'yarn'

build-artifacts:
needs: make-release-candidate
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest]
steps:
- name: Checkout Repository 📥
uses: actions/checkout@v4

- name: Setup Node.js 🌐
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'yarn'

- name: Install and Build 📦
run: |
yarn
yarn binary:build
- name: Save Artifacts For Supabase CDN 🏗
uses: actions/upload-artifact@v4
with:
name: build-supabase-artifact-${{ matrix.os }}
path: './build/stage/libpg-query-node/'

- name: Save Artifacts For NPM 🏗
uses: actions/upload-artifact@v4
with:
name: build-npm-artifact-${{ matrix.os }}
path: |
${{ matrix.os == 'macos-latest' && './libpg_query/osx/libpg_query.a' ||
matrix.os == 'ubuntu-latest' && './libpg_query/linux/libpg_query.a' }}
build-wasm:
needs: build-artifacts
runs-on: ubuntu-latest
steps:
- name: Checkout Repository 📥
uses: actions/checkout@v4

- name: Setup Node.js 🌐
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'yarn'

- name: Install and Build 🚀
run: |
yarn
- name: Install Emscripten ✍🏻
run: |
sudo apt-get update
sudo apt-get install cmake python3 python3-pip
git clone --branch 3.1.59 --depth 1 https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install 3.1.59
./emsdk activate 3.1.59
source ./emsdk_env.sh
- name: Build with Emscripten 🏗
run: |
source ./emsdk/emsdk_env.sh
emmake make
emmake make build
- name: Archive production artifacts 🏛
uses: actions/upload-artifact@v4
with:
name: wasm-artifacts
path: wasm

prepare-and-publish:
needs: build-wasm
runs-on: ubuntu-latest
steps:
- name: Checkout Repository 📥
uses: actions/checkout@v4

- name: Get Artifacts 📚
uses: actions/download-artifact@v4
with:
path: downloaded-artifacts

- name: Prepare artifacts 📦
run: |
find ./downloaded-artifacts/
cp ./downloaded-artifacts/build-npm-artifact-ubuntu-latest/libpg_query.a ./libpg_query/linux/libpg_query.a
cp ./downloaded-artifacts/build-npm-artifact-macos-latest/libpg_query.a ./libpg_query/osx/libpg_query.a
cp ./downloaded-artifacts/wasm-artifacts/libpg-query.js ./wasm/libpg-query.js
cp ./downloaded-artifacts/wasm-artifacts/libpg-query.wasm ./wasm/libpg-query.wasm
rm -rf ./downloaded-artifacts
# - name: Setup AWS CLI
# run: sudo apt-get update && sudo apt-get install awscli -y

# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v4
# with:
# aws-access-key-id: ${{ secrets.SUPABASE_AWS_KEY }}
# aws-secret-access-key: ${{ secrets.SUPABASE_AWS_SECRET }}
# aws-region: us-east-1

# - name: List Bucket Contents
# run: aws s3 ls s3://supabase-public-artifacts-bucket/

# - name: Publish to NPM 🚀
# run: |
# npm publish
# env:
# NODE_AUTH_TOKEN: ${{secrets.NPM_API_KEY}}
48 changes: 19 additions & 29 deletions .github/workflows/build-supabase-artifacts.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Supabase Artifacts 🏗
name: Build Supabase Artifacts Linux 🏗

on:
workflow_dispatch:
Expand All @@ -8,7 +8,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
os: [macos-latest, ubuntu-latest]
steps:
- name: Checkout Repository 📥
uses: actions/checkout@v4
Expand All @@ -19,35 +19,25 @@ jobs:
node-version: '20.x'
cache: 'yarn'

- name: Install Dependencies 🧶
- name: Configure AWS CLI for Supabase
env:
AWS_ACCESS_KEY_ID: ${{ secrets.SUPABASE_AWS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.SUPABASE_AWS_SECRET }}
AWS_EC2_METADATA_DISABLED: true
run: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile supabase-dev
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile supabase-dev
aws configure set region us-east-1 --profile supabase-dev
- name: Install and Build Dependencies 🧶
run: |
yarn
yarn binary:build
- name: Save Artifacts For Supabase CDN 🏗
uses: actions/upload-artifact@v4
with:
name: build-supabase-artifact-${{ matrix.os }}
path: './build/stage/libpg-query-node/'

prepare-and-publish:
needs: build-matrix
runs-on: ubuntu-latest
steps:
- name: Checkout Repository 📥
uses: actions/checkout@v4

- name: Get Artifacts 📖
uses: actions/download-artifact@v4
with:
path: downloaded-artifacts

- name: Prepare artifacts 📦
run: |
find ./downloaded-artifacts
- name: Publish binary
env:
AWS_ACCESS_KEY_ID: ${{ secrets.SUPABASE_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.SUPABASE_SECRET_ACCESS_KEY }}
AWS_REGION: 'us-east-1'
run: yarn binary:publish

# - name: Publish to NPM 🚀
# run: |
# # Assuming you've set up your package.json and .npmrc correctly
# npm publish
# env:
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ libs/
npm-debug.log
libpg_query/**/*.a
libpg_query/**/*.h
libpg_query/**/*.proto
wasm/libpg-query.js
*.wasm
.cache
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/run-tests-win.yml">
<img height="20" src="https://github.com/launchql/libpg-query-node/actions/workflows/run-tests-win.yml/badge.svg" />
</a>

</p>

The real PostgreSQL parser, exposed for nodejs.
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export function parseQuery(sql: string): Promise<ParseResult>;
export function parsePlPgSQL(funcsSql: string): Promise<any>;
export function parseQuerySync(sql: string): ParseResult;
export function parsePlPgSQLSync(funcsSql: string): any;
export function deparse(parseTree: any): Promise<string>;
export function deparseSync(parseTree: any): any;
export function fingerprint(sql: string): Promise<string>;
export function fingerprintSync(sql: string): string;
export * from '@pgsql/types';
20 changes: 19 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const PgQuery = require('./build/Release/queryparser.node');
const PgQuery = require('./build/Release/queryparser');
const { pg_query } = require('./proto');


module.exports = {
parseQuery(query) {
Expand All @@ -9,6 +11,16 @@ module.exports = {
});
},

deparse(parseTree) {
const msg = pg_query.ParseResult.fromObject(parseTree);
const data = pg_query.ParseResult.encode(msg).finish();
return new Promise((resolve, reject) => {
PgQuery.deparseAsync(data, (err, result) => {
err ? reject(err) : resolve(result);
});
});
},

parsePlPgSQL(query) {
return new Promise((resolve, reject) => {
PgQuery.parsePlPgSQLAsync(query, (err, result) => {
Expand All @@ -21,6 +33,12 @@ module.exports = {
return JSON.parse(PgQuery.parseQuerySync(query));
},

deparseSync(parseTree) {
const msg = pg_query.ParseResult.fromObject(parseTree);
const data = pg_query.ParseResult.encode(msg).finish();
return PgQuery.deparseSync(data);
},

parsePlPgSQLSync(query) {
return JSON.parse(PgQuery.parsePlPgSQLSync(query));
},
Expand Down
Empty file added libpg_query/protobuf/.gitkeep
Empty file.
14 changes: 11 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",
"version": "15.2.0-rc.deparse.3",
"description": "The real PostgreSQL query parser",
"homepage": "https://github.com/launchql/libpg-query-node",
"main": "index.js",
Expand All @@ -12,6 +12,7 @@
"binding.gyp",
"index.js",
"index.d.ts",
"proto.js",
"libpg_query/*",
"script/*",
"src/*",
Expand All @@ -30,6 +31,7 @@
}
},
"scripts": {
"protogen": "node ./script/protogen.js 15-4.2.4",
"clean": "rimraf build",
"configure": "node-pre-gyp configure",
"install": "node-pre-gyp install --fallback-to-build --loglevel verbose",
Expand All @@ -51,7 +53,9 @@
"url": "git://github.com/launchql/libpg-query-node.git"
},
"devDependencies": {
"@launchql/proto-cli": "1.25.0",
"@yamlize/cli": "^0.8.0",
"aws-sdk": "2.1691.0",
"chai": "^3.5.0",
"emnapi": "^0.43.1",
"lodash": "^4.17.15",
Expand All @@ -60,6 +64,7 @@
},
"dependencies": {
"@emnapi/runtime": "^0.43.1",
"@launchql/protobufjs": "7.2.6",
"@mapbox/node-pre-gyp": "^1.0.8",
"@pgsql/types": "^15.0.1",
"node-addon-api": "^7.0.0",
Expand All @@ -77,7 +82,10 @@
"binary": {
"module_name": "queryparser",
"module_path": "./build/Release/",
"host": "https://supabase-public-artifacts-bucket.s3.amazonaws.com",
"remote_path": "./libpg-query-node/"
"host": "https://gnbyoxcowpfpalflhptv.supabase.co/storage/v1/s3",
"remote_path": "./libpg-query-node/",
"bucket": "public-artifacts",
"region": "us-east-1",
"s3ForcePathStyle": true
}
}
Loading

0 comments on commit a5616ba

Please sign in to comment.