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

Function insert_record

24-class-metaprog/persistent/dblib.py:118–127  ·  view source on GitHub ↗
(table_name: str, data: dict[str, Any])

Source from the content-addressed store, hash-verified

116
117
118def insert_record(table_name: str, data: dict[str, Any]) -> int:
119 check_identifier(table_name)
120 con = get_connection()
121 placeholders = ', '.join(['?'] * len(data))
122 sql = f'INSERT INTO {table_name} VALUES (NULL, {placeholders})'
123 cursor = con.execute(sql, tuple(data.values()))
124 pk = cursor.lastrowid
125 con.commit()
126 cursor.close()
127 return pk
128
129
130def fetch_record(table_name: str, pk: int) -> sqlite3.Row:

Callers 4

test_insert_recordFunction · 0.90
test_fetch_recordFunction · 0.90
test_update_recordFunction · 0.90
test_delete_recordFunction · 0.90

Calls 5

check_identifierFunction · 0.85
get_connectionFunction · 0.85
executeMethod · 0.80
valuesMethod · 0.80
closeMethod · 0.45

Tested by 4

test_insert_recordFunction · 0.72
test_fetch_recordFunction · 0.72
test_update_recordFunction · 0.72
test_delete_recordFunction · 0.72