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})
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
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
miniorm-1.2.1.tar.gz
(3.3 kB
view hashes)