-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from Ed-XCF/feature/hybrid-property-to-dict
to dict support hybrid_property and add Comparator
- Loading branch information
Showing
4 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from collections import defaultdict | ||
|
||
from sqlalchemy import case | ||
from sqlalchemy.ext.hybrid import Comparator | ||
from sqlalchemy.util.langhelpers import dictlike_iteritems | ||
|
||
|
||
class CaseComparator(Comparator): | ||
def __init__(self, whens, expression): | ||
super().__init__(expression) | ||
self.whens, self.reversed_whens = dictlike_iteritems(whens), defaultdict(list) | ||
for k, v in self.whens: | ||
self.reversed_whens[v].append(k) | ||
|
||
def __clause_element__(self): | ||
return case(self.whens, self.expression) | ||
|
||
def __eq__(self, other): | ||
return super().__clause_element__().in_(self.reversed_whens[other]) |
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
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
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