-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathlib.rs
More file actions
735 lines (629 loc) · 19.3 KB
/
lib.rs
File metadata and controls
735 lines (629 loc) · 19.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
mod client;
use crate::client::{
AdbcConnectionCore as CoreConnection, AdbcDatabaseCore as CoreDatabase,
AdbcResultIteratorCore as CoreResultIterator, AdbcStatementCore as CoreStatement, ClientError,
ConnectOptions as CoreConnectOptions, GetObjectsOptions as CoreGetObjectsOptions,
GetTableSchemaOptions as CoreGetTableSchemaOptions,
};
use adbc_core::options::AdbcVersion;
use napi::bindgen_prelude::{
AsyncTask, Buffer, Error, JsObjectValue, Result, Status, ToNapiValue, Unknown,
};
use napi::{Env, Task};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
#[macro_use]
extern crate napi_derive;
fn to_napi_err(err: ClientError) -> Error {
match err {
ClientError::Adbc(e) => Error::new(Status::GenericFailure, e.message),
ClientError::Arrow(e) => Error::new(Status::GenericFailure, format!("Arrow Error: {e}")),
ClientError::Other(e) => Error::new(Status::GenericFailure, format!("Internal Error: {e}")),
}
}
/// Converts an ADBC error into a `napi::Error` whose JS form is a structured `AdbcError`
/// object with `name`, `code`, `vendorCode`, and `sqlState` properties.
///
/// The JS object is stored via `napi_ref` (napi-rs's `maybe_raw` field) so napi-rs uses it
/// directly as the throw/rejection value. This avoids `env.throw()`, which sets a V8 pending
/// exception that would escape `Task::reject` as an uncaughtException instead of rejecting
/// the Promise.
fn build_adbc_err(env: Env, ae: adbc_core::error::Error) -> Error {
let adbc_core::error::Error {
message,
status,
vendor_code,
sqlstate,
..
} = ae;
// details (ADBC 1.1.0 key-value metadata) are not yet exposed to JS.
let Ok(mut js_err) = env.create_error(Error::new(Status::GenericFailure, message.as_str()))
else {
return Error::new(Status::GenericFailure, message);
};
let _ = js_err.set_named_property("name", "AdbcError");
let _ = js_err.set_named_property("code", format!("{status:?}").as_str());
if vendor_code != i32::MIN {
let _ = js_err.set_named_property("vendorCode", vendor_code);
}
let sqlstate_bytes: [u8; 5] = sqlstate.map(|c| c as u8);
if sqlstate_bytes.iter().any(|&b| b != 0) {
let sql_state = std::str::from_utf8(&sqlstate_bytes).unwrap_or("");
let _ = js_err.set_named_property("sqlState", sql_state);
}
let raw_env = env.raw();
match unsafe { ToNapiValue::to_napi_value(raw_env, js_err) } {
Ok(raw_val) => Error::from(unsafe { Unknown::from_raw_unchecked(raw_env, raw_val) }),
Err(fallback) => fallback,
}
}
/// For synchronous `#[napi]` methods: converts a `ClientError` to a `napi::Error` that,
/// when propagated by napi-rs, throws a structured `AdbcError` JS object.
fn sync_adbc_err(err: ClientError, env: Env) -> Error {
match err {
ClientError::Adbc(ae) => build_adbc_err(env, ae),
other => to_napi_err(other),
}
}
/// Captures an ADBC error from a thread-pool `compute()` result into `sink` so that
/// `reject()` (main JS thread) can later call `build_adbc_err` with an `Env`.
fn capture_adbc_err<T>(
result: crate::client::Result<T>,
sink: &mut Option<adbc_core::error::Error>,
) -> Result<T> {
result.map_err(|e| match e {
ClientError::Adbc(ae) => {
let napi_err = Error::new(Status::GenericFailure, ae.message.as_str());
*sink = Some(ae);
napi_err
}
other => to_napi_err(other),
})
}
fn reject_adbc<T>(
env: Env,
adbc_err: &mut Option<adbc_core::error::Error>,
err: Error,
) -> Result<T> {
Err(
adbc_err
.take()
.map(|ae| build_adbc_err(env, ae))
.unwrap_or(err),
)
}
fn closed_err() -> Error {
Error::new(Status::GenericFailure, "Object is closed")
}
#[napi]
pub fn crate_version() -> String {
env!("CARGO_PKG_VERSION").to_string()
}
#[napi]
pub fn default_adbc_version() -> String {
match AdbcVersion::default() {
AdbcVersion::V100 => "1.0.0".to_string(),
AdbcVersion::V110 => "1.1.0".to_string(),
_ => "unknown".to_string(),
}
}
#[napi]
pub fn default_load_flags() -> u32 {
adbc_core::LOAD_FLAG_DEFAULT
}
// Options
#[napi(object)]
pub struct ConnectOptions {
pub driver: String,
pub entrypoint: Option<String>,
pub manifest_search_paths: Option<Vec<String>>,
pub profile_search_paths: Option<Vec<String>>,
pub load_flags: Option<u32>,
pub database_options: Option<HashMap<String, String>>,
}
impl From<ConnectOptions> for CoreConnectOptions {
fn from(opts: ConnectOptions) -> Self {
Self {
driver: opts.driver,
entrypoint: opts.entrypoint,
manifest_search_paths: opts.manifest_search_paths,
profile_search_paths: opts.profile_search_paths,
load_flags: opts.load_flags,
database_options: opts.database_options,
}
}
}
#[napi(object)]
pub struct GetObjectsOptions {
pub depth: i32,
pub catalog: Option<String>,
pub db_schema: Option<String>,
pub table_name: Option<String>,
pub table_type: Option<Vec<String>>,
pub column_name: Option<String>,
}
impl From<GetObjectsOptions> for CoreGetObjectsOptions {
fn from(opts: GetObjectsOptions) -> Self {
Self {
depth: opts.depth,
catalog: opts.catalog,
db_schema: opts.db_schema,
table_name: opts.table_name,
table_type: opts.table_type,
column_name: opts.column_name,
}
}
}
#[napi(object)]
pub struct GetTableSchemaOptions {
pub catalog: Option<String>,
pub db_schema: Option<String>,
pub table_name: String,
}
impl From<GetTableSchemaOptions> for CoreGetTableSchemaOptions {
fn from(opts: GetTableSchemaOptions) -> Self {
Self {
catalog: opts.catalog,
db_schema: opts.db_schema,
table_name: opts.table_name,
}
}
}
// --- Database ---
#[napi]
pub struct _NativeAdbcDatabase {
inner: Option<Arc<CoreDatabase>>,
}
#[napi]
impl _NativeAdbcDatabase {
#[napi(constructor)]
pub fn new(opts: ConnectOptions) -> Result<Self> {
let db = CoreDatabase::new(opts.into()).map_err(to_napi_err)?;
Ok(Self {
inner: Some(Arc::new(db)),
})
}
#[napi]
pub fn connect(
&self,
options: Option<HashMap<String, String>>,
) -> Result<AsyncTask<ConnectTask>> {
let db = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(ConnectTask {
database: db.clone(),
options,
adbc_err: None,
}))
}
#[napi]
pub fn close(&mut self) -> Result<()> {
self.inner.take();
Ok(())
}
}
pub struct ConnectTask {
database: Arc<CoreDatabase>,
options: Option<HashMap<String, String>>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for ConnectTask {
type Output = CoreConnection;
type JsValue = _NativeAdbcConnection;
fn compute(&mut self) -> Result<Self::Output> {
capture_adbc_err(
self.database.connect(self.options.take()),
&mut self.adbc_err,
)
}
fn resolve(&mut self, _env: Env, output: Self::Output) -> Result<Self::JsValue> {
Ok(_NativeAdbcConnection {
inner: Some(Arc::new(output)),
})
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
// --- Connection ---
#[napi]
pub struct _NativeAdbcConnection {
inner: Option<Arc<CoreConnection>>,
}
#[napi]
impl _NativeAdbcConnection {
#[napi]
pub fn create_statement(&self) -> Result<AsyncTask<CreateStatementTask>> {
let conn = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(CreateStatementTask {
connection: conn.clone(),
adbc_err: None,
}))
}
#[napi]
pub fn set_option(&self, env: Env, key: String, value: String) -> Result<()> {
let conn = self.inner.as_ref().ok_or_else(closed_err)?;
conn
.set_option(&key, &value)
.map_err(|e| sync_adbc_err(e, env))
}
#[napi]
pub fn get_objects(&self, opts: GetObjectsOptions) -> Result<AsyncTask<GetObjectsTask>> {
let conn = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(GetObjectsTask {
connection: conn.clone(),
options: Some(opts.into()),
adbc_err: None,
}))
}
#[napi]
pub fn get_table_schema(
&self,
opts: GetTableSchemaOptions,
) -> Result<AsyncTask<GetTableSchemaTask>> {
let conn = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(GetTableSchemaTask {
connection: conn.clone(),
options: Some(opts.into()),
adbc_err: None,
}))
}
#[napi]
pub fn get_table_types(&self) -> Result<AsyncTask<GetTableTypesTask>> {
let conn = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(GetTableTypesTask {
connection: conn.clone(),
adbc_err: None,
}))
}
#[napi]
pub fn get_info(&self, info_codes: Option<Vec<u32>>) -> Result<AsyncTask<GetInfoTask>> {
let conn = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(GetInfoTask {
connection: conn.clone(),
info_codes,
adbc_err: None,
}))
}
#[napi]
pub fn commit(&self) -> Result<AsyncTask<CommitTask>> {
let conn = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(CommitTask {
connection: conn.clone(),
adbc_err: None,
}))
}
#[napi]
pub fn rollback(&self) -> Result<AsyncTask<RollbackTask>> {
let conn = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(RollbackTask {
connection: conn.clone(),
adbc_err: None,
}))
}
#[napi]
pub fn close(&mut self) -> Result<()> {
self.inner.take();
Ok(())
}
}
pub struct CreateStatementTask {
connection: Arc<CoreConnection>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for CreateStatementTask {
type Output = CoreStatement;
type JsValue = _NativeAdbcStatement;
fn compute(&mut self) -> Result<Self::Output> {
capture_adbc_err(self.connection.new_statement(), &mut self.adbc_err)
}
fn resolve(&mut self, _env: Env, output: Self::Output) -> Result<Self::JsValue> {
Ok(_NativeAdbcStatement {
inner: Some(Arc::new(Mutex::new(output))),
})
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
// Metadata Tasks
pub struct GetObjectsTask {
connection: Arc<CoreConnection>,
options: Option<CoreGetObjectsOptions>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for GetObjectsTask {
type Output = CoreResultIterator;
type JsValue = _NativeAdbcResultIterator;
fn compute(&mut self) -> Result<Self::Output> {
let opts = self.options.take().expect("compute called twice");
capture_adbc_err(self.connection.get_objects(opts), &mut self.adbc_err)
}
fn resolve(&mut self, _env: Env, output: Self::Output) -> Result<Self::JsValue> {
Ok(_NativeAdbcResultIterator {
inner: Some(Arc::new(Mutex::new(output))),
})
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
pub struct GetTableSchemaTask {
connection: Arc<CoreConnection>,
options: Option<CoreGetTableSchemaOptions>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for GetTableSchemaTask {
type Output = Vec<u8>;
type JsValue = Buffer;
fn compute(&mut self) -> Result<Self::Output> {
let opts = self.options.take().expect("compute called twice");
capture_adbc_err(self.connection.get_table_schema(opts), &mut self.adbc_err)
}
fn resolve(&mut self, _env: Env, output: Self::Output) -> Result<Self::JsValue> {
Ok(Buffer::from(output))
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
pub struct GetTableTypesTask {
connection: Arc<CoreConnection>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for GetTableTypesTask {
type Output = CoreResultIterator;
type JsValue = _NativeAdbcResultIterator;
fn compute(&mut self) -> Result<Self::Output> {
capture_adbc_err(self.connection.get_table_types(), &mut self.adbc_err)
}
fn resolve(&mut self, _env: Env, output: Self::Output) -> Result<Self::JsValue> {
Ok(_NativeAdbcResultIterator {
inner: Some(Arc::new(Mutex::new(output))),
})
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
pub struct GetInfoTask {
connection: Arc<CoreConnection>,
info_codes: Option<Vec<u32>>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for GetInfoTask {
type Output = CoreResultIterator;
type JsValue = _NativeAdbcResultIterator;
fn compute(&mut self) -> Result<Self::Output> {
capture_adbc_err(
self.connection.get_info(self.info_codes.take()),
&mut self.adbc_err,
)
}
fn resolve(&mut self, _env: Env, output: Self::Output) -> Result<Self::JsValue> {
Ok(_NativeAdbcResultIterator {
inner: Some(Arc::new(Mutex::new(output))),
})
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
pub struct CommitTask {
connection: Arc<CoreConnection>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for CommitTask {
type Output = ();
type JsValue = ();
fn compute(&mut self) -> Result<Self::Output> {
capture_adbc_err(self.connection.commit(), &mut self.adbc_err)
}
fn resolve(&mut self, _env: Env, _output: Self::Output) -> Result<Self::JsValue> {
Ok(())
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
pub struct RollbackTask {
connection: Arc<CoreConnection>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for RollbackTask {
type Output = ();
type JsValue = ();
fn compute(&mut self) -> Result<Self::Output> {
capture_adbc_err(self.connection.rollback(), &mut self.adbc_err)
}
fn resolve(&mut self, _env: Env, _output: Self::Output) -> Result<Self::JsValue> {
Ok(())
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
// --- Statement ---
#[napi]
pub struct _NativeAdbcStatement {
inner: Option<Arc<Mutex<CoreStatement>>>,
}
#[napi]
impl _NativeAdbcStatement {
#[napi]
pub fn set_sql_query(&self, env: Env, query: String) -> Result<()> {
let mutex = self.inner.as_ref().ok_or_else(closed_err)?;
let mut stmt = mutex
.lock()
.map_err(|e| Error::from_reason(e.to_string()))?;
stmt
.set_sql_query(&query)
.map_err(|e| sync_adbc_err(e, env))
}
#[napi]
pub fn set_option(&self, env: Env, key: String, value: String) -> Result<()> {
let mutex = self.inner.as_ref().ok_or_else(closed_err)?;
let mut stmt = mutex
.lock()
.map_err(|e| Error::from_reason(e.to_string()))?;
stmt
.set_option(&key, &value)
.map_err(|e| sync_adbc_err(e, env))
}
#[napi]
pub fn execute_query(&self) -> Result<AsyncTask<ExecuteQueryTask>> {
let mutex = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(ExecuteQueryTask {
statement: mutex.clone(),
adbc_err: None,
}))
}
#[napi]
pub fn execute_update(&self) -> Result<AsyncTask<ExecuteUpdateTask>> {
let mutex = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(ExecuteUpdateTask {
statement: mutex.clone(),
adbc_err: None,
}))
}
#[napi]
pub fn bind(&self, data: Buffer) -> Result<AsyncTask<BindTask>> {
let mutex = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(BindTask {
statement: mutex.clone(),
data: data.to_vec(),
adbc_err: None,
}))
}
#[napi]
pub fn close(&mut self) -> Result<()> {
self.inner.take();
Ok(())
}
}
pub struct ExecuteQueryTask {
statement: Arc<Mutex<CoreStatement>>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for ExecuteQueryTask {
type Output = CoreResultIterator;
type JsValue = _NativeAdbcResultIterator;
fn compute(&mut self) -> Result<Self::Output> {
let mut stmt = self
.statement
.lock()
.map_err(|e| Error::from_reason(e.to_string()))?;
capture_adbc_err(stmt.execute_query(), &mut self.adbc_err)
}
fn resolve(&mut self, _env: Env, output: Self::Output) -> Result<Self::JsValue> {
Ok(_NativeAdbcResultIterator {
inner: Some(Arc::new(Mutex::new(output))),
})
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
pub struct ExecuteUpdateTask {
statement: Arc<Mutex<CoreStatement>>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for ExecuteUpdateTask {
type Output = i64;
type JsValue = i64;
fn compute(&mut self) -> Result<Self::Output> {
let mut stmt = self
.statement
.lock()
.map_err(|e| Error::from_reason(e.to_string()))?;
capture_adbc_err(stmt.execute_update(), &mut self.adbc_err)
}
fn resolve(&mut self, _env: Env, output: Self::Output) -> Result<Self::JsValue> {
Ok(output)
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
pub struct BindTask {
statement: Arc<Mutex<CoreStatement>>,
data: Vec<u8>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for BindTask {
type Output = ();
type JsValue = ();
fn compute(&mut self) -> Result<Self::Output> {
let mut stmt = self
.statement
.lock()
.map_err(|e| Error::from_reason(e.to_string()))?;
capture_adbc_err(
stmt.bind(std::mem::take(&mut self.data)),
&mut self.adbc_err,
)
}
fn resolve(&mut self, _env: Env, _output: Self::Output) -> Result<Self::JsValue> {
Ok(())
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
// --- Iterators ---
pub struct IteratorNextTask {
iterator: Arc<Mutex<CoreResultIterator>>,
adbc_err: Option<adbc_core::error::Error>,
}
impl Task for IteratorNextTask {
type Output = Option<Vec<u8>>;
type JsValue = Option<Buffer>;
fn compute(&mut self) -> Result<Self::Output> {
let mut iterator = self
.iterator
.lock()
.map_err(|e| Error::from_reason(e.to_string()))?;
capture_adbc_err(iterator.next(), &mut self.adbc_err)
}
fn resolve(&mut self, _env: Env, output: Self::Output) -> Result<Self::JsValue> {
Ok(output.map(Buffer::from))
}
fn reject(&mut self, env: Env, err: Error) -> Result<Self::JsValue> {
reject_adbc(env, &mut self.adbc_err, err)
}
}
#[napi]
pub struct _NativeAdbcResultIterator {
inner: Option<Arc<Mutex<CoreResultIterator>>>,
}
#[napi]
impl _NativeAdbcResultIterator {
#[napi]
pub fn next(&self) -> Result<AsyncTask<IteratorNextTask>> {
let iterator = self.inner.as_ref().ok_or_else(closed_err)?;
Ok(AsyncTask::new(IteratorNextTask {
iterator: iterator.clone(),
adbc_err: None,
}))
}
#[napi]
pub fn close(&mut self) -> Result<()> {
self.inner.take();
Ok(())
}
}