Skip to content
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
4,234 changes: 4,234 additions & 0 deletions protos/18/pg_query.proto

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions scripts/fetch-protos.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function getVersionMappings() {
const versionsDir = path.join(__dirname, '..', 'versions');
const mappings = [];

for (const version of ['13', '14', '15', '16', '17']) {
for (const version of ['13', '14', '15', '16', '17', '18']) {
const packagePath = path.join(versionsDir, version, 'package.json');
if (fs.existsSync(packagePath)) {
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
Expand Down Expand Up @@ -70,7 +70,9 @@ async function fetchProtos() {
}

// Use the libpgQueryTag from the Makefile
const url = `https://raw.githubusercontent.com/pganalyze/libpg_query/refs/tags/${libpgQueryTag}/protobuf/pg_query.proto`;
// For dev branches (containing 'dev'), use refs/heads/, otherwise use refs/tags/
const refType = libpgQueryTag.includes('dev') ? 'heads' : 'tags';
const url = `https://raw.githubusercontent.com/pganalyze/libpg_query/refs/${refType}/${libpgQueryTag}/protobuf/pg_query.proto`;
const destPath = path.join(versionDir, 'pg_query.proto');

console.log(`Fetching protobuf for PostgreSQL ${pgVersion} with tag ${libpgQueryTag}...`);
Expand All @@ -93,4 +95,4 @@ if (require.main === module) {
fetchProtos().catch(console.error);
}

module.exports = { fetchProtos, getVersionMappings };
module.exports = { fetchProtos, getVersionMappings };
22 changes: 22 additions & 0 deletions versions/18/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2021 Dan Lynch <pyramation@gmail.com>
Copyright (c) 2025 Constructive <developers@constructive.io>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
99 changes: 99 additions & 0 deletions versions/18/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# DO NOT MODIFY MANUALLY — this is generated from the templates dir
#
# To make changes, edit the files in the templates/ directory and run:
# npm run copy:templates

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 := 18-latest-dev

CACHE_DIR := .cache

OS ?= $(shell uname -s)
ARCH ?= $(shell uname -m)

ifdef EMSCRIPTEN
PLATFORM := emscripten
else ifeq ($(OS),Darwin)
PLATFORM := darwin
else ifeq ($(OS),Linux)
PLATFORM := linux
else
$(error Unsupported platform: $(OS))
endif

ifdef EMSCRIPTEN
ARCH := wasm
endif

PLATFORM_ARCH := $(PLATFORM)-$(ARCH)
SRC_FILES := src/wasm_wrapper.c
LIBPG_QUERY_DIR := $(CACHE_DIR)/$(PLATFORM_ARCH)/libpg_query/$(LIBPG_QUERY_TAG)
LIBPG_QUERY_ARCHIVE := $(LIBPG_QUERY_DIR)/libpg_query.a
LIBPG_QUERY_HEADER := $(LIBPG_QUERY_DIR)/pg_query.h
CXXFLAGS := -O3 -flto

ifdef EMSCRIPTEN
OUT_FILES := $(foreach EXT,.js .wasm,$(WASM_OUT_DIR)/$(WASM_OUT_NAME)$(EXT))
else
$(error Native builds are no longer supported. Use EMSCRIPTEN=1 for WASM builds only.)
endif

# Clone libpg_query source (lives in CACHE_DIR)
$(LIBPG_QUERY_DIR):
mkdir -p $(CACHE_DIR)
git clone -b $(LIBPG_QUERY_TAG) --single-branch $(LIBPG_QUERY_REPO) $(LIBPG_QUERY_DIR)

$(LIBPG_QUERY_HEADER): $(LIBPG_QUERY_DIR)

# Build libpg_query
$(LIBPG_QUERY_ARCHIVE): $(LIBPG_QUERY_DIR)
cd $(LIBPG_QUERY_DIR); $(MAKE) build

# Build libpg-query-node WASM module
$(OUT_FILES): $(LIBPG_QUERY_ARCHIVE) $(LIBPG_QUERY_HEADER) $(SRC_FILES)
ifdef EMSCRIPTEN
mkdir -p $(WASM_OUT_DIR)
$(CC) \
-v \
$(CXXFLAGS) \
-I$(LIBPG_QUERY_DIR) \
-I$(LIBPG_QUERY_DIR)/vendor \
-L$(LIBPG_QUERY_DIR) \
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
-sENVIRONMENT="web,node,worker" \
-sASSERTIONS=0 \
-sSINGLE_FILE=0 \
-sMODULARIZE=1 \
-sEXPORT_ES6=0 \
-sALLOW_MEMORY_GROWTH=1 \
-sINITIAL_MEMORY=134217728 \
-sMAXIMUM_MEMORY=1073741824 \
-sSTACK_SIZE=33554432 \
-lpg_query \
-o $@ \
$(SRC_FILES)
else
$(error Native builds are no longer supported. Use EMSCRIPTEN=1 for WASM builds only.)
endif

# Commands
build: $(OUT_FILES)

build-cache: $(LIBPG_QUERY_ARCHIVE) $(LIBPG_QUERY_HEADER)

rebuild: clean build

rebuild-cache: clean-cache build-cache

clean:
-@ rm -r $(OUT_FILES) > /dev/null 2>&1

clean-cache:
-@ rm -rf $(LIBPG_QUERY_DIR)

.PHONY: build build-cache rebuild rebuild-cache clean clean-cache
52 changes: 52 additions & 0 deletions versions/18/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@libpg-query/v18",
"version": "18.0.0-dev.0",
"description": "The real PostgreSQL query parser (PG 18 dev)",
"homepage": "https://github.com/constructive-io/libpg-query-node",
"main": "./wasm/index.cjs",
"module": "./wasm/index.js",
"typings": "./wasm/index.d.ts",
"publishConfig": {
"access": "public"
},
"x-publish": {
"publishName": "libpg-query",
"pgVersion": "18",
"distTag": "pg18-dev",
"libpgQueryTag": "18-latest-dev"
},
"files": [
"wasm/*"
],
"scripts": {
"clean": "pnpm wasm:clean && rimraf wasm/*.js wasm/*.cjs wasm/*.d.ts",
"build:js": "node scripts/build.js",
"build": "pnpm clean && pnpm wasm:build && pnpm build:js",
"publish:pkg": "node ../../scripts/publish-single-version.js",
"wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make",
"wasm:build": "pnpm wasm:make build",
"wasm:rebuild": "pnpm wasm:make rebuild",
"wasm:clean": "pnpm wasm:make clean",
"wasm:clean-cache": "pnpm wasm:make clean-cache",
"test": "node --test test/parsing.test.js test/errors.test.js"
},
"author": "Constructive <developers@constructive.io>",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/constructive-io/libpg-query-node.git"
},
"devDependencies": {},
"dependencies": {
"@pgsql/types": "^17.6.2"
},
"keywords": [
"sql",
"postgres",
"postgresql",
"pg",
"query",
"plpgsql",
"database"
]
}
39 changes: 39 additions & 0 deletions versions/18/scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

// Run TypeScript compilation
console.log('Compiling TypeScript...');
const tscPath = path.join(__dirname, '../../../node_modules/.bin/tsc');
execSync(`${tscPath}`, { stdio: 'inherit', cwd: path.join(__dirname, '..') });
execSync(`${tscPath} -p tsconfig.esm.json`, { stdio: 'inherit', cwd: path.join(__dirname, '..') });

// Rename files to have correct extensions
const wasmDir = path.join(__dirname, '../wasm');
const cjsDir = path.join(__dirname, '../cjs');
const esmDir = path.join(__dirname, '../esm');

// Ensure wasm directory exists
if (!fs.existsSync(wasmDir)) {
fs.mkdirSync(wasmDir, { recursive: true });
}

// Rename CommonJS files
fs.renameSync(
path.join(cjsDir, 'index.js'),
path.join(wasmDir, 'index.cjs')
);

// Rename ESM files
fs.renameSync(
path.join(esmDir, 'index.js'),
path.join(wasmDir, 'index.js')
);

// Rename declaration files
fs.renameSync(
path.join(cjsDir, 'index.d.ts'),
path.join(wasmDir, 'index.d.ts')
);

console.log('Build completed successfully!');
Loading