Skip to main content

A simple mysql orm for python3

Project description

中文-Chinese - a simple mysql orm for python3

Functional overview

  • Model-Oriented operations
  • Basic CRUD
  • Operator query
  • Automatic safety escape


shell>pip install Pmorm


from pmorm 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")


# Insert
jack = Worker(username='Jack', password='JackSoHandsome', salary=3999.2)

mary = Worker()
mary.username = 'Mary'
mary.password = 'MarySoBeautiful'

# Get all and get the first
all_workers =
the_first_worker =

# Query by operators
rich_workers =>=3000.0).all()

# Complex query by operators & and |
worker_jack =
	((Worker.username == 'jack') & (Worker.password == 'JackSoHandsome')) | (Worker.salary=='3999.2')

# Order the rows
the_richest_worker =[-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

# Delete one row


Currently supported MySQL fields

Pmorm Mysql
PrimaryKeyField NO
BooleanField BOOLEAN
IntField INT
BigIntField BIGINT
FloatField FLOAT
DoubleField DOUBLE
VarcharField VARCHAR
TextField TEXT

PrimaryKeyField must be defined in each model, so a basic model looks like...

mydb = Mysql('localhost', 'root', 'your-passwd', 'your-database')
class ModelName(mydb.Model):
    __table__ = 'mytable'

    id = mydb.PrimaryKeyField()
    # Other fields...

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Pmorm, version 0.21
Filename, size File type Python version Upload date Hashes
Filename, size Pmorm-0.21-py3-none-any.whl (7.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size Pmorm-0.21.tar.gz (7.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page