tinydb migration
This commit is contained in:
parent
7e8930faba
commit
b258194d6f
4 changed files with 195 additions and 158 deletions
|
|
@ -15,3 +15,24 @@ def setup():
|
|||
from stacosys.model.comment import Comment
|
||||
|
||||
get_db().create_tables([Site, Comment], safe=True)
|
||||
|
||||
from playhouse.shortcuts import model_to_dict
|
||||
import json
|
||||
|
||||
def tojson_model(comment):
|
||||
dcomment = model_to_dict(comment)
|
||||
del dcomment['site']
|
||||
tcomment = json.dumps(dcomment, indent=4, sort_keys=True, default=str)
|
||||
return json.loads(tcomment)
|
||||
|
||||
def tojson_models(models):
|
||||
print(json.dumps(list(models.dicts()), indent=4, sort_keys=True, default=str))
|
||||
|
||||
def dump_db():
|
||||
from tinydb import TinyDB, Query
|
||||
from stacosys.model.comment import Comment
|
||||
db = TinyDB('db.json')
|
||||
for comment in Comment.select():
|
||||
cc = tojson_model(comment)
|
||||
print(cc)
|
||||
db.insert(cc)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue