-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
executable file
·55 lines (44 loc) · 1.63 KB
/
models.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
52
53
54
55
import uuid
import json
from graphene_pynamodb.relationships import OneToOne
from pynamodb.attributes import MapAttribute, ListAttribute, UnicodeAttribute, NumberAttribute
from pynamodb.indexes import AllProjection
from pynamodb.indexes import GlobalSecondaryIndex
from pynamodb.models import Model
from pynamodb.constants import NULL
from flask import jsonify
class User(Model):
class Meta:
table_name = "dunkin"
host = "https://dynamodb.us-east-1.amazonaws.com"
def __init__(self, hash_key=None, range_key=None, **args):
Model.__init__(self, hash_key, range_key, **args)
if not self.id:
self.id = str(uuid.uuid4())
id = UnicodeAttribute(hash_key=True)
role = UnicodeAttribute(null=False)
name = UnicodeAttribute(null=False)
picture = UnicodeAttribute(null=True)
email = UnicodeAttribute(null=False)
sessions = NumberAttribute(null=True)
completions = NumberAttribute(null=True)
last_login = NumberAttribute(null=False)
class IdIndex(GlobalSecondaryIndex):
class Meta:
projection = AllProjection()
index_name = 'uid-index'
read_capacity_units = 1
write_capacity_units = 1
uid = UnicodeAttribute(hash_key=True)
class Session(Model):
class Meta:
table_name = "sessions"
host = "https://dynamodb.us-east-1.amazonaws.com"
index_name = 'uid-index'
sid = UnicodeAttribute(hash_key=True)
uid = OneToOne(User)
id_index = IdIndex()
time = NumberAttribute(null=True)
start_timestamp = NumberAttribute(range_key=True)
end_timestamp = NumberAttribute(null=True)
result = UnicodeAttribute()