Trait ABQuery

Source
pub trait ABQuery {
    const QUERY: &'static str;

    // Required method
    fn from_row(row: &Row<'_>) -> Self;
}
Expand description

A trait for standardizing how types are created from the Apple Books databases.

This trait allows for instances to be created generically over the rows of their respective databases BKLibrary*.sqlite and AEAnnotation*.sqlite.

The ABQuery::from_row() and ABQuery::QUERY methods are strongly coupled in that the declared rows in the SELECT statement must map directly to the rusqlite’s Row::get() method e.g. the first row of the SELECT statement maps to row.get(0) etc. The unwrap on the Row::get() methods will panic if the index is out of range or the there’s a type mismatch to the struct field it’s been mapped to.

The databases seem to be related via a UUID field.

Book         ZBKLIBRARYASSET.ZASSETID ─────────┐
Annotation   ZAEANNOTATION.ZANNOTATIONASSETID ─┘

Required Associated Constants§

Source

const QUERY: &'static str

The query to retrieve rows from the database. The rows are then passed into ABQuery::from_row() to create instances of the implementing type.

Required Methods§

Source

fn from_row(row: &Row<'_>) -> Self

Constructs an instance of the implementing type from a rusqlite::Row.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl ABQuery for Annotation

Source§

const QUERY: &'static str = { "SELECT\n ZANNOTATIONSELECTEDTEXT, -- 0 body\n ZANNOTATIONNOTE, -- 1 notes\n ZANNOTATIONSTYLE, -- 2 style\n ZANNOTATIONUUID, -- 3 id\n ZAEANNOTATION.ZANNOTATIONASSETID, -- 4 book_id\n ZANNOTATIONCREATIONDATE, -- 5 created\n ZANNOTATIONMODIFICATIONDATE, -- 6 modified\n ZANNOTATIONLOCATION -- 7 location\n FROM ZAEANNOTATION\n WHERE ZANNOTATIONSELECTEDTEXT IS NOT NULL\n AND ZANNOTATIONDELETED = 0\n ORDER BY ZANNOTATIONASSETID;" }

Source§

impl ABQuery for Book

Source§

const QUERY: &'static str = { "SELECT\n ZBKLIBRARYASSET.ZTITLE, -- 0 title\n ZBKLIBRARYASSET.ZAUTHOR, -- 1 author\n ZBKLIBRARYASSET.ZASSETID, -- 2 id\n ZBKLIBRARYASSET.ZLASTOPENDATE -- 3 last_opened\n FROM ZBKLIBRARYASSET\n ORDER BY ZBKLIBRARYASSET.ZTITLE;" }