tweak the docs

This commit is contained in:
Joe Ardent 2023-07-28 07:40:05 -07:00
parent 9e7b7c31dc
commit c9a949d5d2

View file

@ -76,13 +76,35 @@ pub mod sqlite_plugin {
Ok(()) 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`), /// Returns the timestamp portion as number of fractional seconds (`f64`),
/// for use in SQLite's `datetime()` function. /// for use in SQLite's `datetime()` function.
/// ///
/// ```text /// ```text
/// sqlite> select julid_seconds(julid_new()); /// sqlite> select julid_seconds(julid_new());
/// 1690480066.208 /// 1690480066.208
/// sqlite> select datetime(julid_timestamp(julid_new()), 'auto'); /// sqlite> select datetime(julid_seconds(julid_new()), 'auto');
/// 2023-07-27 17:47:50 /// 2023-07-27 17:47:50
/// ``` /// ```
pub fn julid_seconds(context: *mut sqlite3_context, id: &[*mut sqlite3_value]) -> Result<()> { 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 /// 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 /// Julid created in a millisecond, its value will be 0. If you are
/// creating more than 65,536 Julids per millisecond, the counter will /// creating more than 65,536 Julids per millisecond, the counter will
/// saturate at 65,536. /// saturate at 65,535.
/// ///
/// ```text /// ```text
/// sqlite> select julid_counter(julid_new()); /// sqlite> select julid_counter(julid_new());
@ -152,26 +174,4 @@ pub mod sqlite_plugin {
Ok(()) 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(())
}
} }