# Path: database.py
# def get_session():
# def teardown_session(exception):
# 
# Path: models/document.py
# class Document(TableBase):
#     """An object refer to an actual plugin-managed document.
# 
#     Every actual document is not only saved in plugins' table, but also has an entry here, so that we can easily get all documents belong to a specific user."""
# 
#     __tablename__ = 'document'
# 
#     def __init__(self, plugin_name: str, doc: PluginDocument):
#         super().__init__()
#         self.owner = doc.owner
#         self.plugin_name = plugin_name
#         self.plugin_document_id = doc.id
# 
#     document_id = Column(Integer(), primary_key=True)
#     owner = Column(Integer(), ForeignKey('user.id'))
#     plugin_name = Column(String(256))
#     plugin_document_id = Column(Integer())
# 
# Path: models/plugin_document.py
# class PluginDocument(object):
#     """Abstract class for all plugins to make their own document type."""
# 
#     def __init__(self):
#         super().__init__()
#         if self.__class__ is PluginDocument:
#             raise NotImplementedError
# 
#     id = Column(Integer(), primary_key=True)
#     @declared_attr
#     def owner(cls):
#         return Column(Integer(), ForeignKey('user.id'))
#     title = Column(String(256))
#     last_modified = Column(Integer())
#     description = Column(Text())


import importlib
import app
from database import session, engine
from models import Document, PluginDocument
        self.document_table = None

    def set_document_type(self, name: str):
        self.type_name = name

    def set_document_table(self, table):
        self.document_table = table
        try:
            table.__table__.create(engine)
        except:
            pass

    def get(self, pid):
        return session.query(self.document_table).get(pid)

    def list(self, owner):
        return session.query(self.document_table).filter(self.document_table.owner == owner).all()

    def create(self, pdoc: PluginDocument):
        session.add(pdoc)
        session.commit()
        doc = Document(self.plugin.name, pdoc)
        session.add(doc)
        session.commit()

    @staticmethod
    def update(pdoc: PluginDocument):
        session.add(pdoc)
        session.commit()


# Path: database.py
# def get_session():
# def teardown_session(exception):
# 
# Path: models/document.py
# class Document(TableBase):
#     """An object refer to an actual plugin-managed document.
# 
#     Every actual document is not only saved in plugins' table, but also has an entry here, so that we can easily get all documents belong to a specific user."""
# 
#     __tablename__ = 'document'
# 
#     def __init__(self, plugin_name: str, doc: PluginDocument):
#         super().__init__()
#         self.owner = doc.owner
#         self.plugin_name = plugin_name
#         self.plugin_document_id = doc.id
# 
#     document_id = Column(Integer(), primary_key=True)
#     owner = Column(Integer(), ForeignKey('user.id'))
#     plugin_name = Column(String(256))
#     plugin_document_id = Column(Integer())
# 
# Path: models/plugin_document.py
# class PluginDocument(object):
#     """Abstract class for all plugins to make their own document type."""
# 
#     def __init__(self):
#         super().__init__()
#         if self.__class__ is PluginDocument:
#             raise NotImplementedError
# 
#     id = Column(Integer(), primary_key=True)
#     @declared_attr
#     def owner(cls):
#         return Column(Integer(), ForeignKey('user.id'))
#     title = Column(String(256))
#     last_modified = Column(Integer())
#     description = Column(Text())


# Path: plugin.py
import importlib
import app
from database import session, engine
from models import Document, PluginDocument

        self.document_table = None

    def set_document_type(self, name: str):
        self.type_name = name

    def set_document_table(self, table):
        self.document_table = table
        try:
            table.__table__.create(engine)
        except:
            pass

    def get(self, pid):
        return session.query(self.document_table).get(pid)

    def list(self, owner):
        return session.query(self.document_table).filter(self.document_table.owner == owner).all()

    def create(self, pdoc: PluginDocument):
        session.add(pdoc)
        session.commit()
        doc = Document(self.plugin.name, pdoc)
        session.add(doc)
        session.commit()

    @staticmethod
    def update(pdoc: PluginDocument):
        session.add(pdoc)
        session.commit()


    def delete(self, pdoc: PluginDocument):