mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -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,
|
usn: Usn,
|
||||||
mtime: TimestampSecs,
|
mtime: TimestampSecs,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let json = serde_json::to_string(val)?;
|
let json = serde_json::to_vec(val)?;
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached(include_str!("add.sql"))?
|
.prepare_cached(include_str!("add.sql"))?
|
||||||
.execute(params![key, usn, mtime, json])?;
|
.execute(params![key, usn, mtime, &json])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,8 @@ impl SqliteStorage {
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached(include_str!("get.sql"))?
|
.prepare_cached(include_str!("get.sql"))?
|
||||||
.query_and_then(&[key], |row| {
|
.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()
|
.next()
|
||||||
.transpose()
|
.transpose()
|
||||||
|
@ -44,7 +45,7 @@ impl SqliteStorage {
|
||||||
self.db
|
self.db
|
||||||
.prepare("select key, val from config")?
|
.prepare("select key, val from config")?
|
||||||
.query_and_then(NO_PARAMS, |row| {
|
.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))
|
Ok((row.get::<usize, String>(0)?, val))
|
||||||
})?
|
})?
|
||||||
.collect()
|
.collect()
|
||||||
|
|
|
@ -15,7 +15,7 @@ impl SqliteStorage {
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached("select config from deck_config")?
|
.prepare_cached("select config from deck_config")?
|
||||||
.query_and_then(NO_PARAMS, |row| -> Result<_> {
|
.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()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ impl SqliteStorage {
|
||||||
self.db
|
self.db
|
||||||
.prepare_cached(include_str!("get.sql"))?
|
.prepare_cached(include_str!("get.sql"))?
|
||||||
.query_and_then(params![dcid], |row| -> Result<_> {
|
.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()
|
.next()
|
||||||
.transpose()
|
.transpose()
|
||||||
|
@ -38,7 +38,7 @@ impl SqliteStorage {
|
||||||
conf.name,
|
conf.name,
|
||||||
conf.mtime,
|
conf.mtime,
|
||||||
conf.usn,
|
conf.usn,
|
||||||
&serde_json::to_string(conf)?,
|
&serde_json::to_vec(conf)?,
|
||||||
])?;
|
])?;
|
||||||
let id = self.db.last_insert_rowid();
|
let id = self.db.last_insert_rowid();
|
||||||
if conf.id.0 != id {
|
if conf.id.0 != id {
|
||||||
|
@ -57,7 +57,7 @@ impl SqliteStorage {
|
||||||
conf.name,
|
conf.name,
|
||||||
conf.mtime,
|
conf.mtime,
|
||||||
conf.usn,
|
conf.usn,
|
||||||
&serde_json::to_string(conf)?,
|
&serde_json::to_vec(conf)?,
|
||||||
conf.id,
|
conf.id,
|
||||||
])?;
|
])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -153,16 +153,21 @@ impl SqliteStorage {
|
||||||
pub(crate) fn open_or_create(path: &Path, i18n: &I18n) -> Result<Self> {
|
pub(crate) fn open_or_create(path: &Path, i18n: &I18n) -> Result<Self> {
|
||||||
let db = open_or_create_collection_db(path)?;
|
let db = open_or_create_collection_db(path)?;
|
||||||
let (create, ver) = schema_version(&db)?;
|
let (create, ver) = schema_version(&db)?;
|
||||||
if ver > SCHEMA_MAX_VERSION {
|
|
||||||
return Err(AnkiError::DBError {
|
let err = match ver {
|
||||||
info: "".to_string(),
|
v if v < SCHEMA_MIN_VERSION => Some(DBErrorKind::FileTooOld),
|
||||||
kind: DBErrorKind::FileTooNew,
|
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)
|
||||||
}
|
}
|
||||||
if ver < SCHEMA_MIN_VERSION {
|
_ => None,
|
||||||
|
};
|
||||||
|
if let Some(kind) = err {
|
||||||
return Err(AnkiError::DBError {
|
return Err(AnkiError::DBError {
|
||||||
info: "".to_string(),
|
info: "".to_string(),
|
||||||
kind: DBErrorKind::FileTooOld,
|
kind,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ create table deck_config (
|
||||||
name text not null collate unicase,
|
name text not null collate unicase,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer not null,
|
||||||
usn integer not null,
|
usn integer not null,
|
||||||
config text not null
|
config blob not null
|
||||||
);
|
);
|
||||||
update col
|
update col
|
||||||
set
|
set
|
||||||
|
|
|
@ -2,7 +2,7 @@ create table config (
|
||||||
key text not null primary key,
|
key text not null primary key,
|
||||||
usn integer not null,
|
usn integer not null,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer not null,
|
||||||
val text not null
|
val blob not null
|
||||||
) without rowid;
|
) without rowid;
|
||||||
update col
|
update col
|
||||||
set
|
set
|
||||||
|
|
Loading…
Reference in a new issue