Skip to content

EasyDatabase

Ashenguard edited this page May 9, 2022 · 4 revisions

Notes:

You can check the source here
Arguments with [O] before the name are optional and not passing them will not cause any issues.
Arguments with [R] before the name are required and not passing them will cause python to raise an exception.
Arguments with [D <value>] before the name have default values that will be used if you do not pass them, But it is not guaranteed there will be no exceptions.
Arguments with [E <value>] before the name have default values but the value will cause an exception.
The STC-<Version> Methods/Properties are subjects to be changed or are depressed and might get removed in the specified version. If no version is specified it means there is no solid plan.
The PUO Methods/Properties are for Private use only which you won't need to use yourself, They just exist for other classes to use.

This class is the main class that you need to initialize first and just pass to your tables.

Initializing

To initialize the class you need to pass the following arguments.

  • [D "127.0.0.1"] host: The IP of the host you are using.
  • [D 3306] port: The Port of the host you are using.
  • [E None] database: The name of the database you want to connect to.
  • [D "root"] user: The username to log in with
  • [E None] password: The password to log in with
  • [O] charset: The encoding your tables will be in, As default, it will ignore the encoding and use what database is already using. You can find all available charsets on Charsets page

Example:

import EasySQL

database = EasySQL.EasyDatabase(host='127.0.0.1', port=3306,
                                database='DatabaseName',
                                user='username', password='PASSWORD',
                                charset=EasySQL.UTF8)

safe

A property of the class which will return the safety lock of the database, Safty lock is a built-in feature that will make sure you do not damage your data accidentally by raising an Exception called DatabaseSafetyException.

remove_safty

A method to disable the safety lock is explained above, You need to pass True to the confirm argument to disable it. And there is no way to re-enable it!

Example:

database.remove_safty(confirm=True)

connection

[PUO]
A property of the class which is used by other methods. This property is also the SQL connector which makes sure you have a stable connection or it will establish one for you.

prepare

[PUO]
A method that is called automatically at the initializing of the database and getting the database ready for you to use.

cursor

[PUO]
Explained with buffered_cursor

buffered_cursor

[PUO]
The SQL cursor allows for the selection, updates, or insertion of data. This cursor has a buffer, enabling extra features. You will not need to use it yourself.

charset

[PUO]
A property of the class which returns the charset you requested at initializing.

name

[PUO]
A property of the class which returns the name of the database.

execute

[PUO]
A method that will request SQL commands to be executed on the database. This method accepts the following arguments:

  • [R] operation: The SQL command you want to execute.
  • [O] params: The parameters to be replaced in the command.
  • [O] buffered: If this command needs to use buffered_cursor or not, As default it uses the normal one
  • [O] auto_commit: If commit method should be executed automatically after executing the command. As default it will execute the commit method.

commit

[PUO]
A method that commits the changes to the server as SQL intended to.

table

A method that is a bit simpler to use for initializing the EasyTable. The arguments are the same as what you need for EasyTable initializing except for the database one as it uses the current one.

describe_table

[PUO] An advanced method that will get the table columns from the database based on the table provided.

Example:

columns = database.describe_table(UsersTable)

Clone this wiki locally