locking: Add a standalone helper to lock record/db