Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails on comment after closing brace in Table spec #27

Closed
marktaff opened this issue Apr 9, 2023 · 2 comments
Closed

Fails on comment after closing brace in Table spec #27

marktaff opened this issue Apr 9, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@marktaff
Copy link

marktaff commented Apr 9, 2023

The error:
pyparsing.exceptions.ParseException: Expected {LineEnd | StringEnd}, found '/' (at char 1112), (line:31, col:3)

Expected behavior:
Personally, I'd like if the comments were put in the <Database> object attached to the table or column as appropriate, as I need to extend dbml for mariadb features they don't support. But at a minimum, it seems like having the parser ignoring comments totally is better than failing.

This dbml snippet will reproduce:

Table nameSuffixOptions {
    id int(11) [primary key, increment]
    suffix varchar(7) [not null]
    sortOrder int(11) [not null]
    createdAt timestamp [default: `CURRENT_TIMESTAMP`]
    updatedAt timestamp [default: `CURRENT_TIMESTAMP`] // maria: [ onupdate: `CURRENT_TIMESTAMP`]
    note: 'Options for name suffixes: Sr., Jr., etc'
} // maria: [engine: innodb, charset: utf8]
@mjfii
Copy link

mjfii commented Apr 20, 2023

The comments are evaluated prior to the object being defined. So this should evaluate:

// maria: [engine: innodb, charset: utf8]
Table nameSuffixOptions {
    id int(11) [primary key, increment]
    suffix varchar(7) [not null]
    sortOrder int(11) [not null]
    createdAt timestamp [default: `CURRENT_TIMESTAMP`]
    // maria: [ onupdate: `CURRENT_TIMESTAMP`]
    updatedAt timestamp [default: `CURRENT_TIMESTAMP`]
    note: 'Options for name suffixes: Sr., Jr., etc'
}

Additionally, you can use the Project DBML object to store metadata:

Project newProject {
  name: 'New Project'
  dbms: 'maria'
  engine: 'innodb'
  charset: 'utf8'
  author: 'markaff'
  Note: '''
  a customized model
  '''
}

Table nameSuffixOptions {
    id int(11) [primary key, increment]
    suffix varchar(7) [not null]
    sortOrder int(11) [not null]
    createdAt timestamp [default: `CURRENT_TIMESTAMP`]
    // maria: [ onupdate: `CURRENT_TIMESTAMP`]
    updatedAt timestamp [default: `CURRENT_TIMESTAMP`]
    note: 'Options for name suffixes: Sr., Jr., etc'
}

You can access it via the project.items dict.

@Vanderhoof Vanderhoof added the bug Something isn't working label Apr 25, 2023
@Vanderhoof Vanderhoof self-assigned this Apr 25, 2023
@Vanderhoof
Copy link
Owner

Vanderhoof commented May 14, 2023

Sorry for a very late reply: I was afk most of the previous weeks due to moving.

I've fixed the error in 1.0.8, thanks a lot for reporting! As @mjfii pointed out, currently PyDBML attaches the comments, which are put directly before the Table, into the parsed Table object. Same behavior is true for any other entity: a comment before the entity gets into the parsed object. To illustrate it on @mjfii 's example:

>>> from pydbml import PyDBML
>>> source = '''
... // maria: [engine: innodb, charset: utf8]
... Table nameSuffixOptions {
...     id int(11) [primary key, increment]
...     suffix varchar(7) [not null]
...     sortOrder int(11) [not null]
...     createdAt timestamp [default: `CURRENT_TIMESTAMP`]
...     // maria: [ onupdate: `CURRENT_TIMESTAMP`]
...     updatedAt timestamp [default: `CURRENT_TIMESTAMP`]
...     note: 'Options for name suffixes: Sr., Jr., etc'
... }
... '''
>>> parsed = PyDBML(source)
>>> parsed.tables[0].comment  # the table object has the comment attribute
'maria: [engine: innodb, charset: utf8]'
>>> parsed.tables[0]['updatedAt']
<Column 'updatedAt', 'timestamp'>
>>> parsed.tables[0]['updatedAt'].comment  # the column `updatedAt` also has the comment, defined right before it
'maria: [ onupdate: `CURRENT_TIMESTAMP`]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants