Skip to content

Commit a517d81

Browse files
committed
traverse
1 parent e0a4cd0 commit a517d81

File tree

7 files changed

+10089
-13
lines changed

7 files changed

+10089
-13
lines changed

.github/workflows/run-tests.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ jobs:
2626
run: cd ./packages/utils && yarn test
2727

2828
- name: transform
29-
run: cd ./packages/transform && yarn test
29+
run: cd ./packages/transform && yarn test
30+
31+
- name: traverse
32+
run: cd ./packages/traverse && yarn test

packages/traverse/README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# @pgsql/traverse
22

3+
<p align="center" width="100%">
4+
<img height="120" src="https://github.com/launchql/pgsql-parser/assets/545047/6440fa7d-918b-4a3b-8d1b-755d85de8bea" />
5+
</p>
6+
7+
8+
<p align="center" width="100%">
9+
<a href="https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml">
10+
<img height="20" src="https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml/badge.svg" />
11+
</a>
12+
<a href="https://github.com/launchql/pgsql-parser/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
13+
</p>
14+
15+
316
PostgreSQL AST traversal utilities for pgsql-parser. This package provides a visitor pattern for traversing PostgreSQL Abstract Syntax Tree (AST) nodes, similar to Babel's traverse functionality but specifically designed for PostgreSQL AST structures.
417

518
## Installation
@@ -284,11 +297,17 @@ visit(ast, visitor);
284297

285298
## Related
286299

287-
* [pgsql-parser](https://www.npmjs.com/package/pgsql-parser): The real PostgreSQL parser for Node.js
288-
* [pgsql-deparser](https://www.npmjs.com/package/pgsql-deparser): Convert PostgreSQL ASTs back into SQL queries
289-
* [@pgsql/types](https://www.npmjs.com/package/@pgsql/types): TypeScript type definitions for PostgreSQL AST nodes
290-
* [@pgsql/utils](https://www.npmjs.com/package/@pgsql/utils): Utility library for PostgreSQL AST node creation
300+
* [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.
301+
* [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`.
302+
* [@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.
303+
* [@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.
304+
* [@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.
305+
* [@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.
306+
* [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.
307+
* [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.
308+
309+
## Disclaimer
291310

292-
## License
311+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
293312

294-
SEE LICENSE IN LICENSE
313+
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.

packages/traverse/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pgsql/traverse",
3-
"version": "17.7.6",
3+
"version": "1.0.0",
44
"author": "Dan Lynch <[email protected]>",
55
"description": "PostgreSQL AST traversal utilities for pgsql-parser",
66
"main": "index.js",
@@ -25,13 +25,14 @@
2525
"prepare": "npm run build",
2626
"build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
2727
"build:dev": "npm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && npm run copy",
28+
"build:proto": "ts-node scripts/pg-proto-parser",
2829
"lint": "eslint . --fix",
2930
"test": "jest",
3031
"test:watch": "jest --watch"
3132
},
3233
"dependencies": {
3334
"@pgsql/types": "^17.6.1",
34-
"@pgsql/transform": "^17.7.1"
35+
"pg-proto-parser": "^1.29.1"
3536
},
3637
"keywords": [
3738
"sql",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { PgProtoParser, PgProtoParserOptions } from 'pg-proto-parser';
2+
import { resolve, join } from 'path';
3+
4+
const versions = ['17'];
5+
const baseDir = resolve(join(__dirname, '../../../__fixtures__/proto'));
6+
7+
for (const version of versions) {
8+
const inFile = join(baseDir, `${version}-latest.proto`);
9+
const outDir = resolve(join(__dirname, `../src/${version}`));
10+
11+
const options: PgProtoParserOptions = {
12+
outDir,
13+
runtimeSchema: {
14+
enabled: true,
15+
filename: 'runtime-schema.ts',
16+
format: 'typescript'
17+
}
18+
};
19+
20+
const parser = new PgProtoParser(inFile, options);
21+
parser.write();
22+
}

0 commit comments

Comments
 (0)