Struct SapDB

Source
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

Source

pub fn new<P>(file: P) -> Result<Self, SAPTestError>
where P: AsRef<Path> + Into<String>,

Initialize database.

  • Creates a sqlite file at the specified file path with the pets and foods 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());
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,