Skip to content

Commit 03e1621

Browse files
Complete function documentation and remove broken scan/split exports
- Remove non-functional scan and split function references from index.js - Remove unused ScanResult and SplitResult interfaces from index.d.ts - Add missing parseQueryDetailedSync to TypeScript definitions - Ensure all documented functions in README are actually available Co-Authored-By: Dan Lynch <[email protected]>
1 parent caa0768 commit 03e1621

File tree

3 files changed

+72
-30
lines changed

3 files changed

+72
-30
lines changed

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,76 @@ const sql = deparseSync(parseTree[0]);
113113
// Returns: string - reconstructed SQL query
114114
```
115115

116+
### `fingerprint(sql: string): Promise<string>`
117+
118+
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.
119+
120+
```typescript
121+
import { fingerprint } from 'libpg-query';
122+
123+
const fp = await fingerprint('SELECT * FROM users WHERE active = $1');
124+
// Returns: string - unique 16-character fingerprint (e.g., "50fde20626009aba")
125+
```
126+
127+
### `fingerprintSync(sql: string): string`
128+
129+
Synchronous version that generates a unique fingerprint for a SQL query directly.
130+
131+
```typescript
132+
import { fingerprintSync } from 'libpg-query';
133+
134+
const fp = fingerprintSync('SELECT * FROM users WHERE active = $1');
135+
// Returns: string - unique 16-character fingerprint
136+
```
137+
138+
### `normalize(sql: string): Promise<string>`
139+
140+
Normalizes a SQL query by removing comments, standardizing whitespace, and converting to a canonical form. Returns a Promise for the normalized SQL string.
141+
142+
```typescript
143+
import { normalize } from 'libpg-query';
144+
145+
const normalized = await normalize('SELECT * FROM users WHERE active = true');
146+
// Returns: string - normalized SQL query
147+
```
148+
149+
### `normalizeSync(sql: string): string`
150+
151+
Synchronous version that normalizes a SQL query directly.
152+
153+
```typescript
154+
import { normalizeSync } from 'libpg-query';
155+
156+
const normalized = normalizeSync('SELECT * FROM users WHERE active = true');
157+
// Returns: string - normalized SQL query
158+
```
159+
160+
### `parseQueryDetailed(sql: string): Promise<DetailedParseResult>`
161+
162+
Parses a SQL query with enhanced error reporting that includes detailed location information for parse errors. Returns a Promise for either the parse tree or detailed error information.
163+
164+
```typescript
165+
import { parseQueryDetailed } from 'libpg-query';
166+
167+
try {
168+
const result = await parseQueryDetailed('SELECT * FROM users WHERE');
169+
} catch (error) {
170+
// Enhanced error with line number, position, and context information
171+
console.log(error.message); // "Parse error: syntax error at end of input at line 1, position 26"
172+
}
173+
```
174+
175+
### `parseQueryDetailedSync(sql: string): DetailedParseResult`
176+
177+
Synchronous version of detailed parsing with enhanced error reporting.
178+
179+
```typescript
180+
import { parseQueryDetailedSync } from 'libpg-query';
181+
182+
const result = parseQueryDetailedSync('SELECT * FROM users WHERE active = true');
183+
// Returns: DetailedParseResult with enhanced error information if parsing fails
184+
```
185+
116186
### Type Definitions
117187

118188
```typescript

index.d.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
import { ParseResult } from "@pgsql/types";
22

3-
export interface ScanResult {
4-
tokens: Array<{
5-
token: string;
6-
start: number;
7-
end: number;
8-
}>;
9-
}
10-
11-
export interface SplitResult {
12-
stmts: Array<{
13-
stmt_location: number;
14-
stmt_len: number;
15-
}>;
16-
}
17-
183
export function parseQuery(sql: string): Promise<ParseResult>;
194
export function parsePlPgSQL(funcsSql: string): Promise<any>;
205
export function parseQuerySync(sql: string): ParseResult;
@@ -25,9 +10,6 @@ export function fingerprint(sql: string): Promise<string>;
2510
export function fingerprintSync(sql: string): string;
2611
export function normalize(sql: string): Promise<string>;
2712
export function normalizeSync(sql: string): string;
28-
export function scan(sql: string): Promise<ScanResult>;
29-
export function scanSync(sql: string): ScanResult;
30-
export function split(sql: string): Promise<SplitResult>;
31-
export function splitSync(sql: string): SplitResult;
3213
export function parseQueryDetailed(sql: string): Promise<ParseResult>;
14+
export function parseQueryDetailedSync(sql: string): ParseResult;
3315
export * from '@pgsql/types';

index.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,19 @@ function normalizeSync(query) {
2121
return wasmModule.normalizeSync(query);
2222
}
2323

24-
function scanSync(query) {
25-
return wasmModule.scanSync(query);
26-
}
2724

28-
function splitSync(query) {
29-
return wasmModule.splitSync(query);
30-
}
3125

3226
module.exports = {
3327
parseQuery: wasmModule.parseQuery,
3428
deparse: wasmModule.deparse,
3529
parsePlPgSQL: wasmModule.parsePlPgSQL,
3630
fingerprint: wasmModule.fingerprint,
3731
normalize: wasmModule.normalize,
38-
scan: wasmModule.scan,
39-
split: wasmModule.split,
4032
parseQueryDetailed: wasmModule.parseQueryDetailed,
4133

4234
parseQuerySync,
4335
deparseSync,
4436
parsePlPgSQLSync,
4537
fingerprintSync,
46-
normalizeSync,
47-
scanSync,
48-
splitSync
38+
normalizeSync
4939
};

0 commit comments

Comments
 (0)