mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-04 17:04:18 +01:00
Merge 'Add time querying to I/O trait for deterministic simulation' from mason
Follow-up PR to this [issue](https://github.com/penberg/limbo/issues/272). Closes #307
This commit is contained in:
@@ -92,6 +92,11 @@ impl limbo_core::IO for PlatformIO {
|
||||
let random_f64 = Math_random();
|
||||
(random_f64 * i64::MAX as f64) as i64
|
||||
}
|
||||
|
||||
fn get_current_time(&self) -> String {
|
||||
let date = Date::new();
|
||||
date.toISOString()
|
||||
}
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
@@ -99,6 +104,17 @@ extern "C" {
|
||||
fn Math_random() -> f64;
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
type Date;
|
||||
|
||||
#[wasm_bindgen(constructor)]
|
||||
fn new() -> Date;
|
||||
|
||||
#[wasm_bindgen(method, getter)]
|
||||
fn toISOString(this: &Date) -> String;
|
||||
}
|
||||
|
||||
pub struct DatabaseStorage {
|
||||
file: Rc<dyn limbo_core::File>,
|
||||
}
|
||||
|
||||
@@ -110,6 +110,10 @@ impl IO for DarwinIO {
|
||||
getrandom::getrandom(&mut buf).unwrap();
|
||||
i64::from_ne_bytes(buf)
|
||||
}
|
||||
|
||||
fn get_current_time(&self) -> String {
|
||||
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
enum CompletionCallback {
|
||||
|
||||
@@ -30,6 +30,10 @@ impl IO for GenericIO {
|
||||
getrandom::getrandom(&mut buf).unwrap();
|
||||
i64::from_ne_bytes(buf)
|
||||
}
|
||||
|
||||
fn get_current_time(&self) -> String {
|
||||
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GenericFile {
|
||||
|
||||
@@ -111,6 +111,10 @@ impl IO for LinuxIO {
|
||||
getrandom::getrandom(&mut buf).unwrap();
|
||||
i64::from_ne_bytes(buf)
|
||||
}
|
||||
|
||||
fn get_current_time(&self) -> String {
|
||||
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LinuxFile {
|
||||
|
||||
@@ -22,6 +22,8 @@ pub trait IO {
|
||||
fn run_once(&self) -> Result<()>;
|
||||
|
||||
fn generate_random_number(&self) -> i64;
|
||||
|
||||
fn get_current_time(&self) -> String;
|
||||
}
|
||||
|
||||
pub type Complete = dyn Fn(Rc<RefCell<Buffer>>);
|
||||
|
||||
@@ -30,6 +30,10 @@ impl IO for WindowsIO {
|
||||
getrandom::getrandom(&mut buf).unwrap();
|
||||
i64::from_ne_bytes(buf)
|
||||
}
|
||||
|
||||
fn get_current_time(&self) -> String {
|
||||
chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WindowsFile {
|
||||
|
||||
@@ -113,6 +113,10 @@ impl IO for SimulatorIO {
|
||||
fn generate_random_number(&self) -> i64 {
|
||||
self.rng.borrow_mut().next_u64() as i64
|
||||
}
|
||||
|
||||
fn get_current_time(&self) -> String {
|
||||
"2024-01-01 00:00:00".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
struct SimulatorFile {
|
||||
|
||||
Reference in New Issue
Block a user