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
16 changes: 15 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
- { name: 'v15', path: 'versions/15', version: '15' }
- { name: 'v16', path: 'versions/16', version: '16' }
- { name: 'v17', path: 'versions/17', version: '17' }
- { name: 'v18', path: 'versions/18', version: '18' }
fail-fast: false
steps:
- name: Checkout Repository 📥
Expand Down Expand Up @@ -83,6 +84,7 @@ jobs:
- { name: 'v15', path: 'versions/15', version: '15' }
- { name: 'v16', path: 'versions/16', version: '16' }
- { name: 'v17', path: 'versions/17', version: '17' }
- { name: 'v18', path: 'versions/18', version: '18' }
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -193,9 +195,15 @@ jobs:
name: wasm-artifacts-v17
path: versions/17/wasm/

- name: Download v18 WASM Artifacts 📥
uses: actions/download-artifact@v4
with:
name: wasm-artifacts-v18
path: versions/18/wasm/

- name: Build Types Packages 🏗
run: |
for version in 13 14 15 16 17; do
for version in 13 14 15 16 17 18; do
echo "Building types for v${version}..."
cd types/${version}
pnpm run build
Expand Down Expand Up @@ -285,6 +293,12 @@ jobs:
name: wasm-artifacts-v17
path: versions/17/wasm/

- name: Download v18 WASM Artifacts 📥
uses: actions/download-artifact@v4
with:
name: wasm-artifacts-v18
path: versions/18/wasm/

- name: Download Parser Artifacts 📥
uses: actions/download-artifact@v4
with:
Expand Down
14 changes: 7 additions & 7 deletions PUBLISH.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ This interactive script will:

The parser package supports multiple build configurations:

#### Full Build (all versions 13-17)
#### Full Build (all versions 13-18)
```bash
pnpm run publish:parser
# or with specific build type
PARSER_BUILD_TYPE=full pnpm run publish:parser
```

#### LTS Build (versions 16-17)
#### LTS Build (versions 15-18)
```bash
PARSER_BUILD_TYPE=lts pnpm run publish:parser
```
Expand Down Expand Up @@ -80,7 +80,7 @@ This command will:

```bash
# Set the version (e.g. 17, 16, 15, etc.)
VERSION=17
VERSION=18

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

```bash
# Set the version (e.g. 17, 16, 15, etc.)
VERSION=17
VERSION=18

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

```bash
# Set the version (e.g. 17, 16, 15, etc.)
VERSION=17
VERSION=18

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

```bash
# Set the version (e.g. 17, 16, 15, etc.)
VERSION=17
VERSION=18

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

# Build and publish a specific version
cd versions/${VERSION}
Expand Down
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/npm/dt/libpg-query"></a>
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/npm/dw/libpg-query"/></a>
<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>
<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 />
<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 />
<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>
<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>
<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>
Expand Down Expand Up @@ -40,14 +40,14 @@ Built to power [pgsql-parser](https://github.com/constructive-io/pgsql-parser),
### 🔀 Multi-Version Support with @pgsql/parser

> **Need to support multiple PostgreSQL versions at runtime?**
> 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!
> 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!
>
> ```typescript
> import { parse } from '@pgsql/parser';
>
> // Parse with specific PostgreSQL version
> const result15 = await parse('SELECT * FROM users', 15);
> const result17 = await parse('SELECT * FROM users', 17);
> const result18 = await parse('SELECT * FROM users', 18);
> ```

## Installation
Expand All @@ -62,7 +62,7 @@ npm install libpg-query
import { parse } from 'libpg-query';

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

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

| Package | Description | PostgreSQL Versions | npm Package |
|---------|-------------|---------------------|-------------|
| **[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) |
| **[@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) |
| **[@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) |
| **[@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) |
| **[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) |
| **[@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) |
| **[@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) |
| **[@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) |
| **[@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) |

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

```bash
# Install specific PostgreSQL version
npm install libpg-query@pg17 # PostgreSQL 17 (latest)
npm install libpg-query@pg18 # PostgreSQL 18 (latest)
npm install libpg-query@pg17 # PostgreSQL 17
npm install libpg-query@pg16 # PostgreSQL 16
npm install @pgsql/types@pg17 # Types for PostgreSQL 17
npm install @pgsql/types@pg18 # Types for PostgreSQL 18
npm install @pgsql/enums@pg15 # Enums for PostgreSQL 15

# Install latest (defaults to pg17)
# Install latest (defaults to pg18)
npm install libpg-query
npm install @pgsql/types
npm install @pgsql/enums
Expand All @@ -108,10 +109,10 @@ npm install @pgsql/enums

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

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

## Build Instructions
Expand Down
81 changes: 81 additions & 0 deletions enums/18/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# @pgsql/enums

<p align="center" width="100%">
<img height="120" src="https://github.com/constructive-io/pgsql-parser/assets/545047/6440fa7d-918b-4a3b-8d1b-755d85de8bea" />
</p>

<p align="center" width="100%">
<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>
<a href="https://www.npmjs.com/package/@pgsql/enums"><img height="20" src="https://img.shields.io/npm/dt/@pgsql/enums"></a>
<a href="https://www.npmjs.com/package/@pgsql/enums"><img height="20" src="https://img.shields.io/npm/dw/@pgsql/enums"/></a>
<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>
<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>
</p>

`@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.


## Installation

Install the package via npm:

```bash
npm install @pgsql/enums
```

## Usage

Here's a simple example showing how to work with enums, converting between enum names and their numeric values:

```ts
import { ObjectType } from '@pgsql/enums';

// Get the numeric value of an enum
const tableValue = ObjectType.OBJECT_TABLE;
console.log(tableValue); // 41

// Convert from value back to enum name
const enumName = ObjectType[41];
console.log(enumName); // "OBJECT_TABLE"

// Use in comparisons
if (someNode.objectType === ObjectType.OBJECT_TABLE) {
console.log("This is a table object");
}
```

## Versions

Our latest is built with PostgreSQL 17 enum definitions.

| PG Major Version | libpg_query | npm dist-tag
|--------------------------|-------------|---------|
| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/@pgsql/enums/v/latest)
| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/@pgsql/enums/v/pg16)
| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/@pgsql/enums/v/pg15)
| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/@pgsql/enums/v/pg14)
| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/@pgsql/enums/v/pg13)

## 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.
* [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/constructive-io/libpg-query-node): The real PostgreSQL parser exposed for Node.js, used primarily in `pgsql-parser` for parsing and deparsing SQL queries.

## Credits

**🛠 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).**


## 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.
18 changes: 18 additions & 0 deletions enums/18/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
transform: {
"^.+\\.tsx?$": [
"ts-jest",
{
babelConfig: false,
tsconfig: "tsconfig.json",
},
],
},
transformIgnorePatterns: [`/node_modules/*`],
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
modulePathIgnorePatterns: ["dist/*"]
};
39 changes: 39 additions & 0 deletions enums/18/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@libpg-query/enums18",
"version": "18.0.0",
"author": "Constructive <developers@constructive.io>",
"description": "PostgreSQL AST enums from the real Postgres parser",
"main": "index.js",
"module": "esm/index.js",
"types": "index.d.ts",
"homepage": "https://github.com/constructive-io/libpg-query-node",
"license": "MIT",
"publishConfig": {
"access": "public",
"directory": "dist"
},
"repository": {
"type": "git",
"url": "https://github.com/constructive-io/libpg-query-node"
},
"bugs": {
"url": "https://github.com/constructive-io/libpg-query-node/issues"
},
"x-publish": {
"publishName": "@pgsql/enums",
"distTag": "pg18"
},
"scripts": {
"copy": "copyfiles -f ../../LICENSE README.md package.json dist",
"clean": "rimraf dist",
"build": "pnpm run clean && tsc && tsc -p tsconfig.esm.json && pnpm run copy",
"build:dev": "pnpm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && pnpm run copy",
"build:proto": "ts-node scripts/pg-proto-parser",
"prepare:enums": "node -e \"require('../../scripts/prepare-enums.js').preparePackageForPublish('.')\"",
"lint": "eslint . --fix"
},
"keywords": [],
"devDependencies": {
"pg-proto-parser": "^1.28.2"
}
}
17 changes: 17 additions & 0 deletions enums/18/scripts/pg-proto-parser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PgProtoParser, PgProtoParserOptions } from 'pg-proto-parser';
import { resolve, join } from 'path';

const inFile: string = join(__dirname, '../../../protos/18/pg_query.proto');
const outDir: string = resolve(join(__dirname, '../src'));

const options: PgProtoParserOptions = {
outDir,
enums: {
enabled: true,
enumsAsTypeUnion: false,
filename: 'index.ts'
}
};
const parser = new PgProtoParser(inFile, options);

parser.write();
Loading
Loading