From 3ca5255cdea0f8353a919f13f69324073dde1c3a Mon Sep 17 00:00:00 2001 From: Grisha Kruglov Date: Tue, 10 Jul 2018 18:20:38 -0700 Subject: [PATCH] Part 2: Add basic support for timelines to the transactor This records transactions onto a default timeline (0). --- db/src/db.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/db/src/db.rs b/db/src/db.rs index 68ae59d3..5ab33df2 100644 --- a/db/src/db.rs +++ b/db/src/db.rs @@ -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