-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql_example.py
More file actions
71 lines (65 loc) · 1.56 KB
/
mysql_example.py
File metadata and controls
71 lines (65 loc) · 1.56 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# coding utf-8
from sqlcollection import Client
# import logging
# logging.basicConfig()
# logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
#
# lookup=[
# {
# u"to": u"hour",
# u"localField": u"project",
# u"from": u"project",
# u"foreignField": u"id",
# u"as": u"project"
# }, {
# u"to": u"project",
# u"localField": u"client",
# u"from": u"client",
# u"foreignField": u"id",
# u"as": u"project.client"
# }
# ]
import json
import datetime
client = Client(url=u'mysql+mysqlconnector://root:localroot1234@127.0.0.1/')
user = client.user_api._user
description = user.get_description(auto_lookup=3)
print(json.dumps(description, indent=4))
cursor = user.find(query={}, auto_lookup=1).sort(u"id").limit(2).skip(0)
for item in cursor:
print(item)
#
# print(u"___count")
# count = hour.find(auto_lookup=0).limit(3).count()
# print(count)
#
# print(u"___count with_limit_and_skip")
# count = hour.find(auto_lookup=0).limit(3).count(with_limit_and_skip=True)
# print(count)
# quit()
#
# ret = user.insert_one({
# "email": "test2",
# "name": "test",
# "hash": "test",
# "salt": "test",
# "customer_id": {
# "id": 1
# }
# }, auto_lookup=1)
# print(ret.inserted_id)
# #
ret = user.delete_many({
u"customer_id.id": 2
}, auto_lookup=3)
#
# ret = hour.update_many({
# u"project.id": 2
# }, {
# u"$set": {
# u"issue": u"updated",
# u"project": {
# u"id": 1
# }
# }
# }, auto_lookup=3)