Exemple #1
0
class ParentsSchema(dpTable):
    __table_name__ = 'parents'

    __engine__ = 'InnoDB'
    __charset__ = 'utf8'

    parent_id = dpAttribute.field(dpAttribute.DataType.BIGINT,
                                  ai=True,
                                  pk=1,
                                  nn=True,
                                  un=True,
                                  comment='Parent ID')
    parent_name = dpAttribute.field(dpAttribute.DataType.VARCHAR(128),
                                    nn=True,
                                    comment='Parent Name')
    parent_type = dpAttribute.field(dpAttribute.DataType.ENUM(
        'FATHER', 'MOTHER'),
                                    nn=True,
                                    default='FATHER',
                                    comment='Parent Type')

    year_of_birth = dpAttribute.field(dpAttribute.DataType.INT,
                                      nn=False,
                                      comment='Year of Birth')  # Test
    datetime_of_birth = dpAttribute.field(dpAttribute.DataType.DATETIME,
                                          nn=False,
                                          comment='Datetime of Birth')  # Test

    primary_key = dpAttribute.index(dpAttribute.IndexType.PRIMARY, 'parent_id')

    idx_parents_parent_type = dpAttribute.index(dpAttribute.IndexType.INDEX,
                                                'parent_type')
    idx_parents_parent_name_type = dpAttribute.index(
        dpAttribute.IndexType.INDEX, ('parent_name', 'parent_type'))
Exemple #2
0
class ChildsSchema(dpTable):
    __table_name__ = 'childs'

    __engine__ = 'InnoDB'

    child_id = dpAttribute.field(dpAttribute.DataType.BIGINT, ai=True, pk=True, nn=True, un=True, comment='Child ID')
    parent_id = dpAttribute.field(dpAttribute.DataType.BIGINT, nn=True, un=True, comment='Parent ID')
    child_name = dpAttribute.field(dpAttribute.DataType.VARCHAR(128), nn=True, comment='Child Name')
    child_type = dpAttribute.field(dpAttribute.DataType.ENUM('BOY', 'GIRL'), nn=True, default='GIRL', comment='Child Type')
    child_age = dpAttribute.field(dpAttribute.DataType.INT, nn=True, un=True, default=1, comment='Child Age')

    primary_key = dpAttribute.index(dpAttribute.IndexType.PRIMARY, 'child_id')

    idx_parents_child_type = dpAttribute.index(dpAttribute.IndexType.INDEX, 'child_type')
    idx_parents_child_name_type = dpAttribute.index(dpAttribute.IndexType.INDEX, ('child_name', 'child_type'))
    idx_parents_child_age = dpAttribute.index(dpAttribute.IndexType.INDEX, 'child_age')

    fk_childs_parent_id = dpAttribute.foreign_key(('parent_id', dpSchema.field().tests.unittest.parents, 'parent_id'))
Exemple #3
0
class FirstSchema(dpTable):
    __table_name__ = 'migration'

    migration_id = dpAttribute.field(dpAttribute.DataType.BIGINT,
                                     ai=True,
                                     pk=True,
                                     nn=True,
                                     un=True,
                                     comment='Migration ID')
    migration_name = dpAttribute.field(dpAttribute.DataType.CHAR(128),
                                       nn=True,
                                       comment='Migration Name (char)')
    migration_type = dpAttribute.field(dpAttribute.DataType.ENUM(
        'AUTO', 'MANUAL'),
                                       nn=True,
                                       default='AUTO',
                                       comment='Migration Type')
    signdate = dpAttribute.field(dpAttribute.DataType.INT,
                                 nn=True,
                                 comment='Signdate')
Exemple #4
0
class ChildToysSchema(dpTable):
    __table_name__ = 'child_toys'

    __engine__ = 'InnoDB'

    child_id = dpAttribute.field(dpAttribute.DataType.BIGINT,
                                 pk=1,
                                 nn=True,
                                 un=True,
                                 comment='Child ID')
    toy_id = dpAttribute.field(dpAttribute.DataType.BIGINT,
                               pk=2,
                               nn=True,
                               un=True,
                               uq=True,
                               comment='Toy ID')

    primary_key = dpAttribute.index(dpAttribute.IndexType.PRIMARY,
                                    ('child_id', 'toy_id'))

    fk_child_toys_child_id = dpAttribute.foreign_key(
        ('child_id', dpSchema.field().tests.unittest.childs, 'child_id'))
    fk_child_toys_toy_id = dpAttribute.foreign_key(
        ('toy_id', dpSchema.field().tests.unittest.toys, 'toy_id'))

    uk_child_toys_toy_id = dpAttribute.index(dpAttribute.IndexType.UNIQUE,
                                             'toy_id')
Exemple #5
0
class ToysSchema(dpTable):
    __table_name__ = 'toys'

    __engine__ = 'InnoDB'
    __charset__ = 'euckr'

    toy_id = dpAttribute.field(dpAttribute.DataType.BIGINT,
                               ai=True,
                               pk=True,
                               nn=True,
                               un=True,
                               comment='Toy ID')
    toy_cd = dpAttribute.field(dpAttribute.DataType.BIGINT(20),
                               uq=True,
                               nn=True,
                               zf=True,
                               un=True,
                               name='toy_code',
                               comment='Toy Code')
    toy_name = dpAttribute.field(dpAttribute.DataType.VARCHAR(128),
                                 nn=True,
                                 comment='Toy Name')
    toy_summary = dpAttribute.field(dpAttribute.DataType.TEXT,
                                    nn=True,
                                    comment='Toy Summary')
    toy_description = dpAttribute.field(dpAttribute.DataType.LONGTEXT,
                                        nn=True,
                                        comment='Toy Description')

    primary_key = dpAttribute.index(dpAttribute.IndexType.PRIMARY, 'toy_id')

    idx_toys_toy_name = dpAttribute.index(dpAttribute.IndexType.INDEX,
                                          'toy_name')

    __dummy_data__ = [{
        'toy_id': 1,
        'toy_code': 1000,
        'toy_name': 'Lego',
        'toy_summary': 'Lego Limited Edition',
        'toy_description': 'Lego Limited Edition.'
    }, {
        'toy_id': 2,
        'toy_code': 2000,
        'toy_name': 'Teddy Bear',
        'toy_summary': 'Teddy Bear Limited Edition',
        'toy_description': 'Teddy Bear Limited Edition.'
    }]
Exemple #6
0
class FieldsSchema(dpTable):
    __table_name__ = 'fields'

    __engine__ = 'MyISAM'

    PK = dpAttribute.field(dpAttribute.DataType.BIGINT, ai=True, pk=True, nn=True, un=True, comment='Primary Key')

    INT = dpAttribute.field(dpAttribute.DataType.INT)
    TINYINT = dpAttribute.field(dpAttribute.DataType.TINYINT)
    SMALLINT = dpAttribute.field(dpAttribute.DataType.SMALLINT)
    MEDIUMINT = dpAttribute.field(dpAttribute.DataType.MEDIUMINT)
    BIGINT = dpAttribute.field(dpAttribute.DataType.BIGINT)
    DOUBLE = dpAttribute.field(dpAttribute.DataType.DOUBLE)
    FLOAT = dpAttribute.field(dpAttribute.DataType.FLOAT)
    DECIMAL = dpAttribute.field(dpAttribute.DataType.DECIMAL(10, 2))

    CHAR = dpAttribute.field(dpAttribute.DataType.CHAR(8))
    VARCHAR = dpAttribute.field(dpAttribute.DataType.VARCHAR(32))
    TEXT = dpAttribute.field(dpAttribute.DataType.TEXT)
    TINYTEXT = dpAttribute.field(dpAttribute.DataType.TINYTEXT)
    MEDIUMTEXT = dpAttribute.field(dpAttribute.DataType.MEDIUMTEXT)
    LONGTEXT = dpAttribute.field(dpAttribute.DataType.LONGTEXT)

    ENUM = dpAttribute.field(dpAttribute.DataType.ENUM('A', 'B', 'C', 'D'))

    BLOB = dpAttribute.field(dpAttribute.DataType.BLOB)
    LONGBLOB = dpAttribute.field(dpAttribute.DataType.LONGBLOB)
    MEDIUMBLOB = dpAttribute.field(dpAttribute.DataType.MEDIUMBLOB)
    TINYBLOB = dpAttribute.field(dpAttribute.DataType.TINYBLOB)

    DATETIME = dpAttribute.field(dpAttribute.DataType.DATETIME)
    DATE = dpAttribute.field(dpAttribute.DataType.DATE)
    TIME = dpAttribute.field(dpAttribute.DataType.TIME)
    TIMESTAMP = dpAttribute.field(dpAttribute.DataType.TIMESTAMP)
    YEAR = dpAttribute.field(dpAttribute.DataType.YEAR)

    BINARY = dpAttribute.field(dpAttribute.DataType.BINARY(6))
    VARBINARY = dpAttribute.field(dpAttribute.DataType.VARBINARY(64))

    idx_fields_char = dpAttribute.index(dpAttribute.IndexType.FULLTEXT, 'CHAR')
    idx_fields_varchar = dpAttribute.index(dpAttribute.IndexType.FULLTEXT, 'VARCHAR')
Exemple #7
0
class FieldsSchema(dpTable):
    __table_name__ = 'fields'

    PK = dpAttribute.field(dpAttribute.DataType.BIGINT,
                           ai=True,
                           pk=True,
                           nn=True,
                           un=True,
                           comment='Primary Key')

    int_field = dpAttribute.field(dpAttribute.DataType.INT, name='int_field')
    tinyint_field = dpAttribute.field(dpAttribute.DataType.TINYINT, nn=True)
    smallint_field = dpAttribute.field(dpAttribute.DataType.SMALLINT)
    mediumint_field = dpAttribute.field(dpAttribute.DataType.MEDIUMINT)
    bigint_field = dpAttribute.field(dpAttribute.DataType.BIGINT)
    double_field = dpAttribute.field(dpAttribute.DataType.DOUBLE)
    float_field = dpAttribute.field(dpAttribute.DataType.FLOAT)
    decimal_field = dpAttribute.field(dpAttribute.DataType.DECIMAL(10, 2))

    char_field = dpAttribute.field(dpAttribute.DataType.CHAR(8))
    varchar_field = dpAttribute.field(dpAttribute.DataType.VARCHAR(32))
    text_field = dpAttribute.field(dpAttribute.DataType.TEXT)
    tinytext_field = dpAttribute.field(dpAttribute.DataType.TINYTEXT)
    mediumtext_field = dpAttribute.field(dpAttribute.DataType.MEDIUMTEXT)
    longtext_field = dpAttribute.field(dpAttribute.DataType.LONGTEXT)

    enum_field = dpAttribute.field(
        dpAttribute.DataType.ENUM('A', 'B', 'C',
                                  'D'))  # NOT SUPPORTED, Ignored

    blob_field = dpAttribute.field(dpAttribute.DataType.BLOB)
    longblob_field = dpAttribute.field(dpAttribute.DataType.LONGBLOB)
    mediumblob_field = dpAttribute.field(dpAttribute.DataType.MEDIUMBLOB)
    tinyblob_field = dpAttribute.field(dpAttribute.DataType.TINYBLOB)

    datetime_field = dpAttribute.field(
        dpAttribute.DataType.DATETIME)  # NOT SUPPORTED, Ignored
    date_field = dpAttribute.field(
        dpAttribute.DataType.DATE)  # NOT SUPPORTED, Ignored
    time_field = dpAttribute.field(
        dpAttribute.DataType.TIME)  # NOT SUPPORTED, Ignored
    timestamp_field = dpAttribute.field(
        dpAttribute.DataType.TIMESTAMP)  # NOT SUPPORTED, Ignored
    year_field = dpAttribute.field(
        dpAttribute.DataType.YEAR)  # NOT SUPPORTED, Ignored

    binary_field = dpAttribute.field(dpAttribute.DataType.BINARY(6))
    varbinary_field = dpAttribute.field(dpAttribute.DataType.VARBINARY(64))

    uq_fields_int_smallint = dpAttribute.index(dpAttribute.IndexType.UNIQUE,
                                               ('int_field', 'smallint_field'))
    uq_fields_int_char = dpAttribute.index(dpAttribute.IndexType.UNIQUE,
                                           ('int_field', 'char_field'))

    idx_fields_int_tinyint = dpAttribute.index(dpAttribute.IndexType.INDEX,
                                               ('int_field', 'tinyint_field'))
    idx_fields_char = dpAttribute.index(dpAttribute.IndexType.FULLTEXT,
                                        'char_field')
    idx_fields_varchar = dpAttribute.index(dpAttribute.IndexType.FULLTEXT,
                                           'varchar_field')

    __dummy_data__ = [{
        'PK': 1,
        'tinyint_field': 100,
        'longtext_field': 'Foo'
    }, {
        'PK': 2,
        'tinyint_field': 101,
        'longtext_field': 'Bar'
    }, {
        'PK': 3,
        'tinyint_field': 102,
        'longtext_field': 'Baz'
    }]
Exemple #8
0
    def _get_exist(proxy, table):
        table_name = table.__table_name__

        output = {
            'col': {},
            'ix': [],  # Index objects
            'ik': [],  # Index Keys
            'fk': [],  # Foreign Keys
            'pk': []   # Priamry Keys
        }

        if not proxy.scalar('SHOW TABLES LIKE %s', table_name):
            return output

        offset = 0
        create_table = proxy.row(
            'SHOW CREATE TABLE `{table_name}`'.replace('{table_name}', table_name))[1].split('\n')[1:-1]

        for e in create_table:
            attrs = e.strip()

            if attrs.startswith('`'):
                continue

            if attrs.upper().startswith('KEY'):
                keys = [e[1:-1] for e in attrs[attrs.find('(')+1:attrs.rfind(')')].split(',')]
                output['ix'].append(dpAttribute.index(dpAttribute.IndexType.INDEX, keys))
                output['ik'].append(keys)

            elif attrs.upper().startswith('PRIMARY KEY'):
                keys = [e[1:-1] for e in attrs[attrs.find('(') + 1:attrs.rfind(')')].split(',')]
                output['ix'].append(dpAttribute.index(dpAttribute.IndexType.PRIMARY, keys))
                output['ik'].append(keys)
                output['pk'] = keys

            elif attrs.upper().startswith('UNIQUE KEY'):
                keys = [e[1:-1] for e in attrs[attrs.find('(') + 1:attrs.rfind(')')].split(',')]
                output['ix'].append(dpAttribute.index(dpAttribute.IndexType.UNIQUE, keys))
                output['ik'].append(keys)
                output['pk'] = keys

            elif attrs.upper().startswith('FULLTEXT KEY'):
                keys = [e[1:-1] for e in attrs[attrs.find('(') + 1:attrs.rfind(')')].split(',')]
                output['ix'].append(dpAttribute.index(dpAttribute.IndexType.FULLTEXT, keys))
                output['ik'].append(keys)

            elif attrs.upper().startswith('CONSTRAINT'):
                v, i = MySqlDriver._get_field_attr(attrs, 0)
                fk_name, i = MySqlDriver._get_field_attr(attrs, i)
                foreign, i = MySqlDriver._get_field_attr(attrs, i)
                key, i = MySqlDriver._get_field_attr(attrs, i)

                if foreign.upper() != 'FOREIGN' or key.upper() != 'KEY':
                    continue

                source_col, i = MySqlDriver._get_field_attr(attrs, i)
                dummy, i = MySqlDriver._get_field_attr(attrs, i)
                dest_table, i = MySqlDriver._get_field_attr(attrs, i)
                dest_col, i = MySqlDriver._get_field_attr(attrs, i)

                source_col = [e[1:-1] for e in source_col[1:-1].split(',')]
                dest_table = dest_table[1:-1]
                dest_col = [e[1:-1] for e in dest_col[1:-1].split(',')]

                output['fk'].append((source_col, dest_table, dest_col))

        for e in create_table:
            attrs = e.strip()
            attr = attrs

            if attr[-1] == ',':
                attr = attr[:-1]

            if not attrs.startswith('`'):
                break

            offset += 1

            i = attrs.find(' ')
            column_name = attrs[1:i-1]
            key = column_name

            data_type = None
            default = None
            comment = ''
            nn = None
            un = None
            zf = None
            ai = None

            prev = None
            i += 1

            while True:
                v, i = MySqlDriver._get_field_attr(attrs, i)

                if v is None:
                    break

                if v.strip().upper().startswith('INT('):
                    data_type = dpAttribute.DataType.INT(int(v[4:-1]))
                elif v.strip().upper().startswith('TINYINT('):
                    data_type = dpAttribute.DataType.TINYINT(int(v[8:-1]))
                elif v.strip().upper().startswith('SMALLINT('):
                    data_type = dpAttribute.DataType.SMALLINT(int(v[9:-1]))
                elif v.strip().upper().startswith('MEDIUMINT('):
                    data_type = dpAttribute.DataType.MEDIUMINT(int(v[10:-1]))
                elif v.strip().upper().startswith('BIGINT('):
                    data_type = dpAttribute.DataType.BIGINT(int(v[7:-1]))

                elif v.strip().upper().startswith('DOUBLE('):
                    data_type = dpAttribute.DataType.DOUBLE(int(v[7:-1]))
                elif v.strip().upper().startswith('DOUBLE'):
                    data_type = dpAttribute.DataType.DOUBLE
                elif v.strip().upper().startswith('FLOAT('):
                    data_type = dpAttribute.DataType.FLOAT(int(v[6:-1]))
                elif v.strip().upper().startswith('FLOAT'):
                    data_type = dpAttribute.DataType.FLOAT
                elif v.strip().upper().startswith('DECIMAL('):
                    m, d = v[8:-1].split(',')
                    data_type = dpAttribute.DataType.DECIMAL(int(m), int(d))

                elif v.strip().upper().startswith('CHAR('):
                    data_type = dpAttribute.DataType.CHAR(int(v[5:-1]))
                elif v.strip().upper().startswith('VARCHAR('):
                    data_type = dpAttribute.DataType.VARCHAR(int(v[8:-1]))

                elif v.strip().upper().startswith('TEXT'):
                    data_type = dpAttribute.DataType.TEXT()
                elif v.strip().upper().startswith('TINYTEXT'):
                    data_type = dpAttribute.DataType.TINYTEXT()
                elif v.strip().upper().startswith('MEDIUMTEXT'):
                    data_type = dpAttribute.DataType.MEDIUMTEXT()
                elif v.strip().upper().startswith('LONGTEXT'):
                    data_type = dpAttribute.DataType.LONGTEXT()

                elif v.strip().upper().startswith('BLOB'):
                    data_type = dpAttribute.DataType.BLOB()
                elif v.strip().upper().startswith('LONGBLOB'):
                    data_type = dpAttribute.DataType.LONGBLOB()
                elif v.strip().upper().startswith('MEDIUMBLOB'):
                    data_type = dpAttribute.DataType.MEDIUMBLOB()
                elif v.strip().upper().startswith('TINYBLOB'):
                    data_type = dpAttribute.DataType.TINYBLOB()

                elif v.strip().upper() == 'DATETIME':
                    data_type = dpAttribute.DataType.DATETIME
                elif v.strip().upper() == 'DATE':
                    data_type = dpAttribute.DataType.DATE
                elif v.strip().upper() == 'TIME':
                    data_type = dpAttribute.DataType.TIME
                elif v.strip().upper() == 'TIMESTAMP':
                    data_type = dpAttribute.DataType.TIMESTAMP
                elif v.strip().upper() == 'YEAR':
                    data_type = dpAttribute.DataType.YEAR
                elif v.strip().upper().startswith('YEAR('):
                    data_type = dpAttribute.DataType.YEAR(int(v[5:-1]))

                elif v.strip().upper().startswith('BINARY('):
                    data_type = dpAttribute.DataType.BINARY(int(v[7:-1]))
                elif v.strip().upper().startswith('VARBINARY('):
                    data_type = dpAttribute.DataType.VARBINARY(int(v[10:-1]))

                elif v.strip().upper().startswith('ENUM('):
                    data_type = dpAttribute.DataType.ENUM(*[(e[1:-1] if e[0] == "'" and e[-1] == "'" else e) for e in v[5:-1].split(',')])

                elif v.strip().upper() == 'UNSIGNED':
                    un = True

                elif v.strip().upper() == 'ZEROFILL':
                    zf = True

                elif v.strip().upper() == 'NULL':
                    if prev == 'NOT':
                        nn = True

                elif v.strip().upper() == 'DEFAULT':
                    default, i = MySqlDriver._get_field_attr(attrs, i)
                    default = default[1:-1] if default[0] == "'" and default[-1] == "'" else default
                    default = default if default and default.upper() != 'NULL' else None

                elif v.strip().upper() == 'AUTO_INCREMENT':
                    ai = True

                elif v.strip().upper() == 'COMMENT':
                    comment, i = MySqlDriver._get_field_attr(attrs, i)

                prev = v.upper()

            if comment and comment.endswith('}') and comment.rfind('{') != -1:
                id_idx = comment.rfind('{')
                key = comment[id_idx+1:-1]
                comment = comment[:id_idx-1]

            output['col'][key] = dpAttribute.field(
                data_type=data_type,
                name=column_name,
                default=default,
                nn=nn,
                un=un,
                zf=zf,
                ai=ai,
                comment=comment,
                query=attr)

        return output
Exemple #9
0
    def _get_exist(proxy, table):
        table_name = table.__table_name__

        output = {
            'col': {},
            'ix': [],  # Index objects
            'ik': [],  # Index Keys
            'fk': [],  # Foreign Keys
            'pk': []  # Priamry Keys
        }

        if not proxy.scalar('SHOW TABLES LIKE %s', table_name):
            return output

        offset = 0
        create_table = proxy.row('SHOW CREATE TABLE `{table_name}`'.replace(
            '{table_name}', table_name))[1].split('\n')[1:-1]

        for e in create_table:
            attrs = e.strip()

            if attrs.startswith('`'):
                continue

            if attrs.upper().startswith('KEY'):
                keys = [
                    e[1:-1] for e in attrs[attrs.find('(') +
                                           1:attrs.rfind(')')].split(',')
                ]
                output['ix'].append(
                    dpAttribute.index(dpAttribute.IndexType.INDEX, keys))
                output['ik'].append(keys)

            elif attrs.upper().startswith('PRIMARY KEY'):
                keys = [
                    e[1:-1] for e in attrs[attrs.find('(') +
                                           1:attrs.rfind(')')].split(',')
                ]
                output['ix'].append(
                    dpAttribute.index(dpAttribute.IndexType.PRIMARY, keys))
                output['ik'].append(keys)
                output['pk'] = keys

            elif attrs.upper().startswith('UNIQUE KEY'):
                keys = [
                    e[1:-1] for e in attrs[attrs.find('(') +
                                           1:attrs.rfind(')')].split(',')
                ]
                output['ix'].append(
                    dpAttribute.index(dpAttribute.IndexType.UNIQUE, keys))
                output['ik'].append(keys)
                output['pk'] = keys

            elif attrs.upper().startswith('FULLTEXT KEY'):
                keys = [
                    e[1:-1] for e in attrs[attrs.find('(') +
                                           1:attrs.rfind(')')].split(',')
                ]
                output['ix'].append(
                    dpAttribute.index(dpAttribute.IndexType.FULLTEXT, keys))
                output['ik'].append(keys)

            elif attrs.upper().startswith('CONSTRAINT'):
                v, i = MySqlDriver._get_field_attr(attrs, 0)
                fk_name, i = MySqlDriver._get_field_attr(attrs, i)
                foreign, i = MySqlDriver._get_field_attr(attrs, i)
                key, i = MySqlDriver._get_field_attr(attrs, i)

                if foreign.upper() != 'FOREIGN' or key.upper() != 'KEY':
                    continue

                source_col, i = MySqlDriver._get_field_attr(attrs, i)
                dummy, i = MySqlDriver._get_field_attr(attrs, i)
                dest_table, i = MySqlDriver._get_field_attr(attrs, i)
                dest_col, i = MySqlDriver._get_field_attr(attrs, i)

                source_col = [e[1:-1] for e in source_col[1:-1].split(',')]
                dest_table = dest_table[1:-1]
                dest_col = [e[1:-1] for e in dest_col[1:-1].split(',')]

                output['fk'].append((source_col, dest_table, dest_col))

        for e in create_table:
            attrs = e.strip()
            attr = attrs

            if attr[-1] == ',':
                attr = attr[:-1]

            if not attrs.startswith('`'):
                break

            offset += 1

            i = attrs.find(' ')
            column_name = attrs[1:i - 1]
            key = column_name

            data_type = None
            default = None
            comment = ''
            nn = None
            un = None
            zf = None
            ai = None

            prev = None
            i += 1

            while True:
                v, i = MySqlDriver._get_field_attr(attrs, i)

                if v is None:
                    break

                if v.strip().upper().startswith('INT('):
                    data_type = dpAttribute.DataType.INT(int(v[4:-1]))
                elif v.strip().upper().startswith('TINYINT('):
                    data_type = dpAttribute.DataType.TINYINT(int(v[8:-1]))
                elif v.strip().upper().startswith('SMALLINT('):
                    data_type = dpAttribute.DataType.SMALLINT(int(v[9:-1]))
                elif v.strip().upper().startswith('MEDIUMINT('):
                    data_type = dpAttribute.DataType.MEDIUMINT(int(v[10:-1]))
                elif v.strip().upper().startswith('BIGINT('):
                    data_type = dpAttribute.DataType.BIGINT(int(v[7:-1]))

                elif v.strip().upper().startswith('DOUBLE('):
                    data_type = dpAttribute.DataType.DOUBLE(int(v[7:-1]))
                elif v.strip().upper().startswith('DOUBLE'):
                    data_type = dpAttribute.DataType.DOUBLE
                elif v.strip().upper().startswith('FLOAT('):
                    data_type = dpAttribute.DataType.FLOAT(int(v[6:-1]))
                elif v.strip().upper().startswith('FLOAT'):
                    data_type = dpAttribute.DataType.FLOAT
                elif v.strip().upper().startswith('DECIMAL('):
                    m, d = v[8:-1].split(',')
                    data_type = dpAttribute.DataType.DECIMAL(int(m), int(d))

                elif v.strip().upper().startswith('CHAR('):
                    data_type = dpAttribute.DataType.CHAR(int(v[5:-1]))
                elif v.strip().upper().startswith('VARCHAR('):
                    data_type = dpAttribute.DataType.VARCHAR(int(v[8:-1]))

                elif v.strip().upper().startswith('TEXT'):
                    data_type = dpAttribute.DataType.TEXT()
                elif v.strip().upper().startswith('TINYTEXT'):
                    data_type = dpAttribute.DataType.TINYTEXT()
                elif v.strip().upper().startswith('MEDIUMTEXT'):
                    data_type = dpAttribute.DataType.MEDIUMTEXT()
                elif v.strip().upper().startswith('LONGTEXT'):
                    data_type = dpAttribute.DataType.LONGTEXT()

                elif v.strip().upper().startswith('BLOB'):
                    data_type = dpAttribute.DataType.BLOB()
                elif v.strip().upper().startswith('LONGBLOB'):
                    data_type = dpAttribute.DataType.LONGBLOB()
                elif v.strip().upper().startswith('MEDIUMBLOB'):
                    data_type = dpAttribute.DataType.MEDIUMBLOB()
                elif v.strip().upper().startswith('TINYBLOB'):
                    data_type = dpAttribute.DataType.TINYBLOB()

                elif v.strip().upper() == 'DATETIME':
                    data_type = dpAttribute.DataType.DATETIME
                elif v.strip().upper() == 'DATE':
                    data_type = dpAttribute.DataType.DATE
                elif v.strip().upper() == 'TIME':
                    data_type = dpAttribute.DataType.TIME
                elif v.strip().upper() == 'TIMESTAMP':
                    data_type = dpAttribute.DataType.TIMESTAMP
                elif v.strip().upper() == 'YEAR':
                    data_type = dpAttribute.DataType.YEAR
                elif v.strip().upper().startswith('YEAR('):
                    data_type = dpAttribute.DataType.YEAR(int(v[5:-1]))

                elif v.strip().upper().startswith('BINARY('):
                    data_type = dpAttribute.DataType.BINARY(int(v[7:-1]))
                elif v.strip().upper().startswith('VARBINARY('):
                    data_type = dpAttribute.DataType.VARBINARY(int(v[10:-1]))

                elif v.strip().upper().startswith('ENUM('):
                    data_type = dpAttribute.DataType.ENUM(
                        *[(e[1:-1] if e[0] == "'" and e[-1] == "'" else e)
                          for e in v[5:-1].split(',')])

                elif v.strip().upper() == 'UNSIGNED':
                    un = True

                elif v.strip().upper() == 'ZEROFILL':
                    zf = True

                elif v.strip().upper() == 'NULL':
                    if prev == 'NOT':
                        nn = True

                elif v.strip().upper() == 'DEFAULT':
                    default, i = MySqlDriver._get_field_attr(attrs, i)
                    default = default[1:-1] if default[0] == "'" and default[
                        -1] == "'" else default
                    default = default if default and default.upper(
                    ) != 'NULL' else None

                elif v.strip().upper() == 'AUTO_INCREMENT':
                    ai = True

                elif v.strip().upper() == 'COMMENT':
                    comment, i = MySqlDriver._get_field_attr(attrs, i)

                prev = v.upper()

            if comment and comment.endswith('}') and comment.rfind('{') != -1:
                id_idx = comment.rfind('{')
                key = comment[id_idx + 1:-1]
                comment = comment[:id_idx - 1]

            output['col'][key] = dpAttribute.field(data_type=data_type,
                                                   name=column_name,
                                                   default=default,
                                                   nn=nn,
                                                   un=un,
                                                   zf=zf,
                                                   ai=ai,
                                                   comment=comment,
                                                   query=attr)

        return output
Exemple #10
0
class ArticlesSchema(dpTable):
    __table_name__ = 'articles'

    article_id = dpAttribute.field(dpAttribute.DataType.INT,
                                   ai=True,
                                   pk=True,
                                   nn=True,
                                   un=True,
                                   comment='Article ID')
    title = dpAttribute.field(dpAttribute.DataType.VARCHAR(128),
                              nn=True,
                              comment='Title')
    content = dpAttribute.field(dpAttribute.DataType.LONGTEXT,
                                nn=True,
                                comment='Content')
    author = dpAttribute.field(dpAttribute.DataType.VARCHAR(64),
                               comment='Author')
    signdate = dpAttribute.field(dpAttribute.DataType.INT, comment='Signdate')

    idx_articles_title = dpAttribute.index(dpAttribute.IndexType.INDEX,
                                           'title')
    idx_articles_author = dpAttribute.index(dpAttribute.IndexType.INDEX,
                                            'author')
    idx_articles_signdate = dpAttribute.index(dpAttribute.IndexType.INDEX,
                                              'signdate')

    __dummy_data__ = [{
        'article_id': 1,
        'title': 'Helloworld!',
        'content': 'Hello!',
        'author': 'James',
        'signdate': 1478772800
    }, {
        'article_id': 2,
        'title': 'Hi!',
        'content': 'Hi! Nice to meet you!',
        'author': 'Amber',
        'signdate': 1478782800
    }, {
        'article_id': 3,
        'title': 'Nice to meet you!',
        'content': 'Hello. Nice to meet you!',
        'author': 'Alice',
        'signdate': 1478792800
    }, {
        'article_id': 4,
        'title': 'Good morning!',
        'content': 'Hi! Good morning!',
        'author': 'Elsa',
        'signdate': 1478802800
    }, {
        'article_id': 5,
        'title': 'Good afternoon!',
        'content': 'Hi! Good afternoon!',
        'author': 'Kevin',
        'signdate': 1478812800
    }, {
        'article_id': 6,
        'title': 'Good evening!',
        'content': 'Hi! Good evening!',
        'author': 'Sam',
        'signdate': 1478822800
    }, {
        'article_id': 7,
        'title': 'Good night!',
        'content': 'Hi! Good night!',
        'author': 'Thomas',
        'signdate': 1478832800
    }, {
        'article_id': 8,
        'title': 'What up!',
        'content': 'Hi! What up!',
        'author': 'Tim',
        'signdate': 1478842800
    }, {
        'article_id': 9,
        'title': 'Yo!',
        'content': 'Hi! Yo!',
        'author': 'William',
        'signdate': 1478852800
    }, {
        'article_id': 10,
        'title': 'Hor are you?',
        'content': 'Hi! What up!',
        'author': 'Oscar',
        'signdate': 1478862800
    }, {
        'article_id': 11,
        'title': 'Good bye!',
        'content': 'Hi! Good bye!',
        'author': 'Walter',
        'signdate': 1478872800
    }, {
        'article_id': 12,
        'title': 'See you again!',
        'content': 'Hi! See you again!',
        'author': 'Jackson',
        'signdate': 1478882800
    }, {
        'article_id': 13,
        'title': 'Hello!',
        'content': 'Hi! What up!',
        'author': 'Mike',
        'signdate': 1478892800
    }]