create models for database
This commit is contained in:
parent
ec6ab3e5d2
commit
c3b32462e4
|
@ -0,0 +1,2 @@
|
|||
from .database import BaseModel
|
||||
from .models import *
|
|
@ -0,0 +1,16 @@
|
|||
from peewee import Model, SqliteDatabase
|
||||
from main import config
|
||||
|
||||
if (DB_PATH := config["DB"]["path"]) is None:
|
||||
DB_PATH = 'app.db'
|
||||
|
||||
database = SqliteDatabase(DB_PATH, pragmas={
|
||||
'journal_mode': 'wal',
|
||||
'cache_size': 10000,
|
||||
'foreign_keys': 1
|
||||
})
|
||||
|
||||
class BaseModel(Model):
|
||||
|
||||
class Meta:
|
||||
database = database
|
|
@ -0,0 +1,14 @@
|
|||
from .collectible import Collectible
|
||||
from .inventory import Inventory
|
||||
from .item import Item
|
||||
from .recipe import ItemRecipe, ItemRecipeShard
|
||||
from .user import User
|
||||
|
||||
__all__ = [
|
||||
Collectible
|
||||
, Inventory
|
||||
, Item
|
||||
, ItemRecipe
|
||||
, ItemRecipeShard
|
||||
, User
|
||||
]
|
|
@ -0,0 +1,6 @@
|
|||
from peewee import CharField
|
||||
from src.db import BaseModel
|
||||
|
||||
class Collectible(BaseModel):
|
||||
name = CharField()
|
||||
picture = CharField()
|
|
@ -0,0 +1,7 @@
|
|||
from peewee import CharField, ForeignKeyField, IntegerField
|
||||
from src.db import BaseModel
|
||||
|
||||
class Inventory(BaseModel):
|
||||
user_id = CharField()
|
||||
item_id = ForeignKeyField(Item)
|
||||
amount = IntegerField(default=0)
|
|
@ -0,0 +1,6 @@
|
|||
from peewee import CharField
|
||||
from src.db.database import BaseModel
|
||||
|
||||
class Item(BaseModel):
|
||||
name = CharField()
|
||||
picture = CharField()
|
|
@ -0,0 +1,10 @@
|
|||
from peewee import ForeignKeyField, IntegerField
|
||||
from . import Collectible, Item
|
||||
|
||||
class ItemRecipe(BaseModel):
|
||||
output_item_id = ForeignKeyField(Item)
|
||||
|
||||
class ItemRecipeShard(BaseModel):
|
||||
recipe_id = ForeignKeyField(ItemRecipe)
|
||||
collectible_id = ForeignKeyField(Collectible)
|
||||
amount = IntegerField()
|
|
@ -0,0 +1,8 @@
|
|||
from peewee import CharField, IntegerField
|
||||
from src.db import BaseModel
|
||||
|
||||
class User(BaseModel):
|
||||
user_id = CharField()
|
||||
xp = IntegerField(default=0) # Total xp accumulated
|
||||
xp_mod = IntegerField(default=100) # XP Modifier in Percent // Can be 0 for XP-Lock, but not negative
|
||||
level = IntegerField(default=1)
|
|
@ -1,13 +1,17 @@
|
|||
from os import getenv
|
||||
from sys import exit
|
||||
|
||||
from configparser import ConfigParser
|
||||
|
||||
def build_config():
|
||||
config_path = getenv("AKWAH_CONFIG_PATH")
|
||||
if config_path == None:
|
||||
if (config_path := getenv("CONFIG_PATH")) is None:
|
||||
config_path = "config.ini"
|
||||
|
||||
config = ConfigParser()
|
||||
try:
|
||||
config.read_file(open(config_path))
|
||||
return config
|
||||
except FileNotFoundError:
|
||||
print("Unable to locate config file. Exiting...")
|
||||
exit(1)
|
||||
|
||||
return config
|
Loading…
Reference in New Issue