# Path: flask_diamond/facets/database.py
# def init_database(self):


from ..facets.database import db
    @classmethod
    def loadf(cls, file_handle):
        "create a Model object from a file_handle pointing to a JSON file"
        return cls.loads(file_handle.read())

    # dump_all

    @classmethod
    def dump_all(cls):
        "write all objects of Model class to an array of python objects"
        return cls.__schema__().dump(cls.query.all(), many=True).data

    @classmethod
    def dumps_all(cls):
        "write all objects of Model class to a JSON-encoded array"
        return cls.__schema__().dumps(cls.query.all(), many=True).data

    @classmethod
    def dumpf_all(cls, file_handle):
        "write all objects of Model class to file_handle as JSON"
        file_handle.write(cls.dumps_all())

    # load_all

    @classmethod
    def load_all(cls, python_objects):
        "create objects of Model class from an array of python objects"
        objs = cls.__schema__().load(python_objects, many=True)
        for obj in objs.data:
            cls.create(_commit=False, **obj)

# Path: flask_diamond/facets/database.py
# def init_database(self):


# Path: flask_diamond/mixins/marshmallow.py
from ..facets.database import db

    @classmethod
    def loadf(cls, file_handle):
        "create a Model object from a file_handle pointing to a JSON file"
        return cls.loads(file_handle.read())

    # dump_all

    @classmethod
    def dump_all(cls):
        "write all objects of Model class to an array of python objects"
        return cls.__schema__().dump(cls.query.all(), many=True).data

    @classmethod
    def dumps_all(cls):
        "write all objects of Model class to a JSON-encoded array"
        return cls.__schema__().dumps(cls.query.all(), many=True).data

    @classmethod
    def dumpf_all(cls, file_handle):
        "write all objects of Model class to file_handle as JSON"
        file_handle.write(cls.dumps_all())

    # load_all

    @classmethod
    def load_all(cls, python_objects):
        "create objects of Model class from an array of python objects"
        objs = cls.__schema__().load(python_objects, many=True)
        for obj in objs.data:
            cls.create(_commit=False, **obj)

        db.session.commit()