db logic