def test_note(self) -> None: n = Note('Table note') t = Table('products', note=n) c = Column('id', 'integer') t.add_column(c) expected = 'CREATE TABLE "products" (\n -- Table note\n "id" integer\n);\n' self.assertEqual(t.sql, expected)
def test_note(self) -> None: t = Table('products') t.add_column(Column('id', 'integer')) n = Note('Index note') r = Index(subject_names=['id'], table=t, note=n) t.add_index(r) expected = 'CREATE INDEX ON "products" ("id"); -- Index note' self.assertEqual(r.sql, expected)
def test_notes(self) -> None: n = Note('EnumItem note') items = [ EnumItem('created', note=n), EnumItem('running'), EnumItem('donef', note=n), EnumItem('failure'), ] e = Enum('job_status', items) expected = \ '''CREATE TYPE "job_status" AS ENUM ( 'created', -- EnumItem note 'running', 'donef', -- EnumItem note 'failure', );''' self.assertEqual(e.sql, expected)
from pydbml.classes import Note from .generic import string_literal pp.ParserElement.setDefaultWhitespaceChars(' \t\r') comment = pp.Suppress("//") + pp.SkipTo(pp.LineEnd()) # optional comment or newline _ = ('\n' | comment)[...].suppress() # optional comment or newline, but comments are captured _c = (pp.Suppress('\n') | comment('comment_before*'))[...] # optional captured comment c = comment('comment')[0, 1] n = pp.LineEnd() end = n | pp.StringEnd() # obligatory newline # n = pp.Suppress('\n')[1, ...] note = pp.CaselessLiteral("note:") + _ - string_literal('text') note.setParseAction(lambda s, l, t: Note(t['text'])) note_object = pp.CaselessLiteral('note') + _ - '{' + _ - string_literal('text') + _ - '}' note_object.setParseAction(lambda s, l, t: Note(t['text'])) pk = pp.CaselessLiteral("pk") unique = pp.CaselessLiteral("unique")
def test_note(self) -> None: n = Note('Column note') r = Column(name='id', type_='integer', note=n) expected = '"id" integer -- Column note' self.assertEqual(r.sql, expected)