Base
tibiawikisql.models.base
¶
Module with base classes used by models.
Classes:
| Name | Description |
|---|---|
WithStatus |
Adds the status field to a model. |
WithVersion |
Adds the version field to a model. |
WithImage |
Adds the image field to a model. |
RowModel |
A mixin class to indicate that this model comes from a SQL table. |
WithStatus
pydantic-model
¶
Bases: BaseModel
Adds the status field to a model.
Show JSON schema:
Fields:
WithVersion
pydantic-model
¶
Bases: BaseModel
Adds the version field to a model.
Show JSON schema:
Fields:
WithImage
pydantic-model
¶
Bases: BaseModel
Adds the image field to a model.
Show JSON schema:
Fields:
RowModel
pydantic-model
¶
Bases: BaseModel
A mixin class to indicate that this model comes from a SQL table.
Show JSON schema:
table
class-attribute
¶
table: type[Table] = NotImplemented
The SQL table where this model is stored.
insert
¶
insert(conn: Connection | Cursor) -> None
Insert the model into its respective database table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection | Cursor
|
A cursor or connection to the database. |
required |
Source code in tibiawikisql/models/base.py
from_row
classmethod
¶
Return an instance of the model from a row or dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
Row | dict[str, Any]
|
A dict representing a row or a Row object. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
An instance of the class, based on the row. |
Source code in tibiawikisql/models/base.py
get_one_by_field
classmethod
¶
get_one_by_field(
conn: Connection | Cursor,
field: str,
value: Any,
use_like: bool = False,
) -> Self | None
Get a single element matching the field's value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection | Cursor
|
A connection or cursor of the database. |
required |
field
|
str
|
The field to filter with. |
required |
value
|
Any
|
The value to look for. |
required |
use_like
|
bool
|
Whether to use |
False
|
Returns:
| Type | Description |
|---|---|
Self | None
|
The object found, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
The specified field doesn't exist in the table. |
Source code in tibiawikisql/models/base.py
get_list_by_field
classmethod
¶
get_list_by_field(
conn: Connection | Cursor,
field: str,
value: Any | None = None,
use_like: bool = False,
sort_by: str | None = None,
ascending: bool = True,
) -> list[Self]
Get a list of elements matching the specified field's value.
Note that this won't get values found in child tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection | Cursor
|
A connection or cursor of the database. |
required |
field
|
str
|
The name of the field to filter by. |
required |
value
|
Any | None
|
The value to filter by. |
None
|
use_like
|
bool
|
Whether to use |
False
|
sort_by
|
str | None
|
The name of the field to sort by. |
None
|
ascending
|
bool
|
Whether to sort ascending or descending. |
True
|
Returns:
| Type | Description |
|---|---|
list[Self]
|
A list containing all matching objects. |
Raises:
| Type | Description |
|---|---|
ValueError
|
The specified field doesn't exist in the table. |
Source code in tibiawikisql/models/base.py
get_by_id
classmethod
¶
get_by_id(
conn: Connection | Cursor, article_id: int
) -> Self | None
Get an entry by its article ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection | Cursor
|
A connection to the database. |
required |
article_id
|
int
|
The article ID to search for. |
required |
Returns:
| Type | Description |
|---|---|
Self | None
|
The model matching the article ID if found. |
Source code in tibiawikisql/models/base.py
get_by_title
classmethod
¶
get_by_title(
conn: Connection | Cursor, title: str
) -> Self | None
Get an entry by its title.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
Connection | Cursor
|
A connection to the database. |
required |
title
|
str
|
The title of the article. |
required |
Returns:
| Type | Description |
|---|---|
Self | None
|
The model matching the article title if found. |