"Sqlazo" is a module that allows you to manage basic procedures in a "sqlite3" database in PYTHON.
Before running any command from this module, I recommend you check these two modules first:
To begin, its use would start with an instance of the Database class, which takes the following parameters as arguments:
name:str
: Name of the database (e.g., 'test.db'
).check_thread:boolean
: Verify multi-thread executions.# Example of initialisation
from sqlazo import Database
db = Database('test.db', False)
# This will create a test.db file ready for use...
table_name:str
: Name of the table to be created.cols:list
: A list of the columns the table will contain; each column (within the list)
must include its configuration.# Columns with their configurations
cols = ['id INTEGER PRIMARY KEY', 'name TEXT NOT NULL', 'age INTEGER NOT NULL']
# Execute "query" (Create table)
db.create_table('user', cols)
table_name:str
: Name of the table to be validated.# Execute "query" (Validate table)
# Returns a boolean indicating the table's existence
db.table_exists('user')
data:list
: Data to be added.cols:list
: Columns into which the data will be inserted.table_name:str
: Name of the table to work with.db.insert_data(['Santiago', 19], ['name', 'age'], 'user')
table_name:str
: Name of the table from which records will be retrieved.db.get_data_all('user')
table_name:str
: Name of the table to work with.condition:str
: Condition for valid returns from the "query".*args:str
: Names of the columns to be selected in the "query".# If the third parameter exists, only those columns will be considered in the "query"
# It will return records that meet the condition and only return the "name" column
# select name from user where id < 3
db.get_data_where('user', 'id < 3', 'name')
# If *args do not exist, it is understood that all columns will be selected
# Returns records valid for the condition and all columns
# select * from user where id < 3*
db.get_data_where('user', 'id < 3')
table:str
: Name of the table to work with.condition:str
: Condition a record must meet to be deleted.# Delete underage users
db.delete_data('user', 'age < 18')
# Close connection with the database
db.close()
# For internal use only
# Example of initialisation
from sqlazo import Database
db = Database('test.db', False)
# Columns with their configurations
cols = ['id INTEGER PRIMARY KEY', 'name TEXT NOT NULL', 'age INTEGER NOT NULL']
# Execute "query" (Create table)
db.create_table('user', cols)
db.insert_data(['Santiago', 19], ['name', 'age'], 'user')
dataAll = db.get_data_all('user')
# If the third parameter exists, only those columns will be considered in the "query"
# It will return records that meet the condition and only return the "name" column
# select name from user where id < 3
data_where1 = db.get_data_where('user', 'id < 3', 'name')
# If *args do not exist, it is understood that all columns will be selected
# Returns records valid for the condition and all columns
# select * from user where id < 3*
data_where12 = db.get_data_where('user', 'id < 3')
# Delete underage users
db.delete_data('user', 'age < 18')
# Close connection with the database
db.close()