Database Manager

This page shows you everything about DatabaseManager.

DatabaseManager

class discordSuperUtils.DatabaseManager(database)

Initializer of DatabaseManager, represents a database manager that manages a database.

database

commit

size

close

tables

insertifnotexists

name

insert

path

createtable

update

updateorinsert

delete

select

Attributes

  • database (sqlite3.Connection)

    • The database used by DatabaseManager.

    • Passed in initializer.

  • size (int)

    • The size of the database in bytes.

  • tables (list)

    • List of all tables of the database.

  • name (str)

    • Name of database.

  • path (str)

    • Path of database.

Methods

  • commit() Commits to the database.

  • close() Closes the database.

  • insertifnotexists(keys, values, table_name, checks) Insert a record into the table if there isn't one already. Parameters

    • keys (list)

      • Keys of values that are going to be inserted.

    • values (list)

      • Values of keys that are going to be inserted.

    • table_name (str)

      • Table to insert into.

    • checks ([{key: value}])

      • Checks that are run before inserting, used to check if a record exists.

  • insert(keys, values, table_name) Insert a record into the table. Parameters

    • keys (list)

      • Keys of values that are going to be inserted.

    • values (list)

      • Values of keys that are going to be inserted.

    • table_name (str):

      • Table to insert into.

  • createtable(table_name, columns, exists=False) Creates a table in the database. Parameters

    • table_name (str)

      • Name of table to make.

    • columns ([{name: name, type: type}])

      • Columns to make in the table.

    • exists (bool)

      • If true, create table only if it doesn't exist.

      • Defualts to false.

  • update(keys, values, table_name, checks) Update a record in the table. Parameters

    • keys (list)

      • Keys of values that are going to be updated.

    • values (list)

      • Values of keys that are going to be updated.

    • table_name (str):

      • Table to update in.

    • checks ([{key: value}])

      • Checks that are run before updating, used to find the record that is going to be updated.

  • updateorinsert(keys, values, table_name, checks, insertkeys, insertvalues) Update a record, incase record does not exist insert it. Parameters

    • keys (list)

      • Keys of values that are going to be updated.

    • values (list)

      • Values of keys that are going to be updated.

    • table_name (str):

      • Table to update or insert into/in.

    • checks ([{key: value}])

      • Checks that are run before updating, used to find the record that is going to be updated. If record is not found, insert one.

    • insertkeys (list)

      • Keys of values that are going to be inserted. Used if record is not found.

    • insertvalues (list)

      • Values of keys that are going to be inserted. Used if record is not found.

  • delete(table_name, checks) Deletes a record in the table. Parameters

    • table_name (str):

      • Table to delete from.

    • checks ([{key: value}])

      • Checks that are run before deleting, used to find the record that is going to be deleted.

  • select(keys, table_name, checks, fetchall=False) Select a record from the table. Parameters

    • keys (list)

      • Keys that are going to be selected.

    • table_name (str):

      • Table to select from.

    • checks ([{key: value}])

      • Checks that are run before selecting, used to find the record that is going to be selecting.

    • fetchall (bool)

      • If true, use fetchall method, else use fetchone.

      • Defaults to false.

Last updated