File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ Napi::Value ParseQueryAsync(const Napi::CallbackInfo& info) {
137137}
138138
139139Napi::Value DeparseAsync (const Napi::CallbackInfo& info) {
140- if (info.Length () < 2 || !info[0 ].IsBuffer () || !info[1 ].IsFunction ()) {
140+ if (info.Length () < 2 || !( info[0 ].IsBuffer () || info[ 0 ]. IsTypedArray () ) || !info[1 ].IsFunction ()) {
141141 Napi::TypeError::New (info.Env (), " Invalid arguments" ).ThrowAsJavaScriptException ();
142142 return info.Env ().Undefined ();
143143 }
Original file line number Diff line number Diff line change 1- import { parseQuery } from '../../../wasm' ;
1+ import { deparse , parseQuery } from '../../../wasm' ;
22
33const sql = 'select * from customers;' ;
44const result = await parseQuery ( sql ) ;
5+ const newSql = await deparse ( result ) ;
56
67console . log ( sql ) ;
78console . log ( result ) ;
9+ console . log ( newSql ) ;
Original file line number Diff line number Diff line change 11import { getDefaultContext } from '@emnapi/runtime' ;
2+ import { pg_query } from '../proto.js' ;
23import PgQueryModule from './libpg-query.js' ;
34
45let PgQuery ;
@@ -30,6 +31,16 @@ export const parseQuery = awaitInit((query) => {
3031 } ) ;
3132} ) ;
3233
34+ export const deparse = awaitInit ( ( parseTree ) => {
35+ const msg = pg_query . ParseResult . fromObject ( parseTree ) ;
36+ const data = pg_query . ParseResult . encode ( msg ) . finish ( ) ;
37+ return new Promise ( ( resolve , reject ) => {
38+ PgQuery . deparseAsync ( data , ( err , result ) => {
39+ err ? reject ( err ) : resolve ( result ) ;
40+ } ) ;
41+ } ) ;
42+ } ) ;
43+
3344export const parsePlPgSQL = awaitInit ( ( query ) => {
3445 return new Promise ( async ( resolve , reject ) => {
3546 PgQuery . parsePlPgSQLAsync ( query , ( err , result ) => {
You can’t perform that action at this time.
0 commit comments