示例#1
0
    if 'note' in t:
        result['note'] = t['note']
    if 'default' in t:
        result['default'] = t['default'][0]
    if 'ref' in t:
        result['ref_blueprints'] = list(t['ref'])
    if 'comment' in t:
        result['comment'] = t['comment'][0]
    return result


column_settings.setParseAction(parse_column_settings)

constraint = pp.CaselessLiteral("unique") | pp.CaselessLiteral("pk")

table_column = _c + (name('name') + column_type('type') +
                     constraint[...]('constraints') + c +
                     column_settings('settings')[0, 1]) + n


def parse_column(s, l, t):
    '''
    address varchar(255) [unique, not null, note: 'to include unit number']
    '''
    init_dict = {
        'name': t['name'],
        'type_': t['type'],
    }
    # deprecated
    for constraint in t.get('constraints', []):
        if constraint == 'pk':
示例#2
0
import pyparsing as pp
from pydbml.definitions.generic import name, string_literal
from pydbml.definitions.common import _, _c, n, note
from pydbml.classes import Project, Note

pp.ParserElement.setDefaultWhitespaceChars(' \t\r')

project_field = pp.Group(name + _ + pp.Suppress(':') + _ - string_literal)

project_element = _ + (note | project_field) + _

project_body = project_element[...]

project = _c + (
    pp.CaselessLiteral('project') + _ -
    name('name') + _ +
    '{' + _ -
    project_body('items') + _ -
    '}'
) + (n | pp.StringEnd())


def parse_project(s, l, t):
    '''
    Project project_name {
      database_type: 'PostgreSQL'
      Note: 'Description of the project'
    }
    '''
    init_dict = {'name': t['name']}
    items = {}
示例#3
0
    if 'note' in t:
        result['note'] = t['note']
    if 'header_color' in t:
        result['header_color'] = t['header_color']
    return result


table_settings.setParseAction(parse_table_settings)

note_element = note | note_object

table_element = _ + (note_element('note') | indexes('indexes')) + _

table_body = table_column[1, ...]('columns') + _ + table_element[...]

table = _c + (pp.CaselessLiteral("table").suppress() + name('name') +
              alias('alias')[0, 1] + table_settings('settings')[0, 1] + _ +
              '{' - table_body + _ + '}') + end


def parse_table(s, l, t):
    '''
    Table bookings as bb [headercolor: #cccccc] {
      id integer
      country varchar [NOT NULL, ref: > countries.country_name]
      booking_date date unique pk
      created_at timestamp

      indexes {
          (id, country) [pk] // composite primary key
      }
示例#4
0
import pyparsing as pp
from pydbml.definitions.generic import name
from pydbml.definitions.common import _, _c, c, n
from pydbml.classes import ReferenceBlueprint

pp.ParserElement.setDefaultWhitespaceChars(' \t\r')

relation = pp.oneOf("> - <")
ref_inline = pp.Literal("ref:") - relation('type') - name(
    'table') - '.' - name('field')


def parse_inline_relation(s, l, t):
    '''
    ref: < table.column
    '''
    return ReferenceBlueprint(type_=t['type'],
                              table2=t['table'],
                              col2=t['field'])


ref_inline.setParseAction(parse_inline_relation)

on_option = (pp.CaselessLiteral('no action') | pp.CaselessLiteral('restrict')
             | pp.CaselessLiteral('cascade') | pp.CaselessLiteral('set null')
             | pp.CaselessLiteral('set default'))
update = pp.CaselessLiteral("update:").suppress() + _ + on_option
delete = pp.CaselessLiteral("delete:").suppress() + _ + on_option

ref_setting = _ + (update('update') | delete('delete')) + _
示例#5
0
import pyparsing as pp
from pydbml.definitions.generic import name
from pydbml.definitions.common import _, _c, end
from pydbml.classes import TableGroup

pp.ParserElement.setDefaultWhitespaceChars(' \t\r')

table_group = _c + (pp.CaselessLiteral('TableGroup') - name('name') + _ - '{' +
                    _ - (name + _)[...]('items') + _ - '}') + end


def parse_table_group(s, l, t):
    '''
    TableGroup tablegroup_name {
        table1
        table2
        table3
    }
    '''
    init_dict = {'name': t['name'], 'items': list(t.get('items', []))}
    if 'comment_before' in t:
        comment = '\n'.join(c[0] for c in t['comment_before'])
        init_dict['comment'] = comment
    return TableGroup(**init_dict)


table_group.setParseAction(parse_table_group)