Skip to content

Schema

tibiawikisql.schema

Defines the SQL schemas to use.

Classes:

Name Description
AchievementTable

Contains achievements from the game.

CharmTable

Contains information about charms.

CreatureTable

Contains information about creatures.

CreatureAbilityTable

Contains the abilities a creature can do.

CreatureMaxDamageTable

Contains information about the max damage a creature can deal.

CreatureSoundTable

Contains the "sounds" a creature can do.

ItemTable

Contains information about items and objects.

ItemSoundTable

Contains the "sounds" an item can do when used.

ItemStoreOfferTable

Contains the Tibia store offers for an item.

CreatureDropTable

Contains the items that a creature can drop.

ItemAttributeTable

Contains additional attributes for an item.

BookTable

Table to store information about books.

DatabaseInfoTable

Contains information about the database.

HouseTable

Contains information about houses and guildhalls.

ImbuementTable

Contains information about imbuements.

ImbuementMaterialTable

Contains the materials needed for imbuements.

ItemKeyTable

Contains information about keys.

MapTable

Contains map images.

SpellTable

Contains information about spells.

NpcTable

Contains information about NPCs.

NpcJobTable

Contains NPC jobs.

NpcRaceTable

Contains NPC races.

NpcBuyingTable

Table storing the sitems an NPC buys.

NpcSellingTable

Table storing the sitems an NPC sells.

NpcDestinationTable

Table containing the destinations an NPC can take the player to.

NpcSpellTable

Stores spells taught by NPCs.

OutfitTable

Table containing information about outfits.

OutfitImageTable

Table containing the different images to represent an outfit and its addon.

QuestTable

Table to store information about quests.

OutfitQuestTable

Table that stores the outfits unlocked by a quest.

QuestDangerTable

Table that stores the creatures faced in a quest.

QuestRewardTable

Table containing the item rewards for a quest.

RashidPositionTable

Stores information about the location of the NPC rashid on each day.

WorldTable

Stores information about game worlds.

MountTable

Stores information about mounts.

UpdateTable

Stores information about game updates.

Functions:

Name Description
create_tables

Create all the tables in the database.

AchievementTable

Bases: Table

Contains achievements from the game.

CharmTable

Bases: Table

Contains information about charms.

CreatureTable

Bases: Table

Contains information about creatures.

CreatureAbilityTable

Bases: Table

Contains the abilities a creature can do.

CreatureMaxDamageTable

Bases: Table

Contains information about the max damage a creature can deal.

CreatureSoundTable

Bases: Table

Contains the "sounds" a creature can do.

ItemTable

Bases: Table

Contains information about items and objects.

ItemSoundTable

Bases: Table

Contains the "sounds" an item can do when used.

ItemStoreOfferTable

Bases: Table

Contains the Tibia store offers for an item.

CreatureDropTable

Bases: Table

Contains the items that a creature can drop.

ItemAttributeTable

Bases: Table

Contains additional attributes for an item.

BookTable

Bases: Table

Table to store information about books.

DatabaseInfoTable

Bases: Table

Contains information about the database.

HouseTable

Bases: Table

Contains information about houses and guildhalls.

ImbuementTable

Bases: Table

Contains information about imbuements.

ImbuementMaterialTable

Bases: Table

Contains the materials needed for imbuements.

ItemKeyTable

Bases: Table

Contains information about keys.

MapTable

Bases: Table

Contains map images.

SpellTable

Bases: Table

Contains information about spells.

NpcTable

Bases: Table

Contains information about NPCs.

NpcJobTable

Bases: Table

Contains NPC jobs.

NpcRaceTable

Bases: Table

Contains NPC races.

NpcBuyingTable

Bases: Table

Table storing the sitems an NPC buys.

NpcSellingTable

Bases: Table

Table storing the sitems an NPC sells.

NpcDestinationTable

Bases: Table

Table containing the destinations an NPC can take the player to.

NpcSpellTable

Bases: Table

Stores spells taught by NPCs.

Attributes:

Name Type Description
npc_id

Foreign key to NPC's article ID.

spell_id

Foreign key to spell's article ID.

knight

Whether the NPC teaches the spell to knights.

sorcerer

Whether the NPC teaches the spell to sorcerers.

paladin

Whether the NPC teaches the spell to paladins.

druid

Whether the NPC teaches the spell to druids.

monk

Whether the NPC teaches the spell to monks.

Methods:

Name Description
get_by_npc_id

Get the entries corresponding to a given NPC, with additional information about the spell.

get_by_spell_id

Get entries matching the spell's article ID, joining additional data about the NPC.

get_by_npc_id classmethod
get_by_npc_id(
    conn: Connection | Cursor, npc_id: int
) -> list[Row]

Get the entries corresponding to a given NPC, with additional information about the spell.

Parameters:

Name Type Description Default
conn Connection | Cursor

Connection to the database.

required
npc_id int

The article ID of the NPC.

required

Returns:

Type Description
list[Row]

A list of rows matching the parameters.

Source code in tibiawikisql/schema.py
@classmethod
def get_by_npc_id(cls, conn: Connection | Cursor, npc_id: int) -> list[Row]:
    """Get the entries corresponding to a given NPC, with additional information about the spell.

    Args:
        conn: Connection to the database.
        npc_id: The article ID of the NPC.

    Returns:
        A list of rows matching the parameters.
    """
    base_query = cls.get_base_select_query()
    this = PTable(cls.__tablename__)
    spell = PTable(SpellTable.__tablename__)
    base_query = base_query.join(spell).on(this.spell_id == spell.article_id)
    return cls.get_list_by_field(conn, "npc_id", npc_id, base_query=base_query)
get_by_spell_id classmethod
get_by_spell_id(
    conn: Connection | Cursor, spell_id: int
) -> list[Row]

Get entries matching the spell's article ID, joining additional data about the NPC.

The schema returned is compatible with the [SpellTeacher][] model.

Parameters:

Name Type Description Default
conn Connection | Cursor

A connection to the database.

required
spell_id int

The article ID of the spell.

required

Returns:

Type Description
list[Row]

The rows containing the NPCs that teach the spell.

Source code in tibiawikisql/schema.py
@classmethod
def get_by_spell_id(cls, conn: Connection | Cursor, spell_id: int) -> list[Row]:
    """Get entries matching the spell's article ID, joining additional data about the NPC.

    The schema returned is compatible with the [SpellTeacher][] model.

    Args:
        conn: A connection to the database.
        spell_id: The article ID of the spell.

    Returns:
        The rows containing the NPCs that teach the spell.
    """
    npc = PTable(NpcTable.__tablename__)
    query = (
        Query.from_(cls.__table__)
        .select(
            cls.__table__.npc_id,
            npc.title.as_("npc_title"),
            npc.city.as_("npc_city"),
            cls.__table__.knight,
            cls.__table__.paladin,
            cls.__table__.sorcerer,
            cls.__table__.druid,
            cls.__table__.monk,
        )
        .join(npc).on(cls.__table__.npc_id == npc.article_id)
    )
    return cls.get_list_by_field(conn, "spell_id", spell_id, base_query=query)

OutfitTable

Bases: Table

Table containing information about outfits.

OutfitImageTable

Bases: Table

Table containing the different images to represent an outfit and its addon.

QuestTable

Bases: Table

Table to store information about quests.

OutfitQuestTable

Bases: Table

Table that stores the outfits unlocked by a quest.

Methods:

Name Description
get_list_by_outfit_id

Get all entries related to a specific outfit, joining quest titles.

get_list_by_outfit_id classmethod
get_list_by_outfit_id(
    conn: Connection | Cursor, outfit_id: int
) -> list[Row] | list[dict[str, Any]]

Get all entries related to a specific outfit, joining quest titles.

Parameters:

Name Type Description Default
conn Connection | Cursor

A connection to the database.

required
outfit_id int

The article ID of the outfit.

required

Returns:

Type Description
list[Row] | list[dict[str, Any]]

The rows matching the criteria.

Source code in tibiawikisql/schema.py
@classmethod
def get_list_by_outfit_id(cls, conn: Connection | Cursor, outfit_id: int) -> list[Row] | list[dict[str, Any]]:
    """Get all entries related to a specific outfit, joining quest titles.

    Args:
        conn: A connection to the database.
        outfit_id: The article ID of the outfit.

    Returns:
        The rows matching the criteria.
    """
    quest = QuestTable.__table__
    query = (
        Query.from_(cls.__table__)
        .select(
            cls.__table__.quest_id,
            quest.title.as_("quest_title"),
            cls.__table__.unlock_type,
        )
        .join(quest).on(quest.article_id == cls.__table__.quest_id)
    )
    return cls.get_list_by_field(conn, "outfit_id", outfit_id, base_query=query)

QuestDangerTable

Bases: Table

Table that stores the creatures faced in a quest.

Methods:

Name Description
get_list_by_quest_id

Get all entries related to a specific quest, joining creature titles.

get_list_by_quest_id classmethod
get_list_by_quest_id(
    conn: Connection | Cursor, quest_id: int
) -> list[Row] | list[dict[str, Any]]

Get all entries related to a specific quest, joining creature titles.

Parameters:

Name Type Description Default
conn Connection | Cursor

A connection to the database.

required
quest_id int

The article ID of the quest.

required

Returns:

Type Description
list[Row] | list[dict[str, Any]]

The rows matching the criteria.

Source code in tibiawikisql/schema.py
@classmethod
def get_list_by_quest_id(cls, conn: Connection | Cursor, quest_id: int) -> list[Row] | list[dict[str, Any]]:
    """Get all entries related to a specific quest, joining creature titles.

    Args:
        conn: A connection to the database.
        quest_id: The article ID of the quest.

    Returns:
        The rows matching the criteria.
    """
    creature = PTable(CreatureTable.__tablename__)
    query = (
        Query.from_(cls.__table__)
        .select(
            cls.__table__.creature_id,
            creature.title.as_("creature_title"),
        )
        .join(creature).on(creature.article_id == cls.__table__.creature_id)
    )
    return cls.get_list_by_field(conn, "quest_id", quest_id, base_query=query)

QuestRewardTable

Bases: Table

Table containing the item rewards for a quest.

Methods:

Name Description
get_list_by_item_id

Get all entries related to a specific item, joining quest titles.

get_list_by_quest_id

Get all entries related to a specific quest, joining item titles.

get_list_by_item_id classmethod
get_list_by_item_id(
    conn: Connection | Cursor, item_id: int
) -> list[Row] | list[dict[str, Any]]

Get all entries related to a specific item, joining quest titles.

Parameters:

Name Type Description Default
conn Connection | Cursor

A connection to the database.

required
item_id int

The article ID of the item.

required

Returns:

Type Description
list[Row] | list[dict[str, Any]]

The rows matching the criteria.

Source code in tibiawikisql/schema.py
@classmethod
def get_list_by_item_id(cls, conn: Connection | Cursor, item_id: int) -> list[Row] | list[dict[str, Any]]:
    """Get all entries related to a specific item, joining quest titles.

    Args:
        conn: A connection to the database.
        item_id: The article ID of the item.

    Returns:
        The rows matching the criteria.
    """
    quest = PTable(QuestTable.__tablename__)
    query = (
        Query.from_(cls.__table__)
        .select(
            cls.__table__.quest_id,
            quest.title.as_("quest_title"),
        )
        .join(quest).on(quest.article_id == cls.__table__.quest_id)
    )
    return cls.get_list_by_field(conn, "item_id", item_id, base_query=query)
get_list_by_quest_id classmethod
get_list_by_quest_id(
    conn: Connection | Cursor, quest_id: int
) -> list[Row] | list[dict[str, Any]]

Get all entries related to a specific quest, joining item titles.

Parameters:

Name Type Description Default
conn Connection | Cursor

A connection to the database.

required
quest_id int

The article ID of the quest.

required

Returns:

Type Description
list[Row] | list[dict[str, Any]]

The rows matching the criteria.

Source code in tibiawikisql/schema.py
@classmethod
def get_list_by_quest_id(cls, conn: Connection | Cursor, quest_id: int) -> list[Row] | list[dict[str, Any]]:
    """Get all entries related to a specific quest, joining item titles.

    Args:
        conn: A connection to the database.
        quest_id: The article ID of the quest.

    Returns:
        The rows matching the criteria.
    """
    item = PTable(ItemTable.__tablename__)
    query = (
        Query.from_(cls.__table__)
        .select(
            cls.__table__.item_id,
            item.title.as_("item_title"),
        )
        .join(item).on(item.article_id == cls.__table__.item_id)
    )
    return cls.get_list_by_field(conn, "quest_id", quest_id, base_query=query)

RashidPositionTable

Bases: Table

Stores information about the location of the NPC rashid on each day.

WorldTable

Bases: Table

Stores information about game worlds.

MountTable

Bases: Table

Stores information about mounts.

UpdateTable

Bases: Table

Stores information about game updates.

create_tables

create_tables(conn: Connection | Cursor) -> None

Create all the tables in the database.

Parameters:

Name Type Description Default
conn Connection | Cursor

A connection to the database.

required
Source code in tibiawikisql/schema.py
def create_tables(conn: Connection | Cursor) -> None:
    """Create all the tables in the database.

    Args:
        conn: A connection to the database.

    """
    for table in Table.all_tables():
        conn.execute(table.get_drop_statement())
        conn.executescript(table.get_create_table_statement())