Created
December 3, 2011 05:11
-
-
Save longfin/1426133 to your computer and use it in GitHub Desktop.
요런 식으로 sqlalchemy의 joinedload, subqueryload를 바꿔치기함
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
def __extend_keys(l): | |
ret = [[]] | |
for p in l: | |
for r in list(ret): | |
if isinstance(p, list): | |
ret.remove(r) | |
for e in p: | |
nr = list(r) | |
nr.append(e) | |
ret.append(nr) | |
else: | |
r.append(p) | |
return ret | |
def __build_wrapper(f): | |
@wraps(f) | |
def wrapper(*keys, **kwargs): | |
extended = __extend_keys(keys) | |
if len(extended) == 1: | |
return f(*keys, **kwargs) | |
else: | |
return [f(*k, **kwargs) for k in extended] | |
return wrapper | |
orm.joinedload = __build_wrapper(orm.joinedload) | |
orm.joinedload_all = __build_wrapper(orm.joinedload_all) | |
orm.subqueryload = __build_wrapper(orm.subqueryload) | |
orm.subqueryload_all = __build_wrapper(orm.subqueryload_all) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
string도 Iterable이라
요런 코드에서 바보가 됨 --;