23 lines
501 B
Python
23 lines
501 B
Python
from peewee import Model, MySQLDatabase
|
|
|
|
from lib.Config import DatabaseConfig
|
|
|
|
database: MySQLDatabase = MySQLDatabase(None)
|
|
|
|
|
|
def init_database_from_config(config: DatabaseConfig):
|
|
database.init(
|
|
host=config['DB_HOST'],
|
|
user=config['DB_USER'],
|
|
password=config['DB_PASS'],
|
|
database=config['DB_NAME'],
|
|
port=int(config['DB_PORT']),
|
|
connect_timeout=5,
|
|
)
|
|
database.connect()
|
|
|
|
|
|
class BaseModel(Model):
|
|
class Meta:
|
|
database = database
|