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

16 deparse #73

Open
wants to merge 6 commits into
base: 16-latest
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
36 changes: 27 additions & 9 deletions .github/workflows/build-wasm-linux.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Wasm Linux 🧪
name: Build Wasm 🛠

on:
workflow_dispatch:
Expand All @@ -16,16 +16,34 @@ jobs:
node-version: '20.x'
cache: 'yarn'

- name: Install Linux Deps 🧶
- name: Cache Emscripten 📇
uses: actions/cache@v2
with:
path: |
emsdk/upstream
emsdk/node
key: ${{ runner.os }}-emsdk-${{ hashFiles('emsdk/emsdk_manifest.json') }}
restore-keys: |
${{ runner.os }}-emsdk-

- name: Install Emscripten ✍🏻
if: steps.cache-emsdk.outputs.cache-hit != 'true'
run: |
sudo apt-get update
sudo apt-get install -y make
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: Install Dependencies 🧶
- name: Build with Emscripten
run: |
yarn
source ./emsdk/emsdk_env.sh
emmake make

- name: Test 🔍
run: |
yarn make:wasm
yarn make build:wasm
- name: Archive production artifacts
uses: actions/upload-artifact@v2
with:
name: compiled-files
path: wasm
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
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export function parseQuery(sql: string): Promise<any>;
export function deparse(parseTree: any): Promise<string>;
export function parsePlPgSQL(funcsSql: string): Promise<any>;
export function parseQuerySync(sql: string): any;
export function deparseSync(parseTree: any): any;
export function parsePlPgSQLSync(funcsSql: string): any;
export function fingerprint(sql: string): Promise<string>;
export function fingerprintSync(sql: string): string;
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.
24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,38 @@
}
},
"scripts": {
"protogen": "node ./script/protogen.js 16-latest",
"clean": "rimraf build",
"configure": "node-pre-gyp configure",
"install": "node-pre-gyp install --fallback-to-build --loglevel verbose",
"rebuild": "node-pre-gyp rebuild --loglevel verbose",
"make:wasm": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make",
"build:wasm": "yarn make:wasm build",
"rebuild:wasm": "yarn make:wasm rebuild",
"clean:wasm": "yarn make:wasm clean",
"clean-cache:wasm": "yarn make:wasm clean-cache",
"wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make",
"wasm:build": "npm run wasm:make build",
"wasm:rebuild": "npm run wasm:make rebuild",
"wasm:clean": "npm run wasm:make clean",
"wasm:clean-cache": "npm run wasm:make clean-cache",
"test": "mocha --timeout 5000",
"binary:build": "node-pre-gyp rebuild package",
"binary:publish": "AWS_PROFILE=supabase-dev node-pre-gyp publish"
},
"binary:publish": "AWS_PROFILE=supabase-dev node-pre-gyp publish",
"clean:all": "npm run clean && npm run wasm:clean && npm run wasm:clean-cache"
},
"author": "Dan Lynch <pyramation@gmail.com> (http://github.com/pyramation)",
"license": "LICENSE IN LICENSE",
"repository": {
"type": "git",
"url": "git://github.com/launchql/libpg-query-node.git"
},
"devDependencies": {
"rimraf": "5.0.0",
"@launchql/proto-cli": "1.25.0",
"chai": "^3.5.0",
"emnapi": "^0.43.1",
"lodash": "^4.17.15",
"mocha": "^5.2.0"
"mocha": "^5.2.0",
"rimraf": "5.0.0"
},
"dependencies": {
"@emnapi/runtime": "^0.43.1",
"@launchql/protobufjs": "7.2.6",
"@mapbox/node-pre-gyp": "^1.0.8",
"node-addon-api": "^7.0.0",
"node-gyp": "^10.0.1"
Expand All @@ -77,4 +81,4 @@
"host": "https://supabase-public-artifacts-bucket.s3.amazonaws.com",
"remote_path": "./libpg-query-node/"
}
}
}
Loading
Loading