Esempio n. 1
0
 
class IntegerDateTime(TypeDecorator):
    """
    Used for working with epoch timestamps.
 
    Converts datetimes into epoch on the way in.
    Converts epoch timestamps to datetimes on the way out.
    """
    impl = Integer()
    def process_bind_param(self, value, dialect):
        return mktime(value.timetuple())
    def process_result_value(self, value, dialect):
        return datetime.fromtimestamp(value)

QuasselDateTime = DateTime()
QuasselDateTime = QuasselDateTime.with_variant(IntegerDateTime(), 'sqlite')

class Base(object):
    def _filter_properties(self):
        # this function decides which properties should be exposed through repr
        # todo: don't show methods
        properties = self.__dict__.keys()
        for prop in properties:
            if not prop.startswith('_'):
                yield (prop, getattr(self, prop))
        return

    def __repr__(self):    
        prop_tuples = self._filter_properties()
        prop_string_tuples = ('{0}={1}'.format(*prop) for prop in prop_tuples)
        prop_output_string = ', '.join(prop_string_tuples)
Esempio n. 2
0
    Used for working with epoch timestamps.
 
    Converts datetimes into epoch on the way in.
    Converts epoch timestamps to datetimes on the way out.
    """
    impl = Integer()

    def process_bind_param(self, value, dialect):
        return mktime(value.timetuple())

    def process_result_value(self, value, dialect):
        return datetime.fromtimestamp(value)


QuasselDateTime = DateTime()
QuasselDateTime = QuasselDateTime.with_variant(IntegerDateTime(), 'sqlite')


class Base(object):
    def _filter_properties(self):
        # this function decides which properties should be exposed through repr
        # todo: don't show methods
        properties = self.__dict__.keys()
        for prop in properties:
            if not prop.startswith('_'):
                yield (prop, getattr(self, prop))
        return

    def __repr__(self):
        prop_tuples = self._filter_properties()
        prop_string_tuples = ('{0}={1}'.format(*prop) for prop in prop_tuples)
Esempio n. 3
0
from flask_sqlalchemy import SQLAlchemy as _BaseSQLAlchemy
from flask_migrate import Migrate

# Recommended naming convensions to make possible to autogenerate migrations
# See http://alembic.zzzcomputing.com/en/latest/naming.html
NAMING_CONVENSION = {
    "ix": 'ix_%(column_0_label)s',
    'uq': 'uq_%(table_name)s_%(column_0_name)s',
    'ck': 'ck_%(table_name)s_%(column_0_name)s',
    'fk': 'fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s',
    'pk': 'pk_%(table_name)s'
}

# Prevent constant migrations from sa.DateTime(timezone=True) to mysql.DATETIME().
DATETIME_TYPE = DateTime(timezone=True)
DATETIME_TYPE = DATETIME_TYPE.with_variant(mysql.DATETIME(), 'mysql')
# mysql boolean
BOOLEAN_TYPE = Boolean()
BOOLEAN_TYPE = BOOLEAN_TYPE.with_variant(mysql.TINYINT(display_width=1),
                                         'mysql')
# Unsigned integer.
UNSIGNEDINT_TYPE = Integer()
UNSIGNEDINT_TYPE = UNSIGNEDINT_TYPE.with_variant(mysql.INTEGER(unsigned=True),
                                                 'mysql')
# Unsigned integer.
UNSIGNEDSMALLINT_TYPE = SmallInteger()
UNSIGNEDSMALLINT_TYPE = UNSIGNEDSMALLINT_TYPE.with_variant(
    mysql.SMALLINT(unsigned=True), 'mysql')


# The “pre ping” feature will normally emit SQL equivalent to “SELECT 1” each time a connection is checked out