@pgsql/utils 13.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Dan Lynch <pyramation@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # @pgsql/utils
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/pgsql-parser/actions/workflows/run-tests.yaml">
9
+ <img height="20" src="https://github.com/launchql/pgsql-parser/actions/workflows/run-tests.yaml/badge.svg" />
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@pgsql/utils"><img height="20" src="https://img.shields.io/npm/dt/@pgsql/utils"></a>
12
+ <a href="https://www.npmjs.com/package/@pgsql/utils"><img height="20" src="https://img.shields.io/npm/dw/@pgsql/utils"/></a>
13
+ <a href="https://github.com/launchql/pgsql-parser/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/utils"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/pgsql-parser?filename=packages%2Fenums%2Fpackage.json"/></a>
15
+ </p>
16
+
17
+ `@pgsql/utils` is a companion utility library for `@pgsql/types`, providing convenient functions to work with PostgreSQL Abstract Syntax Tree (AST) node enumerations in a type-safe manner. This library simplifies the process of converting between enum names and their respective integer values, as defined in the PostgreSQL parser output.
18
+
19
+ ## Features
20
+
21
+ - Type-safe enum value conversion: Convert between string and integer representations of PostgreSQL AST enum values.
22
+ - Comprehensive coverage: Supports all enum types defined in the PostgreSQL AST.
23
+ - Designed to be used alongside the `@pgsql/types` package for a complete AST handling solution.
24
+
25
+ ## Installation
26
+
27
+ To add `@pgsql/utils` to your project, use the following npm command:
28
+
29
+ ```bash
30
+ npm install @pgsql/utils
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ `@pgsql/utils` provides the `getEnumValue` function to convert between the string and integer representations of enum values.
36
+
37
+ Here are a couple of examples demonstrating how to use `@pgsql/utils` in real applications:
38
+
39
+ ### Example 1: Converting Enum Name to Integer
40
+
41
+ Suppose you are working with the A_Expr_Kind enum and you have the name of an enum value. You can get its integer representation like this:
42
+
43
+ ```ts
44
+ import { getEnumValue } from '@pgsql/utils';
45
+
46
+ const enumName = 'AEXPR_OP';
47
+ const enumValue = getEnumValue('A_Expr_Kind', enumName);
48
+
49
+ console.log(enumValue); // Outputs the integer value corresponding to 'AEXPR_OP'
50
+ ```
51
+
52
+ ### Example 2: Converting Integer to Enum Name
53
+
54
+ ```ts
55
+ import { getEnumValue } from '@pgsql/utils';
56
+
57
+ const intValue = 1;
58
+ const enumName = getEnumValue('SortByDir', intValue);
59
+
60
+ console.log(enumName); // Outputs 'SORTBY_ASC' if 1 corresponds to 'SORTBY_ASC'
61
+ ```
62
+
63
+ ## Related
64
+
65
+ * [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.
66
+ * [pgsql-deparser](https://github.com/launchql/pgsql-deparser): A streamlined tool designed for converting PostgreSQL ASTs back into SQL queries, focusing solely on deparser functionality to complement `pgsql-parser`.
67
+ * [pgsql-enums](https://github.com/launchql/pgsql-enums): A utility package offering easy access to PostgreSQL enumeration types in JSON format, aiding in string and integer conversions of enums used within ASTs to compliment `pgsql-parser`
68
+ * [@pgsql/enums](https://github.com/launchql/pgsql-parser/tree/master/packages/enums): Provides PostgreSQL AST enums in TypeScript, enhancing type safety and usability in projects interacting with PostgreSQL AST nodes.
69
+ * [@pgsql/types](https://github.com/launchql/pgsql-parser/tree/master/packages/types): Offers TypeScript type definitions for PostgreSQL AST nodes, facilitating type-safe construction, analysis, and manipulation of ASTs.
70
+ * [@pgsql/utils](https://github.com/launchql/pgsql-parser/tree/master/packages/utils): A utility library for working with PostgreSQL AST node enumerations in a type-safe way, easing enum name and value conversions.
71
+ * [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.
72
+ * [libpg-query-node](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.
73
+
74
+ ## Disclaimer
75
+
76
+ AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED “AS IS”, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
77
+
78
+ 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.