pub trait DataObject: DataResult<DBO = Self> {
    type PKType: PrimaryKeyType;
    type Fields: Default;

    const PKCOL: &'static str;
    const TABLE: &'static str;
    const AUTO_PK: bool;

    // Required methods
    fn pk(&self) -> &Self::PKType;
    fn save(&mut self, conn: &impl ConnectionMethods) -> Result<()>;
    fn delete(&self, conn: &impl ConnectionMethods) -> Result<()>;

    // Provided methods
    fn get(
        conn: &impl ConnectionMethods,
        id: impl Borrow<Self::PKType>
    ) -> Result<Self>
       where Self: Sized { ... }
    fn try_get(
        conn: &impl ConnectionMethods,
        id: impl Borrow<Self::PKType>
    ) -> Result<Option<Self>>
       where Self: Sized { ... }
}
Expand description

An object in the database.

Rather than implementing this type manually, use the #[model] attribute.

Required Associated Types§

source

type PKType: PrimaryKeyType

The type of the primary key field.

source

type Fields: Default

Required Associated Constants§

source

const PKCOL: &'static str

The name of the primary key column.

source

const TABLE: &'static str

The name of the table.

source

const AUTO_PK: bool

Whether or not this model uses an automatic primary key set on the first save.

Required Methods§

source

fn pk(&self) -> &Self::PKType

Get the primary key

source

fn save(&mut self, conn: &impl ConnectionMethods) -> Result<()>

Save the object to the database.

source

fn delete(&self, conn: &impl ConnectionMethods) -> Result<()>

Delete the object from the database.

Provided Methods§

source

fn get( conn: &impl ConnectionMethods, id: impl Borrow<Self::PKType> ) -> Result<Self>where Self: Sized,

Find this object in the database based on primary key. Returns Error::NoSuchObject if the primary key does not exist.

source

fn try_get( conn: &impl ConnectionMethods, id: impl Borrow<Self::PKType> ) -> Result<Option<Self>>where Self: Sized,

Find this object in the database based on primary key. Returns None if the primary key does not exist.

Implementors§