mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
use blobs for config
This commit is contained in:
parent
676f4e74a8
commit
34cca119e3
5 changed files with 24 additions and 18 deletions
|
@ -16,10 +16,10 @@ impl SqliteStorage {
|
|||
usn: Usn,
|
||||
mtime: TimestampSecs,
|
||||
) -> Result<()> {
|
||||
let json = serde_json::to_string(val)?;
|
||||
let json = serde_json::to_vec(val)?;
|
||||
self.db
|
||||
.prepare_cached(include_str!("add.sql"))?
|
||||
.execute(params![key, usn, mtime, json])?;
|
||||
.execute(params![key, usn, mtime, &json])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,8 @@ impl SqliteStorage {
|
|||
self.db
|
||||
.prepare_cached(include_str!("get.sql"))?
|
||||
.query_and_then(&[key], |row| {
|
||||
serde_json::from_str(row.get_raw(0).as_str()?).map_err(Into::into)
|
||||
let blob = row.get_raw(0).as_blob()?;
|
||||
serde_json::from_slice(blob).map_err(Into::into)
|
||||
})?
|
||||
.next()
|
||||
.transpose()
|
||||
|
@ -44,7 +45,7 @@ impl SqliteStorage {
|
|||
self.db
|
||||
.prepare("select key, val from config")?
|
||||
.query_and_then(NO_PARAMS, |row| {
|
||||
let val: Value = serde_json::from_str(row.get_raw(1).as_str()?)?;
|
||||
let val: Value = serde_json::from_slice(row.get_raw(1).as_blob()?)?;
|
||||
Ok((row.get::<usize, String>(0)?, val))
|
||||
})?
|
||||
.collect()
|
||||
|
|
|
@ -15,7 +15,7 @@ impl SqliteStorage {
|
|||
self.db
|
||||
.prepare_cached("select config from deck_config")?
|
||||
.query_and_then(NO_PARAMS, |row| -> Result<_> {
|
||||
Ok(serde_json::from_str(row.get_raw(0).as_str()?)?)
|
||||
Ok(serde_json::from_slice(row.get_raw(0).as_blob()?)?)
|
||||
})?
|
||||
.collect()
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ impl SqliteStorage {
|
|||
self.db
|
||||
.prepare_cached(include_str!("get.sql"))?
|
||||
.query_and_then(params![dcid], |row| -> Result<_> {
|
||||
Ok(serde_json::from_str(row.get_raw(0).as_str()?)?)
|
||||
Ok(serde_json::from_slice(row.get_raw(0).as_blob()?)?)
|
||||
})?
|
||||
.next()
|
||||
.transpose()
|
||||
|
@ -38,7 +38,7 @@ impl SqliteStorage {
|
|||
conf.name,
|
||||
conf.mtime,
|
||||
conf.usn,
|
||||
&serde_json::to_string(conf)?,
|
||||
&serde_json::to_vec(conf)?,
|
||||
])?;
|
||||
let id = self.db.last_insert_rowid();
|
||||
if conf.id.0 != id {
|
||||
|
@ -57,7 +57,7 @@ impl SqliteStorage {
|
|||
conf.name,
|
||||
conf.mtime,
|
||||
conf.usn,
|
||||
&serde_json::to_string(conf)?,
|
||||
&serde_json::to_vec(conf)?,
|
||||
conf.id,
|
||||
])?;
|
||||
Ok(())
|
||||
|
|
|
@ -153,16 +153,21 @@ impl SqliteStorage {
|
|||
pub(crate) fn open_or_create(path: &Path, i18n: &I18n) -> Result<Self> {
|
||||
let db = open_or_create_collection_db(path)?;
|
||||
let (create, ver) = schema_version(&db)?;
|
||||
if ver > SCHEMA_MAX_VERSION {
|
||||
|
||||
let err = match ver {
|
||||
v if v < SCHEMA_MIN_VERSION => Some(DBErrorKind::FileTooOld),
|
||||
v if v > SCHEMA_MAX_VERSION => Some(DBErrorKind::FileTooNew),
|
||||
12 | 13 => {
|
||||
// as schema definition changed, user must perform clean
|
||||
// shutdown to return to schema 11 prior to running this version
|
||||
Some(DBErrorKind::FileTooNew)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
if let Some(kind) = err {
|
||||
return Err(AnkiError::DBError {
|
||||
info: "".to_string(),
|
||||
kind: DBErrorKind::FileTooNew,
|
||||
});
|
||||
}
|
||||
if ver < SCHEMA_MIN_VERSION {
|
||||
return Err(AnkiError::DBError {
|
||||
info: "".to_string(),
|
||||
kind: DBErrorKind::FileTooOld,
|
||||
kind,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ create table deck_config (
|
|||
name text not null collate unicase,
|
||||
mtime_secs integer not null,
|
||||
usn integer not null,
|
||||
config text not null
|
||||
config blob not null
|
||||
);
|
||||
update col
|
||||
set
|
||||
|
|
|
@ -2,7 +2,7 @@ create table config (
|
|||
key text not null primary key,
|
||||
usn integer not null,
|
||||
mtime_secs integer not null,
|
||||
val text not null
|
||||
val blob not null
|
||||
) without rowid;
|
||||
update col
|
||||
set
|
||||
|
|
Loading…
Reference in a new issue