Skip to content

Commit eaa4b7b

Browse files
Modernize README and remove binary build infrastructure
- Remove AWS dependencies (aws-sdk, @yamlize/cli) from package.json - Update README with WASM-first messaging and TypeScript examples - Replace CommonJS examples with modern TypeScript imports - Add comprehensive TypeScript API documentation with types - Update CI badge to point to new modular workflow - Remove binary build references and modernize documentation Co-Authored-By: Dan Lynch <[email protected]>
1 parent 514a83f commit eaa4b7b

File tree

2 files changed

+85
-20
lines changed

2 files changed

+85
-20
lines changed

README.md

Lines changed: 85 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,14 @@
99
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/npm/dw/libpg-query"/></a>
1010
<a href="https://github.com/launchql/libpg-query/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
1111
<a href="https://www.npmjs.com/package/libpg-query"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/libpg-query-node"/></a><br />
12-
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/run-tests-linux.yml">
13-
<img height="20" src="https://github.com/launchql/libpg-query-node/actions/workflows/run-tests-linux.yml/badge.svg" />
14-
</a>
15-
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/run-tests-mac.yml">
16-
<img height="20" src="https://github.com/launchql/libpg-query-node/actions/workflows/run-tests-mac.yml/badge.svg" />
17-
</a>
18-
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/run-tests-win.yml">
19-
<img height="20" src="https://github.com/launchql/libpg-query-node/actions/workflows/run-tests-win.yml/badge.svg" />
12+
<a href="https://github.com/launchql/libpg-query-node/actions/workflows/ci.yml">
13+
<img height="20" src="https://github.com/launchql/libpg-query-node/actions/workflows/ci.yml/badge.svg" />
2014
</a>
2115
</p>
2216

23-
The real PostgreSQL parser, exposed for nodejs.
17+
The real PostgreSQL parser for Node.js, powered by **WebAssembly (WASM)** for true cross-platform compatibility.
2418

25-
Primarily used for the node.js parser and deparser [pgsql-parser](https://github.com/pyramation/pgsql-parser)
19+
A WASM-based PostgreSQL query parser that provides the same functionality as the native PostgreSQL parser without requiring native compilation or platform-specific binaries. Primarily used for the node.js parser and deparser [pgsql-parser](https://github.com/pyramation/pgsql-parser).
2620

2721

2822
## Table of Contents
@@ -45,9 +39,24 @@ npm install libpg-query
4539

4640
## Example
4741

48-
```js
49-
const parser = require('libpg-query');
50-
parser.parseQuery('select 1').then(console.log);
42+
```typescript
43+
import { parseQuery, parseQuerySync } from 'libpg-query';
44+
45+
// Async usage (recommended)
46+
const result = await parseQuery('SELECT * FROM users WHERE id = $1');
47+
console.log(result);
48+
49+
// Sync usage
50+
const syncResult = parseQuerySync('SELECT * FROM users WHERE id = $1');
51+
console.log(syncResult);
52+
```
53+
54+
### CommonJS Usage
55+
56+
```javascript
57+
const { parseQuery, parseQuerySync } = require('libpg-query');
58+
59+
parseQuery('SELECT * FROM users WHERE id = $1').then(console.log);
5160
```
5261

5362
## Build Instructions
@@ -138,15 +147,73 @@ All tests should pass:
138147

139148
## Documentation
140149

141-
### `query.parseQuery(sql)`/`parseQuerySync`
150+
### `parseQuery(sql: string): Promise<ParseResult[]>`
142151

143-
Parses the sql and returns a Promise for the parse tree (or returns the parse tree directly in the sync version). May reject with/throw a parse error.
152+
Parses the SQL and returns a Promise for the parse tree. May reject with a parse error.
144153

145-
The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as Postgres expects).
154+
```typescript
155+
import { parseQuery } from 'libpg-query';
156+
157+
const result = await parseQuery('SELECT * FROM users WHERE active = true');
158+
// Returns: ParseResult[] - array of parsed query objects
159+
```
160+
161+
### `parseQuerySync(sql: string): ParseResult[]`
162+
163+
Synchronous version that returns the parse tree directly. May throw a parse error.
164+
165+
```typescript
166+
import { parseQuerySync } from 'libpg-query';
167+
168+
const result = parseQuerySync('SELECT * FROM users WHERE active = true');
169+
// Returns: ParseResult[] - array of parsed query objects
170+
```
146171

147-
### `query.parsePlPgSQL(funcsSql)`/`query.parsePlPgSQLSync(funcsSql)`
172+
### `parsePlPgSQL(funcsSql: string): Promise<ParseResult>`
173+
174+
Parses the contents of a PL/pgSQL function from a `CREATE FUNCTION` declaration. Returns a Promise for the parse tree.
175+
176+
```typescript
177+
import { parsePlPgSQL } from 'libpg-query';
178+
179+
const functionSql = `
180+
CREATE FUNCTION get_user_count() RETURNS integer AS $$
181+
BEGIN
182+
RETURN (SELECT COUNT(*) FROM users);
183+
END;
184+
$$ LANGUAGE plpgsql;
185+
`;
186+
187+
const result = await parsePlPgSQL(functionSql);
188+
```
189+
190+
### `parsePlPgSQLSync(funcsSql: string): ParseResult`
191+
192+
Synchronous version of PL/pgSQL parsing.
193+
194+
```typescript
195+
import { parsePlPgSQLSync } from 'libpg-query';
196+
197+
const result = parsePlPgSQLSync(functionSql);
198+
```
199+
200+
### Type Definitions
201+
202+
```typescript
203+
interface ParseResult {
204+
version: number;
205+
stmts: Statement[];
206+
}
207+
208+
interface Statement {
209+
stmt_type: string;
210+
stmt_len: number;
211+
stmt_location: number;
212+
query: string;
213+
}
214+
```
148215

149-
Parses the contents of a PL/PGSql function, from a `CREATE FUNCTION` declaration, and returns a Promise for the parse tree (or returns the parse tree directly in the sync version). May reject with/throw a parse error.
216+
**Note:** The return value is an array, as multiple queries may be provided in a single string (semicolon-delimited, as PostgreSQL expects).
150217

151218
## Versions
152219

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
},
4747
"devDependencies": {
4848
"@launchql/proto-cli": "1.25.0",
49-
"@yamlize/cli": "^0.8.0",
50-
"aws-sdk": "2.1691.0",
5149
"chai": "^3.5.0",
5250
"lodash": "^4.17.15",
5351
"mocha": "^5.2.0",

0 commit comments

Comments
 (0)