Skip to content

Commit 9ecd980

Browse files
committed
detailed methods removed
1 parent 8d0ff03 commit 9ecd980

File tree

6 files changed

+1
-213
lines changed

6 files changed

+1
-213
lines changed

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# 17.2.1
22
* Add normalize() and normalizeSync() functions for SQL normalization
3-
* Add parseQueryDetailed() and parseQueryDetailedSync() with enhanced error reporting
43
* Add fingerprint() and fingerprintSync() functions for query fingerprinting
54
* Add isReady() function to check WASM module initialization status
65
* Improve memory management and error handling in WASM wrapper

README.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -157,32 +157,6 @@ const normalized = normalizeSync('SELECT * FROM users WHERE active = true');
157157
// Returns: string - normalized SQL query
158158
```
159159

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-
186160
### Initialization
187161

188162
The library provides both async and sync methods. Async methods handle initialization automatically, while sync methods require explicit initialization.

test/parsing.test.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,4 @@ describe("Query Parsing", () => {
8080
);
8181
});
8282
});
83-
84-
describe("Detailed Error Parsing", () => {
85-
it("should provide detailed error information for invalid queries", async () => {
86-
try {
87-
await query.parseQueryDetailed("SELECT FROM");
88-
throw new Error("should have thrown");
89-
} catch (e) {
90-
expect(e.message).to.include("Parse error:");
91-
expect(e.message).to.include("line");
92-
expect(e.message).to.include("position");
93-
}
94-
});
95-
96-
it("should parse valid queries with detailed parsing", async () => {
97-
const result = await query.parseQueryDetailed("SELECT 1");
98-
expect(result.stmts).to.have.lengthOf(1);
99-
expect(result.stmts[0].stmt.SelectStmt).to.exist;
100-
});
101-
});
10283
});

wasm/index.cjs

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -154,45 +154,6 @@ const normalize = awaitInit(async (query) => {
154154
}
155155
});
156156

157-
const parseQueryDetailed = awaitInit(async (query) => {
158-
const queryPtr = stringToPtr(query);
159-
let resultPtr;
160-
161-
try {
162-
resultPtr = wasmModule._wasm_parse_query_detailed(queryPtr);
163-
164-
const hasError = wasmModule.HEAPU32[resultPtr >> 2];
165-
166-
if (hasError) {
167-
const messagePtr = wasmModule.HEAPU32[(resultPtr + 4) >> 2];
168-
const funcnamePtr = wasmModule.HEAPU32[(resultPtr + 8) >> 2];
169-
const filenamePtr = wasmModule.HEAPU32[(resultPtr + 12) >> 2];
170-
const lineno = wasmModule.HEAPU32[(resultPtr + 16) >> 2];
171-
const cursorpos = wasmModule.HEAPU32[(resultPtr + 20) >> 2];
172-
const contextPtr = wasmModule.HEAPU32[(resultPtr + 24) >> 2];
173-
174-
const error = {
175-
message: messagePtr ? ptrToString(messagePtr) : '',
176-
funcname: funcnamePtr ? ptrToString(funcnamePtr) : null,
177-
filename: filenamePtr ? ptrToString(filenamePtr) : null,
178-
lineno: lineno,
179-
cursorpos: cursorpos,
180-
context: contextPtr ? ptrToString(contextPtr) : null
181-
};
182-
183-
wasmModule._wasm_free_detailed_result(resultPtr);
184-
throw new Error(error.message);
185-
} else {
186-
const dataPtr = wasmModule.HEAPU32[(resultPtr + 28) >> 2];
187-
const result = JSON.parse(ptrToString(dataPtr));
188-
wasmModule._wasm_free_detailed_result(resultPtr);
189-
return result;
190-
}
191-
} finally {
192-
wasmModule._free(queryPtr);
193-
}
194-
});
195-
196157
// Sync versions
197158
function parseQuerySync(query) {
198159
if (!wasmModule) {
@@ -326,60 +287,16 @@ function normalizeSync(query) {
326287
}
327288
}
328289

329-
function parseQueryDetailedSync(query) {
330-
if (!wasmModule) {
331-
throw new Error('WASM module not initialized. Call loadModule() first.');
332-
}
333-
const queryPtr = stringToPtr(query);
334-
let resultPtr;
335-
336-
try {
337-
resultPtr = wasmModule._wasm_parse_query_detailed(queryPtr);
338-
339-
const hasError = wasmModule.HEAPU32[resultPtr >> 2];
340-
341-
if (hasError) {
342-
const messagePtr = wasmModule.HEAPU32[(resultPtr + 4) >> 2];
343-
const funcnamePtr = wasmModule.HEAPU32[(resultPtr + 8) >> 2];
344-
const filenamePtr = wasmModule.HEAPU32[(resultPtr + 12) >> 2];
345-
const lineno = wasmModule.HEAPU32[(resultPtr + 16) >> 2];
346-
const cursorpos = wasmModule.HEAPU32[(resultPtr + 20) >> 2];
347-
const contextPtr = wasmModule.HEAPU32[(resultPtr + 24) >> 2];
348-
349-
const error = {
350-
message: messagePtr ? ptrToString(messagePtr) : '',
351-
funcname: funcnamePtr ? ptrToString(funcnamePtr) : null,
352-
filename: filenamePtr ? ptrToString(filenamePtr) : null,
353-
lineno: lineno,
354-
cursorpos: cursorpos,
355-
context: contextPtr ? ptrToString(contextPtr) : null
356-
};
357-
358-
wasmModule._wasm_free_detailed_result(resultPtr);
359-
throw new Error(error.message);
360-
} else {
361-
const dataPtr = wasmModule.HEAPU32[(resultPtr + 28) >> 2];
362-
const result = JSON.parse(ptrToString(dataPtr));
363-
wasmModule._wasm_free_detailed_result(resultPtr);
364-
return result;
365-
}
366-
} finally {
367-
wasmModule._free(queryPtr);
368-
}
369-
}
370-
371290
module.exports = {
372291
loadModule,
373292
parseQuery,
374293
deparse,
375294
parsePlPgSQL,
376295
fingerprint,
377296
normalize,
378-
parseQueryDetailed,
379297
parseQuerySync,
380298
deparseSync,
381299
parsePlPgSQLSync,
382300
fingerprintSync,
383-
normalizeSync,
384-
parseQueryDetailedSync
301+
normalizeSync
385302
};

wasm/index.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@ export function fingerprint(sql: string): Promise<string>;
1212
export function fingerprintSync(sql: string): string;
1313
export function normalize(sql: string): Promise<string>;
1414
export function normalizeSync(sql: string): string;
15-
export function parseQueryDetailed(sql: string): Promise<ParseResult>;
16-
export function parseQueryDetailedSync(sql: string): ParseResult;
1715

1816
export * from '@pgsql/types';

wasm/index.js

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -154,45 +154,6 @@ export const normalize = awaitInit(async (query) => {
154154
}
155155
});
156156

157-
export const parseQueryDetailed = awaitInit(async (query) => {
158-
const queryPtr = stringToPtr(query);
159-
let resultPtr;
160-
161-
try {
162-
resultPtr = wasmModule._wasm_parse_query_detailed(queryPtr);
163-
164-
const hasError = wasmModule.HEAPU32[resultPtr >> 2];
165-
166-
if (hasError) {
167-
const messagePtr = wasmModule.HEAPU32[(resultPtr + 4) >> 2];
168-
const funcnamePtr = wasmModule.HEAPU32[(resultPtr + 8) >> 2];
169-
const filenamePtr = wasmModule.HEAPU32[(resultPtr + 12) >> 2];
170-
const lineno = wasmModule.HEAPU32[(resultPtr + 16) >> 2];
171-
const cursorpos = wasmModule.HEAPU32[(resultPtr + 20) >> 2];
172-
const contextPtr = wasmModule.HEAPU32[(resultPtr + 24) >> 2];
173-
174-
const error = {
175-
message: messagePtr ? ptrToString(messagePtr) : '',
176-
funcname: funcnamePtr ? ptrToString(funcnamePtr) : null,
177-
filename: filenamePtr ? ptrToString(filenamePtr) : null,
178-
lineno: lineno,
179-
cursorpos: cursorpos,
180-
context: contextPtr ? ptrToString(contextPtr) : null
181-
};
182-
183-
wasmModule._wasm_free_detailed_result(resultPtr);
184-
throw new Error(error.message);
185-
} else {
186-
const dataPtr = wasmModule.HEAPU32[(resultPtr + 28) >> 2];
187-
const result = JSON.parse(ptrToString(dataPtr));
188-
wasmModule._wasm_free_detailed_result(resultPtr);
189-
return result;
190-
}
191-
} finally {
192-
wasmModule._free(queryPtr);
193-
}
194-
});
195-
196157
// Sync versions
197158
export function parseQuerySync(query) {
198159
if (!wasmModule) {
@@ -325,45 +286,3 @@ export function normalizeSync(query) {
325286
}
326287
}
327288
}
328-
329-
export function parseQueryDetailedSync(query) {
330-
if (!wasmModule) {
331-
throw new Error('WASM module not initialized. Call loadModule() first.');
332-
}
333-
const queryPtr = stringToPtr(query);
334-
let resultPtr;
335-
336-
try {
337-
resultPtr = wasmModule._wasm_parse_query_detailed(queryPtr);
338-
339-
const hasError = wasmModule.HEAPU32[resultPtr >> 2];
340-
341-
if (hasError) {
342-
const messagePtr = wasmModule.HEAPU32[(resultPtr + 4) >> 2];
343-
const funcnamePtr = wasmModule.HEAPU32[(resultPtr + 8) >> 2];
344-
const filenamePtr = wasmModule.HEAPU32[(resultPtr + 12) >> 2];
345-
const lineno = wasmModule.HEAPU32[(resultPtr + 16) >> 2];
346-
const cursorpos = wasmModule.HEAPU32[(resultPtr + 20) >> 2];
347-
const contextPtr = wasmModule.HEAPU32[(resultPtr + 24) >> 2];
348-
349-
const error = {
350-
message: messagePtr ? ptrToString(messagePtr) : '',
351-
funcname: funcnamePtr ? ptrToString(funcnamePtr) : null,
352-
filename: filenamePtr ? ptrToString(filenamePtr) : null,
353-
lineno: lineno,
354-
cursorpos: cursorpos,
355-
context: contextPtr ? ptrToString(contextPtr) : null
356-
};
357-
358-
wasmModule._wasm_free_detailed_result(resultPtr);
359-
throw new Error(error.message);
360-
} else {
361-
const dataPtr = wasmModule.HEAPU32[(resultPtr + 28) >> 2];
362-
const result = JSON.parse(ptrToString(dataPtr));
363-
wasmModule._wasm_free_detailed_result(resultPtr);
364-
return result;
365-
}
366-
} finally {
367-
wasmModule._free(queryPtr);
368-
}
369-
}

0 commit comments

Comments
 (0)