Skip to content

Commit 5b641c1

Browse files
committed
updates
1 parent 8e624a0 commit 5b641c1

File tree

16 files changed

+16
-250
lines changed

16 files changed

+16
-250
lines changed

parser/scripts/prepare.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// run "pnpm build:parser:full" in root
12
const fs = require('fs');
23
const path = require('path');
34

parser/templates/index.cjs.template

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ class Parser {
3232

3333
parseSync(query) {
3434
if (!this.parser) {
35-
throw new Error('Parser not loaded. Call parse() first or use parseSync after loading.');
36-
}
37-
if (!this.parser.parseSync) {
38-
throw new Error(`parseSync not supported in PostgreSQL ${this.version}`);
35+
throw new Error('Parser not loaded. Call loadParser() first or use parseSync after loading.');
3936
}
4037
try {
4138
return this.parser.parseSync(query);
@@ -44,21 +41,6 @@ class Parser {
4441
}
4542
}
4643

47-
async fingerprint(query) {
48-
await this.loadParser();
49-
if (this.parser.fingerprint) {
50-
return this.parser.fingerprint(query);
51-
}
52-
throw new Error(`Fingerprint not supported in PostgreSQL ${this.version}`);
53-
}
54-
55-
async normalize(query) {
56-
await this.loadParser();
57-
if (this.parser.normalize) {
58-
return this.parser.normalize(query);
59-
}
60-
throw new Error(`Normalize not supported in PostgreSQL ${this.version}`);
61-
}
6244
}
6345

6446
// Export versions

parser/templates/index.d.ts.template

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ export interface ParseResult {
1515

1616
export declare class Parser {
1717
constructor(version?: ${VERSION_UNION});
18+
loadParser(): Promise<void>;
1819
parse(query: string): Promise<ParseResult>;
1920
parseSync(query: string): ParseResult;
20-
fingerprint(query: string): Promise<string>;
21-
normalize(query: string): Promise<string>;
2221
}
2322

2423
export default Parser;

parser/templates/index.js.template

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ export class Parser {
3232

3333
parseSync(query) {
3434
if (!this.parser) {
35-
throw new Error('Parser not loaded. Call parse() first or use parseSync after loading.');
36-
}
37-
if (!this.parser.parseSync) {
38-
throw new Error(`parseSync not supported in PostgreSQL ${this.version}`);
35+
throw new Error('Parser not loaded. Call loadParser() first or use parseSync after loading.');
3936
}
4037
try {
4138
return this.parser.parseSync(query);
@@ -44,21 +41,6 @@ export class Parser {
4441
}
4542
}
4643

47-
async fingerprint(query) {
48-
await this.loadParser();
49-
if (this.parser.fingerprint) {
50-
return this.parser.fingerprint(query);
51-
}
52-
throw new Error(`Fingerprint not supported in PostgreSQL ${this.version}`);
53-
}
54-
55-
async normalize(query) {
56-
await this.loadParser();
57-
if (this.parser.normalize) {
58-
return this.parser.normalize(query);
59-
}
60-
throw new Error(`Normalize not supported in PostgreSQL ${this.version}`);
61-
}
6244
}
6345

6446
// Re-export all versions for direct access

templates/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ifdef EMSCRIPTEN
6262
-I$(LIBPG_QUERY_DIR) \
6363
-I$(LIBPG_QUERY_DIR)/vendor \
6464
-L$(LIBPG_QUERY_DIR) \
65-
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query','_wasm_free_string','_wasm_parse_query_raw','_wasm_free_parse_result']" \
65+
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
6666
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
6767
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
6868
-sENVIRONMENT="web,node" \

templates/src/wasm_wrapper.c

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ static int validate_input(const char* input) {
77
return input != NULL && strlen(input) > 0;
88
}
99

10-
static char* safe_strdup(const char* str) {
11-
if (!str) return NULL;
12-
char* result = strdup(str);
13-
if (!result) {
14-
return NULL;
15-
}
16-
return result;
17-
}
18-
1910
static void* safe_malloc(size_t size) {
2011
void* ptr = malloc(size);
2112
if (!ptr && size > 0) {
@@ -24,34 +15,10 @@ static void* safe_malloc(size_t size) {
2415
return ptr;
2516
}
2617

27-
EMSCRIPTEN_KEEPALIVE
28-
char* wasm_parse_query(const char* input) {
29-
if (!validate_input(input)) {
30-
return safe_strdup("Invalid input: query cannot be null or empty");
31-
}
32-
33-
PgQueryParseResult result = pg_query_parse(input);
34-
35-
if (result.error) {
36-
char* error_msg = safe_strdup(result.error->message);
37-
pg_query_free_parse_result(result);
38-
return error_msg ? error_msg : safe_strdup("Memory allocation failed");
39-
}
40-
41-
char* parse_tree = safe_strdup(result.parse_tree);
42-
pg_query_free_parse_result(result);
43-
return parse_tree;
44-
}
45-
46-
EMSCRIPTEN_KEEPALIVE
47-
void wasm_free_string(char* str) {
48-
free(str);
49-
}
50-
5118
// Raw struct access functions for parse
5219
EMSCRIPTEN_KEEPALIVE
5320
PgQueryParseResult* wasm_parse_query_raw(const char* input) {
54-
if (!input) {
21+
if (!validate_input(input)) {
5522
return NULL;
5623
}
5724

versions/13/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ ifdef EMSCRIPTEN
6767
-I$(LIBPG_QUERY_DIR) \
6868
-I$(LIBPG_QUERY_DIR)/vendor \
6969
-L$(LIBPG_QUERY_DIR) \
70-
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query','_wasm_free_string','_wasm_parse_query_raw','_wasm_free_parse_result']" \
70+
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
7171
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
7272
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
7373
-sENVIRONMENT="web,node" \

versions/13/src/wasm_wrapper.c

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ static int validate_input(const char* input) {
1414
return input != NULL && strlen(input) > 0;
1515
}
1616

17-
static char* safe_strdup(const char* str) {
18-
if (!str) return NULL;
19-
char* result = strdup(str);
20-
if (!result) {
21-
return NULL;
22-
}
23-
return result;
24-
}
25-
2617
static void* safe_malloc(size_t size) {
2718
void* ptr = malloc(size);
2819
if (!ptr && size > 0) {
@@ -31,34 +22,10 @@ static void* safe_malloc(size_t size) {
3122
return ptr;
3223
}
3324

34-
EMSCRIPTEN_KEEPALIVE
35-
char* wasm_parse_query(const char* input) {
36-
if (!validate_input(input)) {
37-
return safe_strdup("Invalid input: query cannot be null or empty");
38-
}
39-
40-
PgQueryParseResult result = pg_query_parse(input);
41-
42-
if (result.error) {
43-
char* error_msg = safe_strdup(result.error->message);
44-
pg_query_free_parse_result(result);
45-
return error_msg ? error_msg : safe_strdup("Memory allocation failed");
46-
}
47-
48-
char* parse_tree = safe_strdup(result.parse_tree);
49-
pg_query_free_parse_result(result);
50-
return parse_tree;
51-
}
52-
53-
EMSCRIPTEN_KEEPALIVE
54-
void wasm_free_string(char* str) {
55-
free(str);
56-
}
57-
5825
// Raw struct access functions for parse
5926
EMSCRIPTEN_KEEPALIVE
6027
PgQueryParseResult* wasm_parse_query_raw(const char* input) {
61-
if (!input) {
28+
if (!validate_input(input)) {
6229
return NULL;
6330
}
6431

versions/14/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ ifdef EMSCRIPTEN
6363
-I$(LIBPG_QUERY_DIR) \
6464
-I$(LIBPG_QUERY_DIR)/vendor \
6565
-L$(LIBPG_QUERY_DIR) \
66-
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query','_wasm_free_string','_wasm_parse_query_raw','_wasm_free_parse_result']" \
66+
-sEXPORTED_FUNCTIONS="['_malloc','_free','_wasm_parse_query_raw','_wasm_free_parse_result']" \
6767
-sEXPORTED_RUNTIME_METHODS="['lengthBytesUTF8','stringToUTF8','getValue','UTF8ToString','HEAPU8','HEAPU32']" \
6868
-sEXPORT_NAME="$(WASM_MODULE_NAME)" \
6969
-sENVIRONMENT="web,node" \

versions/14/src/wasm_wrapper.c

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ static int validate_input(const char* input) {
1414
return input != NULL && strlen(input) > 0;
1515
}
1616

17-
static char* safe_strdup(const char* str) {
18-
if (!str) return NULL;
19-
char* result = strdup(str);
20-
if (!result) {
21-
return NULL;
22-
}
23-
return result;
24-
}
25-
2617
static void* safe_malloc(size_t size) {
2718
void* ptr = malloc(size);
2819
if (!ptr && size > 0) {
@@ -31,34 +22,10 @@ static void* safe_malloc(size_t size) {
3122
return ptr;
3223
}
3324

34-
EMSCRIPTEN_KEEPALIVE
35-
char* wasm_parse_query(const char* input) {
36-
if (!validate_input(input)) {
37-
return safe_strdup("Invalid input: query cannot be null or empty");
38-
}
39-
40-
PgQueryParseResult result = pg_query_parse(input);
41-
42-
if (result.error) {
43-
char* error_msg = safe_strdup(result.error->message);
44-
pg_query_free_parse_result(result);
45-
return error_msg ? error_msg : safe_strdup("Memory allocation failed");
46-
}
47-
48-
char* parse_tree = safe_strdup(result.parse_tree);
49-
pg_query_free_parse_result(result);
50-
return parse_tree;
51-
}
52-
53-
EMSCRIPTEN_KEEPALIVE
54-
void wasm_free_string(char* str) {
55-
free(str);
56-
}
57-
5825
// Raw struct access functions for parse
5926
EMSCRIPTEN_KEEPALIVE
6027
PgQueryParseResult* wasm_parse_query_raw(const char* input) {
61-
if (!input) {
28+
if (!validate_input(input)) {
6229
return NULL;
6330
}
6431

0 commit comments

Comments
 (0)