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

Function fetch_record

24-class-metaprog/persistent/dblib.py:130–140  ·  view source on GitHub ↗
(table_name: str, pk: int)

Source from the content-addressed store, hash-verified

128
129
130def fetch_record(table_name: str, pk: int) -> sqlite3.Row:
131 check_identifier(table_name)
132 con = get_connection()
133 sql = f'SELECT * FROM {table_name} WHERE pk = ? LIMIT 2'
134 result = list(con.execute(sql, (pk,)))
135 if len(result) == 0:
136 raise NoSuchRecord(pk)
137 elif len(result) == 1:
138 return result[0]
139 else:
140 raise UnexpectedMultipleResults()
141
142
143def update_record(

Callers 4

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
NoSuchRecordClass · 0.85
executeMethod · 0.80

Tested by 4

test_fetch_recordFunction · 0.72
test_update_recordFunction · 0.72
test_delete_recordFunction · 0.72