Struct semilattice_database::Session
source · pub struct Session { /* private fields */ }Implementations§
source§impl Session
impl Session
sourcepub fn name(&mut self) -> &str
pub fn name(&mut self) -> &str
Examples found in repository?
src/lib.rs (line 102)
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
pub fn session_clear(&self, session: &mut Session) -> Result<(), std::io::Error> {
let session_dir = self.session_dir(session.name());
session.session_data = None;
if std::path::Path::new(&session_dir).exists() {
std::fs::remove_dir_all(&session_dir)?;
}
Ok(())
}
pub fn session_start(&self, session: &mut Session) {
let session_dir = self.session_dir(session.name());
if let Ok(session_data) = Session::new_data(&session_dir) {
session.session_data = Some(session_data);
}
}
pub fn session_restart(&self, session: &mut Session) -> Result<(), std::io::Error> {
self.session_clear(session)?;
self.session_start(session);
Ok(())
}
pub fn update(
&self,
session: &mut Session,
records: Vec<Record>,
) -> Result<(), std::io::Error> {
let session_dir = self.session_dir(session.name());
if let None = session.session_data {
if let Ok(session_data) = Session::new_data(&session_dir) {
session.session_data = Some(session_data);
}
}
if let Some(ref mut session_data) = session.session_data {
let sequence = session_data.sequence_number.next();
update::update_recursive(
self,
session_data,
&mut session.temporary_data,
&session_dir,
sequence,
&records,
None,
)?;
}
Ok(())
}sourcepub fn new_data(session_dir: &str) -> Result<SessionData, Error>
pub fn new_data(session_dir: &str) -> Result<SessionData, Error>
Examples found in repository?
src/lib.rs (line 111)
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
pub fn session_start(&self, session: &mut Session) {
let session_dir = self.session_dir(session.name());
if let Ok(session_data) = Session::new_data(&session_dir) {
session.session_data = Some(session_data);
}
}
pub fn session_restart(&self, session: &mut Session) -> Result<(), std::io::Error> {
self.session_clear(session)?;
self.session_start(session);
Ok(())
}
pub fn update(
&self,
session: &mut Session,
records: Vec<Record>,
) -> Result<(), std::io::Error> {
let session_dir = self.session_dir(session.name());
if let None = session.session_data {
if let Ok(session_data) = Session::new_data(&session_dir) {
session.session_data = Some(session_data);
}
}
if let Some(ref mut session_data) = session.session_data {
let sequence = session_data.sequence_number.next();
update::update_recursive(
self,
session_data,
&mut session.temporary_data,
&session_dir,
sequence,
&records,
None,
)?;
}
Ok(())
}More examples
src/session.rs (line 97)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
pub fn new(main_database: &Database, name: impl Into<String>) -> Result<Self, std::io::Error> {
let mut name: String = name.into();
assert!(name != "");
if name == "" {
name = "untitiled".to_owned();
}
let session_dir = main_database.root_dir().to_string() + "/sessions/" + &name;
if !std::path::Path::new(&session_dir).exists() {
std::fs::create_dir_all(&session_dir).unwrap();
}
let session_data = Self::new_data(&session_dir)?;
let temporary_data = Self::init_temporary_data(&session_data);
Ok(Self {
name,
session_data: Some(session_data),
temporary_data,
})
}pub fn begin_search(&self, collection_id: i32) -> SessionSearch<'_>
pub fn search(
&self,
collection_id: i32,
condtions: &Vec<Condition>
) -> SessionSearch<'_>
pub fn field_bytes<'a>(
&'a self,
database: &'a Database,
collection_id: i32,
row: i64,
key: &str
) -> &[u8] ⓘ
pub fn collection_field_bytes<'a>(
&'a self,
collection: &'a Collection,
row: i64,
key: &str
) -> &[u8] ⓘ
pub fn temporary_collection(
&self,
collection_id: i32
) -> Option<&HashMap<i64, TemporaryDataEntity>>
sourcepub fn depends(
&self,
key: Option<&str>,
pend_row: u32
) -> Option<Vec<SessionDepend>>
pub fn depends(
&self,
key: Option<&str>,
pend_row: u32
) -> Option<Vec<SessionDepend>>
Examples found in repository?
src/lib.rs (line 235)
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
pub fn depends(
&self,
key: Option<&str>,
pend_collection_id: i32,
pend_row: i64,
session: Option<&Session>,
) -> Vec<SessionDepend> {
let mut r: Vec<SessionDepend> = vec![];
if pend_row > 0 {
let depends = self.relation.depends(
key,
&CollectionRow::new(pend_collection_id, pend_row as u32),
);
for i in depends {
r.push(i.into());
}
} else {
if let Some(session) = session {
if let Some(session_depends) = session.depends(key, (-pend_row) as u32) {
r = session_depends;
}
}
}
r
}