pub struct SapDB {
pub file: String,
pub pool: Pool<SqliteConnectionManager>,
}
Expand description
A Super Auto Pets database.
Fields§
§file: String
Database file.
pool: Pool<SqliteConnectionManager>
Database pooled connection.
Implementations§
Source§impl SapDB
impl SapDB
Sourcepub fn new<P>(file: P) -> Result<Self, SAPTestError>
pub fn new<P>(file: P) -> Result<Self, SAPTestError>
Initialize database.
- Creates a
sqlite
file at the specifiedfile
path with thepets
andfoods
tables. - Updates all tables with the most recent information from the SAP wiki.
§Example
use std::path::Path;
use saptest::SapDB;
let db_path = "./sap.db";
let db = SapDB::new(db_path);
assert!(db.is_ok());
assert!(Path::new(db_path).exists());
Sourcepub fn execute_query(
&self,
sap_query: SAPQuery,
) -> Result<Vec<SAPRecord>, SAPTestError>
pub fn execute_query( &self, sap_query: SAPQuery, ) -> Result<Vec<SAPRecord>, SAPTestError>
Execute SELECT
query in the Super Auto Pets database with a SAPQuery
.
§Examples
Pet Query
use saptest::{SAPDB, SAPQuery, Entity, PetName, db::{pack::Pack, record::SAPRecord}};
let query = SAPQuery::builder()
.set_table(Entity::Pet)
.set_param("name", vec![PetName::Tiger])
.set_param("lvl", vec![2])
.set_param("pack", vec![Pack::Turtle]);
let pets = SAPDB.execute_query(query).unwrap();
let Some(SAPRecord::Pet(record)) = pets.first() else { panic!("No Record found.")};
assert!(record.name == PetName::Tiger && record.lvl == 2 && record.pack == Pack::Turtle)
Food Query
use saptest::{SAPDB, SAPQuery, Entity, FoodName, db::{pack::Pack, record::SAPRecord}};
let query = SAPQuery::builder()
.set_table(Entity::Food)
.set_param("name", vec![FoodName::Apple])
.set_param("pack", vec![Pack::Turtle]);
let foods = SAPDB.execute_query(query).unwrap();
let Some(SAPRecord::Food(record)) = foods.first() else { panic!("No Record found.")};
assert!(record.name == FoodName::Apple && record.pack == Pack::Turtle)
Toy Query
use saptest::{SAPDB, SAPQuery, Entity, ToyName, db::record::SAPRecord};
let mut query = SAPQuery::builder()
.set_table(Entity::Toy)
.set_param("name", vec![ToyName::Balloon])
.set_param("lvl", vec![2]);
let toys = SAPDB.execute_query(query).unwrap();
let Some(SAPRecord::Toy(record)) = toys.first() else { panic!("No Record found.")};
assert!(record.name == ToyName::Balloon && record.lvl == 2)
Auto Trait Implementations§
impl Freeze for SapDB
impl !RefUnwindSafe for SapDB
impl Send for SapDB
impl Sync for SapDB
impl Unpin for SapDB
impl !UnwindSafe for SapDB
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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