pub struct Record { /* private fields */ }Expand description
A dynamic record: an entity name, an optional id, and its attributes.
Implementations§
Source§impl Record
impl Record
Sourcepub fn new(entity: impl Into<String>) -> Self
pub fn new(entity: impl Into<String>) -> Self
An empty record for entity, with no id (the shape of a create).
Sourcepub fn with_id(entity: impl Into<String>, id: i64) -> Self
pub fn with_id(entity: impl Into<String>, id: i64) -> Self
An empty record for an existing row (the shape of an update).
Sourcepub fn entity(&self) -> &str
pub fn entity(&self) -> &str
The entity this record belongs to: a fixed table or a runtime content type.
Sourcepub fn set(
&mut self,
key: impl Into<String>,
value: impl Into<AttrValue>,
) -> &mut Self
pub fn set( &mut self, key: impl Into<String>, value: impl Into<AttrValue>, ) -> &mut Self
Sets an attribute, replacing any previous value. Chainable.
Sourcepub fn get(&self, key: &str) -> Option<&AttrValue>
pub fn get(&self, key: &str) -> Option<&AttrValue>
An attribute, or None when the key is absent. An attribute that is
present and null returns Some(AttrValue::Null), which is a different
thing: absent means “not part of this write”, null means “write NULL”.
Sourcepub fn set_original(&mut self, previous: Record)
pub fn set_original(&mut self, previous: Record)
Records the row as it stood before this write, read inside the same transaction. The pipeline sets it on an update when the persister can supply one.
Sourcepub fn has_original(&self) -> bool
pub fn has_original(&self) -> bool
Whether a pre-write snapshot is available. A create never has one, and neither does an update whose persister does not supply one.
Sourcepub fn changed(&self, key: &str) -> bool
pub fn changed(&self, key: &str) -> bool
Whether this write changes key. Always false without a snapshot, so a
change-based listener should check Record::has_original first rather
than read “unchanged” into its absence.
The comparison is text-level today: a snapshot is read back as text, so a
listener that re-types an unchanged value (a date parsed into a
AttrValue::DateTime) reads as changed. Fine for stamping, not yet
sufficient for a per-attribute diff.
Sourcepub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, Error>
pub fn deserialize<T: DeserializeOwned>(&self) -> Result<T, Error>
Reads the attributes into a struct, for code that would rather work with types than a bag. Attributes the target does not name are ignored.
Sourcepub fn from_text_map(
entity: impl Into<String>,
data: &HashMap<String, String>,
) -> Self
pub fn from_text_map( entity: impl Into<String>, data: &HashMap<String, String>, ) -> Self
Builds a record from an all-text submission, the shape the form write
path uses today. Every value arrives as AttrValue::Text, because a
string carries no type; typed values come from field types and listeners.
Sourcepub fn to_text_map(&self) -> HashMap<String, String>
pub fn to_text_map(&self) -> HashMap<String, String>
The record as an all-text map, for a storage layer that binds strings. A null attribute becomes an empty string, matching that path’s existing “empty means none” contract.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Record
impl RefUnwindSafe for Record
impl Send for Record
impl Sync for Record
impl Unpin for Record
impl UnsafeUnpin for Record
impl UnwindSafe for Record
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more