knowledge: API migration to SQLAlchemy

* Replaces run_sql queries with SQLAchemy query.

* Refactors module in order to move logic from api to model.

Signed-off-by: Leonardo Rossi <leonardo.r@cern.ch>
`if kbtype in ['t', 'd', 'w']:`

or even better these values shall be defined as class property e.g.: `KnwKB.TYPES=set('t', 'd', 'w')`