Part 2: Add basic support for timelines to the transactor

This records transactions onto a default timeline (0).
This commit is contained in:
Grisha Kruglov 2018-07-10 18:20:38 -07:00 committed by Grisha Kruglov
parent 0974108a52
commit 3ca5255cde

View file

@ -194,8 +194,9 @@ lazy_static! {
// differentiate, e.g., keywords and strings.
r#"CREATE UNIQUE INDEX idx_datoms_unique_value ON datoms (a, value_type_tag, v) WHERE unique_value IS NOT 0"#,
r#"CREATE TABLE transactions (e INTEGER NOT NULL, a SMALLINT NOT NULL, v BLOB NOT NULL, tx INTEGER NOT NULL, added TINYINT NOT NULL DEFAULT 1, value_type_tag SMALLINT NOT NULL)"#,
r#"CREATE INDEX idx_transactions_tx ON transactions (tx, added)"#,
r#"CREATE TABLE timelined_transactions (e INTEGER NOT NULL, a SMALLINT NOT NULL, v BLOB NOT NULL, tx INTEGER NOT NULL, added TINYINT NOT NULL DEFAULT 1, value_type_tag SMALLINT NOT NULL, timeline TINYINT NOT NULL DEFAULT 0)"#,
r#"CREATE INDEX idx_timelined_transactions_timeline ON timelined_transactions (timeline)"#,
r#"CREATE VIEW transactions AS SELECT e, a, v, value_type_tag, tx, added FROM timelined_transactions WHERE timeline IS 0"#,
// Fulltext indexing.
// A fulltext indexed value v is an integer rowid referencing fulltext_values.
@ -569,7 +570,7 @@ fn insert_transaction(conn: &rusqlite::Connection, tx: Entid) -> Result<()> {
// at this point.
let s = r#"
INSERT INTO transactions (e, a, v, tx, added, value_type_tag)
INSERT INTO timelined_transactions (e, a, v, tx, added, value_type_tag)
SELECT e0, a0, v0, ?, 1, value_type_tag0
FROM temp.search_results
WHERE added0 IS 1 AND ((rid IS NULL) OR ((rid IS NOT NULL) AND (v0 IS NOT v)))"#;
@ -578,7 +579,7 @@ fn insert_transaction(conn: &rusqlite::Connection, tx: Entid) -> Result<()> {
stmt.execute(&[&tx]).context(DbErrorKind::TxInsertFailedToAddMissingDatoms)?;
let s = r#"
INSERT INTO transactions (e, a, v, tx, added, value_type_tag)
INSERT INTO timelined_transactions (e, a, v, tx, added, value_type_tag)
SELECT e0, a0, v, ?, 0, value_type_tag0
FROM temp.search_results
WHERE rid IS NOT NULL AND