A simple mysql orm for python3
Project description
中文-Chinese
FlagBox - a simple mysql orm for python3
Functional overview
- Model-Oriented operations
- Basic CRUD
- Operator query
- Automatic safety escape
- Deadlock retry
Installing
shell>pip install flagbox
Basic
from flagbox import Mysql
# Create a connection.Automatically create database(if it is not created)
db = Mysql('localhost', 'root', 'your-password', 'testdb1')
class Worker(db.Model):
__table__ = 'worker'
id = db.PrimaryKeyField()
username = db.VarcharField(max_length=32, nullable=False, unique=True, default=None, comment="Worker's username")
password = db.VarcharField(max_length=32, nullable=False, unique=False, default=None, comment="Worker's password")
salary = db.FloatField(nullable=False, unique=False, default=0.0, comment="Worker's monthly salary")
Worker.create_table()
# Insert
jack = Worker(username='Jack', password='JackSoHandsome', salary=3999.2)
jack.insert()
mary = Worker()
mary.username = 'Mary'
mary.password = 'MarySoBeautiful'
mary.insert()
# Get all and get the first
all_workers = Worker.select().all()
the_first_worker = Worker.select().first()
# Query by operators
rich_workers = Worker.select(Worker.salary>=3000.0).all()
# Complex query by operators & and |
worker_jack = Worker.select(
((Worker.username == 'jack') & (Worker.password == 'JackSoHandsome')) | (Worker.salary=='3999.2')
).first()
# Order the rows
the_richest_worker = Worker.select(orders=[-Worker.salary]).first()
# Use the result
for worker in all_workers:
print('username:{} password:{} salary:{}'.format(worker.username, worker.password, worker.salary))
print('And the richest worker is {}'.format(the_richest_worker.username))
# Update one row
worker_jack.salary = 3000.0
worker_jack.update()
# Delete one row
worker_jack.delete()
Else
Currently supported MySQL fields
FlagBox | Mysql |
---|---|
PrimaryKeyField | NO |
BooleanField | BOOLEAN |
IntField | INT |
BigIntField | BIGINT |
FloatField | FLOAT |
DoubleField | DOUBLE |
VarcharField | VARCHAR |
TextField | TEXT |
PrimaryKeyField must be defined as the primary key.A basic definition below
mydb = Mysql('localhost', 'root', 'your-passwd', 'your-database')
class ModelName(mydb.Model):
__table__ = 'mytable'
id = mydb.PrimaryKeyField()
# Other fields...
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
FlagBox-0.21.tar.gz
(8.2 kB
view details)
Built Distribution
File details
Details for the file FlagBox-0.21.tar.gz
.
File metadata
- Download URL: FlagBox-0.21.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.9.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fbe27a9daa69e9e1b7b056e05c1d70efd98f0e72c8e3991222c07437462dbfb4 |
|
MD5 | bfd1267d1a9a434718ae69250858a525 |
|
BLAKE2b-256 | f3f9affc399990a22e19432dc22715707d896dbea91e23e0a75965a46334546c |
File details
Details for the file FlagBox-0.21-py3-none-any.whl
.
File metadata
- Download URL: FlagBox-0.21-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.9.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b997b55c865fef227c06086709704494d72ecae23f2fc5fcc6a40ce81f69db08 |
|
MD5 | 944d4edd60ab3b52e030d64e6f1b991b |
|
BLAKE2b-256 | 34e41851ec564720b964cbd2add1df5a481c830e5da25e3fc02867536e7a8bfe |