-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_peewee_sqlserver.py
More file actions
34 lines (28 loc) · 1.01 KB
/
Copy pathtest_peewee_sqlserver.py
File metadata and controls
34 lines (28 loc) · 1.01 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
import peewee as pw
import random
from datetime import date
myDB = pw.MySQLDatabase("test", host="localhost", port=3306, user="python", passwd="spartak")
class MySQLModel(pw.Model):
"""A base model that will use our MySQL database"""
class Meta:
database = myDB
class User(MySQLModel):
id = pw.PrimaryKeyField()
email = pw.CharField(index = True)
password = pw.CharField()
hiredate = pw.DateTimeField()
class Broker(MySQLModel):
broker_id = pw.PrimaryKeyField()
email = pw.CharField(index = True)
active = pw.BooleanField(default=False)
rep_id = pw.ForeignKeyField(User)
# when you're ready to start querying, remember to connect
myDB.connect()
myDB.create_tables([User, Broker], safe=True)
user = User(email='ekibalko@franklinamerican.com', password='secret', hiredate=date(2010, 5, 2))
broker = Broker(email='broker@morg.com', active=True, rep_id = user)
user.save()
broker.save()
for user in User.select():
print user.id, user.email, user.password, user.hiredate
myDB.close()