|
| 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%2F13%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 | +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://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. |
| 64 | +* [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`. |
| 65 | +* [@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. |
| 66 | +* [@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. |
| 67 | +* [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. |
| 68 | +* [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. |
| 69 | + |
| 70 | +## Disclaimer |
| 71 | + |
| 72 | +AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND. |
| 73 | + |
| 74 | +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