sqlalchemy ORM models for quest databases and json parsing scripts

also minor bugfixes
next is testing and implementation
This commit is contained in:
louis 2019-05-15 12:32:33 -04:00
parent 6c455fe30b
commit 8b7815500e
10 changed files with 267 additions and 15 deletions

4
db/__init__.py Normal file
View file

@ -0,0 +1,4 @@
from .base import init
from .quest import Quest, QuestScene, QuestPart
from .resource import ResourceEntry
from .base import session

28
db/base.py Normal file
View file

@ -0,0 +1,28 @@
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy import text
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
engine = create_engine('sqlite:///:memory:', echo=False)
session = sessionmaker(bind=engine, autoflush=False, autocommit=False)()
session.flush = lambda:None
DATABASES = {
"QuestMst.db": "Quest",
"QuestSceneMst.db": "QuestScene",
"QuestPartMst.db": "QuestPart",
"ResourceEntry.db": "ResourceEntry"
}
def init(path):
for d in DATABASES:
if not os.path.isfile(os.path.join(path, d)):
raise FileNotFoundError("Database {} not found".format(d))
for d in DATABASES:
t = text("attach database :path as :schema")
engine.execute(t, path=os.path.join(path, d), schema=DATABASES[d])

67
db/quest.py Normal file
View file

@ -0,0 +1,67 @@
from sqlalchemy import Column, Integer, BigInteger, String, ForeignKey
from sqlalchemy.orm import relationship
from .base import Base
class Quest(Base):
__tablename__ = 'QuestMstRecord'
__table_args__ = {'schema': 'Quest'}
questMstId = Column(Integer, primary_key=True)
questType = Column(Integer)
sortNum = Column(Integer)
name = Column(String)
prevQuestMstId = Column(Integer)
eventItemMstIds = Column(Integer)
valid = Column(Integer)
baseQuestMstId = Column(Integer)
updatedTime = Column(BigInteger)
scenes = relationship("QuestScene")
def __repr__(self):
return "<Quest(questMstId={}, name={})>".format(self.questMstId, self.name)
class QuestScene(Base):
__tablename__ = 'QuestSceneMstRecord'
__table_args__ = {'schema': 'QuestScene'}
questSceneMstId = Column(Integer, primary_key=True)
questMstId = Column(Integer, ForeignKey("Quest.QuestMstRecord.questMstId"))
_type = Column("type", Integer)
sortNum = Column(Integer)
name = Column(String)
_filter = Column("filter", Integer)
prevQuestSceneMstId = Column(Integer, ForeignKey("QuestScene.QuestSceneMstRecord.questSceneMstId"))
releaseSerial = Column(Integer)
releaseEvolutionLevel = Column(Integer)
summaryText = Column(String)
presentType = Column(String)
objectId = Column(Integer)
num = Column(Integer)
appearanceType = Column(Integer)
isPrologue = Column(Integer)
isEpilogue = Column(Integer)
viewType = Column(Integer)
updatedTime = Column(BigInteger)
previous = relationship("QuestScene", remote_side=[questSceneMstId])
parts = relationship("QuestPart")
class QuestPart(Base):
__tablename__ = 'QuestPartMstRecord'
__table_args__ = {'schema': 'QuestPart'}
questSceneMstId = Column(Integer, ForeignKey("QuestScene.QuestSceneMstRecord.questSceneMstId"), primary_key=True) # now this is pod racing
partNum = Column(Integer, primary_key=True)
waveNum = Column(Integer)
stamina = Column(Integer)
exp = Column(Integer)
expertPoint = Column(Integer)
recommendLevel = Column(Integer)
beforeTalkName = Column(String)
afterTalkName = Column(String)
battleBackgroundImg = Column(String)
musicMstId = Column(Integer)
isFixedDeck = Column(Integer)
updatedTime = Column(BigInteger)

13
db/resource.py Normal file
View file

@ -0,0 +1,13 @@
from sqlalchemy import Column, BigInteger, String
from .base import Base
class ResourceEntry(Base):
__tablename__ = 'ResourceEntryRecord'
__table_args__ = {'schema': 'ResourceEntry'}
path = Column(String, primary_key=True)
serverPath = Column(String)
localPath = Column(String)
digest = Column(String)
fileSize = Column(BigInteger)