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
const parseTree =parseSync('SELECT * FROM users WHERE active = true');
113
-
const sql =deparseSync(parseTree);
114
-
// Returns: string - reconstructed SQL query
115
-
```
116
-
117
-
### `fingerprint(sql: string): Promise<string>`
118
-
119
-
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.
120
-
121
-
```typescript
122
-
import { fingerprint } from'libpg-query';
123
-
124
-
const fp =awaitfingerprint('SELECT * FROM users WHERE active = $1');
Normalizes a SQL query by removing comments, standardizing whitespace, and converting to a canonical form. Returns a Promise for the normalized SQL string.
142
-
143
-
```typescript
144
-
import { normalize } from'libpg-query';
145
-
146
-
const normalized =awaitnormalize('SELECT * FROM users WHERE active = true');
147
-
// Returns: string - normalized SQL query
148
-
```
149
-
150
-
### `normalizeSync(sql: string): string`
151
-
152
-
Synchronous version that normalizes a SQL query directly.
153
-
154
-
```typescript
155
-
import { normalizeSync } from'libpg-query';
156
-
157
-
const normalized =normalizeSync('SELECT * FROM users WHERE active = true');
158
-
// Returns: string - normalized SQL query
159
-
```
160
-
161
-
### `scan(sql: string): Promise<ScanResult>`
162
-
163
-
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.
164
-
165
-
```typescript
166
-
import { scan } from'libpg-query';
167
-
168
-
const result =awaitscan('SELECT * FROM users WHERE id = $1');
169
-
// Returns: ScanResult - detailed tokenization information
Synchronous version that scans (tokenizes) a SQL query directly.
176
-
177
-
```typescript
178
-
import { scanSync } from'libpg-query';
179
-
180
-
const result =scanSync('SELECT * FROM users WHERE id = $1');
181
-
// Returns: ScanResult - detailed tokenization information
182
-
```
87
+
**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.
183
88
184
89
### Initialization
185
90
@@ -190,40 +95,36 @@ The library provides both async and sync methods. Async methods handle initializ
190
95
Async methods handle initialization automatically and are always safe to use:
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 {
243
144
query:string;
244
145
}
245
146
246
-
interfaceScanResult {
247
-
version:number;
248
-
tokens:ScanToken[];
249
-
}
250
-
251
-
interfaceScanToken {
252
-
start:number; // Starting position in the SQL string
253
-
end:number; // Ending position in the SQL string
254
-
text:string; // The actual token text
255
-
tokenType:number; // Numeric token type identifier
256
-
tokenName:string; // Human-readable token type name
0 commit comments