You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+122-1Lines changed: 122 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,6 +132,7 @@ await deparse(stmt);
132
132
|[**@pgsql/cli**](./packages/pgsql-cli)| Unified CLI for all PostgreSQL AST operations | • Parse SQL to AST<br>• Deparse AST to SQL<br>• Generate TypeScript from protobuf<br>• Single tool for all operations |
|[**pg-proto-parser**](./packages/proto-parser)| PostgreSQL protobuf parser and code generator | • Generate TypeScript interfaces from protobuf<br>• Create enum mappings and utilities<br>• AST helper generation |
135
+
|[**@pgsql/transform**](./packages/transform)| Multi-version PostgreSQL AST transformer | • Transform ASTs between PostgreSQL versions (13→17)<br>• Single source of truth deparser pipeline<br>• Backward compatibility for legacy SQL |
The `@pgsql/transform` package enables transformation of PostgreSQL ASTs between different PostgreSQL versions, providing a crucial component for building a single source of truth deparser that works with legacy SQL code.
224
+
225
+
### Core Use Case
226
+
227
+
The transform package serves as the backbone for maintaining backward compatibility in the deparser pipeline. It allows you to:
228
+
229
+
-**Transform legacy ASTs**: Convert ASTs from older PostgreSQL versions (13, 14, 15, 16) to the latest version (17)
230
+
-**Build unified deparsers**: Create a single deparser that can handle SQL from multiple PostgreSQL versions
231
+
-**Maintain compatibility**: Support legacy codebases while leveraging the latest PostgreSQL parser features
232
+
233
+
### Key Limitation
234
+
235
+
The transform package only supports ASTs that derive from SQL parseable by PostgreSQL 17. This means:
236
+
237
+
- ✅ **Supported**: SQL code from PG13-16 that is still valid in PG17
238
+
- ❌ **Not supported**: Deprecated PG13 syntax that was removed in later versions
239
+
- ❌ **Not supported**: SQL that cannot be parsed by the PG17 parser
240
+
241
+
This limitation is by design - it ensures that all transformed ASTs can be reliably deparsed using the latest PostgreSQL grammar.
The transform package is designed to work seamlessly with the broader pgsql-parser ecosystem:
334
+
335
+
1.**Parse** legacy SQL using version-specific parsers
336
+
2.**Transform** the resulting AST to the latest version
337
+
3.**Deparse** using the unified, latest-version deparser
338
+
339
+
This architecture enables a single source of truth for SQL generation while maintaining support for legacy codebases.
340
+
220
341
## Related
221
342
222
343
*[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.
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
234
355
235
-
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.
356
+
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.
`@pgsql/types` is a TypeScript library providing type 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 interact with the AST nodes generated by PostgreSQL query parsing.
15
+
`@pgsql/transform` is a TypeScript library for transforming PostgreSQL ASTs between different PostgreSQL versions. It serves as a crucial component for building a single source of truth deparser that can handle SQL from multiple PostgreSQL versions while maintaining backward compatibility.
16
+
17
+
## 🎯 Core Purpose
18
+
19
+
The transform package enables you to:
20
+
21
+
-**Transform legacy ASTs**: Convert ASTs from PostgreSQL versions 13-16 to version 17
22
+
-**Build unified deparsers**: Create a single deparser pipeline that works with multiple PostgreSQL versions
23
+
-**Maintain backward compatibility**: Support legacy codebases while leveraging the latest PostgreSQL features
24
+
25
+
## ⚠️ Key Limitation
26
+
27
+
This package only supports ASTs derived from SQL that is parseable by PostgreSQL 17. This means:
28
+
29
+
- ✅ **Supported**: SQL from PG13-16 that remains valid in PG17
30
+
- ❌ **Not supported**: Deprecated syntax from older versions that was removed
31
+
- ❌ **Not supported**: SQL that cannot be parsed by the PG17 parser
32
+
33
+
This design ensures all transformed ASTs can be reliably deparsed using the latest PostgreSQL grammar.
The transform package fits into the broader pgsql-parser ecosystem:
111
+
112
+
1.**Parse** legacy SQL with version-specific parsers
113
+
2.**Transform** ASTs to the latest version
114
+
3.**Deparse** using the unified, latest-version deparser
115
+
116
+
This enables a single source of truth for SQL generation while supporting legacy codebases.
18
117
19
118
## Related
20
119
@@ -31,4 +130,4 @@
31
130
32
131
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
33
132
34
-
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.
133
+
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