Skip to content
forked from 2shou/QuickORM

A simple ORM provides elegant API for Python-MySQL operation

Notifications You must be signed in to change notification settings

maplet/QuickORM

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

QuickORM

A simple ORM provides elegant API for Python-MySQL operation

Connect to MySQL

from data_handler import Database

db_config = {
    'host': 'localhost',
    'port': 3306,
    'user': 'root',
    'password': '123456',
    'database': 'test'
}
Database.connect(**db_config)

Define a model

from data_handler import Model, Field

class TestModel(Model):
  db_table = 'test'
  a = Field()
  b = Field()

Insert

test = TestModel()
test.a = 5
test.b = 'john'
test.save()

Query

for r in TestModel.where(a=5, b='john').select():
  print r.a
  print r.b

Count

print TestModel.where(a=5, b='john').count()

Update

TestModel.where(a=5, b='john').update(a=1)

Execute raw SQL

from data_handler import execute_raw_sql

results = execute_raw_sql('select b, count(*) from test where b = %s group by b;', (1,))
for val, cnt in results:
  print val, cnt

About

A simple ORM provides elegant API for Python-MySQL operation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%