Skip to content

Commit eeecfcb

Browse files
authored
Merge pull request #149 from constructive-io/feat/pg18-setup
feat: add PostgreSQL 18 support
2 parents 99dee5f + 4d5170d commit eeecfcb

49 files changed

Lines changed: 10032 additions & 42 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
- { name: 'v15', path: 'versions/15', version: '15' }
2020
- { name: 'v16', path: 'versions/16', version: '16' }
2121
- { name: 'v17', path: 'versions/17', version: '17' }
22+
- { name: 'v18', path: 'versions/18', version: '18' }
2223
fail-fast: false
2324
steps:
2425
- name: Checkout Repository 📥
@@ -83,6 +84,7 @@ jobs:
8384
- { name: 'v15', path: 'versions/15', version: '15' }
8485
- { name: 'v16', path: 'versions/16', version: '16' }
8586
- { name: 'v17', path: 'versions/17', version: '17' }
87+
- { name: 'v18', path: 'versions/18', version: '18' }
8688
fail-fast: false
8789
runs-on: ${{ matrix.os }}
8890
steps:
@@ -193,9 +195,15 @@ jobs:
193195
name: wasm-artifacts-v17
194196
path: versions/17/wasm/
195197

198+
- name: Download v18 WASM Artifacts 📥
199+
uses: actions/download-artifact@v4
200+
with:
201+
name: wasm-artifacts-v18
202+
path: versions/18/wasm/
203+
196204
- name: Build Types Packages 🏗
197205
run: |
198-
for version in 13 14 15 16 17; do
206+
for version in 13 14 15 16 17 18; do
199207
echo "Building types for v${version}..."
200208
cd types/${version}
201209
pnpm run build
@@ -285,6 +293,12 @@ jobs:
285293
name: wasm-artifacts-v17
286294
path: versions/17/wasm/
287295

296+
- name: Download v18 WASM Artifacts 📥
297+
uses: actions/download-artifact@v4
298+
with:
299+
name: wasm-artifacts-v18
300+
path: versions/18/wasm/
301+
288302
- name: Download Parser Artifacts 📥
289303
uses: actions/download-artifact@v4
290304
with:

PUBLISH.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ This interactive script will:
4545

4646
The parser package supports multiple build configurations:
4747

48-
#### Full Build (all versions 13-17)
48+
#### Full Build (all versions 13-18)
4949
```bash
5050
pnpm run publish:parser
5151
# or with specific build type
5252
PARSER_BUILD_TYPE=full pnpm run publish:parser
5353
```
5454

55-
#### LTS Build (versions 16-17)
55+
#### LTS Build (versions 15-18)
5656
```bash
5757
PARSER_BUILD_TYPE=lts pnpm run publish:parser
5858
```
@@ -80,7 +80,7 @@ This command will:
8080

8181
```bash
8282
# Set the version (e.g. 17, 16, 15, etc.)
83-
VERSION=17
83+
VERSION=18
8484

8585
cd types/${VERSION}
8686
pnpm version patch
@@ -94,7 +94,7 @@ Promote to latest (optional)
9494

9595
```bash
9696
# Set the version (e.g. 17, 16, 15, etc.)
97-
VERSION=17
97+
VERSION=18
9898

9999
# Promote pg${VERSION} tag to latest
100100
npm dist-tag add @pgsql/types@pg${VERSION} latest
@@ -109,7 +109,7 @@ npm dist-tag add @pgsql/types@pg${VERSION} latest
109109

110110
```bash
111111
# Set the version (e.g. 17, 16, 15, etc.)
112-
VERSION=17
112+
VERSION=18
113113

114114
cd enums/${VERSION}
115115
pnpm version patch
@@ -123,7 +123,7 @@ Promote to latest (optional)
123123

124124
```bash
125125
# Set the version (e.g. 17, 16, 15, etc.)
126-
VERSION=17
126+
VERSION=18
127127

128128
# Promote pg${VERSION} tag to latest
129129
npm dist-tag add @pgsql/enums@pg${VERSION} latest
@@ -139,7 +139,7 @@ npm dist-tag add @pgsql/enums@pg${VERSION} latest
139139
### Quick Publish
140140
```bash
141141
# Set the version (e.g. 17, 16, 15, etc.)
142-
VERSION=17
142+
VERSION=18
143143

144144
# Build and publish a specific version
145145
cd versions/${VERSION}

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/npm/dt/libpg-query"></a>
99
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/npm/dw/libpg-query"/></a>
1010
<a href="https://github.com/constructive-io/libpg-query/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
11-
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/libpg-query-node?filename=versions%2F17%2Fpackage.json"/></a><br />
11+
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/libpg-query-node?filename=versions%2F18%2Fpackage.json"/></a><br />
1212
<a href="https://github.com/constructive-io/libpg-query-node/actions/workflows/ci.yml"><img height="20" src="https://github.com/constructive-io/libpg-query-node/actions/workflows/ci.yml/badge.svg" /></a>
1313
<a href="https://github.com/constructive-io/libpg-query-node/actions/workflows/ci.yml"><img height="20" src="https://img.shields.io/badge/macOS-available-333333?logo=apple&logoColor=white" /></a>
1414
<a href="https://github.com/constructive-io/libpg-query-node/actions/workflows/ci.yml"><img height="20" src="https://img.shields.io/badge/Windows-available-333333?logo=windows&logoColor=white" /></a>
@@ -40,14 +40,14 @@ Built to power [pgsql-parser](https://github.com/constructive-io/pgsql-parser),
4040
### 🔀 Multi-Version Support with @pgsql/parser
4141

4242
> **Need to support multiple PostgreSQL versions at runtime?**
43-
> Use [`@pgsql/parser`](https://github.com/constructive-io/libpg-query-node/tree/main/parser) for dynamic version selection — parse SQL with PostgreSQL 15, 16, or 17 in a single package!
43+
> Use [`@pgsql/parser`](https://github.com/constructive-io/libpg-query-node/tree/main/parser) for dynamic version selection — parse SQL with PostgreSQL 15, 16, 17, or 18 in a single package!
4444
>
4545
> ```typescript
4646
> import { parse } from '@pgsql/parser';
4747
>
4848
> // Parse with specific PostgreSQL version
4949
> const result15 = await parse('SELECT * FROM users', 15);
50-
> const result17 = await parse('SELECT * FROM users', 17);
50+
> const result18 = await parse('SELECT * FROM users', 18);
5151
> ```
5252
5353
## Installation
@@ -62,7 +62,7 @@ npm install libpg-query
6262
import { parse } from 'libpg-query';
6363

6464
const result = await parse('SELECT * FROM users WHERE active = true');
65-
// {"version":170004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]}
65+
// {"version":180004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]}
6666
```
6767

6868
## 📦 Packages
@@ -73,10 +73,10 @@ This repository contains multiple packages to support different PostgreSQL versi
7373

7474
| Package | Description | PostgreSQL Versions | npm Package |
7575
|---------|-------------|---------------------|-------------|
76-
| **[libpg-query](https://github.com/constructive-io/libpg-query-node/tree/main/versions)** | Lightweight parser (parse only) | 13, 14, 15, 16, 17 | [`libpg-query`](https://www.npmjs.com/package/libpg-query) |
77-
| **[@pgsql/parser](https://github.com/constructive-io/libpg-query-node/tree/main/parser)** | Multi-version parser (runtime selection) | 15, 16, 17 | [`@pgsql/parser`](https://www.npmjs.com/package/@pgsql/parser) |
78-
| **[@pgsql/types](https://github.com/constructive-io/libpg-query-node/tree/main/types)** | TypeScript type definitions | 13, 14, 15, 16, 17 | [`@pgsql/types`](https://www.npmjs.com/package/@pgsql/types) |
79-
| **[@pgsql/enums](https://github.com/constructive-io/libpg-query-node/tree/main/enums)** | TypeScript enum definitions | 13, 14, 15, 16, 17 | [`@pgsql/enums`](https://www.npmjs.com/package/@pgsql/enums) |
76+
| **[libpg-query](https://github.com/constructive-io/libpg-query-node/tree/main/versions)** | Lightweight parser (parse only) | 13, 14, 15, 16, 17, 18 | [`libpg-query`](https://www.npmjs.com/package/libpg-query) |
77+
| **[@pgsql/parser](https://github.com/constructive-io/libpg-query-node/tree/main/parser)** | Multi-version parser (runtime selection) | 15, 16, 17, 18 | [`@pgsql/parser`](https://www.npmjs.com/package/@pgsql/parser) |
78+
| **[@pgsql/types](https://github.com/constructive-io/libpg-query-node/tree/main/types)** | TypeScript type definitions | 13, 14, 15, 16, 17, 18 | [`@pgsql/types`](https://www.npmjs.com/package/@pgsql/types) |
79+
| **[@pgsql/enums](https://github.com/constructive-io/libpg-query-node/tree/main/enums)** | TypeScript enum definitions | 13, 14, 15, 16, 17, 18 | [`@pgsql/enums`](https://www.npmjs.com/package/@pgsql/enums) |
8080
| **[@libpg-query/parser](https://github.com/constructive-io/libpg-query-node/tree/main/full)** | Full parser with all features | 17 only | [`@libpg-query/parser`](https://www.npmjs.com/package/@libpg-query/parser) |
8181

8282
### Version Tags
@@ -85,12 +85,13 @@ Each versioned package uses npm dist-tags for PostgreSQL version selection:
8585

8686
```bash
8787
# Install specific PostgreSQL version
88-
npm install libpg-query@pg17 # PostgreSQL 17 (latest)
88+
npm install libpg-query@pg18 # PostgreSQL 18 (latest)
89+
npm install libpg-query@pg17 # PostgreSQL 17
8990
npm install libpg-query@pg16 # PostgreSQL 16
90-
npm install @pgsql/types@pg17 # Types for PostgreSQL 17
91+
npm install @pgsql/types@pg18 # Types for PostgreSQL 18
9192
npm install @pgsql/enums@pg15 # Enums for PostgreSQL 15
9293

93-
# Install latest (defaults to pg17)
94+
# Install latest (defaults to pg18)
9495
npm install libpg-query
9596
npm install @pgsql/types
9697
npm install @pgsql/enums
@@ -108,10 +109,10 @@ npm install @pgsql/enums
108109

109110
For detailed API documentation and usage examples, see the package-specific READMEs:
110111

111-
- **libpg-query** - [Parser API Documentation](https://github.com/constructive-io/libpg-query-node/tree/main/versions/17)
112+
- **libpg-query** - [Parser API Documentation](https://github.com/constructive-io/libpg-query-node/tree/main/versions/18)
112113
- **@pgsql/parser** - [Multi-Version Parser Documentation](https://github.com/constructive-io/libpg-query-node/tree/main/parser)
113-
- **@pgsql/types** - [Types Documentation](https://github.com/constructive-io/libpg-query-node/tree/main/types/17)
114-
- **@pgsql/enums** - [Enums Documentation](https://github.com/constructive-io/libpg-query-node/tree/main/enums/17)
114+
- **@pgsql/types** - [Types Documentation](https://github.com/constructive-io/libpg-query-node/tree/main/types/18)
115+
- **@pgsql/enums** - [Enums Documentation](https://github.com/constructive-io/libpg-query-node/tree/main/enums/18)
115116
- **@libpg-query/parser** - [Full Parser Documentation](https://github.com/constructive-io/libpg-query-node/tree/main/full)
116117

117118
## Build Instructions

enums/18/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# @pgsql/enums
2+
3+
<p align="center" width="100%">
4+
<img height="120" src="https://github.com/constructive-io/pgsql-parser/assets/545047/6440fa7d-918b-4a3b-8d1b-755d85de8bea" />
5+
</p>
6+
7+
<p align="center" width="100%">
8+
<a href="https://github.com/constructive-io/libpg-query-node/actions/workflows/ci.yml">
9+
<img height="20" src="https://github.com/constructive-io/libpg-query-node/actions/workflows/ci.yml/badge.svg" />
10+
</a>
11+
<a href="https://www.npmjs.com/package/@pgsql/enums"><img height="20" src="https://img.shields.io/npm/dt/@pgsql/enums"></a>
12+
<a href="https://www.npmjs.com/package/@pgsql/enums"><img height="20" src="https://img.shields.io/npm/dw/@pgsql/enums"/></a>
13+
<a href="https://github.com/constructive-io/libpg-query-node/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
14+
<a href="https://www.npmjs.com/package/@pgsql/enums"><img height="20" src="https://img.shields.io/github/package-json/v/constructive-io/libpg-query-node?filename=enums%2F17%2Fpackage.json"/></a>
15+
</p>
16+
17+
`@pgsql/enums` is a TypeScript library providing enum definitions for PostgreSQL AST nodes, primarily used in conjunction with [`pgsql-parser`](https://github.com/constructive-io/pgsql-parser). It offers a comprehensive and type-safe way to work with PostgreSQL enum values in query parsing and AST manipulation.
18+
19+
20+
## Installation
21+
22+
Install the package via npm:
23+
24+
```bash
25+
npm install @pgsql/enums
26+
```
27+
28+
## Usage
29+
30+
Here's a simple example showing how to work with enums, converting between enum names and their numeric values:
31+
32+
```ts
33+
import { ObjectType } from '@pgsql/enums';
34+
35+
// Get the numeric value of an enum
36+
const tableValue = ObjectType.OBJECT_TABLE;
37+
console.log(tableValue); // 41
38+
39+
// Convert from value back to enum name
40+
const enumName = ObjectType[41];
41+
console.log(enumName); // "OBJECT_TABLE"
42+
43+
// Use in comparisons
44+
if (someNode.objectType === ObjectType.OBJECT_TABLE) {
45+
console.log("This is a table object");
46+
}
47+
```
48+
49+
## Versions
50+
51+
Our latest is built with PostgreSQL 17 enum definitions.
52+
53+
| PG Major Version | libpg_query | npm dist-tag
54+
|--------------------------|-------------|---------|
55+
| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/@pgsql/enums/v/latest)
56+
| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/@pgsql/enums/v/pg16)
57+
| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/@pgsql/enums/v/pg15)
58+
| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/@pgsql/enums/v/pg14)
59+
| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/@pgsql/enums/v/pg13)
60+
61+
## Related
62+
63+
* [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.
64+
* [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`.
65+
* [@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.
66+
* [@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.
67+
* [@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.
68+
* [@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.
69+
* [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.
70+
* [libpg-query](https://github.com/constructive-io/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries.
71+
72+
## Credits
73+
74+
**🛠 Built by the [Constructive](https://constructive.io) team — creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on [GitHub](https://github.com/constructive-io).**
75+
76+
77+
## Disclaimer
78+
79+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
80+
81+
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.

enums/18/jest.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: "ts-jest",
4+
testEnvironment: "node",
5+
transform: {
6+
"^.+\\.tsx?$": [
7+
"ts-jest",
8+
{
9+
babelConfig: false,
10+
tsconfig: "tsconfig.json",
11+
},
12+
],
13+
},
14+
transformIgnorePatterns: [`/node_modules/*`],
15+
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
16+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
17+
modulePathIgnorePatterns: ["dist/*"]
18+
};

enums/18/package.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "@libpg-query/enums18",
3+
"version": "18.0.0",
4+
"author": "Constructive <developers@constructive.io>",
5+
"description": "PostgreSQL AST enums from the real Postgres parser",
6+
"main": "index.js",
7+
"module": "esm/index.js",
8+
"types": "index.d.ts",
9+
"homepage": "https://github.com/constructive-io/libpg-query-node",
10+
"license": "MIT",
11+
"publishConfig": {
12+
"access": "public",
13+
"directory": "dist"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/constructive-io/libpg-query-node"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/constructive-io/libpg-query-node/issues"
21+
},
22+
"x-publish": {
23+
"publishName": "@pgsql/enums",
24+
"distTag": "pg18"
25+
},
26+
"scripts": {
27+
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
28+
"clean": "rimraf dist",
29+
"build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && pnpm run copy",
30+
"build:dev": "pnpm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && pnpm run copy",
31+
"build:proto": "ts-node scripts/pg-proto-parser",
32+
"prepare:enums": "node -e \"require('../../scripts/prepare-enums.js').preparePackageForPublish('.')\"",
33+
"lint": "eslint . --fix"
34+
},
35+
"keywords": [],
36+
"devDependencies": {
37+
"pg-proto-parser": "^1.28.2"
38+
}
39+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { PgProtoParser, PgProtoParserOptions } from 'pg-proto-parser';
2+
import { resolve, join } from 'path';
3+
4+
const inFile: string = join(__dirname, '../../../protos/18/pg_query.proto');
5+
const outDir: string = resolve(join(__dirname, '../src'));
6+
7+
const options: PgProtoParserOptions = {
8+
outDir,
9+
enums: {
10+
enabled: true,
11+
enumsAsTypeUnion: false,
12+
filename: 'index.ts'
13+
}
14+
};
15+
const parser = new PgProtoParser(inFile, options);
16+
17+
parser.write();

0 commit comments

Comments
 (0)