add unicase collation

sqlite's like is hard-coded to use ASCII comparisons, so we can't
take advantage of this yet
This commit is contained in:
Damien Elmes 2020-03-21 12:40:20 +10:00
parent d1ebdbdcce
commit 4ff17d31b3
2 changed files with 11 additions and 2 deletions

View file

@ -38,12 +38,13 @@ slog-async = "2.4.0"
slog-envlogger = "2.2.0" slog-envlogger = "2.2.0"
serde_repr = "0.1.5" serde_repr = "0.1.5"
num_enum = "0.4.2" num_enum = "0.4.2"
unicase = "2.6.0"
[target.'cfg(target_vendor="apple")'.dependencies] [target.'cfg(target_vendor="apple")'.dependencies]
rusqlite = { version = "0.21.0", features = ["trace", "functions"] } rusqlite = { version = "0.21.0", features = ["trace", "functions", "collation"] }
[target.'cfg(not(target_vendor="apple"))'.dependencies] [target.'cfg(not(target_vendor="apple"))'.dependencies]
rusqlite = { version = "0.21.0", features = ["trace", "functions", "bundled"] } rusqlite = { version = "0.21.0", features = ["trace", "functions", "collation", "bundled"] }
[target.'cfg(linux)'.dependencies] [target.'cfg(linux)'.dependencies]
reqwest = { version = "0.10.1", features = ["json", "native-tls-vendored"] } reqwest = { version = "0.10.1", features = ["json", "native-tls-vendored"] }

View file

@ -14,14 +14,20 @@ use crate::{
}; };
use regex::Regex; use regex::Regex;
use rusqlite::{params, Connection, NO_PARAMS}; use rusqlite::{params, Connection, NO_PARAMS};
use std::cmp::Ordering;
use std::{ use std::{
collections::HashMap, collections::HashMap,
path::{Path, PathBuf}, path::{Path, PathBuf},
}; };
use unicase::UniCase;
const SCHEMA_MIN_VERSION: u8 = 11; const SCHEMA_MIN_VERSION: u8 = 11;
const SCHEMA_MAX_VERSION: u8 = 11; const SCHEMA_MAX_VERSION: u8 = 11;
fn unicase_compare(s1: &str, s2: &str) -> Ordering {
UniCase::new(s1).cmp(&UniCase::new(s2))
}
// currently public for dbproxy // currently public for dbproxy
#[derive(Debug)] #[derive(Debug)]
pub struct SqliteStorage { pub struct SqliteStorage {
@ -53,6 +59,8 @@ fn open_or_create_collection_db(path: &Path) -> Result<Connection> {
add_field_index_function(&db)?; add_field_index_function(&db)?;
add_regexp_function(&db)?; add_regexp_function(&db)?;
db.create_collation("unicase", unicase_compare)?;
Ok(db) Ok(db)
} }