Skip to content
Merged
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
41 changes: 25 additions & 16 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,36 @@ on:
jobs:
parser-tests:
runs-on: ubuntu-latest
strategy:
matrix:
package:
- deparser
- parser
- pgsql-cli
- proto-parser
- transform
- traverse
- utils
steps:
- name: checkout
uses: actions/checkout@v3

- name: deps
run: yarn
- name: setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: build
run: yarn build

- name: deparser
run: cd ./packages/deparser && yarn test
- name: setup node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'

- name: proto-parser
run: cd ./packages/proto-parser && yarn test
- name: install dependencies
run: pnpm install

- name: utils
run: cd ./packages/utils && yarn test

- name: transform
run: cd ./packages/transform && yarn test
- name: build
run: pnpm build

- name: traverse
run: cd ./packages/traverse && yarn test
- name: test
run: pnpm --filter ${{ matrix.package }} test
17 changes: 17 additions & 0 deletions FOOTER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Related

* [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration.
* [pgsql-deparser](https://www.npmjs.com/package/pgsql-deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
* [@pgsql/parser](https://www.npmjs.com/package/@pgsql/parser): Multi-version PostgreSQL parser with dynamic version selection at runtime, supporting PostgreSQL 15, 16, and 17 in a single package.
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
* [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): Provides TypeScript enum definitions for PostgreSQL constants, enabling type-safe usage of PostgreSQL enums and constants in your applications.
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs.
* [@pgsql/traverse](https://www.npmjs.com/package/@pgsql/traverse): PostgreSQL AST traversal utilities for pgsql-parser, providing a visitor pattern for traversing PostgreSQL Abstract Syntax Tree nodes, similar to Babel's traverse functionality but specifically designed for PostgreSQL AST structures.
* [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
* [libpg-query](https://github.com/launchql/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries.

## Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
12 changes: 6 additions & 6 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"lerna": "6",
"conventionalCommits": true,
"npmClient": "yarn",
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "independent",
"npmClient": "pnpm",
"npmClientArgs": [
"--no-lockfile"
"--frozen-lockfile"
],
"packages": [
"packages/*"
],
"version": "independent",
"registry": "https://registry.npmjs.org",
"command": {
"create": {
Expand All @@ -18,7 +17,8 @@
},
"publish": {
"allowBranch": "main",
"message": "chore(release): publish"
"message": "chore(release): publish",
"conventionalCommits": true
}
}
}
39 changes: 18 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,33 @@
"packages/*"
],
"scripts": {
"clean": "lerna run clean",
"build": "lerna run build --stream",
"build:dev": "lerna run build:dev --stream; yarn symlink",
"lint": "lerna run lint --parallel",
"symlink": "symlink-workspace --logLevel error",
"postinstall": "yarn symlink",
"bump-versions": "ts-node scripts/bump-versions.ts"
"build": "pnpm -r run build",
"clean": "pnpm -r run clean",
"test": "pnpm -r run test",
"lint": "pnpm -r run lint",
"deps": "pnpm up -r -i -L",
"bump-versions": "ts-node scripts/bump-versions.ts",
"update-workspace": "makage update-workspace"
},
"devDependencies": {
"@types/jest": "^29.5.11",
"@types/jest": "^30.0.0",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"copyfiles": "^2.4.1",
"eslint-config-prettier": "^9.1.0",
"@typescript-eslint/eslint-plugin": "^8.47.0",
"@typescript-eslint/parser": "^8.47.0",
"eslint": "^9.39.1",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-simple-import-sort": "^12.1.0",
"eslint-plugin-unused-imports": "^4.0.0",
"eslint": "^8.56.0",
"glob": "^11.0.0",
"jest": "^29.6.2",
"jest-diff": "30.0.0",
"lerna": "^6",
"jest": "^30.2.0",
"jest-diff": "30.2.0",
"lerna": "^8.2.4",
"makage": "^0.1.3",
"prettier": "^3.0.2",
"rimraf": "4.4.1",
"strip-ansi": "^6",
"semver": "^7.7.2",
"symlink-workspace": "^1.10.0",
"strip-ansi": "^6",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.1.6"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
}
20 changes: 1 addition & 19 deletions packages/deparser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,4 @@ Built on the excellent work of several contributors:
* **[Lukas Fittl](https://github.com/lfittl)** for [libpg_query](https://github.com/pganalyze/libpg_query) — the core PostgreSQL parser that powers this project
* **[Greg Richardson](https://github.com/gregnr)** for AST guidance and pushing the transition to WASM and multiple PG runtimes for better interoperability
* **[Ethan Resnick](https://github.com/ethanresnick)** for the original Node.js N-API bindings
* **[Zac McCormick](https://github.com/zhm)** for the foundational [node-pg-query-native](https://github.com/zhm/node-pg-query-native) parser

## Related

* [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration.
* [pgsql-deparser](https://www.npmjs.com/package/pgsql-deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
* [@pgsql/parser](https://www.npmjs.com/package/@pgsql/parser): Multi-version PostgreSQL parser with dynamic version selection at runtime, supporting PostgreSQL 15, 16, and 17 in a single package.
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
* [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): Provides TypeScript enum definitions for PostgreSQL constants, enabling type-safe usage of PostgreSQL enums and constants in your applications.
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs.
* [@pgsql/traverse](https://www.npmjs.com/package/@pgsql/traverse): PostgreSQL AST traversal utilities for pgsql-parser, providing a visitor pattern for traversing PostgreSQL Abstract Syntax Tree nodes, similar to Babel's traverse functionality but specifically designed for PostgreSQL AST structures.
* [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
* [libpg-query](https://github.com/launchql/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries.

## Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
* **[Zac McCormick](https://github.com/zhm)** for the foundational [node-pg-query-native](https://github.com/zhm/node-pg-query-native) parser
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`should format foreign key constraint with pretty option enabled 1`] = `"SELECT '123'::int;"`;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`should format pg_catalog.char with pretty option enabled 1`] = `
"CREATE TABLE dashboard_jobs.jobs (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: original/alter/alter-table-column-1.sql 1`] = `"ALTER TABLE public.table1 ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (SEQUENCE NAME public.table1 START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1)"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/casing-1.sql 1`] = `"INSERT INTO users (name) VALUES ('John Doe')"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/constraints-1.sql 1`] = `"ALTER TABLE public.users ADD CONSTRAINT users_pkey PRIMARY KEY (id)"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/create_policy-1.sql 1`] = `"CREATE POLICY user_policy ON users AS PERMISSIVE FOR ALL TO authenticated_users USING (user_id = current_user_id())"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/create_table-1.sql 1`] = `"CREATE TABLE users (id serial PRIMARY KEY, name text NOT NULL, email text UNIQUE)"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/cte-1.sql 1`] = `"WITH regional_sales AS (SELECT region, sum(sales_amount) AS total_sales FROM sales GROUP BY region) SELECT * FROM regional_sales"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/misc-1.sql 1`] = `"WITH recent_orders AS (SELECT o.id, o.user_id, o.created_at FROM orders AS o WHERE o.created_at > (now() - '30 days'::interval)), high_value_orders AS (SELECT r.user_id, count(*) AS order_count, sum(oi.price * oi.quantity) AS total_spent FROM recent_orders AS r JOIN order_items AS oi ON r.id = oi.order_id GROUP BY r.user_id) SELECT u.id, u.name, h.total_spent FROM users AS u JOIN high_value_orders AS h ON u.id = h.user_id WHERE h.total_spent > 1000 ORDER BY h.total_spent DESC"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: misc/pg_catalog-1.sql 1`] = `"SELECT pg_catalog.json_object('{}')"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/procedures-1.sql 1`] = `"SELECT handle_insert('TYPE_A')"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/selects-1.sql 1`] = `"SELECT 1"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/tables-1.sql 1`] = `"CREATE TABLE public.users (id serial PRIMARY KEY, name text NOT NULL)"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/triggers-1.sql 1`] = `"CREATE TRIGGER audit_insert_trigger AFTER INSERT ON public.users FOR EACH ROW EXECUTE FUNCTION log_user_insert ()"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`non-pretty: pretty/types-1.sql 1`] = `"CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy')"`;

Expand Down
9 changes: 5 additions & 4 deletions packages/deparser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
"url": "https://github.com/launchql/pgsql-parser/issues"
},
"scripts": {
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
"clean": "rimraf dist",
"prepare": "npm run build",
"copy": "makage assets",
"clean": "makage clean dist",
"prepublishOnly": "npm run build",
"build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
"build:dev": "npm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && npm run copy",
"kitchen-sink": "npm run fixtures && npm run fixtures:kitchen-sink",
Expand Down Expand Up @@ -53,7 +53,8 @@
"database"
],
"devDependencies": {
"libpg-query": "17.6.0"
"libpg-query": "17.6.0",
"makage": "^0.1.3"
},
"dependencies": {
"@pgsql/types": "^17.6.1"
Expand Down
1 change: 0 additions & 1 deletion packages/deparser/test-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { deparseSync as deparse, DeparserOptions } from '../src';
import { cleanTree } from '../scripts/clean-utils';
import { readFileSync } from 'fs';
import * as path from 'path';
import { expect } from '@jest/globals';
import { diff } from 'jest-diff'

export async function expectParseDeparse(sql1: string, options: DeparserOptions = { pretty: false }) {
Expand Down
20 changes: 1 addition & 19 deletions packages/parser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,4 @@ Built on the excellent work of several contributors:
* **[Lukas Fittl](https://github.com/lfittl)** for [libpg_query](https://github.com/pganalyze/libpg_query) — the core PostgreSQL parser that powers this project
* **[Greg Richardson](https://github.com/gregnr)** for AST guidance and pushing the transition to WASM and multiple PG runtimes for better interoperability
* **[Ethan Resnick](https://github.com/ethanresnick)** for the original Node.js N-API bindings
* **[Zac McCormick](https://github.com/zhm)** for the foundational [node-pg-query-native](https://github.com/zhm/node-pg-query-native) parser

## Related

* [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration.
* [pgsql-deparser](https://www.npmjs.com/package/pgsql-deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
* [@pgsql/parser](https://www.npmjs.com/package/@pgsql/parser): Multi-version PostgreSQL parser with dynamic version selection at runtime, supporting PostgreSQL 15, 16, and 17 in a single package.
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
* [@pgsql/enums](https://www.npmjs.com/package/@pgsql/enums): Provides TypeScript enum definitions for PostgreSQL constants, enabling type-safe usage of PostgreSQL enums and constants in your applications.
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): A comprehensive utility library for PostgreSQL, offering type-safe AST node creation and enum value conversions, simplifying the construction and manipulation of PostgreSQL ASTs.
* [@pgsql/traverse](https://www.npmjs.com/package/@pgsql/traverse): PostgreSQL AST traversal utilities for pgsql-parser, providing a visitor pattern for traversing PostgreSQL Abstract Syntax Tree nodes, similar to Babel's traverse functionality but specifically designed for PostgreSQL AST structures.
* [pg-proto-parser](https://www.npmjs.com/package/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
* [libpg-query](https://github.com/launchql/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries.

## Disclaimer

AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.

No developer or entity involved in creating Software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the Software code or Software CLI, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
* **[Zac McCormick](https://github.com/zhm)** for the foundational [node-pg-query-native](https://github.com/zhm/node-pg-query-native) parser
Loading