MCPcopy Create free account
hub / github.com/Vanderhoof/PyDBML / render_column

Function render_column

pydbml/renderer/sql/default/column.py:18–45  ·  view source on GitHub ↗

Returns inline SQL of the column, which should be a part of table definition: "id" integer PRIMARY KEY AUTOINCREMENT

(model: Column)

Source from the content-addressed store, hash-verified

16
17@DefaultSQLRenderer.renderer_for(Column)
18def render_column(model: Column) -> str:
19 '''
20 Returns inline SQL of the column, which should be a part of table definition:
21
22 "id" integer PRIMARY KEY AUTOINCREMENT
23 '''
24
25 components = [f'"{model.name}"']
26 if isinstance(model.type, Enum):
27 components.append(get_full_name_for_sql_enum(model.type))
28 else:
29 components.append(str(model.type))
30
31 table_has_composite_pk = model.table._has_composite_pk() if model.table else False
32 if model.pk and not table_has_composite_pk: # composite PKs are rendered in table sql
33 components.append('PRIMARY KEY')
34 if model.autoinc:
35 components.append('AUTOINCREMENT')
36 if model.unique:
37 components.append('UNIQUE')
38 if model.not_null:
39 components.append('NOT NULL')
40 if model.default is not None:
41 components.append(f'DEFAULT {default_to_str(model.default)}')
42
43 result = comment_to_sql(model.comment) if model.comment else ''
44 result += ' '.join(components)
45 return result

Callers 8

test_commentMethod · 0.90
test_enumMethod · 0.90
test_complexMethod · 0.90
test_stringMethod · 0.90
test_booleanMethod · 0.90
test_simpleMethod · 0.90
test_complexMethod · 0.90
test_stringMethod · 0.90

Calls 3

comment_to_sqlFunction · 0.85
_has_composite_pkMethod · 0.80
default_to_strFunction · 0.70

Tested by 8

test_commentMethod · 0.72
test_enumMethod · 0.72
test_complexMethod · 0.72
test_stringMethod · 0.72
test_booleanMethod · 0.72
test_simpleMethod · 0.72
test_complexMethod · 0.72
test_stringMethod · 0.72