@@ -39,26 +39,26 @@ npm install libpg-query
3939
4040## Usage
4141
42- ### ` parseQuery(sql : string): Promise<ParseResult[] >`
42+ ### ` parse(query : string): Promise<ParseResult>`
4343
4444Parses the SQL and returns a Promise for the parse tree. May reject with a parse error.
4545
4646``` typescript
47- import { parseQuery } from ' libpg-query' ;
47+ import { parse } from ' libpg-query' ;
4848
49- const result = await parseQuery (' SELECT * FROM users WHERE active = true' );
50- // Returns: ParseResult[] - array of parsed query objects
49+ const result = await parse (' SELECT * FROM users WHERE active = true' );
50+ // Returns: ParseResult - parsed query object
5151```
5252
53- ### ` parseQuerySync(sql : string): ParseResult[] `
53+ ### ` parseSync(query : string): ParseResult`
5454
5555Synchronous version that returns the parse tree directly. May throw a parse error.
5656
5757``` typescript
58- import { parseQuerySync } from ' libpg-query' ;
58+ import { parseSync } from ' libpg-query' ;
5959
60- const result = parseQuerySync (' SELECT * FROM users WHERE active = true' );
61- // Returns: ParseResult[] - array of parsed query objects
60+ const result = parseSync (' SELECT * FROM users WHERE active = true' );
61+ // Returns: ParseResult - parsed query object
6262```
6363
6464### ` parsePlPgSQL(funcsSql: string): Promise<ParseResult> `
@@ -94,10 +94,10 @@ const result = parsePlPgSQLSync(functionSql);
9494Converts a parse tree back to SQL string. Returns a Promise for the SQL string.
9595
9696``` typescript
97- import { parseQuery , deparse } from ' libpg-query' ;
97+ import { parse , deparse } from ' libpg-query' ;
9898
99- const parseTree = await parseQuery (' SELECT * FROM users WHERE active = true' );
100- const sql = await deparse (parseTree [ 0 ] );
99+ const parseTree = await parse (' SELECT * FROM users WHERE active = true' );
100+ const sql = await deparse (parseTree );
101101// Returns: string - reconstructed SQL query
102102```
103103
@@ -106,10 +106,10 @@ const sql = await deparse(parseTree[0]);
106106Synchronous version that converts a parse tree back to SQL string directly.
107107
108108``` typescript
109- import { parseQuerySync , deparseSync } from ' libpg-query' ;
109+ import { parseSync , deparseSync } from ' libpg-query' ;
110110
111- const parseTree = parseQuerySync (' SELECT * FROM users WHERE active = true' );
112- const sql = deparseSync (parseTree [ 0 ] );
111+ const parseTree = parseSync (' SELECT * FROM users WHERE active = true' );
112+ const sql = deparseSync (parseTree );
113113// Returns: string - reconstructed SQL query
114114```
115115
@@ -166,37 +166,37 @@ The library provides both async and sync methods. Async methods handle initializ
166166Async methods handle initialization automatically and are always safe to use:
167167
168168``` typescript
169- import { parseQuery , deparse } from ' libpg-query' ;
169+ import { parse , deparse } from ' libpg-query' ;
170170
171171// These handle initialization automatically
172- const result = await parseQuery (' SELECT * FROM users' );
173- const sql = await deparse (result [ 0 ] );
172+ const result = await parse (' SELECT * FROM users' );
173+ const sql = await deparse (result );
174174```
175175
176176#### Sync Methods
177177
178178Sync methods require explicit initialization using ` loadModule() ` :
179179
180180``` typescript
181- import { loadModule , parseQuerySync } from ' libpg-query' ;
181+ import { loadModule , parseSync } from ' libpg-query' ;
182182
183183// Initialize first
184184await loadModule ();
185185
186186// Now safe to use sync methods
187- const result = parseQuerySync (' SELECT * FROM users' );
187+ const result = parseSync (' SELECT * FROM users' );
188188```
189189
190190### ` loadModule(): Promise<void> `
191191
192192Explicitly initializes the WASM module. Required before using any sync methods.
193193
194194``` typescript
195- import { loadModule , parseQuerySync } from ' libpg-query' ;
195+ import { loadModule , parseSync } from ' libpg-query' ;
196196
197197// Initialize before using sync methods
198198await loadModule ();
199- const result = parseQuerySync (' SELECT * FROM users' );
199+ const result = parseSync (' SELECT * FROM users' );
200200```
201201
202202Note: We recommend using async methods as they handle initialization automatically. Use sync methods only when necessary, and always call ` loadModule() ` first.
0 commit comments