forked from klen/py-frameworks-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
34 lines (22 loc) · 683 Bytes
/
db.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
import os
import peewee
from mixer.backend.peewee import mixer
from playhouse.db_url import connect
HOST = os.environ.get('DHOST', '127.0.0.1')
PEEWEE_CONNECTION = 'postgres+pool://benchmark:benchmark@%s:5432/benchmark' % HOST
db = connect(PEEWEE_CONNECTION)
db.connect()
class Message(peewee.Model):
content = peewee.CharField(max_length=512)
def __unicode__(self):
return "%s: %s" % (self.id, self.content)
class Meta:
database = db
try:
Message.create_table()
except Exception:
db.rollback()
for n in range(0, 10000, 1000):
mixer.cycle(1000).blend(Message)
print("Generated %d messages from 10000." % (n + 1000))
db.close()