|
|
|
@ -100,20 +100,34 @@ impl DbHandle {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn write_note(&mut self, master_key: [u8; 32], note: Note) {
|
|
|
|
|
let existing_notes = self.read_notes(master_key).unwrap();
|
|
|
|
|
let namespace_id = self.get_namespace_id(¬e.namespace, master_key).unwrap();
|
|
|
|
|
let tx = self.conn.transaction().unwrap();
|
|
|
|
|
|
|
|
|
|
for existing_note in existing_notes {
|
|
|
|
|
if existing_note.namespace == note.namespace
|
|
|
|
|
&& existing_note.category == note.category
|
|
|
|
|
&& existing_note.title == note.title
|
|
|
|
|
{
|
|
|
|
|
tx.execute("DELETE FROM notes WHERE id=$1;", params![existing_note.id])
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let encrypted_title = crypt::encrypt_value(¬e.title, master_key);
|
|
|
|
|
let encrypted_value = crypt::encrypt_value(¬e.value, master_key);
|
|
|
|
|
self.conn
|
|
|
|
|
.execute(
|
|
|
|
|
"INSERT INTO notes (namespace, category, title, value) VALUES ($1, $2, $3, $4);",
|
|
|
|
|
params![
|
|
|
|
|
namespace_id,
|
|
|
|
|
note.category,
|
|
|
|
|
encrypted_title,
|
|
|
|
|
encrypted_value
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
tx.execute(
|
|
|
|
|
"INSERT INTO notes (namespace, category, title, value) VALUES ($1, $2, $3, $4);",
|
|
|
|
|
params![
|
|
|
|
|
namespace_id,
|
|
|
|
|
note.category,
|
|
|
|
|
encrypted_title,
|
|
|
|
|
encrypted_value
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
let _ = tx.commit().unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn read_notes(&mut self, master_key: [u8; 32]) -> rusqlite::Result<Vec<Note>> {
|
|
|
|
|