Skip to main content

mini mysql db orm :: miniorm

Project description

============
Examples
============

dbargkws = {'user': 'test',
'password': 'test',
'host': 'localhost',
'port': "3306",
'database': 'test',
'autocommit': False,
'charset': 'utf8'
}

from miniorm import Model
user_model = Model.make("User", dbargkws, "users") #users is db tablename

-----------
select
-----------
s = user_model.get_by_map({"id": u.id}, select_cols=["id", 'name'])

-----------
select like
-----------
s = user_model.get_by_map({"id": u.id, "name$like":"john"}, select_cols=["id", 'name'])

-----------
select gt/gte/lt/lte
-----------
s = user_model.get_by_map({"id$gt": 1, "name$like":"john"}, select_cols=["id", 'name'])

-----------
select order by/pagination/
-----------
s = user_model.get_by_map({"name$like":"john"}, start=0,limit=20, and_or="and", order_by=["id desc", "name"])

-----------
count distinct
-----------
usercont = user_model.count_by_map({"id$gt": 1, "name$like":"john"}, distinct="pid")

-----------
update or insert
-----------
- by namedtuple
User = namedtuple("User", ['id', 'name', 'pwd', 'email'])
user = User(None, '1', '2', "10000003exeee@a.com")
ins, updates, nops = user_model.save(user)

- by dict
user = {'name':"ww", 'pwd':"pwd", 'email': "xxx"}
ins, updates, nops = user_model.save(user)

-----------
delete
-----------
uid = 1
user_model.delete_by_id(uid)
user_model.delete_by_map({"id":uid})

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 miniorm, version 1.2.1
Filename, size File type Python version Upload date Hashes
Filename, size miniorm-1.2.1.tar.gz (3.3 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 SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page