1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 04:52:26 -05:00

setReadBigints

This commit is contained in:
Divy Srivastava 2024-12-14 13:16:15 +05:30
parent 95763d3f43
commit 008738058f
2 changed files with 15 additions and 1 deletions

View file

@ -1,5 +1,6 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::cell::Cell;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
@ -155,6 +156,7 @@ impl DatabaseSync {
Ok(StatementSync { Ok(StatementSync {
inner: raw_stmt, inner: raw_stmt,
db: self.conn.clone(), db: self.conn.clone(),
use_big_ints: Cell::new(false),
}) })
} }
} }

View file

@ -1,6 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::Cell;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
@ -22,6 +23,8 @@ pub struct RunStatementResult {
pub struct StatementSync { pub struct StatementSync {
pub inner: *mut ffi::sqlite3_stmt, pub inner: *mut ffi::sqlite3_stmt,
pub db: Rc<RefCell<Option<rusqlite::Connection>>>, pub db: Rc<RefCell<Option<rusqlite::Connection>>>,
pub use_big_ints: Cell<bool>,
} }
impl Drop for StatementSync { impl Drop for StatementSync {
@ -118,7 +121,11 @@ impl StatementSync {
match ffi::sqlite3_column_type(self.inner, index) { match ffi::sqlite3_column_type(self.inner, index) {
ffi::SQLITE_INTEGER => { ffi::SQLITE_INTEGER => {
let value = ffi::sqlite3_column_int64(self.inner, index); let value = ffi::sqlite3_column_int64(self.inner, index);
v8::Integer::new(scope, value as _).into() if self.use_big_ints.get() {
v8::BigInt::new_from_i64(scope, value).into()
} else {
v8::Integer::new(scope, value as _).into()
}
} }
ffi::SQLITE_FLOAT => { ffi::SQLITE_FLOAT => {
let value = ffi::sqlite3_column_double(self.inner, index); let value = ffi::sqlite3_column_double(self.inner, index);
@ -321,4 +328,9 @@ impl StatementSync {
let arr = v8::Array::new_with_elements(scope, &arr); let arr = v8::Array::new_with_elements(scope, &arr);
Ok(arr) Ok(arr)
} }
#[fast]
fn set_read_big_ints(&self, enabled: bool) {
self.use_big_ints.set(enabled);
}
} }