-
Notifications
You must be signed in to change notification settings - Fork 5
/
test3.py
51 lines (44 loc) · 1.53 KB
/
test3.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
from pmydb import Engine
from pmydb.case import *
e = Engine() # 实例化数据库引擎对象
e.select_db('test_db') # 选择数据库 test_db
'''
# 向表 `t_test` 中添加一些数据
e.insert(table_name='t_test', f_name='shiyanlou_003', f_age=30)
e.insert(table_name='t_test', f_name='shiyanlou_004', f_age=40)
e.insert(table_name='t_test', f_name='xiaoming', f_age=50)
e.insert(table_name='t_test', f_name='echo', f_age=50)
'''
print('\n')
print("-"*5, "这里是表 t_test 的全部数据", "-"*5)
all_data = e.search("t_test")
for i in all_data:
print(i)
print("-" * 30)
print("-"*5, "查询年龄在5岁以上的用户", "-"*5)
test1_data = e.search(table_name="t_test", fields=['f_id'], f_age=GreaterCase(5))
for i in test1_data:
print(i)
print("-" * 30)
print("-"*5, "查询年龄在[30,40,50,60],f_id在[3,4,5]的用户", "-"*5)
test1_data = e.search(table_name="t_test", f_age=InCase([30,40,50,60]),f_id=InCase([3,4,5]))
for i in test1_data:
print(i)
print("-" * 30)
print("-"*5, "查询id在range(5)的用户", "-"*5)
test1_data = e.search(table_name="t_test", f_id=RangeCase(0,5))
for i in test1_data:
print(i)
print("-" * 30)
print("-"*5, "查询f_name类似ou_001的用户", "-"*5)
test1_data = e.search(table_name="t_test", f_name=LikeCase('ou_001'))
for i in test1_data:
print(i)
print("-" * 30)
print("-"*5, "查询test_db全部数据", "-"*5)
test1_data = e.search(table_name="t_test", fields='*')
for i in test1_data:
print(i)
print("-" * 30)
# 保存更改到数据库中
#e.commit()