Breathe life back into this project. #1
6 changed files with 2033 additions and 1093 deletions
991
db/src/cache.rs
991
db/src/cache.rs
File diff suppressed because it is too large
Load diff
1775
db/src/db.rs
1775
db/src/db.rs
File diff suppressed because it is too large
Load diff
|
@ -205,15 +205,15 @@ pub fn datoms_after<S: Borrow<Schema>>(conn: &rusqlite::Connection, schema: &S,
|
||||||
let mut stmt: rusqlite::Statement = conn.prepare("SELECT e, a, v, value_type_tag, tx FROM datoms WHERE tx > ? ORDER BY e ASC, a ASC, value_type_tag ASC, v ASC, tx ASC")?;
|
let mut stmt: rusqlite::Statement = conn.prepare("SELECT e, a, v, value_type_tag, tx FROM datoms WHERE tx > ? ORDER BY e ASC, a ASC, value_type_tag ASC, v ASC, tx ASC")?;
|
||||||
|
|
||||||
let r: Result<Vec<_>> = stmt.query_and_then(&[&tx], |row| {
|
let r: Result<Vec<_>> = stmt.query_and_then(&[&tx], |row| {
|
||||||
let e: i64 = row.get_checked(0)?;
|
let e: i64 = row.get(0)?;
|
||||||
let a: i64 = row.get_checked(1)?;
|
let a: i64 = row.get(1)?;
|
||||||
|
|
||||||
if a == entids::DB_TX_INSTANT {
|
if a == entids::DB_TX_INSTANT {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let v: rusqlite::types::Value = row.get_checked(2)?;
|
let v: rusqlite::types::Value = row.get(2)?;
|
||||||
let value_type_tag: i32 = row.get_checked(3)?;
|
let value_type_tag: i32 = row.get(3)?;
|
||||||
|
|
||||||
let attribute = borrowed_schema.require_attribute_for_entid(a)?;
|
let attribute = borrowed_schema.require_attribute_for_entid(a)?;
|
||||||
let value_type_tag = if !attribute.fulltext { value_type_tag } else { ValueType::Long.value_type_tag() };
|
let value_type_tag = if !attribute.fulltext { value_type_tag } else { ValueType::Long.value_type_tag() };
|
||||||
|
@ -221,7 +221,7 @@ pub fn datoms_after<S: Borrow<Schema>>(conn: &rusqlite::Connection, schema: &S,
|
||||||
let typed_value = TypedValue::from_sql_value_pair(v, value_type_tag)?.map_ident(borrowed_schema);
|
let typed_value = TypedValue::from_sql_value_pair(v, value_type_tag)?.map_ident(borrowed_schema);
|
||||||
let (value, _) = typed_value.to_edn_value_pair();
|
let (value, _) = typed_value.to_edn_value_pair();
|
||||||
|
|
||||||
let tx: i64 = row.get_checked(4)?;
|
let tx: i64 = row.get(4)?;
|
||||||
|
|
||||||
Ok(Some(Datom {
|
Ok(Some(Datom {
|
||||||
e: EntidOrIdent::Entid(e),
|
e: EntidOrIdent::Entid(e),
|
||||||
|
@ -245,11 +245,11 @@ pub fn transactions_after<S: Borrow<Schema>>(conn: &rusqlite::Connection, schema
|
||||||
let mut stmt: rusqlite::Statement = conn.prepare("SELECT e, a, v, value_type_tag, tx, added FROM transactions WHERE tx > ? ORDER BY tx ASC, e ASC, a ASC, value_type_tag ASC, v ASC, added ASC")?;
|
let mut stmt: rusqlite::Statement = conn.prepare("SELECT e, a, v, value_type_tag, tx, added FROM transactions WHERE tx > ? ORDER BY tx ASC, e ASC, a ASC, value_type_tag ASC, v ASC, added ASC")?;
|
||||||
|
|
||||||
let r: Result<Vec<_>> = stmt.query_and_then(&[&tx], |row| {
|
let r: Result<Vec<_>> = stmt.query_and_then(&[&tx], |row| {
|
||||||
let e: i64 = row.get_checked(0)?;
|
let e: i64 = row.get(0)?;
|
||||||
let a: i64 = row.get_checked(1)?;
|
let a: i64 = row.get(1)?;
|
||||||
|
|
||||||
let v: rusqlite::types::Value = row.get_checked(2)?;
|
let v: rusqlite::types::Value = row.get(2)?;
|
||||||
let value_type_tag: i32 = row.get_checked(3)?;
|
let value_type_tag: i32 = row.get(3)?;
|
||||||
|
|
||||||
let attribute = borrowed_schema.require_attribute_for_entid(a)?;
|
let attribute = borrowed_schema.require_attribute_for_entid(a)?;
|
||||||
let value_type_tag = if !attribute.fulltext { value_type_tag } else { ValueType::Long.value_type_tag() };
|
let value_type_tag = if !attribute.fulltext { value_type_tag } else { ValueType::Long.value_type_tag() };
|
||||||
|
@ -257,8 +257,8 @@ pub fn transactions_after<S: Borrow<Schema>>(conn: &rusqlite::Connection, schema
|
||||||
let typed_value = TypedValue::from_sql_value_pair(v, value_type_tag)?.map_ident(borrowed_schema);
|
let typed_value = TypedValue::from_sql_value_pair(v, value_type_tag)?.map_ident(borrowed_schema);
|
||||||
let (value, _) = typed_value.to_edn_value_pair();
|
let (value, _) = typed_value.to_edn_value_pair();
|
||||||
|
|
||||||
let tx: i64 = row.get_checked(4)?;
|
let tx: i64 = row.get(4)?;
|
||||||
let added: bool = row.get_checked(5)?;
|
let added: bool = row.get(5)?;
|
||||||
|
|
||||||
Ok(Datom {
|
Ok(Datom {
|
||||||
e: EntidOrIdent::Entid(e),
|
e: EntidOrIdent::Entid(e),
|
||||||
|
@ -279,8 +279,8 @@ pub fn fulltext_values(conn: &rusqlite::Connection) -> Result<FulltextValues> {
|
||||||
let mut stmt: rusqlite::Statement = conn.prepare("SELECT rowid, text FROM fulltext_values ORDER BY rowid")?;
|
let mut stmt: rusqlite::Statement = conn.prepare("SELECT rowid, text FROM fulltext_values ORDER BY rowid")?;
|
||||||
|
|
||||||
let r: Result<Vec<_>> = stmt.query_and_then(&[], |row| {
|
let r: Result<Vec<_>> = stmt.query_and_then(&[], |row| {
|
||||||
let rowid: i64 = row.get_checked(0)?;
|
let rowid: i64 = row.get(0)?;
|
||||||
let text: String = row.get_checked(1)?;
|
let text: String = row.get(1)?;
|
||||||
Ok((rowid, text))
|
Ok((rowid, text))
|
||||||
})?.collect();
|
})?.collect();
|
||||||
|
|
||||||
|
@ -305,7 +305,7 @@ pub fn dump_sql_query(conn: &rusqlite::Connection, sql: &str, params: &[&ToSql])
|
||||||
|
|
||||||
let r: Result<Vec<_>> = stmt.query_and_then(params, |row| {
|
let r: Result<Vec<_>> = stmt.query_and_then(params, |row| {
|
||||||
for i in 0..row.column_count() {
|
for i in 0..row.column_count() {
|
||||||
let value: rusqlite::types::Value = row.get_checked(i)?;
|
let value: rusqlite::types::Value = row.get(i)?;
|
||||||
write!(&mut tw, "{:?}\t", value).unwrap();
|
write!(&mut tw, "{:?}\t", value).unwrap();
|
||||||
}
|
}
|
||||||
write!(&mut tw, "\n").unwrap();
|
write!(&mut tw, "\n").unwrap();
|
||||||
|
|
|
@ -61,7 +61,7 @@ use watcher::{
|
||||||
fn collect_ordered_txs_to_move(conn: &rusqlite::Connection, txs_from: RangeFrom<Entid>, timeline: Entid) -> Result<Vec<Entid>> {
|
fn collect_ordered_txs_to_move(conn: &rusqlite::Connection, txs_from: RangeFrom<Entid>, timeline: Entid) -> Result<Vec<Entid>> {
|
||||||
let mut stmt = conn.prepare("SELECT tx, timeline FROM timelined_transactions WHERE tx >= ? AND timeline = ? GROUP BY tx ORDER BY tx DESC")?;
|
let mut stmt = conn.prepare("SELECT tx, timeline FROM timelined_transactions WHERE tx >= ? AND timeline = ? GROUP BY tx ORDER BY tx DESC")?;
|
||||||
let mut rows = stmt.query_and_then(&[&txs_from.start, &timeline], |row: &rusqlite::Row| -> Result<(Entid, Entid)>{
|
let mut rows = stmt.query_and_then(&[&txs_from.start, &timeline], |row: &rusqlite::Row| -> Result<(Entid, Entid)>{
|
||||||
Ok((row.get_checked(0)?, row.get_checked(1)?))
|
Ok((row.get(0)?, row.get(1)?))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut txs = vec![];
|
let mut txs = vec![];
|
||||||
|
@ -106,7 +106,7 @@ fn remove_tx_from_datoms(conn: &rusqlite::Connection, tx_id: Entid) -> Result<()
|
||||||
fn is_timeline_empty(conn: &rusqlite::Connection, timeline: Entid) -> Result<bool> {
|
fn is_timeline_empty(conn: &rusqlite::Connection, timeline: Entid) -> Result<bool> {
|
||||||
let mut stmt = conn.prepare("SELECT timeline FROM timelined_transactions WHERE timeline = ? GROUP BY timeline")?;
|
let mut stmt = conn.prepare("SELECT timeline FROM timelined_transactions WHERE timeline = ? GROUP BY timeline")?;
|
||||||
let rows = stmt.query_and_then(&[&timeline], |row| -> Result<i64> {
|
let rows = stmt.query_and_then(&[&timeline], |row| -> Result<i64> {
|
||||||
Ok(row.get_checked(0)?)
|
Ok(row.get(0)?)
|
||||||
})?;
|
})?;
|
||||||
Ok(rows.count() == 0)
|
Ok(rows.count() == 0)
|
||||||
}
|
}
|
||||||
|
@ -115,15 +115,15 @@ fn is_timeline_empty(conn: &rusqlite::Connection, timeline: Entid) -> Result<boo
|
||||||
fn reversed_terms_for(conn: &rusqlite::Connection, tx_id: Entid) -> Result<Vec<TermWithoutTempIds>> {
|
fn reversed_terms_for(conn: &rusqlite::Connection, tx_id: Entid) -> Result<Vec<TermWithoutTempIds>> {
|
||||||
let mut stmt = conn.prepare("SELECT e, a, v, value_type_tag, tx, added FROM timelined_transactions WHERE tx = ? AND timeline = ? ORDER BY tx DESC")?;
|
let mut stmt = conn.prepare("SELECT e, a, v, value_type_tag, tx, added FROM timelined_transactions WHERE tx = ? AND timeline = ? ORDER BY tx DESC")?;
|
||||||
let mut rows = stmt.query_and_then(&[&tx_id, &::TIMELINE_MAIN], |row| -> Result<TermWithoutTempIds> {
|
let mut rows = stmt.query_and_then(&[&tx_id, &::TIMELINE_MAIN], |row| -> Result<TermWithoutTempIds> {
|
||||||
let op = match row.get_checked(5)? {
|
let op = match row.get(5)? {
|
||||||
true => OpType::Retract,
|
true => OpType::Retract,
|
||||||
false => OpType::Add
|
false => OpType::Add
|
||||||
};
|
};
|
||||||
Ok(Term::AddOrRetract(
|
Ok(Term::AddOrRetract(
|
||||||
op,
|
op,
|
||||||
KnownEntid(row.get_checked(0)?),
|
KnownEntid(row.get(0)?),
|
||||||
row.get_checked(1)?,
|
row.get(1)?,
|
||||||
TypedValue::from_sql_value_pair(row.get_checked(2)?, row.get_checked(3)?)?,
|
TypedValue::from_sql_value_pair(row.get(2)?, row.get(3)?)?,
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,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(&[], |row| -> Result<(String, Partition)> {
|
||||||
Ok((row.get_checked(0)?, Partition::new(row.get_checked(1)?, row.get_checked(2)?, row.get_checked(3)?, row.get_checked(4)?)))
|
Ok((row.get(0)?, Partition::new(row.get(1)?, row.get(2)?, row.get(3)?, row.get(4)?)))
|
||||||
})?.collect();
|
})?.collect();
|
||||||
m
|
m
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,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(&[], |row| -> Result<Entid> {
|
||||||
Ok(row.get_checked(0)?)
|
Ok(row.get(0)?)
|
||||||
})?.collect();
|
})?.collect();
|
||||||
|
|
||||||
let mut txs = txs.into_iter();
|
let mut txs = txs.into_iter();
|
||||||
|
@ -131,7 +131,7 @@ impl SyncMetadata {
|
||||||
};
|
};
|
||||||
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(&[], |row| -> Result<Entid> {
|
||||||
Ok(row.get_checked(0)?)
|
Ok(row.get(0)?)
|
||||||
})?.collect();
|
})?.collect();
|
||||||
|
|
||||||
let mut all = Vec::with_capacity(txs.len());
|
let mut all = Vec::with_capacity(txs.len());
|
||||||
|
@ -144,14 +144,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 = db_tx.query_row("SELECT count(rowid) FROM timelined_transactions WHERE timeline = 0 AND tx = ? AND e != ?", &[&tx_id, &tx_id], |row| -> Result<i64> {
|
let count = db_tx.query_row("SELECT count(rowid) FROM timelined_transactions WHERE timeline = 0 AND tx = ? AND e != ?", &[&tx_id, &tx_id], |row| -> Result<i64> {
|
||||||
Ok(row.get_checked(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 = db_tx.query_row("SELECT count(rowid) FROM timelined_transactions WHERE timeline = 0 AND tx = ? AND e = ?", &[&tx_id, &e], |row| -> Result<i64> {
|
let count = db_tx.query_row("SELECT count(rowid) FROM timelined_transactions WHERE timeline = 0 AND tx = ? AND e = ?", &[&tx_id, &e], |row| -> Result<i64> {
|
||||||
Ok(row.get_checked(0)?)
|
Ok(row.get(0)?)
|
||||||
})?;
|
})?;
|
||||||
Ok(count? > 0)
|
Ok(count? > 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,11 +118,11 @@ where T: Sized + Iterator<Item=Result<TxPart>> + 't {
|
||||||
fn to_tx_part(row: &rusqlite::Row) -> Result<TxPart> {
|
fn to_tx_part(row: &rusqlite::Row) -> Result<TxPart> {
|
||||||
Ok(TxPart {
|
Ok(TxPart {
|
||||||
partitions: None,
|
partitions: None,
|
||||||
e: row.get_checked(0)?,
|
e: row.get(0)?,
|
||||||
a: row.get_checked(1)?,
|
a: row.get(1)?,
|
||||||
v: TypedValue::from_sql_value_pair(row.get_checked(2)?, row.get_checked(3)?)?,
|
v: TypedValue::from_sql_value_pair(row.get(2)?, row.get(3)?)?,
|
||||||
tx: row.get_checked(4)?,
|
tx: row.get(4)?,
|
||||||
added: row.get_checked(5)?,
|
added: row.get(5)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue