author

Reads and writes rows of the authors table, the people and agents that act on entities.

const SELECT_COLUMNS

source

const SELECT_COLUMNS: &str = "id, author_type, name, email, created_at, updated_at";

The columns of authors, in the order that Author::try_from(Row) reads them.

fn create

source

pub async fn create(conn: &Connection, author: &Author) -> Result<Author, Error>

Create a new author and persist it.

Parameter Type Description
conn &Connection the database connection
author &Author the author to insert, with its id and timestamps already set
returns Result<Author, Error> The author as read back from the database after the insert, or an error when the insert fails or the row cannot be read back.

fn find_by_id

source

pub async fn find_by_id(conn: &Connection, id: impl Into<Id>) -> Result<Option<Author>, Error>

Find an author by their Id.

Parameter Type Description
conn &Connection the database connection
id impl Into<Id> the full id of the author
returns Result<Option<Author>, Error> The author, or None when no author has that id.

fn find_by_name

source

pub async fn find_by_name(
    conn: &Connection,
    name: &str,
    email: Option<&str>,
) -> Result<Option<Author>, Error>

Find an author by name, optionally filtering by email.

Parameter Type Description
conn &Connection the database connection
name &str the exact name to match
email Option<&str> the exact email to match; None matches only authors with no email
returns Result<Option<Author>, Error> The first matching author, or None when none matches.

fn find_or_create

source

pub async fn find_or_create(
    conn: &Connection,
    name: &str,
    email: Option<&str>,
    author_type: AuthorType,
) -> Result<Author, Error>

Find an existing author by name/email or create a new one.

Parameter Type Description
conn &Connection the database connection
name &str the author’s name
email Option<&str> the author’s email, if any; it is part of the match
author_type AuthorType the type given to a newly created author; an existing author keeps its own type
returns Result<Author, Error> The existing author with that name and email, or the one just created.