outsourcing some template classes

Signed-off-by: anti-freak <antifreak2011@gmail.com>
rewrite database class (add template typename "TIndex")

Signed-off-by: anti-freak <antifreak2011@gmail.com>
revert second database template parameter

Signed-off-by: anti-freak <antifreak2011@gmail.com>