-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
66 lines (44 loc) · 1.45 KB
/
app.py
File metadata and controls
66 lines (44 loc) · 1.45 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
import db
import orm
# import databases
# import sqlalchemy
import asyncio
import functools
def async_adapter(wrapped_func):
""" Decorator used to run async test cases. """
@functools.wraps(wrapped_func)
def run_sync(*args, **kwargs):
loop = asyncio.get_event_loop()
task = wrapped_func(*args, **kwargs)
return loop.run_until_complete(task)
return run_sync
@async_adapter
async def test1():
print("script principal")
db.metadata.create_all(db.engine)
async with db.database:
await db.Test1.objects.create(name="toto")
t = "tassqdfqsdfqsdfsdfqsdfta"
# print(str(db.Test1.fields["name"].__getattribute__("max_length")))
t_max = db.Test1.fields["name"].max_length
print(f"max length of name : {t_max}")
await db.Test1.objects.create(name=f"{t[:t_max]}")
all_obj = await db.Test1.objects.all()
print(type(all_obj))
print(all_obj)
print(type(all_obj[0]))
print(all_obj[0])
print(type(all_obj[0].name))
print(all_obj[0].name)
print("#" * 20)
async with db.database:
await db.Test2.objects.create(name="toto", key="key-ok", value=5)
await db.Test2.objects.create(name="toto2", key="fix-len", value=123456789)
all_obj = await db.Test2.objects.all()
print(type(all_obj))
print(all_obj)
print(type(all_obj[0]))
print(all_obj[0])
print(type(all_obj[0].name))
print(all_obj[0].name)
test1()