diff --git a/BUILD_SIZE_REPORT.md b/BUILD_SIZE_REPORT.md deleted file mode 100644 index 2d42636f..00000000 --- a/BUILD_SIZE_REPORT.md +++ /dev/null @@ -1,53 +0,0 @@ -# Build Size Analysis Report - -Generated on: 2025-06-22T06:22:35.227Z - -## Summary - -| Package | Total Size | Total Gzipped | Reduction | -|---------|------------|---------------|-----------| -| libpg-query (Original) | 2.07 MB | 428.77 KB | Baseline | -| @libpg-query/v17 | 2.05 MB | 427.95 KB | 0.7% | - -## Detailed Breakdown - -### libpg-query (Original) - -| File | Size | Gzipped | Gzip Ratio | -|------|------|---------|------------| -| WASM Binary | 1.99 MB | 409.96 KB | 79.9% | -| WASM Loader | 58.66 KB | 16.24 KB | 72.3% | -| ES Module | 9.48 KB | 1.07 KB | 88.8% | -| CommonJS | 10.75 KB | 1.5 KB | 86.1% | - -### @libpg-query/v17 - -| File | Size | Gzipped | Gzip Ratio | -|------|------|---------|------------| -| WASM Binary | 1.99 MB | 409.96 KB | 79.9% | -| WASM Loader | 58.66 KB | 16.24 KB | 72.3% | -| ES Module | 2.29 KB | 694 Bytes | 70.4% | -| CommonJS | 3.29 KB | 1.06 KB | 67.7% | - -## Size Comparison - -### WASM Binary Comparison - -| Package | WASM Size | Difference | -|---------|-----------|------------| -| libpg-query (Original) | 1.99 MB | Baseline | -| @libpg-query/v17 | 1.99 MB | 0.0 KB (0.0%) | - -### JavaScript Bundle Comparison - -| Package | ES Module | CommonJS | Combined | -|---------|-----------|----------|----------| -| libpg-query (Original) | 9.48 KB | 10.75 KB | 20.23 KB | -| @libpg-query/v17 | 2.29 KB | 3.29 KB | 5.57 KB | - -## Notes - -- Gzipped sizes represent the approximate size when served with compression -- The WASM binary is the largest component and is shared across all API methods -- JavaScript wrapper size varies based on the number of exported functions -- @libpg-query/v17 only exports parse/parseSync, reducing JavaScript bundle size diff --git a/README.md b/README.md index d056ca44..8d8cbefa 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,27 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this npm install libpg-query ``` +## Example + +```typescript +import { parse } from 'libpg-query'; + +const result = await parse('SELECT * FROM users WHERE active = true'); +// {"version":170004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]} +``` + +## Versions + +Our latest is built with `17-latest` branch from libpg_query + +| PG Major Version | libpg_query | npm dist-tag +|--------------------------|-------------|---------| +| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) +| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) +| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) +| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) +| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) + ## Usage ### `parse(query: string): Promise` @@ -62,124 +83,8 @@ const result = parseSync('SELECT * FROM users WHERE active = true'); // Returns: ParseResult - parsed query object ``` -### `parsePlPgSQL(funcsSql: string): Promise` - -Parses the contents of a PL/pgSQL function from a `CREATE FUNCTION` declaration. Returns a Promise for the parse tree. - -```typescript -import { parsePlPgSQL } from 'libpg-query'; - -const functionSql = ` -CREATE FUNCTION get_user_count() RETURNS integer AS $$ -BEGIN - RETURN (SELECT COUNT(*) FROM users); -END; -$$ LANGUAGE plpgsql; -`; - -const result = await parsePlPgSQL(functionSql); -``` - -### `parsePlPgSQLSync(funcsSql: string): ParseResult` - -Synchronous version of PL/pgSQL parsing. - -```typescript -import { parsePlPgSQLSync } from 'libpg-query'; - -const result = parsePlPgSQLSync(functionSql); -``` - -### `deparse(parseTree: ParseResult): Promise` - -Converts a parse tree back to SQL string. Returns a Promise for the SQL string. - -```typescript -import { parse, deparse } from 'libpg-query'; - -const parseTree = await parse('SELECT * FROM users WHERE active = true'); -const sql = await deparse(parseTree); -// Returns: string - reconstructed SQL query -``` - -### `deparseSync(parseTree: ParseResult): string` - -Synchronous version that converts a parse tree back to SQL string directly. - -```typescript -import { parseSync, deparseSync } from 'libpg-query'; - -const parseTree = parseSync('SELECT * FROM users WHERE active = true'); -const sql = deparseSync(parseTree); -// Returns: string - reconstructed SQL query -``` - -### `fingerprint(sql: string): Promise` - -Generates a unique fingerprint for a SQL query that can be used for query identification and caching. Returns a Promise for a 16-character fingerprint string. - -```typescript -import { fingerprint } from 'libpg-query'; - -const fp = await fingerprint('SELECT * FROM users WHERE active = $1'); -// Returns: string - unique 16-character fingerprint (e.g., "50fde20626009aba") -``` - -### `fingerprintSync(sql: string): string` -Synchronous version that generates a unique fingerprint for a SQL query directly. - -```typescript -import { fingerprintSync } from 'libpg-query'; - -const fp = fingerprintSync('SELECT * FROM users WHERE active = $1'); -// Returns: string - unique 16-character fingerprint -``` - -### `normalize(sql: string): Promise` - -Normalizes a SQL query by removing comments, standardizing whitespace, and converting to a canonical form. Returns a Promise for the normalized SQL string. - -```typescript -import { normalize } from 'libpg-query'; - -const normalized = await normalize('SELECT * FROM users WHERE active = true'); -// Returns: string - normalized SQL query -``` - -### `normalizeSync(sql: string): string` - -Synchronous version that normalizes a SQL query directly. - -```typescript -import { normalizeSync } from 'libpg-query'; - -const normalized = normalizeSync('SELECT * FROM users WHERE active = true'); -// Returns: string - normalized SQL query -``` - -### `scan(sql: string): Promise` - -Scans (tokenizes) a SQL query and returns detailed information about each token. Returns a Promise for a ScanResult containing all tokens with their positions, types, and classifications. - -```typescript -import { scan } from 'libpg-query'; - -const result = await scan('SELECT * FROM users WHERE id = $1'); -// Returns: ScanResult - detailed tokenization information -console.log(result.tokens[0]); // { start: 0, end: 6, text: "SELECT", tokenType: 651, tokenName: "UNKNOWN", keywordKind: 4, keywordName: "RESERVED_KEYWORD" } -``` - -### `scanSync(sql: string): ScanResult` - -Synchronous version that scans (tokenizes) a SQL query directly. - -```typescript -import { scanSync } from 'libpg-query'; - -const result = scanSync('SELECT * FROM users WHERE id = $1'); -// Returns: ScanResult - detailed tokenization information -``` +**Note:** If you need additional functionality like `fingerprint`, `scan`, `deparse`, or `normalize`, check out the full package (`@pgsql/parser`) in the [./full](https://github.com/launchql/libpg-query-node/tree/17-latest/libpg-query) folder of the repo. ### Initialization @@ -190,12 +95,10 @@ The library provides both async and sync methods. Async methods handle initializ Async methods handle initialization automatically and are always safe to use: ```typescript -import { parse, deparse, scan } from 'libpg-query'; +import { parse } from 'libpg-query'; // These handle initialization automatically const result = await parse('SELECT * FROM users'); -const sql = await deparse(result); -const tokens = await scan('SELECT * FROM users'); ``` #### Sync Methods @@ -203,14 +106,13 @@ const tokens = await scan('SELECT * FROM users'); Sync methods require explicit initialization using `loadModule()`: ```typescript -import { loadModule, parseSync, scanSync } from 'libpg-query'; +import { loadModule, parseSync } from 'libpg-query'; // Initialize first await loadModule(); // Now safe to use sync methods const result = parseSync('SELECT * FROM users'); -const tokens = scanSync('SELECT * FROM users'); ``` ### `loadModule(): Promise` @@ -218,12 +120,11 @@ const tokens = scanSync('SELECT * FROM users'); Explicitly initializes the WASM module. Required before using any sync methods. ```typescript -import { loadModule, parseSync, scanSync } from 'libpg-query'; +import { loadModule, parseSync } from 'libpg-query'; // Initialize before using sync methods await loadModule(); const result = parseSync('SELECT * FROM users'); -const tokens = scanSync('SELECT * FROM users'); ``` Note: We recommend using async methods as they handle initialization automatically. Use sync methods only when necessary, and always call `loadModule()` first. @@ -243,20 +144,6 @@ interface Statement { query: string; } -interface ScanResult { - version: number; - tokens: ScanToken[]; -} - -interface ScanToken { - start: number; // Starting position in the SQL string - end: number; // Ending position in the SQL string - text: string; // The actual token text - tokenType: number; // Numeric token type identifier - tokenName: string; // Human-readable token type name - keywordKind: number; // Numeric keyword classification - keywordName: string; // Human-readable keyword classification -} ``` **Note:** The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as PostgreSQL expects). @@ -316,25 +203,6 @@ pnpm run test pnpm run clean && pnpm run build && pnpm run test ``` - - -## Versions - -Our latest is built with `17-latest` branch from libpg_query - - -| PG Major Version | libpg_query | npm dist-tag -|--------------------------|-------------|---------| -| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) -| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) -| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) -| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) -| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) -| 12 | (n/a) | | -| 11 | (n/a) | | -| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) | - - ## Troubleshooting ### Common Issues diff --git a/libpg-query/.npmignore b/full/.npmignore similarity index 100% rename from libpg-query/.npmignore rename to full/.npmignore diff --git a/libpg-query/CHANGELOG.md b/full/CHANGELOG.md similarity index 100% rename from libpg-query/CHANGELOG.md rename to full/CHANGELOG.md diff --git a/libpg-query/Makefile b/full/Makefile similarity index 100% rename from libpg-query/Makefile rename to full/Makefile diff --git a/libpg-query/README.md b/full/README.md similarity index 100% rename from libpg-query/README.md rename to full/README.md diff --git a/libpg-query/SCAN.md b/full/SCAN.md similarity index 100% rename from libpg-query/SCAN.md rename to full/SCAN.md diff --git a/libpg-query/libpg_query.md b/full/libpg_query.md similarity index 100% rename from libpg-query/libpg_query.md rename to full/libpg_query.md diff --git a/libpg-query/libpg_query/protobuf/.gitkeep b/full/libpg_query/protobuf/.gitkeep similarity index 100% rename from libpg-query/libpg_query/protobuf/.gitkeep rename to full/libpg_query/protobuf/.gitkeep diff --git a/libpg-query/package.json b/full/package.json similarity index 96% rename from libpg-query/package.json rename to full/package.json index fc33fc11..2641b2f4 100644 --- a/libpg-query/package.json +++ b/full/package.json @@ -1,6 +1,6 @@ { - "name": "libpg-query", - "version": "17.3.3", + "name": "@pgsql/parser", + "version": "17.5.0", "description": "The real PostgreSQL query parser", "homepage": "https://github.com/launchql/libpg-query-node", "main": "./wasm/index.cjs", diff --git a/libpg-query/proto.js b/full/proto.js similarity index 100% rename from libpg-query/proto.js rename to full/proto.js diff --git a/libpg-query/scripts/build.js b/full/scripts/build.js similarity index 100% rename from libpg-query/scripts/build.js rename to full/scripts/build.js diff --git a/libpg-query/scripts/protogen.js b/full/scripts/protogen.js similarity index 100% rename from libpg-query/scripts/protogen.js rename to full/scripts/protogen.js diff --git a/libpg-query/src/index.ts b/full/src/index.ts similarity index 100% rename from libpg-query/src/index.ts rename to full/src/index.ts diff --git a/libpg-query/src/libpg-query.d.ts b/full/src/libpg-query.d.ts similarity index 100% rename from libpg-query/src/libpg-query.d.ts rename to full/src/libpg-query.d.ts diff --git a/libpg-query/src/proto.d.ts b/full/src/proto.d.ts similarity index 100% rename from libpg-query/src/proto.d.ts rename to full/src/proto.d.ts diff --git a/libpg-query/src/wasm_wrapper.c b/full/src/wasm_wrapper.c similarity index 100% rename from libpg-query/src/wasm_wrapper.c rename to full/src/wasm_wrapper.c diff --git a/libpg-query/test/deparsing.test.js b/full/test/deparsing.test.js similarity index 100% rename from libpg-query/test/deparsing.test.js rename to full/test/deparsing.test.js diff --git a/libpg-query/test/fingerprint.test.js b/full/test/fingerprint.test.js similarity index 100% rename from libpg-query/test/fingerprint.test.js rename to full/test/fingerprint.test.js diff --git a/libpg-query/test/normalize.test.js b/full/test/normalize.test.js similarity index 100% rename from libpg-query/test/normalize.test.js rename to full/test/normalize.test.js diff --git a/libpg-query/test/parsing.test.js b/full/test/parsing.test.js similarity index 100% rename from libpg-query/test/parsing.test.js rename to full/test/parsing.test.js diff --git a/libpg-query/test/plpgsql.test.js b/full/test/plpgsql.test.js similarity index 100% rename from libpg-query/test/plpgsql.test.js rename to full/test/plpgsql.test.js diff --git a/libpg-query/test/scan.test.js b/full/test/scan.test.js similarity index 100% rename from libpg-query/test/scan.test.js rename to full/test/scan.test.js diff --git a/libpg-query/tsconfig.esm.json b/full/tsconfig.esm.json similarity index 100% rename from libpg-query/tsconfig.esm.json rename to full/tsconfig.esm.json diff --git a/libpg-query/tsconfig.json b/full/tsconfig.json similarity index 100% rename from libpg-query/tsconfig.json rename to full/tsconfig.json diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 4392b2e2..ec375850 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,5 +1,5 @@ packages: - - 'libpg-query' + - 'full' - 'versions/17' - 'versions/16' - 'versions/15' diff --git a/types/13/package.json b/types/13/package.json index f8e99daf..23787a53 100644 --- a/types/13/package.json +++ b/types/13/package.json @@ -1,6 +1,6 @@ { "name": "@libpg-query/types13", - "version": "13.10.1", + "version": "13.10.2", "author": "Dan Lynch ", "description": "PostgreSQL AST types from the real Postgres parser", "main": "index.js", diff --git a/versions/13/README.md b/versions/13/README.md index 5da03391..8d8cbefa 100644 --- a/versions/13/README.md +++ b/versions/13/README.md @@ -38,6 +38,27 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this npm install libpg-query ``` +## Example + +```typescript +import { parse } from 'libpg-query'; + +const result = await parse('SELECT * FROM users WHERE active = true'); +// {"version":170004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]} +``` + +## Versions + +Our latest is built with `17-latest` branch from libpg_query + +| PG Major Version | libpg_query | npm dist-tag +|--------------------------|-------------|---------| +| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) +| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) +| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) +| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) +| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) + ## Usage ### `parse(query: string): Promise` @@ -63,9 +84,7 @@ const result = parseSync('SELECT * FROM users WHERE active = true'); ``` - - - +**Note:** If you need additional functionality like `fingerprint`, `scan`, `deparse`, or `normalize`, check out the full package (`@pgsql/parser`) in the [./full](https://github.com/launchql/libpg-query-node/tree/17-latest/libpg-query) folder of the repo. ### Initialization @@ -125,20 +144,6 @@ interface Statement { query: string; } -interface ScanResult { - version: number; - tokens: ScanToken[]; -} - -interface ScanToken { - start: number; // Starting position in the SQL string - end: number; // Ending position in the SQL string - text: string; // The actual token text - tokenType: number; // Numeric token type identifier - tokenName: string; // Human-readable token type name - keywordKind: number; // Numeric keyword classification - keywordName: string; // Human-readable keyword classification -} ``` **Note:** The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as PostgreSQL expects). @@ -198,25 +203,6 @@ pnpm run test pnpm run clean && pnpm run build && pnpm run test ``` - - -## Versions - -Our latest is built with `17-latest` branch from libpg_query - - -| PG Major Version | libpg_query | npm dist-tag -|--------------------------|-------------|---------| -| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) -| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) -| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) -| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) -| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) -| 12 | (n/a) | | -| 11 | (n/a) | | -| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) | - - ## Troubleshooting ### Common Issues diff --git a/versions/14/README.md b/versions/14/README.md index 5da03391..8d8cbefa 100644 --- a/versions/14/README.md +++ b/versions/14/README.md @@ -38,6 +38,27 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this npm install libpg-query ``` +## Example + +```typescript +import { parse } from 'libpg-query'; + +const result = await parse('SELECT * FROM users WHERE active = true'); +// {"version":170004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]} +``` + +## Versions + +Our latest is built with `17-latest` branch from libpg_query + +| PG Major Version | libpg_query | npm dist-tag +|--------------------------|-------------|---------| +| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) +| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) +| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) +| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) +| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) + ## Usage ### `parse(query: string): Promise` @@ -63,9 +84,7 @@ const result = parseSync('SELECT * FROM users WHERE active = true'); ``` - - - +**Note:** If you need additional functionality like `fingerprint`, `scan`, `deparse`, or `normalize`, check out the full package (`@pgsql/parser`) in the [./full](https://github.com/launchql/libpg-query-node/tree/17-latest/libpg-query) folder of the repo. ### Initialization @@ -125,20 +144,6 @@ interface Statement { query: string; } -interface ScanResult { - version: number; - tokens: ScanToken[]; -} - -interface ScanToken { - start: number; // Starting position in the SQL string - end: number; // Ending position in the SQL string - text: string; // The actual token text - tokenType: number; // Numeric token type identifier - tokenName: string; // Human-readable token type name - keywordKind: number; // Numeric keyword classification - keywordName: string; // Human-readable keyword classification -} ``` **Note:** The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as PostgreSQL expects). @@ -198,25 +203,6 @@ pnpm run test pnpm run clean && pnpm run build && pnpm run test ``` - - -## Versions - -Our latest is built with `17-latest` branch from libpg_query - - -| PG Major Version | libpg_query | npm dist-tag -|--------------------------|-------------|---------| -| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) -| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) -| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) -| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) -| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) -| 12 | (n/a) | | -| 11 | (n/a) | | -| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) | - - ## Troubleshooting ### Common Issues diff --git a/versions/15/README.md b/versions/15/README.md index 5da03391..8d8cbefa 100644 --- a/versions/15/README.md +++ b/versions/15/README.md @@ -38,6 +38,27 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this npm install libpg-query ``` +## Example + +```typescript +import { parse } from 'libpg-query'; + +const result = await parse('SELECT * FROM users WHERE active = true'); +// {"version":170004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]} +``` + +## Versions + +Our latest is built with `17-latest` branch from libpg_query + +| PG Major Version | libpg_query | npm dist-tag +|--------------------------|-------------|---------| +| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) +| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) +| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) +| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) +| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) + ## Usage ### `parse(query: string): Promise` @@ -63,9 +84,7 @@ const result = parseSync('SELECT * FROM users WHERE active = true'); ``` - - - +**Note:** If you need additional functionality like `fingerprint`, `scan`, `deparse`, or `normalize`, check out the full package (`@pgsql/parser`) in the [./full](https://github.com/launchql/libpg-query-node/tree/17-latest/libpg-query) folder of the repo. ### Initialization @@ -125,20 +144,6 @@ interface Statement { query: string; } -interface ScanResult { - version: number; - tokens: ScanToken[]; -} - -interface ScanToken { - start: number; // Starting position in the SQL string - end: number; // Ending position in the SQL string - text: string; // The actual token text - tokenType: number; // Numeric token type identifier - tokenName: string; // Human-readable token type name - keywordKind: number; // Numeric keyword classification - keywordName: string; // Human-readable keyword classification -} ``` **Note:** The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as PostgreSQL expects). @@ -198,25 +203,6 @@ pnpm run test pnpm run clean && pnpm run build && pnpm run test ``` - - -## Versions - -Our latest is built with `17-latest` branch from libpg_query - - -| PG Major Version | libpg_query | npm dist-tag -|--------------------------|-------------|---------| -| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) -| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) -| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) -| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) -| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) -| 12 | (n/a) | | -| 11 | (n/a) | | -| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) | - - ## Troubleshooting ### Common Issues diff --git a/versions/16/README.md b/versions/16/README.md index 5da03391..8d8cbefa 100644 --- a/versions/16/README.md +++ b/versions/16/README.md @@ -38,6 +38,27 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this npm install libpg-query ``` +## Example + +```typescript +import { parse } from 'libpg-query'; + +const result = await parse('SELECT * FROM users WHERE active = true'); +// {"version":170004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]} +``` + +## Versions + +Our latest is built with `17-latest` branch from libpg_query + +| PG Major Version | libpg_query | npm dist-tag +|--------------------------|-------------|---------| +| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) +| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) +| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) +| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) +| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) + ## Usage ### `parse(query: string): Promise` @@ -63,9 +84,7 @@ const result = parseSync('SELECT * FROM users WHERE active = true'); ``` - - - +**Note:** If you need additional functionality like `fingerprint`, `scan`, `deparse`, or `normalize`, check out the full package (`@pgsql/parser`) in the [./full](https://github.com/launchql/libpg-query-node/tree/17-latest/libpg-query) folder of the repo. ### Initialization @@ -125,20 +144,6 @@ interface Statement { query: string; } -interface ScanResult { - version: number; - tokens: ScanToken[]; -} - -interface ScanToken { - start: number; // Starting position in the SQL string - end: number; // Ending position in the SQL string - text: string; // The actual token text - tokenType: number; // Numeric token type identifier - tokenName: string; // Human-readable token type name - keywordKind: number; // Numeric keyword classification - keywordName: string; // Human-readable keyword classification -} ``` **Note:** The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as PostgreSQL expects). @@ -198,25 +203,6 @@ pnpm run test pnpm run clean && pnpm run build && pnpm run test ``` - - -## Versions - -Our latest is built with `17-latest` branch from libpg_query - - -| PG Major Version | libpg_query | npm dist-tag -|--------------------------|-------------|---------| -| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) -| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) -| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) -| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) -| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) -| 12 | (n/a) | | -| 11 | (n/a) | | -| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) | - - ## Troubleshooting ### Common Issues diff --git a/versions/17/README.md b/versions/17/README.md index 5da03391..8d8cbefa 100644 --- a/versions/17/README.md +++ b/versions/17/README.md @@ -38,6 +38,27 @@ Built to power [pgsql-parser](https://github.com/pyramation/pgsql-parser), this npm install libpg-query ``` +## Example + +```typescript +import { parse } from 'libpg-query'; + +const result = await parse('SELECT * FROM users WHERE active = true'); +// {"version":170004,"stmts":[{"stmt":{"SelectStmt":{"targetList":[{"ResTarget" ... "op":"SETOP_NONE"}}}]} +``` + +## Versions + +Our latest is built with `17-latest` branch from libpg_query + +| PG Major Version | libpg_query | npm dist-tag +|--------------------------|-------------|---------| +| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) +| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) +| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) +| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) +| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) + ## Usage ### `parse(query: string): Promise` @@ -63,9 +84,7 @@ const result = parseSync('SELECT * FROM users WHERE active = true'); ``` - - - +**Note:** If you need additional functionality like `fingerprint`, `scan`, `deparse`, or `normalize`, check out the full package (`@pgsql/parser`) in the [./full](https://github.com/launchql/libpg-query-node/tree/17-latest/libpg-query) folder of the repo. ### Initialization @@ -125,20 +144,6 @@ interface Statement { query: string; } -interface ScanResult { - version: number; - tokens: ScanToken[]; -} - -interface ScanToken { - start: number; // Starting position in the SQL string - end: number; // Ending position in the SQL string - text: string; // The actual token text - tokenType: number; // Numeric token type identifier - tokenName: string; // Human-readable token type name - keywordKind: number; // Numeric keyword classification - keywordName: string; // Human-readable keyword classification -} ``` **Note:** The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as PostgreSQL expects). @@ -198,25 +203,6 @@ pnpm run test pnpm run clean && pnpm run build && pnpm run test ``` - - -## Versions - -Our latest is built with `17-latest` branch from libpg_query - - -| PG Major Version | libpg_query | npm dist-tag -|--------------------------|-------------|---------| -| 17 | 17-6.1.0 | [`pg17`](https://www.npmjs.com/package/libpg-query/v/latest) -| 16 | 16-5.2.0 | [`pg16`](https://www.npmjs.com/package/libpg-query/v/pg16) -| 15 | 15-4.2.4 | [`pg15`](https://www.npmjs.com/package/libpg-query/v/pg15) -| 14 | 14-3.0.0 | [`pg14`](https://www.npmjs.com/package/libpg-query/v/pg14) -| 13 | 13-2.2.0 | [`pg13`](https://www.npmjs.com/package/libpg-query/v/pg13) -| 12 | (n/a) | | -| 11 | (n/a) | | -| 10 | 10-latest | | `@1.3.1` ([tree](https://github.com/pyramation/pgsql-parser/tree/39b7b1adc8914253226e286a48105785219a81ca)) | - - ## Troubleshooting ### Common Issues