pub mod migrations;
use cot::db::migrations::SyncDynMigration;
use crate::App;
use crate::db::{Auto, model};
#[derive(Debug, Clone)]
#[model]
pub struct Session {
#[model(primary_key)]
pub(crate) id: Auto<i32>,
#[model(unique)]
pub(crate) key: String,
pub(crate) data: String,
pub(crate) expiry: chrono::DateTime<chrono::FixedOffset>,
}
#[derive(Debug, Copy, Clone)]
#[non_exhaustive]
pub struct SessionApp;
impl SessionApp {
#[must_use]
pub fn new() -> Self {
Self {}
}
}
impl Default for SessionApp {
fn default() -> Self {
Self::new()
}
}
impl App for SessionApp {
fn name(&self) -> &'static str {
"cot_session"
}
fn migrations(&self) -> Vec<Box<SyncDynMigration>> {
cot::db::migrations::wrap_migrations(migrations::MIGRATIONS)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::App;
#[test]
fn test_session_app_basic_behavior() {
let app1 = SessionApp::new();
let app2 = SessionApp::default();
assert_eq!(app1.name(), "cot_session");
assert_eq!(app2.name(), "cot_session");
let migrations = app1.migrations();
assert!(!migrations.is_empty());
}
}