forked from 2shou/QuickORM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
38 lines (31 loc) · 764 Bytes
/
test.py
File metadata and controls
38 lines (31 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from data_handler import Database, Model, Field, execute_raw_sql
# connect database
db_config = {
'host': 'localhost',
'port': 3306,
'user': 'root',
'password': '123456',
'database': 'test'
}
Database.connect(**db_config)
# define model
class TestModel(Model):
db_table = 'test' # point table name
a = Field()
b = Field()
# create instance
test = TestModel()
test.a = 'john'
test.b = 3
test.save()
# select
for r in TestModel.where(a='john', b=3).limit(1, offset=2).select():
print type(r)
print r.a
print r.b
# update
TestModel.where(a='john', b=3).update(b=1)
# 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