sqlite_jsonschema/
lib.rs

1mod jsonschema;
2
3use crate::jsonschema::jsonschema_matches;
4
5use sqlite_loadable::prelude::*;
6use sqlite_loadable::{api, define_scalar_function, Result};
7
8pub fn jsonschema_version(
9    context: *mut sqlite3_context,
10    _values: &[*mut sqlite3_value],
11) -> Result<()> {
12    api::result_text(context, format!("v{}", env!("CARGO_PKG_VERSION")))?;
13    Ok(())
14}
15
16pub fn jsonschema_debug(
17    context: *mut sqlite3_context,
18    _values: &[*mut sqlite3_value],
19) -> Result<()> {
20    api::result_text(
21        context,
22        format!(
23            "Version: v{}
24Source: {}
25",
26            env!("CARGO_PKG_VERSION"),
27            env!("GIT_HASH")
28        ),
29    )?;
30    Ok(())
31}
32
33#[sqlite_entrypoint]
34pub fn sqlite3_jsonschema_init(db: *mut sqlite3) -> Result<()> {
35    define_scalar_function(
36        db,
37        "jsonschema_version",
38        0,
39        jsonschema_version,
40        FunctionFlags::UTF8 | FunctionFlags::DETERMINISTIC,
41    )?;
42    define_scalar_function(
43        db,
44        "jsonschema_debug",
45        0,
46        jsonschema_debug,
47        FunctionFlags::UTF8 | FunctionFlags::DETERMINISTIC,
48    )?;
49    define_scalar_function(
50        db,
51        "jsonschema_matches",
52        2,
53        jsonschema_matches,
54        FunctionFlags::UTF8,
55    )?;
56
57    Ok(())
58}