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>
Reading again the old comment, I think I understand better the logic: It's permitted modify the key, only if this does not lead overwrite another existent key.
If we want to follow this logic and preserve existent key, I think is necessary to leave the "if".