SQL Database management without even a SQL line
Project description
EasySQL
This library allow you to run SQL Databases without knowing even SQL.
This library will create SQL queries and execute them as you request and is very simple to use.
Support
You can find support on our discord server here:
https://discord.gg/6exsySK
Pay us a visit there ✌
Wiki
The official wiki of this library is now available at Github
How to install
To install just use following command
pip install PyEasySQL
This library will have dev/beta builds on the github, to install them you can use
pip install --upgrade git+https://github.com/Ashengaurd/EasySQL.git
By installing this library following libraries and their dependencies will be installed too.
mysql-connector: Which is the basic library for connecting to database
Example
import EasySQL
# Define database which will be needed by any table you create.
database = EasySQL.EasyDatabase(host='127.0.0.1', port=3306,
database='DatabaseName',
user='username', password='PASSWORD')
# Define tables and columns
ID = EasySQL.EasyColumn('ID', EasySQL.INT, primary=True, auto_increment=True)
Name = EasySQL.EasyColumn('Name', EasySQL.STRING(255), not_null=True, default='Missing')
Balance = EasySQL.EasyColumn('Balance', EasySQL.INT, not_null=True)
Premium = EasySQL.EasyColumn('Premium', EasySQL.BOOL, not_null=True, default=False)
table = EasySQL.EasyTable(database, 'Users', [ID, Name, Balance, Premium])
# Insert values with a simple command
table.insert([Name, Premium, Balance], ['Ashenguard', True, 10])
table.insert([Name, Premium], ['Sam', False])
# Some random data
from random import randint
for i in range(5):
table.insert([Name, Balance], [f'User-{i}', randint(0, 20)])
# Selecting data with another simple command
### Get all the data
all = table.select()
### Something that does not exist
empty = table.select(ID, where=EasySQL.WhereIsEqual(Name, "NO-ONE"))
### To select multiple data give a list of columns as 1st argument
premiums = table.select([ID, Name], EasySQL.WhereIsEqual(Premium, True))
### You can have more complicated condition with AND (&), OR (|) and NOT (~)
specific = table.select(Name, where=EasySQL.WhereIsLike(Name, "Ash%").AND(EasySQL.WhereIsLesserEqual(ID, 5)))
### Giving no column will select all the columns, Also you can use limit, offset and order sorting data
second = table.select(order=Balance, descending=True, limit=1, offset=1)
top5 = table.select(order=Balance, descending=True, limit=5)
# The result will be an EmptySelectData if nothing was found, A SelectData if only one was found, Or a tuple of SelectData
# All 3 of them are iterable, so it is safe to use a `for` loop for any result
# To get data from the result you can use `get`, but it only contains columns requested in select method.
for data in top5:
print(f'{data.get(ID)}: {data.get(Name)}\tBalance: {data.get(Balance)}')
# To delete data just use the delete method
table.delete(EasySQL.WhereIsGreater(ID, 5))
# Update data with following command
table.update(Premium, True, EasySQL.WhereIsEqual(ID, 3).OR(EasySQL.WhereIsEqual(Name, 'Sam')))
# Not sure if you should update or insert? Use set and it will be handled
table.set([ID, Name, Balance, Premium], [5, 'Nathaniel', 50, False], where=EasySQL.WhereIsEqual(ID, 5))
# Safety error on delete/update/set without a where statement
# table.delete() -> raise EasySQL.DatabaseSafetyException
# Turn the safety off with following command.
database.remove_safety(confirm=True)
# Now there will be no error, it will clean the all data that's why we had safety lock
table.delete()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for PyEasySQL-2.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94ce798374b853669a5419b99f585c7d3993907502ac41783b6c7464d50cb86f |
|
MD5 | f02e64fcc964adb91f1e7324fe3093f7 |
|
BLAKE2b-256 | 8fd0d14eeb180a27c86ea21f071c057771d8962909c3781ad5aa2682b5ea121d |