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>
35: D203 Expected 1 blank line *before* class docstring, found 0
38: D401 First line should be imperative: 'Return', not 'Returns'
89:9: E303 too many blank lines (2)
95:37: E203 whitespace before ':'
153:56: E202 whitespace before '}'
157: D400 First line should end with '.', not 'k'
157: D205 Blank line missing between one-line summary and description
167:31: E261 at least two spaces before inline comment
167:32: E262 inline comment should start with '# '
171:69: E231 missing whitespace after ':'
171:62: E225 missing whitespace around operator
172:72: E231 missing whitespace after ':'
173:73: E231 missing whitespace after ':'
174:72: E231 missing whitespace after ':'
179:5: E303 too many blank lines (2)
179: D205 Blank line missing between one-line summary and description
213:5: E303 too many blank lines (2)
213: D205 Blank line missing between one-line summary and description
262:67: E225 missing whitespace around operator
262:90: E225 missing whitespace around operator
277:40: E201 whitespace after '{'
281:73: E203 whitespace before ','
288: D401 First line should be imperative: 'Return', not 'Returns'
288: D202 No blank lines allowed *after* method docstring, found 1
322:29: E231 missing whitespace after ':'
323:32: E231 missing whitespace after ':'
324:33: E231 missing whitespace after ':'
327:37: E231 missing whitespace after ':'
328:39: E231 missing whitespace after ':'
361:34: E231 missing whitespace after ':'
361:46: E231 missing whitespace after ':'
362:38: E231 missing whitespace after ':'
423:25: E231 missing whitespace after ':'
425:56: E231 missing whitespace after ':'
427:62: E202 whitespace before '}'
471:20: E231 missing whitespace after ':'
472:23: E231 missing whitespace after ':'
473:25: E231 missing whitespace after ':'
475:58: E202 whitespace before '}'
488:21: E261 at least two spaces before inline comment
488:22: E262 inline comment should start with '# '
522:25: E128 continuation line under-indented for visual indent
522:32: E231 missing whitespace after ':'
523:25: E128 continuation line under-indented for visual indent
523:29: E231 missing whitespace after ':'
524:25: E128 continuation line under-indented for visual indent
524:32: E231 missing whitespace after ':'
525:25: E128 continuation line under-indented for visual indent
526:25: E128 continuation line under-indented for visual indent
527:25: E128 continuation line under-indented for visual indent
528:25: E128 continuation line under-indented for visual indent
528:32: E231 missing whitespace after ':'
529:25: E128 continuation line under-indented for visual indent
529:33: E231 missing whitespace after ':'
530:25: E128 continuation line under-indented for visual indent
531:25: E128 continuation line under-indented for visual indent
562: D401 First line should be imperative: 'Return', not 'Returns'
562: D202 No blank lines allowed *after* method docstring, found 1
585:29: E231 missing whitespace after ':'
586:32: E231 missing whitespace after ':'
587:33: E231 missing whitespace after ':'
591:37: E231 missing whitespace after ':'
592:39: E231 missing whitespace after ':'
600:20: E231 missing whitespace after ':'
601:23: E231 missing whitespace after ':'
602:24: E231 missing whitespace after ':'
603:25: E231 missing whitespace after ':'
607:152: E128 continuation line under-indented for visual indent
628:35: E231 missing whitespace after ':'
629:52: E231 missing whitespace after ':'
633: D401 First line should be imperative: 'Return', not 'Returns'
633: D202 No blank lines allowed *after* method docstring, found 1
654:34: E231 missing whitespace after ':'
655:37: E231 missing whitespace after ':'
656:38: E231 missing whitespace after ':'
658:36: E203 whitespace before ':'
660:42: E231 missing whitespace after ':'
661:44: E231 missing whitespace after ':'
675:104: E231 missing whitespace after ':'
676:106: E231 missing whitespace after ':'
677:102: E231 missing whitespace after ':'
688:5: E303 too many blank lines (2)
688: D401 First line should be imperative: 'Return', not 'Returns'
688: D400 First line should end with '.', not 'o'
688: D205 Blank line missing between one-line summary and description
704:24: E225 missing whitespace around operator
706:25: E127 continuation line over-indented for visual indent
709:25: E127 continuation line over-indented for visual indent
718:31: E225 missing whitespace around operator
730:25: E201 whitespace after '{'
730:106: E202 whitespace before '}'
730:31: E231 missing whitespace after ':'
730:43: E231 missing whitespace after ':'
730:56: E231 missing whitespace after ':'
730:85: E231 missing whitespace after ':'
743:67: E201 whitespace after '{'
743:84: E202 whitespace before '}'
743:73: E231 missing whitespace after ':'
749:67: E201 whitespace after '{'
749:73: E231 missing whitespace after ':'
749:86: E231 missing whitespace after ':'
750:69: E127 continuation line over-indented for visual indent
750:76: E231 missing whitespace after ':'
751:125: E202 whitespace before '}'
751:75: E231 missing whitespace after ':'
751:104: E231 missing whitespace after ':'
755:67: E201 whitespace after '{'
755:107: E202 whitespace before '}'
755:85: E231 missing whitespace after ':'
755:97: E231 missing whitespace after ':'