-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase_init.py
More file actions
52 lines (31 loc) · 1.34 KB
/
database_init.py
File metadata and controls
52 lines (31 loc) · 1.34 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from __future__ import annotations
from sqlalchemy import create_engine, ForeignKey
from sqlalchemy.orm import declarative_base, sessionmaker, relationship, Mapped
from sqlalchemy.schema import Column
from sqlalchemy.types import Integer, String
engine = create_engine('sqlite:///database/database.db', echo=True)
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
class Users(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column('name', String(20))
password = Column('password', String(50))
current_game_id = Column('game id', Integer, default=0)
amount_of_played_games = Column('amount of games', Integer, default=0)
token: Mapped["Tokens"] = relationship(back_populates='user')
class Tokens(Base):
__tablename__ = 'tokens'
id = Column(Integer, primary_key=True)
token = Column('token', String(100))
user_id = Column(ForeignKey('users.id'))
user: Mapped["Users"] = relationship(back_populates='token')
class Rooms(Base):
__tablename__ = 'rooms'
id = Column(Integer, primary_key=True)
password = Column('password', String(50))
websocket_address = Column('websocket', String(50))
max_players = Column('max_players', Integer)
amount_of_players = Column('players', Integer, default=0)
Base.metadata.create_all(engine)