Move time extension to core

This commit is contained in:
Pekka Enberg
2025-06-29 14:48:17 +03:00
parent 12131babae
commit 39fd84f297
9 changed files with 64 additions and 101 deletions

13
Cargo.lock generated
View File

@@ -1878,18 +1878,6 @@ dependencies = [
"turso",
]
[[package]]
name = "limbo_time"
version = "0.1.0-pre.2"
dependencies = [
"chrono",
"mimalloc",
"strum",
"strum_macros",
"thiserror 2.0.12",
"turso_ext",
]
[[package]]
name = "linked-hash-map"
version = "0.5.6"
@@ -3717,7 +3705,6 @@ dependencies = [
"limbo_percentile",
"limbo_regexp",
"limbo_series",
"limbo_time",
"lru",
"miette",
"mimalloc",

View File

@@ -19,7 +19,6 @@ members = [
"extensions/regexp",
"extensions/series",
"extensions/tests",
"extensions/time",
"macros",
"simulator",
"sqlite3",
@@ -50,7 +49,6 @@ limbo_percentile = { path = "extensions/percentile", version = "0.1.0-pre.2" }
limbo_regexp = { path = "extensions/regexp", version = "0.1.0-pre.2" }
limbo_series = { path = "extensions/series", version = "0.1.0-pre.2" }
turso_sqlite3_parser = { path = "vendored/sqlite3-parser", version = "0.1.0-pre.2" }
limbo_time = { path = "extensions/time", version = "0.1.0-pre.2" }
limbo_uuid = { path = "extensions/uuid", version = "0.1.0-pre.2" }
strum = { version = "0.26", features = ["derive"] }
strum_macros = "0.26"

View File

@@ -22,11 +22,11 @@ uuid = ["dep:uuid"]
io_uring = ["dep:io-uring", "rustix/io_uring", "dep:libc"]
percentile = ["limbo_percentile/static"]
regexp = ["limbo_regexp/static"]
time = ["limbo_time/static"]
crypto = ["limbo_crypto/static"]
series = ["limbo_series/static"]
ipaddr = ["limbo_ipaddr/static"]
static = ["turso_ext/static"]
time = []
fuzz = []
csv = ["limbo_csv/static"]
omit_autovacuum = []
@@ -65,7 +65,6 @@ libm = "0.2"
turso_macros = { workspace = true }
limbo_regexp = { workspace = true, optional = true, features = ["static"] }
limbo_percentile = { workspace = true, optional = true, features = ["static"] }
limbo_time = { workspace = true, optional = true, features = ["static"] }
limbo_crypto = { workspace = true, optional = true, features = ["static"] }
limbo_series = { workspace = true, optional = true, features = ["static"] }
limbo_ipaddr = { workspace = true, optional = true, features = ["static"] }

View File

@@ -183,9 +183,7 @@ impl Connection {
return Err("Failed to register regexp extension".to_string());
}
#[cfg(feature = "time")]
if unsafe { !limbo_time::register_extension_static(&mut ext_api).is_ok() } {
return Err("Failed to register time extension".to_string());
}
crate::time::register_extension(&mut ext_api);
#[cfg(feature = "crypto")]
if unsafe { !limbo_crypto::register_extension_static(&mut ext_api).is_ok() } {
return Err("Failed to register crypto extension".to_string());

View File

@@ -17,9 +17,11 @@ mod pseudo;
pub mod result;
mod schema;
mod storage;
#[allow(dead_code)]
#[cfg(feature = "time")]
mod time;
mod translate;
pub mod types;
#[allow(dead_code)]
mod util;
#[cfg(feature = "uuid")]
mod uuid;

View File

@@ -5,7 +5,7 @@ use chrono::{prelude::*, DurationRound};
use turso_ext::Value;
use crate::{Result, TimeError};
use crate::time::{Result, TimeError};
const DAYS_BEFORE_EPOCH: i64 = 719162;
const TIME_BLOB_SIZE: usize = 13;

View File

@@ -3,64 +3,68 @@ use std::str::FromStr as _;
use chrono::prelude::*;
use core::cmp::Ordering;
use thiserror::Error;
use turso_ext::ValueType;
use turso_ext::{register_extension, scalar, ResultCode, Value};
use crate::ext::register_scalar_function;
use turso_ext::{scalar, ExtensionApi, ResultCode, Value, ValueType};
mod time;
mod internal;
use time::*;
use internal::*;
register_extension! {
scalars: {
time_now,
time_date,
make_date,
make_timestamp,
time_get,
time_get_year,
time_get_month,
time_get_day,
time_get_hour,
time_get_minute,
time_get_second,
time_get_nano,
time_get_weekday,
time_get_yearday,
time_get_isoyear,
time_get_isoweek,
time_unix,
to_timestamp,
time_milli,
time_micro,
time_nano,
time_to_unix,
time_to_milli,
time_to_micro,
time_to_nano,
time_after,
time_before,
time_compare,
time_equal,
dur_ns,
dur_us,
dur_ms,
dur_s,
dur_m,
dur_h,
time_add,
time_add_date,
time_sub,
time_since,
time_until,
time_trunc,
time_round,
time_fmt_iso,
time_fmt_datetime,
time_fmt_date,
time_fmt_time,
time_parse,
},
pub fn register_extension(ext_api: &mut ExtensionApi) {
unsafe {
register_scalar_function(ext_api.ctx, c"time_now".as_ptr(), time_now);
register_scalar_function(ext_api.ctx, c"time_date".as_ptr(), time_date);
register_scalar_function(ext_api.ctx, c"make_date".as_ptr(), make_date);
register_scalar_function(ext_api.ctx, c"make_timestamp".as_ptr(), make_timestamp);
register_scalar_function(ext_api.ctx, c"time_get".as_ptr(), time_get);
register_scalar_function(ext_api.ctx, c"time_get_year".as_ptr(), time_get_year);
register_scalar_function(ext_api.ctx, c"time_get_month".as_ptr(), time_get_month);
register_scalar_function(ext_api.ctx, c"time_get_day".as_ptr(), time_get_day);
register_scalar_function(ext_api.ctx, c"time_get_hour".as_ptr(), time_get_hour);
register_scalar_function(ext_api.ctx, c"time_get_minute".as_ptr(), time_get_minute);
register_scalar_function(ext_api.ctx, c"time_get_second".as_ptr(), time_get_second);
register_scalar_function(ext_api.ctx, c"time_get_nano".as_ptr(), time_get_nano);
register_scalar_function(ext_api.ctx, c"time_get_weekday".as_ptr(), time_get_weekday);
register_scalar_function(ext_api.ctx, c"time_get_yearday".as_ptr(), time_get_yearday);
register_scalar_function(ext_api.ctx, c"time_get_isoyear".as_ptr(), time_get_isoyear);
register_scalar_function(ext_api.ctx, c"time_get_isoweek".as_ptr(), time_get_isoweek);
register_scalar_function(ext_api.ctx, c"time_unix".as_ptr(), time_unix);
register_scalar_function(ext_api.ctx, c"to_timestamp".as_ptr(), to_timestamp);
register_scalar_function(ext_api.ctx, c"time_milli".as_ptr(), time_milli);
register_scalar_function(ext_api.ctx, c"time_micro".as_ptr(), time_micro);
register_scalar_function(ext_api.ctx, c"time_nano".as_ptr(), time_nano);
register_scalar_function(ext_api.ctx, c"time_to_unix".as_ptr(), time_to_unix);
register_scalar_function(ext_api.ctx, c"time_to_milli".as_ptr(), time_to_milli);
register_scalar_function(ext_api.ctx, c"time_to_micro".as_ptr(), time_to_micro);
register_scalar_function(ext_api.ctx, c"time_to_nano".as_ptr(), time_to_nano);
register_scalar_function(ext_api.ctx, c"time_after".as_ptr(), time_after);
register_scalar_function(ext_api.ctx, c"time_before".as_ptr(), time_before);
register_scalar_function(ext_api.ctx, c"time_compare".as_ptr(), time_compare);
register_scalar_function(ext_api.ctx, c"time_equal".as_ptr(), time_equal);
register_scalar_function(ext_api.ctx, c"dur_ns".as_ptr(), dur_ns);
register_scalar_function(ext_api.ctx, c"dur_us".as_ptr(), dur_us);
register_scalar_function(ext_api.ctx, c"dur_ms".as_ptr(), dur_ms);
register_scalar_function(ext_api.ctx, c"dur_s".as_ptr(), dur_s);
register_scalar_function(ext_api.ctx, c"dur_m".as_ptr(), dur_m);
register_scalar_function(ext_api.ctx, c"dur_h".as_ptr(), dur_h);
register_scalar_function(ext_api.ctx, c"time_add".as_ptr(), time_add);
register_scalar_function(ext_api.ctx, c"time_add_date".as_ptr(), time_add_date);
register_scalar_function(ext_api.ctx, c"time_sub".as_ptr(), time_sub);
register_scalar_function(ext_api.ctx, c"time_since".as_ptr(), time_since);
register_scalar_function(ext_api.ctx, c"time_until".as_ptr(), time_until);
register_scalar_function(ext_api.ctx, c"time_trunc".as_ptr(), time_trunc);
register_scalar_function(ext_api.ctx, c"time_round".as_ptr(), time_round);
register_scalar_function(ext_api.ctx, c"time_fmt_iso".as_ptr(), time_fmt_iso);
register_scalar_function(
ext_api.ctx,
c"time_fmt_datetime".as_ptr(),
time_fmt_datetime,
);
register_scalar_function(ext_api.ctx, c"time_fmt_date".as_ptr(), time_fmt_date);
register_scalar_function(ext_api.ctx, c"time_fmt_time".as_ptr(), time_fmt_time);
register_scalar_function(ext_api.ctx, c"time_parse".as_ptr(), time_parse);
}
}
macro_rules! ok_tri {

View File

@@ -1,24 +0,0 @@
[package]
authors.workspace = true
edition.workspace = true
license.workspace = true
name = "limbo_time"
repository.workspace = true
version.workspace = true
description = "Limbo time extension"
[lib]
crate-type = ["cdylib", "lib"]
[features]
static = ["turso_ext/static"]
[target.'cfg(not(target_family = "wasm"))'.dependencies]
mimalloc = { version = "0.1", default-features = false }
[dependencies]
chrono = "0.4.39"
turso_ext = { workspace = true, features = ["static"] }
strum = "0.26.3"
strum_macros = "0.26.3"
thiserror = "2.0.11"

View File

@@ -7,7 +7,6 @@ cargo publish -p limbo_csv
cargo publish -p limbo_percentile
cargo publish -p limbo_regexp
cargo publish -p limbo_series
cargo publish -p limbo_time
cargo publish -p limbo_ipaddr
cargo publish -p turso_sqlite3_parser
cargo publish -p turso_core