Breathe life back into this project. #1
3 changed files with 17 additions and 17 deletions
|
@ -97,7 +97,7 @@ impl SyncMetadata {
|
||||||
},
|
},
|
||||||
PartitionsTable::Tolstoy => {
|
PartitionsTable::Tolstoy => {
|
||||||
let mut stmt: ::rusqlite::Statement = tx.prepare("SELECT part, start, end, idx, allow_excision FROM tolstoy_parts")?;
|
let mut stmt: ::rusqlite::Statement = tx.prepare("SELECT part, start, end, idx, allow_excision FROM tolstoy_parts")?;
|
||||||
let m: Result<PartitionMap> = stmt.query_and_then(&[], |row| -> Result<(String, Partition)> {
|
let m: Result<PartitionMap> = stmt.query_and_then(rusqlite::params![], |row| -> Result<(String, Partition)> {
|
||||||
Ok((row.get(0)?, Partition::new(row.get(1)?, row.get(2)?, row.get(3)?, row.get(4)?)))
|
Ok((row.get(0)?, Partition::new(row.get(1)?, row.get(2)?, row.get(3)?, row.get(4)?)))
|
||||||
})?.collect();
|
})?.collect();
|
||||||
m
|
m
|
||||||
|
@ -107,7 +107,7 @@ impl SyncMetadata {
|
||||||
|
|
||||||
pub fn root_and_head_tx(tx: &rusqlite::Transaction) -> Result<(Entid, Entid)> {
|
pub fn root_and_head_tx(tx: &rusqlite::Transaction) -> Result<(Entid, Entid)> {
|
||||||
let mut stmt: ::rusqlite::Statement = tx.prepare("SELECT tx FROM timelined_transactions WHERE timeline = 0 GROUP BY tx ORDER BY tx")?;
|
let mut stmt: ::rusqlite::Statement = tx.prepare("SELECT tx FROM timelined_transactions WHERE timeline = 0 GROUP BY tx ORDER BY tx")?;
|
||||||
let txs: Vec<_> = stmt.query_and_then(&[], |row| -> Result<Entid> {
|
let txs: Vec<_> = stmt.query_and_then(rusqlite::params![], |row| -> Result<Entid> {
|
||||||
Ok(row.get(0)?)
|
Ok(row.get(0)?)
|
||||||
})?.collect();
|
})?.collect();
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ impl SyncMetadata {
|
||||||
None => format!("WHERE timeline = 0")
|
None => format!("WHERE timeline = 0")
|
||||||
};
|
};
|
||||||
let mut stmt: ::rusqlite::Statement = db_tx.prepare(&format!("SELECT tx FROM timelined_transactions {} GROUP BY tx ORDER BY tx", after_clause))?;
|
let mut stmt: ::rusqlite::Statement = db_tx.prepare(&format!("SELECT tx FROM timelined_transactions {} GROUP BY tx ORDER BY tx", after_clause))?;
|
||||||
let txs: Vec<_> = stmt.query_and_then(&[], |row| -> Result<Entid> {
|
let txs: Vec<_> = stmt.query_and_then(rusqlite::params![], |row| -> Result<Entid> {
|
||||||
Ok(row.get(0)?)
|
Ok(row.get(0)?)
|
||||||
})?.collect();
|
})?.collect();
|
||||||
|
|
||||||
|
@ -143,14 +143,14 @@ impl SyncMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_tx_empty(db_tx: &rusqlite::Transaction, tx_id: Entid) -> Result<bool> {
|
pub fn is_tx_empty(db_tx: &rusqlite::Transaction, tx_id: Entid) -> Result<bool> {
|
||||||
let count: i64 = db_tx.query_row("SELECT count(rowid) FROM timelined_transactions WHERE timeline = 0 AND tx = ? AND e != ?", &[&tx_id, &tx_id], |row| {
|
let count: i64 = db_tx.query_row("SELECT count(rowid) FROM timelined_transactions WHERE timeline = 0 AND tx = ? AND e != ?", rusqlite::params![&tx_id, &tx_id], |row| {
|
||||||
Ok(row.get(0)?)
|
Ok(row.get(0)?)
|
||||||
})?;
|
})?;
|
||||||
Ok(count == 0)
|
Ok(count == 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_entity_assertions_in_tx(db_tx: &rusqlite::Transaction, e: Entid, tx_id: Entid) -> Result<bool> {
|
pub fn has_entity_assertions_in_tx(db_tx: &rusqlite::Transaction, e: Entid, tx_id: Entid) -> Result<bool> {
|
||||||
let count: i64 = db_tx.query_row("SELECT count(rowid) FROM timelined_transactions WHERE timeline = 0 AND tx = ? AND e = ?", &[&tx_id, &e], |row| {
|
let count: i64 = db_tx.query_row("SELECT count(rowid) FROM timelined_transactions WHERE timeline = 0 AND tx = ? AND e = ?", rusqlite::params![&tx_id, &e], |row| {
|
||||||
Ok(row.get(0)?)
|
Ok(row.get(0)?)
|
||||||
})?;
|
})?;
|
||||||
Ok(count > 0)
|
Ok(count > 0)
|
||||||
|
@ -203,11 +203,11 @@ mod tests {
|
||||||
|
|
||||||
// last attribute is the timeline (0).
|
// last attribute is the timeline (0).
|
||||||
|
|
||||||
db_tx.execute("INSERT INTO timelined_transactions VALUES (?, ?, ?, ?, ?, ?, ?)", &[&268435457, &3, &1529971773701734_i64, &268435457, &1, &4, &0]).expect("inserted");
|
db_tx.execute("INSERT INTO timelined_transactions VALUES (?, ?, ?, ?, ?, ?, ?)", rusqlite::params![&268435457, &3, &1529971773701734_i64, &268435457, &1, &4, &0]).expect("inserted");
|
||||||
db_tx.execute("INSERT INTO timelined_transactions VALUES (?, ?, ?, ?, ?, ?, ?)", &[&65536, &1, &":person/name", &268435457, &1, &13, &0]).expect("inserted");
|
db_tx.execute("INSERT INTO timelined_transactions VALUES (?, ?, ?, ?, ?, ?, ?)", rusqlite::params![&65536, &1, &":person/name", &268435457, &1, &13, &0]).expect("inserted");
|
||||||
db_tx.execute("INSERT INTO timelined_transactions VALUES (?, ?, ?, ?, ?, ?, ?)", &[&65536, &7, &27, &268435457, &1, &0, &0]).expect("inserted");
|
db_tx.execute("INSERT INTO timelined_transactions VALUES (?, ?, ?, ?, ?, ?, ?)", rusqlite::params![&65536, &7, &27, &268435457, &1, &0, &0]).expect("inserted");
|
||||||
db_tx.execute("INSERT INTO timelined_transactions VALUES (?, ?, ?, ?, ?, ?, ?)", &[&65536, &9, &36, &268435457, &1, &0, &0]).expect("inserted");
|
db_tx.execute("INSERT INTO timelined_transactions VALUES (?, ?, ?, ?, ?, ?, ?)", rusqlite::params![&65536, &9, &36, &268435457, &1, &0, &0]).expect("inserted");
|
||||||
db_tx.execute("INSERT INTO timelined_transactions VALUES (?, ?, ?, ?, ?, ?, ?)", &[&65536, &11, &1, &268435457, &1, &1, &0]).expect("inserted");
|
db_tx.execute("INSERT INTO timelined_transactions VALUES (?, ?, ?, ?, ?, ?, ?)", rusqlite::params![&65536, &11, &1, &268435457, &1, &1, &0]).expect("inserted");
|
||||||
|
|
||||||
let (root_tx, last_tx) = SyncMetadata::root_and_head_tx(&db_tx).expect("last tx");
|
let (root_tx, last_tx) = SyncMetadata::root_and_head_tx(&db_tx).expect("last tx");
|
||||||
assert_eq!(268435456, root_tx);
|
assert_eq!(268435456, root_tx);
|
||||||
|
|
|
@ -37,7 +37,7 @@ lazy_static! {
|
||||||
|
|
||||||
pub fn ensure_current_version(tx: &mut rusqlite::Transaction) -> Result<()> {
|
pub fn ensure_current_version(tx: &mut rusqlite::Transaction) -> Result<()> {
|
||||||
for statement in (&SCHEMA_STATEMENTS).iter() {
|
for statement in (&SCHEMA_STATEMENTS).iter() {
|
||||||
tx.execute(statement, &[])?;
|
tx.execute(statement, rusqlite::params![])?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial partition information is what we'd see at bootstrap, and is used during first sync.
|
// Initial partition information is what we'd see at bootstrap, and is used during first sync.
|
||||||
|
@ -45,7 +45,7 @@ pub fn ensure_current_version(tx: &mut rusqlite::Transaction) -> Result<()> {
|
||||||
tx.execute("INSERT OR IGNORE INTO tolstoy_parts VALUES (?, ?, ?, ?, ?)", rusqlite::params![&name.to_string(), start, end, index, allow_excision])?;
|
tx.execute("INSERT OR IGNORE INTO tolstoy_parts VALUES (?, ?, ?, ?, ?)", rusqlite::params![&name.to_string(), start, end, index, allow_excision])?;
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.execute("INSERT OR IGNORE INTO tolstoy_metadata (key, value) VALUES (?, zeroblob(16))", &[&REMOTE_HEAD_KEY])?;
|
tx.execute("INSERT OR IGNORE INTO tolstoy_metadata (key, value) VALUES (?, zeroblob(16))", rusqlite::params![&REMOTE_HEAD_KEY])?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ pub mod tests {
|
||||||
assert!(ensure_current_version(&mut tx).is_ok());
|
assert!(ensure_current_version(&mut tx).is_ok());
|
||||||
|
|
||||||
let mut stmt = tx.prepare("SELECT key FROM tolstoy_metadata WHERE value = zeroblob(16)").unwrap();
|
let mut stmt = tx.prepare("SELECT key FROM tolstoy_metadata WHERE value = zeroblob(16)").unwrap();
|
||||||
let mut keys_iter = stmt.query_map(&[], |r| r.get(0)).expect("query works");
|
let mut keys_iter = stmt.query_map(rusqlite::params![], |r| r.get(0)).expect("query works");
|
||||||
|
|
||||||
let first: Result<String> = keys_iter.next().unwrap().map_err(|e| e.into());
|
let first: Result<String> = keys_iter.next().unwrap().map_err(|e| e.into());
|
||||||
let second: Option<_> = keys_iter.next();
|
let second: Option<_> = keys_iter.next();
|
||||||
|
@ -127,14 +127,14 @@ pub mod tests {
|
||||||
let test_uuid = Uuid::new_v4();
|
let test_uuid = Uuid::new_v4();
|
||||||
{
|
{
|
||||||
let uuid_bytes = test_uuid.as_bytes().to_vec();
|
let uuid_bytes = test_uuid.as_bytes().to_vec();
|
||||||
match tx.execute("UPDATE tolstoy_metadata SET value = ? WHERE key = ?", &[&uuid_bytes, &REMOTE_HEAD_KEY]) {
|
match tx.execute("UPDATE tolstoy_metadata SET value = ? WHERE key = ?", rusqlite::params![&uuid_bytes, &REMOTE_HEAD_KEY]) {
|
||||||
Err(e) => panic!("Error running an update: {}", e),
|
Err(e) => panic!("Error running an update: {}", e),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_idx = USER0 + 1;
|
let new_idx = USER0 + 1;
|
||||||
match tx.execute("UPDATE tolstoy_parts SET idx = ? WHERE part = ?", &[&new_idx, &PARTITION_USER]) {
|
match tx.execute("UPDATE tolstoy_parts SET idx = ? WHERE part = ?", rusqlite::params![&new_idx, &PARTITION_USER]) {
|
||||||
Err(e) => panic!("Error running an update: {}", e),
|
Err(e) => panic!("Error running an update: {}", e),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ pub mod tests {
|
||||||
|
|
||||||
// Check that running ensure_current_version on an initialized conn doesn't change anything.
|
// Check that running ensure_current_version on an initialized conn doesn't change anything.
|
||||||
let mut stmt = tx.prepare("SELECT value FROM tolstoy_metadata").unwrap();
|
let mut stmt = tx.prepare("SELECT value FROM tolstoy_metadata").unwrap();
|
||||||
let mut values_iter = stmt.query_map(&[], |r| {
|
let mut values_iter = stmt.query_map(rusqlite::params![], |r| {
|
||||||
let raw_uuid: Vec<u8> = r.get(0);
|
let raw_uuid: Vec<u8> = r.get(0);
|
||||||
Uuid::from_bytes(raw_uuid.as_slice()).unwrap()
|
Uuid::from_bytes(raw_uuid.as_slice()).unwrap()
|
||||||
}).expect("query works");
|
}).expect("query works");
|
||||||
|
|
|
@ -137,7 +137,7 @@ impl Processor {
|
||||||
let select_query = format!("SELECT e, a, v, value_type_tag, tx, added FROM timelined_transactions {} ORDER BY tx", tx_filter);
|
let select_query = format!("SELECT e, a, v, value_type_tag, tx, added FROM timelined_transactions {} ORDER BY tx", tx_filter);
|
||||||
let mut stmt = sqlite.prepare(&select_query)?;
|
let mut stmt = sqlite.prepare(&select_query)?;
|
||||||
|
|
||||||
let mut rows = stmt.query_and_then(&[], to_tx_part)?.peekable();
|
let mut rows = stmt.query_and_then(rusqlite::params![], to_tx_part)?.peekable();
|
||||||
|
|
||||||
// Walk the transaction table, keeping track of the current "tx".
|
// Walk the transaction table, keeping track of the current "tx".
|
||||||
// Whenever "tx" changes, construct a datoms iterator and pass it to the receiver.
|
// Whenever "tx" changes, construct a datoms iterator and pass it to the receiver.
|
||||||
|
|
Loading…
Reference in a new issue