# Path: scribeui_pyramid/modules/app/interfaces.py
# class IDBSession(Interface):
#     pass


from datetime import (
    date,
    datetime
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import (
    scoped_session,
    sessionmaker,
)
from sqlalchemy import engine_from_config
from zope.sqlalchemy import ZopeTransactionExtension
from .interfaces import IDBSession
import sqlalchemy as sa

    @classmethod
    def all(cls, page=None, limit=None):
        """Get all objects from the system

        :param page: pagination page number. Start at 1.

        :param limit: pagination page limit. Start at 1.
        """

        query = DBSession.query(cls)

        if limit:
            query = query.limit(limit)
        if page and limit:
            offset = (page - 1) * limit
            query = query.offset(offset)

        return query.all()

    @classmethod
    def by_id(cls, id):
        """Get an object from the system via the id"""

        return cls.query.filter(cls.id == id).one()


def includeme(config):
    settings = config.registry.settings
    init_sqla(settings)

# Path: scribeui_pyramid/modules/app/interfaces.py
# class IDBSession(Interface):
#     pass


# Path: scribeui_pyramid/modules/app/sqla.py
from datetime import (
    date,
    datetime
)
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import (
    scoped_session,
    sessionmaker,
)
from sqlalchemy import engine_from_config
from zope.sqlalchemy import ZopeTransactionExtension
from .interfaces import IDBSession
import sqlalchemy as sa


    @classmethod
    def all(cls, page=None, limit=None):
        """Get all objects from the system

        :param page: pagination page number. Start at 1.

        :param limit: pagination page limit. Start at 1.
        """

        query = DBSession.query(cls)

        if limit:
            query = query.limit(limit)
        if page and limit:
            offset = (page - 1) * limit
            query = query.offset(offset)

        return query.all()

    @classmethod
    def by_id(cls, id):
        """Get an object from the system via the id"""

        return cls.query.filter(cls.id == id).one()


def includeme(config):
    settings = config.registry.settings
    init_sqla(settings)

    config.registry.registerUtility(DBSession, IDBSession)