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>
502: D103 Docstring missing
533: D202 No blank lines allowed *after* function docstring, found 1
568: D202 No blank lines allowed *after* function docstring, found 1
602: D202 No blank lines allowed *after* function docstring, found 1
637: D209 Put multi-line docstring closing quotes on separate line
637: D202 No blank lines allowed *after* function docstring, found 1
637: D205 Blank line missing between one-line summary and description
668: D209 Put multi-line docstring closing quotes on separate line
668: D205 Blank line missing between one-line summary and description
668: D208 Docstring is over-indented
723: D209 Put multi-line docstring closing quotes on separate line
723: D202 No blank lines allowed *after* function docstring, found 1
723: D400 First line should end with '.', not 'x'
723: D205 Blank line missing between one-line summary and description
749:17: E221 multiple spaces before operator
805: D209 Put multi-line docstring closing quotes on separate line
805: D202 No blank lines allowed *after* function docstring, found 1
805: D400 First line should end with '.', not 'd'
805: D205 Blank line missing between one-line summary and description
831:17: E221 multiple spaces before operator
886: D209 Put multi-line docstring closing quotes on separate line
886: D202 No blank lines allowed *after* function docstring, found 1
886: D205 Blank line missing between one-line summary and description
929: D209 Put multi-line docstring closing quotes on separate line
929: D202 No blank lines allowed *after* function docstring, found 1
929: D205 Blank line missing between one-line summary and description
968: D209 Put multi-line docstring closing quotes on separate line
968: D202 No blank lines allowed *after* function docstring, found 1
968: D205 Blank line missing between one-line summary and description
1002: D202 No blank lines allowed *after* function docstring, found 1
1002: D205 Blank line missing between one-line summary and description
1045: D202 No blank lines allowed *after* function docstring, found 1
1045: D205 Blank line missing between one-line summary and description
1083: D205 Blank line missing between one-line summary and description
1083: D208 Docstring is over-indented
1128: D209 Put multi-line docstring closing quotes on separate line
1128: D400 First line should end with '.', not 'x'
1128: D205 Blank line missing between one-line summary and description
1128: D208 Docstring is over-indented
1213:15: E221 multiple spaces before operator
1223: D400 First line should end with '.', not 't'
1223: D205 Blank line missing between one-line summary and description
1223: D208 Docstring is over-indented
1238: D103 Docstring missing
1289: D209 Put multi-line docstring closing quotes on separate line
1289: D202 No blank lines allowed *after* function docstring, found 1
1289: D205 Blank line missing between one-line summary and description
1325:15: E221 multiple spaces before operator
1335: D209 Put multi-line docstring closing quotes on separate line
1335: D202 No blank lines allowed *after* function docstring, found 1
1335: D205 Blank line missing between one-line summary and description
1400:15: E221 multiple spaces before operator
1410: D209 Put multi-line docstring closing quotes on separate line
1410: D205 Blank line missing between one-line summary and description
1410: D208 Docstring is over-indented
1462:15: E221 multiple spaces before operator
1472: D202 No blank lines allowed *after* function docstring, found 1
1472: D205 Blank line missing between one-line summary and description
1472: D208 Docstring is over-indented
1563: D202 No blank lines allowed *after* function docstring, found 1
1563: D400 First line should end with '.', not 'n'
1563: D205 Blank line missing between one-line summary and description
1563: D208 Docstring is over-indented
1586:76: E221 multiple spaces before operator
1628: D209 Put multi-line docstring closing quotes on separate line
1628: D202 No blank lines allowed *after* function docstring, found 1
1628: D205 Blank line missing between one-line summary and description
1628: D208 Docstring is over-indented
1697: D209 Put multi-line docstring closing quotes on separate line
1697: D202 No blank lines allowed *after* function docstring, found 1
1697: D205 Blank line missing between one-line summary and description
1697: D208 Docstring is over-indented
1766: D209 Put multi-line docstring closing quotes on separate line
1766: D202 No blank lines allowed *after* function docstring, found 1
1766: D205 Blank line missing between one-line summary and description
1766: D208 Docstring is over-indented
1836: D209 Put multi-line docstring closing quotes on separate line
1836: D202 No blank lines allowed *after* function docstring, found 1
1836: D205 Blank line missing between one-line summary and description
1872:15: E221 multiple spaces before operator
1917:267: E221 multiple spaces before operator
1951: D202 No blank lines allowed *after* function docstring, found 1
1962:280: E221 multiple spaces before operator
2008: D205 Blank line missing between one-line summary and description
2008: D208 Docstring is over-indented
2039:24: W601 .has_key() is deprecated, use 'in'
2073: D209 Put multi-line docstring closing quotes on separate line
2073: D202 No blank lines allowed *after* function docstring, found 1
2073: D205 Blank line missing between one-line summary and description
2118: D209 Put multi-line docstring closing quotes on separate line
2118: D202 No blank lines allowed *after* function docstring, found 1
2118: D205 Blank line missing between one-line summary and description
2153: D209 Put multi-line docstring closing quotes on separate line
2153: D202 No blank lines allowed *after* function docstring, found 1
2153: D205 Blank line missing between one-line summary and description
2180:18: E713 test for membership should be 'not in'
2194: D209 Put multi-line docstring closing quotes on separate line
2194: D202 No blank lines allowed *after* function docstring, found 1
2194: D205 Blank line missing between one-line summary and description
2228: D209 Put multi-line docstring closing quotes on separate line
2228: D202 No blank lines allowed *after* function docstring, found 1
2228: D205 Blank line missing between one-line summary and description
2242: D209 Put multi-line docstring closing quotes on separate line
2242: D202 No blank lines allowed *after* function docstring, found 1
2242: D205 Blank line missing between one-line summary and description
2248:11: E221 multiple spaces before operator
2262:9: E221 multiple spaces before operator
2269:23: W601 .has_key() is deprecated, use 'in'
2305:15: E221 multiple spaces before operator
2313: D202 No blank lines allowed *after* function docstring, found 1
2313: D400 First line should end with '.', not 's'
2319: D401 First line should be imperative: 'Return', not 'Returns'
2319: D209 Put multi-line docstring closing quotes on separate line
2319: D202 No blank lines allowed *after* function docstring, found 1
2319: D205 Blank line missing between one-line summary and description
2338: D103 Docstring missing
2352: D401 First line should be imperative: 'Return', not 'Returns'
2352: D202 No blank lines allowed *after* function docstring, found 1
2352: D400 First line should end with '.', not 'e'
2361: D401 First line should be imperative: 'Return', not 'Returns'
2361: D202 No blank lines allowed *after* function docstring, found 1
2361: D400 First line should end with '.', not 'e'
2370: D401 First line should be imperative: 'Return', not 'Returns'
2370: D202 No blank lines allowed *after* function docstring, found 1
2370: D400 First line should end with '.', not 'e'
2379: D401 First line should be imperative: 'Return', not 'Returns'
2379: D202 No blank lines allowed *after* function docstring, found 1
2379: D400 First line should end with '.', not 'e'
2388: D401 First line should be imperative: 'Return', not 'Returns'
2388: D202 No blank lines allowed *after* function docstring, found 1
2388: D400 First line should end with '.', not 'e'
2397: D401 First line should be imperative: 'Return', not 'Returns'
2397: D209 Put multi-line docstring closing quotes on separate line
2397: D202 No blank lines allowed *after* function docstring, found 1
2397: D205 Blank line missing between one-line summary and description
2419: D401 First line should be imperative: 'Return', not 'Returns'
2419: D209 Put multi-line docstring closing quotes on separate line
2419: D202 No blank lines allowed *after* function docstring, found 1
2419: D205 Blank line missing between one-line summary and description
2438: D401 First line should be imperative: 'Return', not 'Returns'
2438: D202 No blank lines allowed *after* function docstring, found 1
2438: D400 First line should end with '.', not 'd'
2453: D401 First line should be imperative: 'Return', not 'Returns'
2453: D202 No blank lines allowed *after* function docstring, found 1
2453: D400 First line should end with '.', not 'e'
2463: D401 First line should be imperative: 'Return', not 'Returns'
2463: D202 No blank lines allowed *after* function docstring, found 1
2463: D400 First line should end with '.', not 'e'
2493: D202 No blank lines allowed *after* function docstring, found 1
2501: D202 No blank lines allowed *after* function docstring, found 1
2509: D202 No blank lines allowed *after* function docstring, found 1
2509: D400 First line should end with '.', not 'x'
2517: D202 No blank lines allowed *after* function docstring, found 1
2517: D400 First line should end with '.', not 's'
2527: D401 First line should be imperative: 'Remove', not 'Removes'
2527: D209 Put multi-line docstring closing quotes on separate line
2527: D202 No blank lines allowed *after* function docstring, found 1
2527: D205 Blank line missing between one-line summary and description
2544: D209 Put multi-line docstring closing quotes on separate line
2544: D202 No blank lines allowed *after* function docstring, found 1
2544: D400 First line should end with '.', not 'd'
2544: D205 Blank line missing between one-line summary and description
2557: D401 First line should be imperative: 'Remove', not 'Removes'
2557: D209 Put multi-line docstring closing quotes on separate line
2557: D202 No blank lines allowed *after* function docstring, found 1
2557: D205 Blank line missing between one-line summary and description
2570: D401 First line should be imperative: 'Delete', not 'Deletes'
2570: D209 Put multi-line docstring closing quotes on separate line
2570: D202 No blank lines allowed *after* function docstring, found 1
2570: D400 First line should end with '.', not 'd'
2570: D205 Blank line missing between one-line summary and description
2641: D209 Put multi-line docstring closing quotes on separate line
2641: D208 Docstring is over-indented
2735: D401 First line should be imperative: 'Create', not 'Creates'
2735: D205 Blank line missing between one-line summary and description
2735: D208 Docstring is over-indented
2758: D401 First line should be imperative: 'Drop', not 'Drops'
2758: D205 Blank line missing between one-line summary and description
2758: D208 Docstring is over-indented
2769: D401 First line should be imperative: 'Add', not 'Adds'
2769: D205 Blank line missing between one-line summary and description
2769: D208 Docstring is over-indented
2785: D401 First line should be imperative: 'Add', not 'Adds'
2785: D400 First line should end with '.', not 'f'
2785: D205 Blank line missing between one-line summary and description
2785: D208 Docstring is over-indented
2802: D401 First line should be imperative: 'Add', not 'Adds'
2802: D400 First line should end with '.', not 'x'
2813: D209 Put multi-line docstring closing quotes on separate line
2813: D202 No blank lines allowed *after* function docstring, found 1
2813: D205 Blank line missing between one-line summary and description
2832: D400 First line should end with '.', not 'e'
2832: D205 Blank line missing between one-line summary and description
2832: D208 Docstring is over-indented
2868: D202 No blank lines allowed *after* function docstring, found 1
2868: D400 First line should end with '.', not 'x'
2883: D401 First line should be imperative: 'Update', not 'Updates'
2883: D400 First line should end with '.', not 'x'
2883: D205 Blank line missing between one-line summary and description
2883: D208 Docstring is over-indented
2902: D400 First line should end with '.', not 'e'
2921: D202 No blank lines allowed *after* function docstring, found 1
2921: D400 First line should end with '.', not 'e'
2932: D400 First line should end with '.', not 'e'
2941: D400 First line should end with '.', not 'e'
2941: D205 Blank line missing between one-line summary and description
2941: D208 Docstring is over-indented
2959: D202 No blank lines allowed *after* function docstring, found 1
2959: D400 First line should end with '.', not 'e'
2959: D205 Blank line missing between one-line summary and description
2959: D208 Docstring is over-indented
2973: D202 No blank lines allowed *after* function docstring, found 1
2973: D400 First line should end with '.', not 'e'
2984: D202 No blank lines allowed *after* function docstring, found 1
2984: D400 First line should end with '.', not 'e'
2995: D202 No blank lines allowed *after* function docstring, found 1
2995: D400 First line should end with '.', not 'x'
3006: D209 Put multi-line docstring closing quotes on separate line
3006: D202 No blank lines allowed *after* function docstring, found 1
3006: D400 First line should end with '.', not 'd'
3006: D205 Blank line missing between one-line summary and description
3020: D202 No blank lines allowed *after* function docstring, found 1
3020: D205 Blank line missing between one-line summary and description
3020: D208 Docstring is over-indented
3036: D209 Put multi-line docstring closing quotes on separate line
3036: D205 Blank line missing between one-line summary and description
3059: D103 Docstring missing
3075: D103 Docstring missing