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

Yamlize/config #1

Draft
wants to merge 56 commits into
base: 15-latest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d4c0438
Add deparse
tomquist Mar 25, 2023
1a47bc8
Upgrade node version
maschwenk Nov 15, 2023
e2b2d34
Upgrade node-gyp
maschwenk Nov 15, 2023
c4dc317
Simplify the readme
maschwenk Nov 15, 2023
4f8765f
Fix link
karlhorky Dec 15, 2023
7a243fe
readme
pyramation Dec 15, 2023
3a8df48
urls
pyramation Dec 15, 2023
e8b09a9
Merge pull request #35 from maschwenk/mfs-testing-docker-stuff
pyramation Jan 10, 2024
0eefcc2
Merge pull request #37 from karlhorky/patch-1
pyramation Jan 10, 2024
7fc19a0
Support PostgreSQL 16, fix tests after upgrading
wale Feb 20, 2024
6740b73
change version to `16.0.0`
wale Feb 20, 2024
735c727
Merge pull request #40 from wale/wale/pg16
pyramation Feb 20, 2024
b700d83
update readme
pyramation Feb 20, 2024
40acfe3
readme and addon
pyramation Feb 21, 2024
a3b2b2a
readme
pyramation Feb 21, 2024
005b5ab
readme
pyramation Feb 21, 2024
8af85c3
readme
pyramation Feb 21, 2024
2f7cc10
readme
pyramation Feb 21, 2024
385fa7c
package
pyramation Feb 21, 2024
30948af
readme
pyramation Feb 21, 2024
492d08c
clean
pyramation Feb 21, 2024
d7073a8
npm publiish
pyramation Feb 21, 2024
efaac85
Merge pull request #43 from launchql/feat/add-workflow
pyramation Feb 21, 2024
378c5c4
Update README.md
pyramation Feb 21, 2024
ba3da3b
feat: support windows binary build
aquariuslt Mar 16, 2024
8ece76c
Merge pull request #45 from aquariuslt/feat/support-windows-build
pyramation Mar 29, 2024
dee1770
update gitignore and readme
pyramation Mar 29, 2024
badd4c8
Merge pull request #46 from launchql/16-latest-windows
pyramation Mar 29, 2024
78ec2c7
Merge branch 'wasm/16-latest' into wasm/origin-branch
pyramation May 1, 2024
76642e0
Merge pull request #50 from launchql/wasm/origin-branch
pyramation May 1, 2024
5df341a
update locks, workflows
pyramation May 2, 2024
09f40ec
remove build step from workflow
pyramation May 2, 2024
811593a
workflows
pyramation May 2, 2024
5ef2190
update wasm to use latest 16 libpg_query
pyramation May 2, 2024
c5a5c05
Merge pull request #54 from launchql/wasm/16-latest
pyramation May 2, 2024
3a44eb7
wasm
pyramation May 2, 2024
d3e5470
Merge pull request #58 from launchql/wasm/16-latest
pyramation May 2, 2024
20cfdbf
build
pyramation May 2, 2024
c81289a
workflow
pyramation May 2, 2024
ab94d5f
workflow
pyramation May 2, 2024
ca49afa
workflow
pyramation May 2, 2024
f1be9a0
workflow
pyramation May 2, 2024
19b30ac
workflow
pyramation May 2, 2024
161eef1
yarn
pyramation May 2, 2024
1348e4c
workflow
pyramation May 2, 2024
e905436
pkg
pyramation May 2, 2024
dbe8ae4
workflow
pyramation May 2, 2024
03f3f15
pkg scripts
pyramation May 2, 2024
16cbb4c
Merge branch 'tom/deparse-pr' into tom/deparse
pyramation May 2, 2024
9b6a671
Merge pull request #32 from tomquist/tom/deparse
pyramation May 2, 2024
ed041ac
use protobufjs with modifications for [json_name]
pyramation May 2, 2024
1355247
lock and proto
pyramation May 2, 2024
fa16a64
package up protogen
pyramation May 3, 2024
5ea5ded
Merge branch 'tom/deparse-pr' into 15-deparse
pyramation May 30, 2024
55e28d7
build config
pyramation Jun 3, 2024
c04be2f
pkg
pyramation Jun 3, 2024
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
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
90 changes: 90 additions & 0 deletions .templates/buildAddon.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
@echo off

set LIBPG_REPO=___LIBPG_REPO___
set LIBPG_COMMIT=___LIBPG_COMMIT___
set LIBPG_BRANCH=___LIBPG_BRANCH___

:: Check if each required variable is set
if "%LIBPG_REPO%"=="" (
echo ERROR: LIBPG_REPO variable is not set.
exit /B 1
)

if "%LIBPG_COMMIT%"=="" (
echo ERROR: LIBPG_COMMIT variable is not set.
exit /B 1
)

if "%LIBPG_BRANCH%"=="" (
echo ERROR: LIBPG_BRANCH variable is not set.
exit /B 1
)

:: The environment variables must be set
echo Using repository: %LIBPG_REPO%
echo Using commit: %LIBPG_COMMIT%
echo Using branch: %LIBPG_BRANCH%

setlocal enabledelayedexpansion

rem Remember current's parent directory and create a new, unique, temporary directory
set buildDir=%cd%
set projectDir=%cd%\..
set tmpDir=%temp%\tmpdir.libpg_query
rmdir /s /q %tmpDir%
md %tmpDir%


rem Define the make target
set makeTarget=build

rem Change to the newly created temp directory
cd /D %tmpDir%


rem Clone the selected branch of the libpg_query Git repo
git clone -b %LIBPG_BRANCH% --single-branch %LIBPG_REPO%
cd libpg_query

rem Checkout the desired commit
git checkout %LIBPG_COMMIT%

rem needed if being invoked from within gyp
set MAKEFLAGS=
set MFLAGS=

rem set path with Windows Developer Command Prompt
echo "please ensure you are running at Windows Developer Command Prompt environments"
nmake /F Makefile.msvc clean
nmake /F Makefile.msvc build


rem Terminate if build fails
if %errorlevel% NEQ 0 (
echo ERROR: 'nmake' command failed
)

rem Search for pg_query.obj (libpg_query.a), error if not found
for /f "delims=" %%f in ('dir /b /s pg_query.lib') do set file=%%f
if not defined file (
echo "ERROR: pg_query.lib not found"

)

rem Error if pg_query.h is missing
for /f "delims=" %%f in ('dir /b /s pg_query.h') do set file=%%f
if not defined file (
echo "ERROR: pg_query.h not found"

)

rem Copy pg_query.lib to windows dir
copy /Y pg_query.lib "%projectDir%\libpg_query\windows\"

rem Copy header
copy /Y pg_query.h "%projectDir%\libpg_query\include\"

rem Cleanup: revert to original directory
cd /D %buildDir%

exit /B 0
84 changes: 84 additions & 0 deletions .templates/buildAddon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env bash

LIBPG_REPO=___LIBPG_REPO___
LIBPG_COMMIT=___LIBPG_COMMIT___
LIBPG_BRANCH=___LIBPG_BRANCH___

# Check if variables are set and exit if not
if [ -z "$LIBPG_COMMIT" ]; then
echo "ERROR: LIBPG_COMMIT variable is not set."
exit 1
fi

if [ -z "$LIBPG_BRANCH" ]; then
echo "ERROR: LIBPG_BRANCH variable is not set."
exit 1
fi

if [ -z "$LIBPG_REPO" ]; then
echo "ERROR: LIBPG_REPO variable is not set."
exit 1
fi

# Remember current directory and create a new, unique, temporary directory
rDIR=$(pwd)
tmpDir=$(mktemp -d 2>/dev/null || mktemp -d -t 'tmpdir.XXXX')

# Define the make target
makeTarget=build

# Change to the newly created temp directory
cd "$tmpDir"

# Clone the selected branch of the libpg_query Git repo
git clone -b $LIBPG_BRANCH --single-branch $LIBPG_REPO
cd libpg_query

# Checkout the desired commit
git checkout $LIBPG_COMMIT

# needed if being invoked from within gyp
unset MAKEFLAGS
unset MFLAGS

# Adaptively build for macOS or Linux
if [ "$(uname)" == "Darwin" ]; then
make CFLAGS='-mmacosx-version-min=10.7' PG_CFLAGS='-mmacosx-version-min=10.7' $makeTarget
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
make CFLAGS='' PG_CFLAGS='' $makeTarget
fi

# Terminate if build fails
if [ $? -ne 0 ]; then
echo "ERROR: 'make' command failed";
exit 1;
fi

# Search for libpg_query.a, error if not found
file=$(ls | grep 'libpg_query.a')
if [ ! $file ]; then
echo "ERROR: libpg_query.a not found";
exit 1;
fi

# Error if pg_query.h is missing
file=$(ls | grep 'pg_query.h')
if [ ! $file ]; then
echo "ERROR: pg_query.h not found";
exit 1;
fi

# Copy queryparser.cc, binding.gyp to current directory
if [ "$(uname)" == "Darwin" ]; then
cp $(pwd)/libpg_query.a $rDIR/libpg_query/osx/
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
cp $(pwd)/libpg_query.a $rDIR/libpg_query/linux/
fi

# Copy header
cp $(pwd)/pg_query.h $rDIR/libpg_query/include/
cp $(pwd)/protobuf/*.proto $rDIR/libpg_query/protobuf/

# Cleanup: revert to original directory and remove the temp
cd "$rDIR"
rm -rf "$tmpDir"
38 changes: 38 additions & 0 deletions .templates/protogen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { exec } = require('child_process');

// Configuration Variables
const branchName = '___LIBPG_BRANCH___';
const protoUrl = `https://raw.githubusercontent.com/pganalyze/libpg_query/${branchName}/protobuf/pg_query.proto`;
const inFile = 'libpg_query/protobuf/pg_query.proto';
const outFile = 'proto.js';

const protogenCmd = [
'pg-proto-parser',
'protogen',
'--protoUrl',
protoUrl,
'--inFile',
inFile,
'--outFile',
outFile,
'--originalPackageName',
'protobufjs/minimal',
'--newPackageName',
'@launchql/protobufjs/minimal'
];

// Step 2: Generate proto.js using pbjs (Assuming pbjs is installed and accessible)
function generateProtoJS(callback) {
exec(protogenCmd.join(' '), (error, stdout, stderr) => {
if (error) {
console.error(`Error during code generation: ${error.message}`);
return;
}
console.log('Generated proto.js from proto file.');
callback();
});
}

generateProtoJS(() => {
console.log('all done 🎉');
});
7 changes: 7 additions & 0 deletions .yamlize/versions/14-latest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
env:
JOB: pg-14
LIBPG_REPO: https://github.com/pganalyze/libpg_query.git
LIBPG_COMMIT: 1577ef7c6c349542149e34ffbfafc244ab942ec6
LIBPG_BRANCH: 14-latest
PGSQL_TYPES: 14.0.0
OPERATION_SYSYTEMS: [linux,mac]
7 changes: 7 additions & 0 deletions .yamlize/versions/15-latest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
env:
JOB: pg-15
LIBPG_REPO: https://github.com/pganalyze/libpg_query.git
LIBPG_COMMIT: db39825bc7c1ddd45962ec6a626d740b7f8f027a
LIBPG_BRANCH: 15-latest
PGSQL_TYPES: 15.0.2
OPERATION_SYSYTEMS: [linux,mac]
7 changes: 7 additions & 0 deletions .yamlize/versions/16-latest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
env:
JOB: pg-16
LIBPG_REPO: https://github.com/pganalyze/libpg_query.git
LIBPG_COMMIT: 1ec38940e5c6f09a4c1d17a46d839a881c4f2db7
LIBPG_BRANCH: 16-latest
PGSQL_TYPES: 16.0.0
OPERATION_SYSYTEMS: [linux,mac,win]
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.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
}
},
"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",
Expand All @@ -40,6 +41,7 @@
"clean:wasm": "yarn make:wasm clean",
"clean-cache:wasm": "yarn make:wasm clean-cache",
"workflows": "node script/workflows.js",
"build:generate": "node script/utils/generate.js",
"test": "mocha --timeout 5000",
"binary:build": "node-pre-gyp rebuild package",
"binary:publish": "AWS_PROFILE=supabase-dev node-pre-gyp publish"
Expand All @@ -51,6 +53,7 @@
"url": "git://github.com/launchql/libpg-query-node.git"
},
"devDependencies": {
"@launchql/proto-cli": "1.25.0",
"@yamlize/cli": "^0.8.0",
"chai": "^3.5.0",
"emnapi": "^0.43.1",
Expand All @@ -60,8 +63,10 @@
},
"dependencies": {
"@emnapi/runtime": "^0.43.1",
"@launchql/protobufjs": "7.2.6",
"@mapbox/node-pre-gyp": "^1.0.8",
"@pgsql/types": "^15.0.1",
"@pgsql/types": "15.0.2",
"js-yaml": "^4.1.0",
"node-addon-api": "^7.0.0",
"node-gyp": "^10.0.1"
},
Expand All @@ -80,4 +85,4 @@
"host": "https://supabase-public-artifacts-bucket.s3.amazonaws.com",
"remote_path": "./libpg-query-node/"
}
}
}
Loading
Loading