-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
35 lines (27 loc) · 961 Bytes
/
database.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
from peewee import *
import datetime
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read("dashbroker.ini")
databaseHost = config.get("Database", "Address")
databaseUsername = config.get("Database", "Username")
databasePassword = config.get("Database", "Password")
databaseName = config.get("Database", "Database")
db = MySQLDatabase(databaseName, host=databaseHost, user=databaseUsername, passwd=databasePassword)
class BaseModel(Model):
class Meta:
database = db
class Housemates(BaseModel):
firstName = CharField()
lastName = CharField()
phoneNumber = CharField()
active = BooleanField()
class Button(BaseModel):
macAddress = CharField(max_length=17, primary_key=True)
name = CharField()
class ButtonLog(BaseModel):
button = ForeignKeyField(Button)
pressedAt = DateTimeField(default=datetime.datetime.now)
reason = CharField()
db.connect()
db.create_tables([Housemates, ButtonLog, Button], safe=True)