sqlalchemy ORM models for quest databases and json parsing scripts
also minor bugfixes next is testing and implementation
This commit is contained in:
parent
6c455fe30b
commit
8b7815500e
10 changed files with 267 additions and 15 deletions
28
db/base.py
Normal file
28
db/base.py
Normal 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])
|
||||
Loading…
Add table
Add a link
Reference in a new issue