Skip to content

Commit b446eb2

Browse files
committed
enums
1 parent de48621 commit b446eb2

40 files changed

+6442
-3
lines changed

enums/13/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# @pgsql/enums
2+
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+
<p align="center" width="100%">
8+
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/ci.yml">
9+
<img height="20" src="https://github.com/launchql/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/launchql/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/launchql/libpg-query-node?filename=packages%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/launchql/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+
`@pgsql/enums` provides TypeScript enum definitions for PostgreSQL Abstract Syntax Tree (AST) nodes. These enums are useful for constructing, analyzing, or manipulating ASTs in a type-safe manner with exact enum values.
31+
32+
Here are a few examples of how you can use these enums in your TypeScript projects:
33+
34+
### Using Enum Values
35+
36+
You can use the enums to work with specific PostgreSQL AST enum values:
37+
38+
```ts
39+
import { ConstrType, ObjectType } from '@pgsql/enums';
40+
41+
function createConstraint() {
42+
return {
43+
contype: ConstrType.CONSTR_PRIMARY
44+
};
45+
}
46+
47+
function getObjectType() {
48+
return ObjectType.OBJECT_TABLE;
49+
}
50+
```
51+
52+
### Type-Safe Enum Operations
53+
54+
Enums help ensure that you use correct PostgreSQL enum values:
55+
56+
```ts
57+
import { CmdType, JoinType } from '@pgsql/enums';
58+
59+
const command = {
60+
cmdType: CmdType.CMD_SELECT,
61+
joinType: JoinType.JOIN_INNER
62+
};
63+
64+
console.log(command);
65+
```
66+
67+
## Versions
68+
69+
Our latest is built with PostgreSQL 17 enum definitions.
70+
71+
| PG Major Version | libpg_query | npm dist-tag
72+
|--------------------------|-------------|---------|
73+
| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/@pgsql/enums/v/latest)
74+
| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/@pgsql/enums/v/pg16)
75+
| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/@pgsql/enums/v/pg15)
76+
| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/@pgsql/enums/v/pg14)
77+
| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/@pgsql/enums/v/pg13)
78+
79+
## Related
80+
81+
* [pgsql-parser](https://github.com/launchql/pgsql-parser): The real PostgreSQL parser for Node.js, providing symmetric parsing and deparsing of SQL statements with actual PostgreSQL parser integration.
82+
* [pgsql-deparser](https://github.com/launchql/pgsql-parser/tree/main/packages/deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
83+
* [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/main/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
84+
* [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/main/packages/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.
85+
* [pg-proto-parser](https://github.com/launchql/pg-proto-parser): A TypeScript tool that parses PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
86+
* [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.
87+
88+
## Disclaimer
89+
90+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
91+
92+
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/13/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/13/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/enums13",
3+
"version": "13.5.3",
4+
"author": "Dan Lynch <[email protected]>",
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/launchql/libpg-query-node",
10+
"license": "SEE LICENSE IN LICENSE",
11+
"publishConfig": {
12+
"access": "public",
13+
"directory": "dist"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/launchql/libpg-query-node"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/launchql/libpg-query-node/issues"
21+
},
22+
"x-publish": {
23+
"publishName": "@pgsql/enums",
24+
"distTag": "pg13"
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/13/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)