make db function now uses primary keys