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
Copy file name to clipboardExpand all lines: README.md
+44-3Lines changed: 44 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -157,6 +157,29 @@ const normalized = normalizeSync('SELECT * FROM users WHERE active = true');
157
157
// Returns: string - normalized SQL query
158
158
```
159
159
160
+
### `scan(sql: string): Promise<ScanResult>`
161
+
162
+
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.
163
+
164
+
```typescript
165
+
import { scan } from'libpg-query';
166
+
167
+
const result =awaitscan('SELECT * FROM users WHERE id = $1');
168
+
// Returns: ScanResult - detailed tokenization information
Synchronous version that scans (tokenizes) a SQL query directly.
175
+
176
+
```typescript
177
+
import { scanSync } from'libpg-query';
178
+
179
+
const result =scanSync('SELECT * FROM users WHERE id = $1');
180
+
// Returns: ScanResult - detailed tokenization information
181
+
```
182
+
160
183
### Initialization
161
184
162
185
The library provides both async and sync methods. Async methods handle initialization automatically, while sync methods require explicit initialization.
@@ -166,37 +189,40 @@ The library provides both async and sync methods. Async methods handle initializ
166
189
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.
@@ -215,6 +241,21 @@ interface Statement {
215
241
stmt_location:number;
216
242
query:string;
217
243
}
244
+
245
+
interfaceScanResult {
246
+
version:number;
247
+
tokens:ScanToken[];
248
+
}
249
+
250
+
interfaceScanToken {
251
+
start:number; // Starting position in the SQL string
252
+
end:number; // Ending position in the SQL string
253
+
text:string; // The actual token text
254
+
tokenType:number; // Numeric token type identifier
255
+
tokenName:string; // Human-readable token type name
0 commit comments