review db logic

moved from https://github.com/daithi-coombes/api-connection-manager/issues/95