Move database logic to its own namespace