|
| 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. |
0 commit comments