add immutable entries for size, etc (does nothing for now)
This commit is contained in:
parent
3599666a01
commit
0920fec0ce
6 changed files with 36 additions and 9 deletions
|
@ -29,6 +29,7 @@ CREATE TABLE data
|
|||
entity BLOB NOT NULL,
|
||||
attribute VARCHAR NOT NULL,
|
||||
value VARCHAR NOT NULL,
|
||||
immutable BOOLEAN NOT NULL,
|
||||
UNIQUE (entity, attribute, value)
|
||||
);
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ pub struct Entry {
|
|||
pub value: EntryValue,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ImmutableEntry(pub Entry);
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct InvariantEntry {
|
||||
pub attribute: String,
|
||||
|
@ -55,6 +58,21 @@ impl TryFrom<&Entry> for models::Entry {
|
|||
entity: e.entity.encode()?,
|
||||
attribute: e.attribute.clone(),
|
||||
value: e.value.to_string()?,
|
||||
immutable: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<&ImmutableEntry> for models::Entry {
|
||||
type Error = anyhow::Error;
|
||||
|
||||
fn try_from(e: &ImmutableEntry) -> Result<Self, Self::Error> {
|
||||
Ok(models::Entry {
|
||||
identity: e.0.address()?.encode()?,
|
||||
entity: e.0.entity.encode()?,
|
||||
attribute: e.0.attribute.clone(),
|
||||
value: e.0.value.to_string()?,
|
||||
immutable: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,4 +46,5 @@ pub struct Entry {
|
|||
pub entity: Vec<u8>,
|
||||
pub attribute: String,
|
||||
pub value: String,
|
||||
pub immutable: bool,
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ table! {
|
|||
entity -> Binary,
|
||||
attribute -> Text,
|
||||
value -> Text,
|
||||
immutable -> Bool,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,11 +11,11 @@ pub mod lang;
|
|||
|
||||
use crate::addressing::{Address, Addressable};
|
||||
use crate::database::constants::{IS_OF_TYPE_ATTR, TYPE_ADDR, TYPE_HAS_ATTR, TYPE_INVARIANT};
|
||||
use crate::database::entry::{Entry, EntryValue};
|
||||
use crate::database::entry::{Entry, EntryValue, ImmutableEntry};
|
||||
use crate::database::inner::models;
|
||||
use crate::database::inner::schema::data;
|
||||
use crate::database::lang::Query;
|
||||
use crate::util::hash::{Hash, Hashable};
|
||||
use crate::util::hash::Hash;
|
||||
use crate::util::LoggerSink;
|
||||
use anyhow::{anyhow, Result};
|
||||
use chrono::NaiveDateTime;
|
||||
|
@ -336,13 +336,19 @@ 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 insert_entry = models::Entry::try_from(&entry)?;
|
||||
|
||||
let entry = Entry::try_from(&insert_entry)?;
|
||||
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)
|
||||
}
|
||||
|
||||
fn _insert_entry(&self, entry: models::Entry) -> Result<Address> {
|
||||
let result = diesel::insert_into(data::table)
|
||||
.values(insert_entry)
|
||||
.values(&entry)
|
||||
.execute(&self.conn);
|
||||
|
||||
if let Some(error) = result.err() {
|
||||
|
@ -352,7 +358,7 @@ impl UpEndConnection {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(Address::Hash(entry.hash()?))
|
||||
Ok(Address::Hash(Hash(entry.identity)))
|
||||
}
|
||||
|
||||
// #[deprecated]
|
||||
|
|
|
@ -363,8 +363,8 @@ fn _process_directory_entry<P: AsRef<Path>>(
|
|||
connection.transaction::<_, Error, _>(|| {
|
||||
connection.insert_file(new_file)?;
|
||||
|
||||
connection.insert_entry(type_entry)?;
|
||||
connection.insert_entry(size_entry)?;
|
||||
connection.insert_entry_immutable(type_entry)?;
|
||||
connection.insert_entry_immutable(size_entry)?;
|
||||
if let Some(mime_entry) = mime_entry {
|
||||
connection.insert_entry(mime_entry)?;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue