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

Function render_reference

pydbml/renderer/sql/default/reference.py:61–82  ·  view source on GitHub ↗

Returns SQL of the reference: ALTER TABLE "orders" ADD FOREIGN KEY ("customer_id") REFERENCES "customers ("id");

(model: Reference)

Source from the content-addressed store, hash-verified

59
60@DefaultSQLRenderer.renderer_for(Reference)
61def render_reference(model: Reference) -> str:
62 '''
63 Returns SQL of the reference:
64
65 ALTER TABLE "orders" ADD FOREIGN KEY ("customer_id") REFERENCES "customers ("id");
66
67 '''
68 validate_for_sql(model)
69
70 if model.type == MANY_TO_MANY:
71 return generate_many_to_many_sql(model)
72
73 result = ''
74 func = generate_inline_sql if model.inline else generate_not_inline_sql
75 if model.type in (MANY_TO_ONE, ONE_TO_ONE):
76 result = func(model=model, source_col=model.col1, ref_col=model.col2)
77 elif model.type == ONE_TO_MANY:
78 result = func(model=model, source_col=model.col2, ref_col=model.col1)
79
80 c = f'CONSTRAINT "{model.name}" ' if model.name else ''
81
82 return result.format(c=c)

Callers 7

test_inlineMethod · 0.90
test_not_inlineMethod · 0.90
test_many_to_manyMethod · 0.90
test_inline_to_oneMethod · 0.90
test_inline_to_manyMethod · 0.90

Calls 2

validate_for_sqlFunction · 0.85

Tested by 7

test_inlineMethod · 0.72
test_not_inlineMethod · 0.72
test_many_to_manyMethod · 0.72
test_inline_to_oneMethod · 0.72
test_inline_to_manyMethod · 0.72