-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
50 lines (38 loc) · 1.41 KB
/
tests.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
# Rethinkdb Wrapper For Tornado Framework
# https://github.com/mehmetkose/torethink
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2016 Mehmet Kose [email protected]
import time
import tornado.ioloop
import tornado.gen
from torethink import Torethink
scheme = {
'db': 'awesome_project',
'host': '127.0.0.1',
'port': 28015,
'tables': {
'user': {
'email': {'default': None, 'specs': []},
'add_date': {'default': int(time.time()), 'specs': ['noedit']},
'update_date': {'default': int(time.time()), 'specs': ['noedit', 'index']},
'is_deleted': {'default': False, 'specs': ['index']},
},
}
}
async def test():
db = await Torethink.init(database=scheme, create_scheme=True)
for i in range(20):
email = "%s@%s.com" % (int(time.time()), int(time.time()))
email_record = scheme['tables'].get('user', {})
email_record['email'] = email
check = {'email': email}
result = await db.insert_unique('user', check, email_record)
print(result)
for user in (await db.list("user")):
print("user email: %s, user id: %s" % (user['email'], user['id']))
async def main():
tornado.ioloop.IOLoop.current().spawn_callback(test)
if __name__ == "__main__":
tornado.ioloop.IOLoop.current().run_sync(main)
tornado.ioloop.IOLoop.current().start()