fix insert_entry retval
parent
0920fec0ce
commit
a4caf9b8b3
|
@ -336,29 +336,31 @@ impl UpEndConnection {
|
|||
|
||||
pub fn insert_entry(&self, entry: Entry) -> Result<Address> {
|
||||
debug!("Inserting: {}", entry);
|
||||
let entry = models::Entry::try_from(&entry)?;
|
||||
self._insert_entry(entry)
|
||||
let db_entry = models::Entry::try_from(&entry)?;
|
||||
self._insert_entry(db_entry)?;
|
||||
entry.address()
|
||||
}
|
||||
|
||||
pub fn insert_entry_immutable(&self, entry: Entry) -> Result<Address> {
|
||||
debug!("Inserting immutably: {}", entry);
|
||||
let entry = models::Entry::try_from(&ImmutableEntry(entry))?;
|
||||
self._insert_entry(entry)
|
||||
let address = entry.address()?;
|
||||
let db_entry = models::Entry::try_from(&ImmutableEntry(entry))?;
|
||||
self._insert_entry(db_entry)?;
|
||||
Ok(address)
|
||||
}
|
||||
|
||||
fn _insert_entry(&self, entry: models::Entry) -> Result<Address> {
|
||||
fn _insert_entry(&self, entry: models::Entry) -> Result<usize> {
|
||||
let result = diesel::insert_into(data::table)
|
||||
.values(&entry)
|
||||
.execute(&self.conn);
|
||||
|
||||
if let Some(error) = result.err() {
|
||||
match error {
|
||||
Error::DatabaseError(DatabaseErrorKind::UniqueViolation, _) => {}
|
||||
_ => return Err(anyhow!(error)),
|
||||
}
|
||||
match result {
|
||||
Ok(num) => Ok(num),
|
||||
Err(error) => match error {
|
||||
Error::DatabaseError(DatabaseErrorKind::UniqueViolation, _) => Ok(0),
|
||||
_ => Err(anyhow!(error)),
|
||||
},
|
||||
}
|
||||
|
||||
Ok(Address::Hash(Hash(entry.identity)))
|
||||
}
|
||||
|
||||
// #[deprecated]
|
||||
|
|
Loading…
Reference in New Issue