-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
48 lines (29 loc) · 809 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
from peewee import *
db = SqliteDatabase('users.db')
class User(Model):
username = CharField()
games = IntegerField(default=0)
winnings = IntegerField(default=0)
class Meta:
database = db
tables = [User]
# User.create(username='new')
def db_inc(username, attr):
sel = User.get(User.username == username)
setattr(sel, attr, getattr(sel, attr) + 1)
sel.save()
# inc('new', 'winnings')
# inc('new', 'games')
def does_exist(path):
return os.path.exists(path)
def create_database(db, tables):
try:
db.create_tables(tables)
except Exception as e:
print(e)
if __name__ == "__main__":
for i in User.select():
print(i.winnings, i.games)
print(User.get(User.username == 'new'))
create_database(db, tables)