Skip to content

tux.database.controllers.note

Classes:

Name Description
NoteController

Controller for managing moderator notes.

Classes

NoteController()

Bases: BaseController[Note]

Controller for managing moderator notes.

This controller provides methods for creating, retrieving, updating, and deleting moderator notes for users in guilds.

Initialize the NoteController with the note table.

Methods:

Name Description
get_all_notes

Get all notes across all guilds.

get_note_by_id

Get a note by its ID.

insert_note

Create a new moderator note.

delete_note_by_id

Delete a note by its ID.

update_note_by_id

Update a note's content.

get_notes_by_user_id

Get all notes for a user across all guilds.

get_notes_by_moderator_id

Get all notes created by a moderator across all guilds.

get_notes_by_guild_id

Get all notes for a guild.

get_notes_by_user_id_and_guild_id

Get all notes for a user in a specific guild.

get_notes_by_moderator_id_and_guild_id

Get all notes created by a moderator in a specific guild.

find_one

Finds the first record matching specified criteria.

get_notes_by_user_id_and_moderator_id

Get all notes for a user created by a specific moderator.

find_unique

Finds a single record by a unique constraint (e.g., ID).

get_notes_by_user_id_moderator_id_and_guild_id

Get all notes for a user created by a specific moderator in a specific guild.

find_many

Finds multiple records matching specified criteria.

count_notes_by_guild_id

Count the number of notes in a guild.

count_notes_by_user_id

Count the number of notes for a user.

count

Counts records matching the specified criteria.

bulk_delete_notes_by_guild_id

Delete all notes for a guild.

create

Creates a new record in the table.

update

Updates a single existing record matching the criteria.

delete

Deletes a single record matching the criteria.

upsert

Updates a record if it exists, otherwise creates it.

update_many

Updates multiple records matching the criteria.

delete_many

Deletes multiple records matching the criteria.

execute_transaction

Executes a series of database operations within a transaction.

connect_or_create_relation

Builds a Prisma 'connect_or_create' relation structure.

safe_get_attr

Safely retrieves an attribute from an object, returning a default if absent.

Source code in tux/database/controllers/note.py
Python
def __init__(self):
    """Initialize the NoteController with the note table."""
    super().__init__("note")
    self.guild_table: GuildActions[Guild] = db.client.guild

Functions

get_all_notes() -> list[Note] async

Get all notes across all guilds.

Returns:

Type Description
list[Note]

List of all notes

Source code in tux/database/controllers/note.py
Python
async def get_all_notes(self) -> list[Note]:
    """Get all notes across all guilds.

    Returns
    -------
    list[Note]
        List of all notes
    """
    return await self.find_many(where={})
get_note_by_id(note_id: int) -> Note | None async

Get a note by its ID.

Parameters:

Name Type Description Default
note_id int

The ID of the note to get

required

Returns:

Type Description
Note | None

The note if found, None otherwise

Source code in tux/database/controllers/note.py
Python
async def get_note_by_id(self, note_id: int) -> Note | None:
    """Get a note by its ID.

    Parameters
    ----------
    note_id : int
        The ID of the note to get

    Returns
    -------
    Note | None
        The note if found, None otherwise
    """
    return await self.find_unique(where={"note_id": note_id})
insert_note(note_user_id: int, note_moderator_id: int, note_content: str, guild_id: int) -> Note async

Create a new moderator note.

Parameters:

Name Type Description Default
note_user_id int

The ID of the user the note is about

required
note_moderator_id int

The ID of the moderator creating the note

required
note_content str

The content of the note

required
guild_id int

The ID of the guild the note belongs to

required

Returns:

Type Description
Note

The created note

Source code in tux/database/controllers/note.py
Python
async def insert_note(
    self,
    note_user_id: int,
    note_moderator_id: int,
    note_content: str,
    guild_id: int,
) -> Note:
    """Create a new moderator note.

    Parameters
    ----------
    note_user_id : int
        The ID of the user the note is about
    note_moderator_id : int
        The ID of the moderator creating the note
    note_content : str
        The content of the note
    guild_id : int
        The ID of the guild the note belongs to

    Returns
    -------
    Note
        The created note
    """
    return await self.create(
        data={
            "note_user_id": note_user_id,
            "note_moderator_id": note_moderator_id,
            "note_content": note_content,
            "guild": self.connect_or_create_relation("guild_id", guild_id),
        },
        include={"guild": True},
    )
_execute_query(operation: Callable[[], Any], error_msg: str) -> Any async

Executes a database query with standardized error logging.

Wraps the Prisma client operation call in a try-except block, logging any exceptions with a contextual error message.

Parameters:

Name Type Description Default
operation Callable[[], Any]

A zero-argument function (e.g., a lambda) that performs the database call.

required
error_msg str

The base error message to log if an exception occurs.

required

Returns:

Type Description
Any

The result of the database operation.

Raises:

Type Description
Exception

Re-raises any exception caught during the database operation.

Source code in tux/database/controllers/note.py
Python
        data={
            "note_user_id": note_user_id,
            "note_moderator_id": note_moderator_id,
            "note_content": note_content,
            "guild": self.connect_or_create_relation("guild_id", guild_id),
        },
        include={"guild": True},
    )

async def delete_note_by_id(self, note_id: int) -> Note | None:
    """Delete a note by its ID.

    Parameters
    ----------
    note_id : int
        The ID of the note to delete

    Returns
    -------
    Note | None
        The deleted note if found, None otherwise
    """
    return await self.delete(where={"note_id": note_id})

async def update_note_by_id(self, note_id: int, note_content: str) -> Note | None:
    """Update a note's content.

    Parameters
    ----------
    note_id : int
        The ID of the note to update
    note_content : str
        The new content for the note

    Returns
    -------
    Note | None
        The updated note if found, None otherwise
    """
    return await self.update(
        where={"note_id": note_id},
        data={"note_content": note_content},
    )

async def get_notes_by_user_id(self, note_user_id: int, limit: int | None = None) -> list[Note]:
    """Get all notes for a user across all guilds.
delete_note_by_id(note_id: int) -> Note | None async

Delete a note by its ID.

Parameters:

Name Type Description Default
note_id int

The ID of the note to delete

required

Returns:

Type Description
Note | None

The deleted note if found, None otherwise

Source code in tux/database/controllers/note.py
Python
async def delete_note_by_id(self, note_id: int) -> Note | None:
    """Delete a note by its ID.

    Parameters
    ----------
    note_id : int
        The ID of the note to delete

    Returns
    -------
    Note | None
        The deleted note if found, None otherwise
    """
    return await self.delete(where={"note_id": note_id})
update_note_by_id(note_id: int, note_content: str) -> Note | None async

Update a note's content.

Parameters:

Name Type Description Default
note_id int

The ID of the note to update

required
note_content str

The new content for the note

required

Returns:

Type Description
Note | None

The updated note if found, None otherwise

Source code in tux/database/controllers/note.py
Python
async def update_note_by_id(self, note_id: int, note_content: str) -> Note | None:
    """Update a note's content.

    Parameters
    ----------
    note_id : int
        The ID of the note to update
    note_content : str
        The new content for the note

    Returns
    -------
    Note | None
        The updated note if found, None otherwise
    """
    return await self.update(
        where={"note_id": note_id},
        data={"note_content": note_content},
    )
get_notes_by_user_id(note_user_id: int, limit: int | None = None) -> list[Note] async

Get all notes for a user across all guilds.

Parameters:

Name Type Description Default
note_user_id int

The ID of the user to get notes for

required
limit int | None

Optional limit on the number of notes to return

None

Returns:

Type Description
list[Note]

List of notes for the user

Source code in tux/database/controllers/note.py
Python
async def get_notes_by_user_id(self, note_user_id: int, limit: int | None = None) -> list[Note]:
    """Get all notes for a user across all guilds.

    Parameters
    ----------
    note_user_id : int
        The ID of the user to get notes for
    limit : int | None
        Optional limit on the number of notes to return

    Returns
    -------
    list[Note]
        List of notes for the user
    """
    return await self.find_many(where={"note_user_id": note_user_id}, take=limit)
_add_include_arg_if_present(args: dict[str, Any], include: dict[str, bool] | None) -> None

Adds the 'include' argument to a dictionary if it is not None.

Source code in tux/database/controllers/note.py
Python
Parameters
----------
note_user_id : int
    The ID of the user to get notes for
_build_find_args(where: dict[str, Any], include: dict[str, bool] | None = None, order: dict[str, str] | None = None, take: int | None = None, skip: int | None = None, cursor: dict[str, Any] | None = None) -> dict[str, Any]

Constructs the keyword arguments dictionary for Prisma find operations.

Source code in tux/database/controllers/note.py
Python
        Optional limit on the number of notes to return

    Returns
    -------
    list[Note]
        List of notes for the user
    """
    return await self.find_many(where={"note_user_id": note_user_id}, take=limit)

async def get_notes_by_moderator_id(self, moderator_id: int, limit: int | None = None) -> list[Note]:
    """Get all notes created by a moderator across all guilds.

    Parameters
    ----------
    moderator_id : int
        The ID of the moderator to get notes for
    limit : int | None
        Optional limit on the number of notes to return

    Returns
    -------
get_notes_by_moderator_id(moderator_id: int, limit: int | None = None) -> list[Note] async

Get all notes created by a moderator across all guilds.

Parameters:

Name Type Description Default
moderator_id int

The ID of the moderator to get notes for

required
limit int | None

Optional limit on the number of notes to return

None

Returns:

Type Description
list[Note]

List of notes created by the moderator

Source code in tux/database/controllers/note.py
Python
async def get_notes_by_moderator_id(self, moderator_id: int, limit: int | None = None) -> list[Note]:
    """Get all notes created by a moderator across all guilds.

    Parameters
    ----------
    moderator_id : int
        The ID of the moderator to get notes for
    limit : int | None
        Optional limit on the number of notes to return

    Returns
    -------
    list[Note]
        List of notes created by the moderator
    """
    return await self.find_many(where={"note_moderator_id": moderator_id}, take=limit)
_build_simple_args(key_name: str, key_value: dict[str, Any], include: dict[str, bool] | None = None) -> dict[str, Any]

Constructs simple keyword arguments for Prisma (e.g., create, delete).

Source code in tux/database/controllers/note.py
Python
        List of notes created by the moderator
    """
    return await self.find_many(where={"note_moderator_id": moderator_id}, take=limit)

async def get_notes_by_guild_id(self, guild_id: int, limit: int | None = None) -> list[Note]:
    """Get all notes for a guild.

    Parameters
    ----------
    guild_id : int
get_notes_by_guild_id(guild_id: int, limit: int | None = None) -> list[Note] async

Get all notes for a guild.

Parameters:

Name Type Description Default
guild_id int

The ID of the guild to get notes for

required
limit int | None

Optional limit on the number of notes to return

None

Returns:

Type Description
list[Note]

List of notes for the guild

Source code in tux/database/controllers/note.py
Python
async def get_notes_by_guild_id(self, guild_id: int, limit: int | None = None) -> list[Note]:
    """Get all notes for a guild.

    Parameters
    ----------
    guild_id : int
        The ID of the guild to get notes for
    limit : int | None
        Optional limit on the number of notes to return

    Returns
    -------
    list[Note]
        List of notes for the guild
    """
    return await self.find_many(where={"guild_id": guild_id}, take=limit)
_build_create_args(data: dict[str, Any], include: dict[str, bool] | None = None) -> dict[str, Any]

Constructs keyword arguments for Prisma create operations.

Source code in tux/database/controllers/note.py
Python
limit : int | None
    Optional limit on the number of notes to return

Returns
-------
list[Note]
    List of notes for the guild
_build_update_args(where: dict[str, Any], data: dict[str, Any], include: dict[str, bool] | None = None) -> dict[str, Any]

Constructs keyword arguments for Prisma update operations.

Source code in tux/database/controllers/note.py
Python
    return await self.find_many(where={"guild_id": guild_id}, take=limit)

async def get_notes_by_user_id_and_guild_id(
    self,
    note_user_id: int,
    guild_id: int,
    limit: int | None = None,
) -> list[Note]:
    """Get all notes for a user in a specific guild.
get_notes_by_user_id_and_guild_id(note_user_id: int, guild_id: int, limit: int | None = None) -> list[Note] async

Get all notes for a user in a specific guild.

Parameters:

Name Type Description Default
note_user_id int

The ID of the user to get notes for

required
guild_id int

The ID of the guild to get notes from

required
limit int | None

Optional limit on the number of notes to return

None

Returns:

Type Description
list[Note]

List of notes for the user in the guild

Source code in tux/database/controllers/note.py
Python
async def get_notes_by_user_id_and_guild_id(
    self,
    note_user_id: int,
    guild_id: int,
    limit: int | None = None,
) -> list[Note]:
    """Get all notes for a user in a specific guild.

    Parameters
    ----------
    note_user_id : int
        The ID of the user to get notes for
    guild_id : int
        The ID of the guild to get notes from
    limit : int | None
        Optional limit on the number of notes to return

    Returns
    -------
    list[Note]
        List of notes for the user in the guild
    """
    return await self.find_many(where={"note_user_id": note_user_id, "guild_id": guild_id}, take=limit)
_build_delete_args(where: dict[str, Any], include: dict[str, bool] | None = None) -> dict[str, Any]

Constructs keyword arguments for Prisma delete operations.

Source code in tux/database/controllers/note.py
Python
----------
note_user_id : int
    The ID of the user to get notes for
guild_id : int
    The ID of the guild to get notes from
limit : int | None
    Optional limit on the number of notes to return
_build_upsert_args(where: dict[str, Any], create: dict[str, Any], update: dict[str, Any], include: dict[str, bool] | None = None) -> dict[str, Any]

Constructs keyword arguments for Prisma upsert operations.

Source code in tux/database/controllers/note.py
Python
    Returns
    -------
    list[Note]
        List of notes for the user in the guild
    """
    return await self.find_many(where={"note_user_id": note_user_id, "guild_id": guild_id}, take=limit)

async def get_notes_by_moderator_id_and_guild_id(
    self,
    moderator_id: int,
    guild_id: int,
    limit: int | None = None,
) -> list[Note]:
    """Get all notes created by a moderator in a specific guild.

    Parameters
    ----------
get_notes_by_moderator_id_and_guild_id(moderator_id: int, guild_id: int, limit: int | None = None) -> list[Note] async

Get all notes created by a moderator in a specific guild.

Parameters:

Name Type Description Default
moderator_id int

The ID of the moderator to get notes for

required
guild_id int

The ID of the guild to get notes from

required
limit int | None

Optional limit on the number of notes to return

None

Returns:

Type Description
list[Note]

List of notes created by the moderator in the guild

Source code in tux/database/controllers/note.py
Python
async def get_notes_by_moderator_id_and_guild_id(
    self,
    moderator_id: int,
    guild_id: int,
    limit: int | None = None,
) -> list[Note]:
    """Get all notes created by a moderator in a specific guild.

    Parameters
    ----------
    moderator_id : int
        The ID of the moderator to get notes for
    guild_id : int
        The ID of the guild to get notes from
    limit : int | None
        Optional limit on the number of notes to return

    Returns
    -------
    list[Note]
        List of notes created by the moderator in the guild
    """
    return await self.find_many(where={"note_moderator_id": moderator_id, "guild_id": guild_id}, take=limit)
find_one(where: dict[str, Any], include: dict[str, bool] | None = None, order: dict[str, str] | None = None) -> Note | None async

Finds the first record matching specified criteria.

Parameters:

Name Type Description Default
where dict[str, Any]

Query conditions to match.

required
include dict[str, bool]

Specifies relations to include in the result.

None
order dict[str, str]

Specifies the field and direction for ordering.

None

Returns:

Type Description
ModelType | None

The found record or None if no match exists.

Source code in tux/database/controllers/note.py
Python
        The ID of the guild to get notes from
    limit : int | None
        Optional limit on the number of notes to return

    Returns
    -------
    list[Note]
        List of notes created by the moderator in the guild
    """
    return await self.find_many(where={"note_moderator_id": moderator_id, "guild_id": guild_id}, take=limit)

async def get_notes_by_user_id_and_moderator_id(
    self,
    user_id: int,
    moderator_id: int,
    limit: int | None = None,
) -> list[Note]:
    """Get all notes for a user created by a specific moderator.

    Parameters
    ----------
    user_id : int
        The ID of the user to get notes for
    moderator_id : int
        The ID of the moderator who created the notes
    limit : int | None
        Optional limit on the number of notes to return
get_notes_by_user_id_and_moderator_id(user_id: int, moderator_id: int, limit: int | None = None) -> list[Note] async

Get all notes for a user created by a specific moderator.

Parameters:

Name Type Description Default
user_id int

The ID of the user to get notes for

required
moderator_id int

The ID of the moderator who created the notes

required
limit int | None

Optional limit on the number of notes to return

None

Returns:

Type Description
list[Note]

List of notes for the user created by the moderator

Source code in tux/database/controllers/note.py
Python
async def get_notes_by_user_id_and_moderator_id(
    self,
    user_id: int,
    moderator_id: int,
    limit: int | None = None,
) -> list[Note]:
    """Get all notes for a user created by a specific moderator.

    Parameters
    ----------
    user_id : int
        The ID of the user to get notes for
    moderator_id : int
        The ID of the moderator who created the notes
    limit : int | None
        Optional limit on the number of notes to return

    Returns
    -------
    list[Note]
        List of notes for the user created by the moderator
    """
    return await self.find_many(where={"note_user_id": user_id, "note_moderator_id": moderator_id}, take=limit)
find_unique(where: dict[str, Any], include: dict[str, bool] | None = None) -> Note | None async

Finds a single record by a unique constraint (e.g., ID).

Parameters:

Name Type Description Default
where dict[str, Any]

Unique query conditions (e.g., {'id': 1}).

required
include dict[str, bool]

Specifies relations to include in the result.

None

Returns:

Type Description
ModelType | None

The found record or None if no match exists.

Source code in tux/database/controllers/note.py
Python
    Returns
    -------
    list[Note]
        List of notes for the user created by the moderator
    """
    return await self.find_many(where={"note_user_id": user_id, "note_moderator_id": moderator_id}, take=limit)

async def get_notes_by_user_id_moderator_id_and_guild_id(
    self,
    user_id: int,
    moderator_id: int,
    guild_id: int,
    limit: int | None = None,
) -> list[Note]:
    """Get all notes for a user created by a specific moderator in a specific guild.

    Parameters
    ----------
    user_id : int
        The ID of the user to get notes for
    moderator_id : int
        The ID of the moderator who created the notes
    guild_id : int
        The ID of the guild to get notes from
get_notes_by_user_id_moderator_id_and_guild_id(user_id: int, moderator_id: int, guild_id: int, limit: int | None = None) -> list[Note] async

Get all notes for a user created by a specific moderator in a specific guild.

Parameters:

Name Type Description Default
user_id int

The ID of the user to get notes for

required
moderator_id int

The ID of the moderator who created the notes

required
guild_id int

The ID of the guild to get notes from

required
limit int | None

Optional limit on the number of notes to return

None

Returns:

Type Description
list[Note]

List of notes for the user created by the moderator in the guild

Source code in tux/database/controllers/note.py
Python
async def get_notes_by_user_id_moderator_id_and_guild_id(
    self,
    user_id: int,
    moderator_id: int,
    guild_id: int,
    limit: int | None = None,
) -> list[Note]:
    """Get all notes for a user created by a specific moderator in a specific guild.

    Parameters
    ----------
    user_id : int
        The ID of the user to get notes for
    moderator_id : int
        The ID of the moderator who created the notes
    guild_id : int
        The ID of the guild to get notes from
    limit : int | None
        Optional limit on the number of notes to return

    Returns
    -------
    list[Note]
        List of notes for the user created by the moderator in the guild
    """
    return await self.find_many(
        where={
            "note_user_id": user_id,
            "note_moderator_id": moderator_id,
            "guild_id": guild_id,
        },
        take=limit,
    )
find_many(where: dict[str, Any], include: dict[str, bool] | None = None, order: dict[str, str] | None = None, take: int | None = None, skip: int | None = None, cursor: dict[str, Any] | None = None) -> list[Note] async

Finds multiple records matching specified criteria.

Parameters:

Name Type Description Default
where dict[str, Any]

Query conditions to match.

required
include dict[str, bool]

Specifies relations to include in the results.

None
order dict[str, str]

Specifies the field and direction for ordering.

None
take int

Maximum number of records to return.

None
skip int

Number of records to skip (for pagination).

None
cursor dict[str, Any]

Cursor for pagination based on a unique field.

None

Returns:

Type Description
list[ModelType]

A list of found records, potentially empty.

Source code in tux/database/controllers/note.py
Python
        Optional limit on the number of notes to return

    Returns
    -------
    list[Note]
        List of notes for the user created by the moderator in the guild
    """
    return await self.find_many(
        where={
            "note_user_id": user_id,
            "note_moderator_id": moderator_id,
            "guild_id": guild_id,
        },
        take=limit,
    )

async def count_notes_by_guild_id(self, guild_id: int) -> int:
    """Count the number of notes in a guild.

    Parameters
    ----------
    guild_id : int
        The ID of the guild to count notes for

    Returns
    -------
    int
        The number of notes in the guild
    """
    return await self.count(where={"guild_id": guild_id})

async def count_notes_by_user_id(self, user_id: int, guild_id: int | None = None) -> int:
    """Count the number of notes for a user.

    Parameters
    ----------
    user_id : int
        The ID of the user to count notes for
    guild_id : int | None
        Optional guild ID to restrict the count to

    Returns
    -------
count_notes_by_guild_id(guild_id: int) -> int async

Count the number of notes in a guild.

Parameters:

Name Type Description Default
guild_id int

The ID of the guild to count notes for

required

Returns:

Type Description
int

The number of notes in the guild

Source code in tux/database/controllers/note.py
Python
async def count_notes_by_guild_id(self, guild_id: int) -> int:
    """Count the number of notes in a guild.

    Parameters
    ----------
    guild_id : int
        The ID of the guild to count notes for

    Returns
    -------
    int
        The number of notes in the guild
    """
    return await self.count(where={"guild_id": guild_id})
count_notes_by_user_id(user_id: int, guild_id: int | None = None) -> int async

Count the number of notes for a user.

Parameters:

Name Type Description Default
user_id int

The ID of the user to count notes for

required
guild_id int | None

Optional guild ID to restrict the count to

None

Returns:

Type Description
int

The number of notes for the user

Source code in tux/database/controllers/note.py
Python
async def count_notes_by_user_id(self, user_id: int, guild_id: int | None = None) -> int:
    """Count the number of notes for a user.

    Parameters
    ----------
    user_id : int
        The ID of the user to count notes for
    guild_id : int | None
        Optional guild ID to restrict the count to

    Returns
    -------
    int
        The number of notes for the user
    """
    where = {"note_user_id": user_id}
    if guild_id is not None:
        where["guild_id"] = guild_id

    return await self.count(where=where)
count(where: dict[str, Any]) -> int async

Counts records matching the specified criteria.

Parameters:

Name Type Description Default
where dict[str, Any]

Query conditions to match.

required

Returns:

Type Description
int

The total number of matching records.

Source code in tux/database/controllers/note.py
Python
        The number of notes for the user
    """
    where = {"note_user_id": user_id}
    if guild_id is not None:
        where["guild_id"] = guild_id

    return await self.count(where=where)

async def bulk_delete_notes_by_guild_id(self, guild_id: int) -> int:
    """Delete all notes for a guild.

    Parameters
    ----------
    guild_id : int
        The ID of the guild to delete notes for

    Returns
    -------
    int
        The number of notes deleted
bulk_delete_notes_by_guild_id(guild_id: int) -> int async

Delete all notes for a guild.

Parameters:

Name Type Description Default
guild_id int

The ID of the guild to delete notes for

required

Returns:

Type Description
int

The number of notes deleted

Source code in tux/database/controllers/note.py
Python
async def bulk_delete_notes_by_guild_id(self, guild_id: int) -> int:
    """Delete all notes for a guild.

    Parameters
    ----------
    guild_id : int
        The ID of the guild to delete notes for

    Returns
    -------
    int
        The number of notes deleted
    """
    return await self.delete_many(where={"guild_id": guild_id})
create(data: dict[str, Any], include: dict[str, bool] | None = None) -> Note async

Creates a new record in the table.

Parameters:

Name Type Description Default
data dict[str, Any]

The data for the new record.

required
include dict[str, bool]

Specifies relations to include in the returned record.

None

Returns:

Type Description
ModelType

The newly created record.

Source code in tux/database/controllers/note.py
Python
return await self.delete_many(where={"guild_id": guild_id})
update(where: dict[str, Any], data: dict[str, Any], include: dict[str, bool] | None = None) -> Note | None async

Updates a single existing record matching the criteria.

Parameters:

Name Type Description Default
where dict[str, Any]

Query conditions to find the record to update.

required
data dict[str, Any]

The data to update the record with.

required
include dict[str, bool]

Specifies relations to include in the returned record.

None

Returns:

Type Description
ModelType | None

The updated record, or None if no matching record was found.

delete(where: dict[str, Any], include: dict[str, bool] | None = None) -> Note | None async

Deletes a single record matching the criteria.

Parameters:

Name Type Description Default
where dict[str, Any]

Query conditions to find the record to delete.

required
include dict[str, bool]

Specifies relations to include in the returned deleted record.

None

Returns:

Type Description
ModelType | None

The deleted record, or None if no matching record was found.

upsert(where: dict[str, Any], create: dict[str, Any], update: dict[str, Any], include: dict[str, bool] | None = None) -> Note async

Updates a record if it exists, otherwise creates it.

Parameters:

Name Type Description Default
where dict[str, Any]

Query conditions to find the existing record.

required
create dict[str, Any]

Data to use if creating a new record.

required
update dict[str, Any]

Data to use if updating an existing record.

required
include dict[str, bool]

Specifies relations to include in the returned record.

None

Returns:

Type Description
ModelType

The created or updated record.

update_many(where: dict[str, Any], data: dict[str, Any]) -> int async

Updates multiple records matching the criteria.

Parameters:

Name Type Description Default
where dict[str, Any]

Query conditions to find the records to update.

required
data dict[str, Any]

The data to update the records with.

required

Returns:

Type Description
int

The number of records updated.

Raises:

Type Description
ValueError

If the database operation does not return a valid count.

delete_many(where: dict[str, Any]) -> int async

Deletes multiple records matching the criteria.

Parameters:

Name Type Description Default
where dict[str, Any]

Query conditions to find the records to delete.

required

Returns:

Type Description
int

The number of records deleted.

Raises:

Type Description
ValueError

If the database operation does not return a valid count.

execute_transaction(callback: Callable[[], Any]) -> Any async

Executes a series of database operations within a transaction.

Ensures atomicity: all operations succeed or all fail and roll back. Note: Does not use _execute_query internally to preserve specific transaction context in error messages.

Parameters:

Name Type Description Default
callback Callable[[], Any]

An async function containing the database operations to execute.

required

Returns:

Type Description
Any

The result returned by the callback function.

Raises:

Type Description
Exception

Re-raises any exception that occurs during the transaction.

connect_or_create_relation(id_field: str, model_id: Any, create_data: dict[str, Any] | None = None) -> dict[str, Any] staticmethod

Builds a Prisma 'connect_or_create' relation structure.

Simplifies linking or creating related records during create/update operations.

Parameters:

Name Type Description Default
id_field str

The name of the ID field used for connection (e.g., 'guild_id').

required
model_id Any

The ID value of the record to connect to.

required
create_data dict[str, Any]

Additional data required if creating the related record. Must include at least the id_field and model_id.

None

Returns:

Type Description
dict[str, Any]

A dictionary formatted for Prisma's connect_or_create.

safe_get_attr(obj: Any, attr: str, default: Any = None) -> Any staticmethod

Safely retrieves an attribute from an object, returning a default if absent.

Parameters:

Name Type Description Default
obj Any

The object to retrieve the attribute from.

required
attr str

The name of the attribute.

required
default Any

The value to return if the attribute is not found. Defaults to None.

None

Returns:

Type Description
Any

The attribute's value or the default value.