rusqlite_regex 0.7.0

A regex extension for rusqlite
//! Raw extension functions.

use std::ffi::{c_char, c_int};

use rusqlite::ffi;
use rusqlite::functions::FunctionFlags;

pub mod meta;
pub mod regex;

/// The entry point for the SQLite extension.
#[allow(unsafe_code, clippy::missing_safety_doc)]
pub unsafe extern "C" fn sqlite3_regex_init(db: *mut ffi::sqlite3, pz_err_msg: *mut *mut c_char, _p_api: *const ffi::sqlite3_api_routines) -> c_int {
    unsafe { rusqlite::auto_extension::init_auto_extension(db, pz_err_msg, |connection| {
        macro_rules! scalar_function {
            ($conn: ident += $module: ident::$function: ident($n: literal)) => {
                $conn.create_scalar_function(
                    stringify!($function),
                    $n,
                    FunctionFlags::SQLITE_UTF8 | FunctionFlags::SQLITE_DETERMINISTIC,
                    $module::$function
                )
            };
        }

        scalar_function!(connection += meta::regex_version(0))?;

        scalar_function!(connection += regex::regex_is_match(2))?;
        scalar_function!(connection += regex::regexp(2))?;
        scalar_function!(connection += regex::regex_replace(3))?;
        scalar_function!(connection += regex::regex_replace_all(3))?;
        scalar_function!(connection += regex::regex_replacen(4))?;

        Ok(())
    }) }
}