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

Function update_record

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

Source from the content-addressed store, hash-verified

141
142
143def update_record(
144 table_name: str, pk: int, data: dict[str, Any]
145) -> tuple[str, tuple[Any, ...]]:
146 check_identifier(table_name)
147 con = get_connection()
148 names = ', '.join(data.keys())
149 placeholders = ', '.join(['?'] * len(data))
150 values = tuple(data.values()) + (pk,)
151 sql = f'UPDATE {table_name} SET ({names}) = ({placeholders}) WHERE pk = ?'
152 con.execute(sql, values)
153 con.commit()
154 return sql, values
155
156
157def delete_record(table_name: str, pk: int) -> sqlite3.Cursor:

Callers 1

test_update_recordFunction · 0.90

Calls 5

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

Tested by 1

test_update_recordFunction · 0.72