pub struct MemoryDatabase { /* private fields */ }Expand description
Records kept in memory, on desktop and in the browser. Any number of spaces share them, and each sees what the others committed.
With Self::stored_in they are also kept in a Storage between runs: read when it
opens, written after every commit. Self::export_json and Self::import_json move all
of them in and out at once.
Implementations§
Source§impl MemoryDatabase
impl MemoryDatabase
Sourcepub fn new(entities: Vec<EntityInfo>) -> Result<Self, ModelError>
pub fn new(entities: Vec<EntityInfo>) -> Result<Self, ModelError>
A database with these entities and no records.
Sourcepub fn stored_in(
self,
storage: impl Storage + 'static,
name: impl Into<String>,
) -> Result<Self, SpaceError>
pub fn stored_in( self, storage: impl Storage + 'static, name: impl Into<String>, ) -> Result<Self, SpaceError>
Keeps the records in storage under name: what is there is read now, and every commit
writes them all back. Records of entities the database no longer has are left out.
Sourcepub fn was_restored(&self) -> bool
pub fn was_restored(&self) -> bool
Whether Self::stored_in found records kept from before, so an app can put its first
records in only once.
Sourcepub fn storage_problem(&self) -> Option<String>
pub fn storage_problem(&self) -> Option<String>
What went wrong the last time the records were written to their storage, if it did.
Sourcepub fn export_json(&self) -> String
pub fn export_json(&self) -> String
Every record, as JSON: {"format": 1, "next_key": 7, "records": {"Account": [{...}]}}.
Dates are {"days": .., "seconds": ..}; the rest are plain JSON values.
Sourcepub fn import_json(&self, text: &str) -> Result<usize, SpaceError>
pub fn import_json(&self, text: &str) -> Result<usize, SpaceError>
Puts these records, as Self::export_json writes them, in place of all there are, and
keeps them if the database is stored. Returns how many there are. Nothing changes if
anything is wrong: an entity it does not have, a record without its key, a value that
cannot be read.
Sourcepub fn space(&self) -> MemoryObjectSpace
pub fn space(&self) -> MemoryObjectSpace
A new unit of work over these records.
Trait Implementations§
Source§impl Clone for MemoryDatabase
impl Clone for MemoryDatabase
Source§fn clone(&self) -> MemoryDatabase
fn clone(&self) -> MemoryDatabase
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more