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

add comment function from field #634

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pony/orm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ class Attribute(object):
'lazy', 'lazy_sql_cache', 'args', 'auto', 'default', 'reverse', 'composite_keys', \
'column', 'columns', 'col_paths', '_columns_checked', 'converters', 'kwargs', \
'cascade_delete', 'index', 'reverse_index', 'original_default', 'sql_default', 'py_check', 'hidden', \
'optimistic', 'fk_name', 'type_has_empty_value', 'interleave'
'optimistic', 'fk_name', 'type_has_empty_value', 'interleave', 'comment'
def __deepcopy__(attr, memo):
return attr # Attribute cannot be cloned by deepcopy()
@cut_traceback
Expand Down Expand Up @@ -2046,6 +2046,7 @@ def __init__(attr, py_type, *args, **kwargs):
attr.is_relation = isinstance(attr.py_type, (EntityMeta, str, types.FunctionType))
attr.is_basic = not attr.is_collection and not attr.is_relation
attr.sql_type = kwargs.pop('sql_type', None)
attr.comment = kwargs.pop('comment', None)
attr.entity = attr.name = None
attr.args = args
attr.auto = kwargs.pop('auto', False)
Expand Down
1 change: 1 addition & 0 deletions pony/orm/dbapiprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def init(converter, kwargs):
converter.max_len = max_len
converter.db_encoding = kwargs.pop('db_encoding', None)
converter.autostrip = kwargs.pop('autostrip', True)
converter.comment = kwargs.pop('comment', None)
def validate(converter, val, obj=None):
if not isinstance(val, str): throw(TypeError,
'Value type for attribute %s must be str. Got: %r' % (converter.attr, type(val)))
Expand Down
9 changes: 9 additions & 0 deletions pony/orm/dbschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,21 @@ def add_default():
append(case('DEFAULT'))
append(column.sql_default)

def add_comment():
comment = column.converter.attr.comment
if comment != None:
append(case('COMMENT'))
append('\'%s\''%comment)

if column.is_pk == 'auto' and column.auto_template and column.converter.py_type in int_types:
append(case(column.auto_template % dict(type=column.sql_type)))
add_default()
add_comment()
else:
append(case(column.sql_type))
add_default()
add_comment()

if column.is_pk:
if schema.dialect == 'SQLite': append(case('NOT NULL'))
append(case('PRIMARY KEY'))
Expand Down