mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
usn newtype
This commit is contained in:
parent
eb89a2db3f
commit
39f916a23e
6 changed files with 33 additions and 5 deletions
|
@ -87,7 +87,7 @@ fn row_to_note(row: &Row) -> Result<Note> {
|
||||||
pub(super) fn set_note(db: &Connection, note: &mut Note, note_type: &NoteType) -> Result<()> {
|
pub(super) fn set_note(db: &Connection, note: &mut Note, note_type: &NoteType) -> Result<()> {
|
||||||
note.mtime = TimestampSecs::now();
|
note.mtime = TimestampSecs::now();
|
||||||
// hard-coded for now
|
// hard-coded for now
|
||||||
note.usn = -1;
|
note.usn = Usn(-1);
|
||||||
let field1_nohtml = strip_html_preserving_image_filenames(¬e.fields()[0]);
|
let field1_nohtml = strip_html_preserving_image_filenames(¬e.fields()[0]);
|
||||||
let csum = field_checksum(field1_nohtml.as_ref());
|
let csum = field_checksum(field1_nohtml.as_ref());
|
||||||
let sort_field = if note_type.sort_field_idx == 0 {
|
let sort_field = if note_type.sort_field_idx == 0 {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
mod sqlite;
|
mod sqlite;
|
||||||
mod timestamp;
|
mod timestamp;
|
||||||
|
mod usn;
|
||||||
|
|
||||||
pub(crate) use sqlite::{SqliteStorage, StorageContext};
|
pub(crate) use sqlite::{SqliteStorage, StorageContext};
|
||||||
|
|
|
@ -297,7 +297,7 @@ impl StorageContext<'_> {
|
||||||
}
|
}
|
||||||
Ok(*self.usn.as_ref().unwrap())
|
Ok(*self.usn.as_ref().unwrap())
|
||||||
} else {
|
} else {
|
||||||
Ok(-1)
|
Ok(Usn(-1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
rslib/src/storage/usn.rs
Normal file
24
rslib/src/storage/usn.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
|
use crate::types::Usn;
|
||||||
|
use rusqlite::{
|
||||||
|
types::{FromSql, FromSqlError, ToSqlOutput, Value, ValueRef},
|
||||||
|
ToSql,
|
||||||
|
};
|
||||||
|
|
||||||
|
impl FromSql for Usn {
|
||||||
|
fn column_result(value: ValueRef<'_>) -> std::result::Result<Self, FromSqlError> {
|
||||||
|
if let ValueRef::Integer(i) = value {
|
||||||
|
Ok(Self(i as i32))
|
||||||
|
} else {
|
||||||
|
Err(FromSqlError::InvalidType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToSql for Usn {
|
||||||
|
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput<'_>> {
|
||||||
|
Ok(ToSqlOutput::Owned(Value::Integer(self.0 as i64)))
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
use std::time;
|
use std::time;
|
||||||
|
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct TimestampSecs(pub i64);
|
pub struct TimestampSecs(pub i64);
|
||||||
|
|
||||||
impl TimestampSecs {
|
impl TimestampSecs {
|
||||||
|
@ -14,7 +14,7 @@ impl TimestampSecs {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct TimestampMillis(pub i64);
|
pub struct TimestampMillis(pub i64);
|
||||||
|
|
||||||
impl TimestampMillis {
|
impl TimestampMillis {
|
||||||
|
|
|
@ -5,4 +5,7 @@
|
||||||
// signed integers, so these numbers are signed as well.
|
// signed integers, so these numbers are signed as well.
|
||||||
|
|
||||||
pub type ObjID = i64;
|
pub type ObjID = i64;
|
||||||
pub type Usn = i32;
|
|
||||||
|
#[repr(transparent)]
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub struct Usn(pub i32);
|
||||||
|
|
Loading…
Reference in a new issue