From c9a949d5d2cf6b41fd30b4c53b212600ba27bfb4 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Fri, 28 Jul 2023 07:40:05 -0700 Subject: [PATCH] tweak the docs --- src/lib.rs | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cfcf79f..8be5e18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,13 +76,35 @@ pub mod sqlite_plugin { Ok(()) } + /// Return the human-readable base32 Crockford encoding of this Julid. + /// ```text + /// sqlite> select julid_string(julid_new()); + /// 01H6C7D9CT00009TF3EXXJHX4Y + /// ``` + pub fn julid_string(context: *mut sqlite3_context, id: &[*mut sqlite3_value]) -> Result<()> { + if let Some(value) = id.get(0) { + let id = api::value_blob(value); + let bytes: [u8; 16] = id.try_into().map_err(|_| { + sqlite_loadable::Error::new_message("Could not convert given value to Julid") + })?; + let id: Julid = bytes.into(); + api::result_text(context, id.as_string())?; + } else { + return Err(sqlite_loadable::Error::new_message( + "Could not convert empty Julid to string", + )); + } + + Ok(()) + } + /// Returns the timestamp portion as number of fractional seconds (`f64`), /// for use in SQLite's `datetime()` function. /// /// ```text /// sqlite> select julid_seconds(julid_new()); /// 1690480066.208 - /// sqlite> select datetime(julid_timestamp(julid_new()), 'auto'); + /// sqlite> select datetime(julid_seconds(julid_new()), 'auto'); /// 2023-07-27 17:47:50 /// ``` pub fn julid_seconds(context: *mut sqlite3_context, id: &[*mut sqlite3_value]) -> Result<()> { @@ -106,7 +128,7 @@ pub mod sqlite_plugin { /// Return the value of the monotonic counter for this Julid. For the first /// Julid created in a millisecond, its value will be 0. If you are /// creating more than 65,536 Julids per millisecond, the counter will - /// saturate at 65,536. + /// saturate at 65,535. /// /// ```text /// sqlite> select julid_counter(julid_new()); @@ -152,26 +174,4 @@ pub mod sqlite_plugin { Ok(()) } - - /// Return the human-readable base32 Crockford encoding of this Julid. - /// ```text - /// sqlite> select julid_string(julid_new()); - /// 01H6C7D9CT00009TF3EXXJHX4Y - /// ``` - pub fn julid_string(context: *mut sqlite3_context, id: &[*mut sqlite3_value]) -> Result<()> { - if let Some(value) = id.get(0) { - let id = api::value_blob(value); - let bytes: [u8; 16] = id.try_into().map_err(|_| { - sqlite_loadable::Error::new_message("Could not convert given value to Julid") - })?; - let id: Julid = bytes.into(); - api::result_text(context, id.as_string())?; - } else { - return Err(sqlite_loadable::Error::new_message( - "Could not convert empty Julid to string", - )); - } - - Ok(()) - } }