MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / make_schema_sql

Function make_schema_sql

24-class-metaprog/persistent/dblib.py:82–90  ·  view source on GitHub ↗
(table_name: str, fields: FieldMap)

Source from the content-addressed store, hash-verified

80
81
82def make_schema_sql(table_name: str, fields: FieldMap) -> str:
83 check_identifier(table_name)
84 pk = 'pk INTEGER PRIMARY KEY,'
85 spcs = ' ' * 4
86 columns = ',\n '.join(
87 f'{field_name} {sql_type}'
88 for field_name, sql_type in gen_columns_sql(fields)
89 )
90 return f'CREATE TABLE {table_name} (\n{spcs}{pk}\n{spcs}{columns}\n)'
91
92
93def create_table(table_name: str, fields: FieldMap) -> None:

Callers 2

test_make_schema_sqlFunction · 0.90
create_tableFunction · 0.85

Calls 2

check_identifierFunction · 0.85
gen_columns_sqlFunction · 0.85

Tested by 1

test_make_schema_sqlFunction · 0.72