> For the complete documentation index, see [llms.txt](https://discord-super-utils.gitbook.io/discord-super-utils/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://discord-super-utils.gitbook.io/discord-super-utils/managers/database-manager.md).

# Database Manager

This page shows you everything about DatabaseManager.

## DatabaseManager

#### **class discordSuperUtils.DatabaseManager(database)**

Initializer of [**`DatabaseManager`**](/discord-super-utils/managers/database-manager.md#databasemanager), represents a database manager that manages a database.

| [**Attributes**](/discord-super-utils/managers/database-manager.md#attributes) | [**Methods**](/discord-super-utils/managers/database-manager.md#methods) |
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------ |
| **`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)**
    * &#x20;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.

    &#x20;

* **`insert(keys, values, table_name)`**\
  **Insert** a record into the **table**.\
  \
  **Parameters**
  * **`keys` (list)**
    * &#x20;Keys of values that are going to be inserted.
  * **`values` (list)**
    * &#x20;Values of keys that are going to be inserted.
  * **`table_name` (str)**:
    * Table to insert into.<br>

* **`createtable(table_name, columns, exists=False)`**\
  **Creates** a **table** in the database.\
  \
  **Parameters**
  * **`table_name` (str)**
    * &#x20;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.<br>

* **`update(keys, values, table_name, checks)`**\
  **Update** a record in the **table**.\
  \
  **Parameters**
  * **`keys` (list)**
    * &#x20;Keys of values that are going to be updated.
  * **`values` (list)**
    * &#x20;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)**
    * &#x20;Keys of values that are going to be updated.
  * **`values` (list)**
    * &#x20;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)**
    * &#x20;Keys of values that are going to be inserted. Used if record is not found.
  * **`insertvalues` (list)**

    * &#x20;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)**
    * &#x20;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.
