@@ -29,6 +29,7 @@ export {
2929} from "./operators.js" ;
3030export type { Operator , RowBatch , FragmentSource , PipelineOptions , PipelineResult } from "./operators.js" ;
3131export { QueryModeError } from "./errors.js" ;
32+ import { QueryModeError } from "./errors.js" ;
3233export type { ErrorCode } from "./errors.js" ;
3334export { LocalExecutor } from "./local-executor.js" ;
3435export { bigIntReplacer } from "./decode.js" ;
@@ -168,11 +169,16 @@ export class QueryMode {
168169 /** List all known tables with column names and row counts (edge mode only). */
169170 async tables ( ) : Promise < { name : string ; columns : string [ ] ; totalRows : number ; updatedAt ?: number ; accessCount ?: number } [ ] > {
170171 if ( ! ( this . executor instanceof RemoteExecutor ) ) {
171- throw new Error ( "tables() is only available in edge mode. Use .table(path).describe() for local files." ) ;
172+ throw new QueryModeError ( "QUERY_FAILED" , "tables() is only available in edge mode. Use .table(path).describe() for local files." ) ;
172173 }
173174 const result = await ( this . executor as RemoteExecutor ) . listTables ( ) ;
174175 return result . tables as { name : string ; columns : string [ ] ; totalRows : number ; updatedAt ?: number ; accessCount ?: number } [ ] ;
175176 }
177+
178+ /** @internal Get the underlying executor (for pg-wire and similar integrations). */
179+ getExecutor ( ) : QueryExecutor {
180+ return this . executor ;
181+ }
176182}
177183
178184/**
@@ -212,7 +218,7 @@ class RemoteExecutor implements QueryExecutor {
212218 /** Append rows via RPC to Master DO. Partitioned writes fan out to separate MasterDOs. */
213219 async append ( table : string , rows : Record < string , unknown > [ ] , options ?: AppendOptions ) : Promise < AppendResult > {
214220 if ( ! this . masterNamespace ) {
215- throw new Error ( "append() requires masterDoNamespace — pass it via QueryMode.remote(queryDO, { masterDO })" ) ;
221+ throw new QueryModeError ( "QUERY_FAILED" , "append() requires masterDoNamespace — pass it via QueryMode.remote(queryDO, { masterDO })" ) ;
216222 }
217223
218224 // Partitioned writes: split by partition key, route each group to a different MasterDO
@@ -252,7 +258,7 @@ class RemoteExecutor implements QueryExecutor {
252258 /** Drop a table via RPC to Master DO — deletes all R2 objects and metadata. */
253259 async drop ( table : string ) : Promise < DropResult > {
254260 if ( ! this . masterNamespace ) {
255- throw new Error ( "drop() requires masterDoNamespace — pass it via QueryMode.remote(queryDO, { masterDO })" ) ;
261+ throw new QueryModeError ( "QUERY_FAILED" , "drop() requires masterDoNamespace — pass it via QueryMode.remote(queryDO, { masterDO })" ) ;
256262 }
257263 const id = this . masterNamespace . idFromName ( "master" ) ;
258264 const masterRpc = this . masterNamespace . get ( id ) as unknown as MasterDORpc ;
0 commit comments