Skip to content

Commit 957d387

Browse files
committed
add version and debug funcs
1 parent 5ce7549 commit 957d387

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

build.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use std::process::Command;
2+
fn main() {
3+
let output = Command::new("git")
4+
.args(["rev-parse", "HEAD"])
5+
.output()
6+
.unwrap();
7+
let git_hash = String::from_utf8(output.stdout).unwrap();
8+
println!("cargo:rustc-env=GIT_HASH={}", git_hash);
9+
}

src/lib.rs

+33-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,27 @@ use sqlite_loadable::{
1414
use zerocopy::AsBytes;
1515

1616
const FLOAT32_VECTOR_SUBTYPE: u8 = 223;
17-
1817
const CLIENT_OPTIONS_POINTER_NAME: &[u8] = b"sqlite-rembed-client-options\0";
1918

19+
pub fn rembed_version(context: *mut sqlite3_context, _values: &[*mut sqlite3_value]) -> Result<()> {
20+
api::result_text(context, format!("v{}", env!("CARGO_PKG_VERSION")))?;
21+
Ok(())
22+
}
23+
24+
pub fn rembed_debug(context: *mut sqlite3_context, _values: &[*mut sqlite3_value]) -> Result<()> {
25+
api::result_text(
26+
context,
27+
format!(
28+
"Version: v{}
29+
Source: {}
30+
",
31+
env!("CARGO_PKG_VERSION"),
32+
env!("GIT_HASH")
33+
),
34+
)?;
35+
Ok(())
36+
}
37+
2038
pub fn rembed_client_options(
2139
context: *mut sqlite3_context,
2240
values: &[*mut sqlite3_value],
@@ -123,6 +141,20 @@ pub fn sqlite3_rembed_init(db: *mut sqlite3) -> Result<()> {
123141

124142
let c = Rc::new(RefCell::new(HashMap::new()));
125143

144+
define_scalar_function(
145+
db,
146+
"rembed_version",
147+
0,
148+
rembed_version,
149+
FunctionFlags::UTF8 | FunctionFlags::DETERMINISTIC,
150+
)?;
151+
define_scalar_function(
152+
db,
153+
"rembed_debug",
154+
0,
155+
rembed_debug,
156+
FunctionFlags::UTF8 | FunctionFlags::DETERMINISTIC,
157+
)?;
126158
define_scalar_function_with_aux(db, "rembed", 2, rembed, flags, Rc::clone(&c))?;
127159
define_scalar_function_with_aux(db, "rembed", 3, rembed, flags, Rc::clone(&c))?;
128160
define_scalar_function(

0 commit comments

Comments
 (0)