use native_db::*; use native_model::{native_model, Model}; use serde::{Deserialize, Serialize}; use shortcut_assert_fs::TmpFs; #[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)] #[native_model(id = 1, version = 1)] #[native_db] struct Item { #[primary_key] id: u32, name: String, } #[test] fn insert_get() { let tf = TmpFs::new().unwrap(); let item = Item { id: 1, name: "test".to_string(), }; let mut models = Models::new(); models.define::().unwrap(); let db = Builder::new() .create(&models, tf.path("test").as_std_path()) .unwrap(); let rw = db.rw_transaction().unwrap(); rw.insert(item.clone()).unwrap(); rw.commit().unwrap(); let stats = db.redb_stats().unwrap(); assert_eq!(stats.primary_tables.len(), 1); assert_eq!(stats.primary_tables[0].name, "1_1_id"); assert_eq!(stats.primary_tables[0].n_entries, Some(1)); let rw = db.rw_transaction().unwrap(); let old_value = rw.remove(item.clone()).unwrap(); assert_eq!(old_value, item); rw.commit().unwrap(); let stats = db.redb_stats().unwrap(); assert_eq!(stats.primary_tables.len(), 1); assert_eq!(stats.primary_tables[0].name, "1_1_id"); assert_eq!(stats.primary_tables[0].n_entries, Some(0)); }