Port database layer from appframework to core

https://github.com/owncloud/core/issues/8190

@LEDfan @DeepDiver1975 @bartv2 @MorrisJobke @cosenal