-
Notifications
You must be signed in to change notification settings - Fork 7
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 #18 from kvesteri/hotfix/17-slow-includes
Fix slow includes, closes #17
- Loading branch information
Showing
7 changed files
with
87 additions
and
40 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import sqlalchemy as sa | ||
from sqlalchemy.ext.hybrid import Comparator | ||
|
||
|
||
class CompositeId(Comparator): | ||
def __init__(self, keys, separator=':', label='id'): | ||
self.keys = keys | ||
self.separator = separator | ||
self.label = label | ||
|
||
def operate(self, op, other): | ||
if isinstance(other, sa.sql.selectable.Select): | ||
return op(sa.tuple_(*self.keys), other) | ||
if not isinstance(other, CompositeId): | ||
other = CompositeId(other) | ||
return sa.and_( | ||
op(key, other_key) | ||
for key, other_key in zip(self.keys, other.keys) | ||
) | ||
|
||
def __clause_element__(self): | ||
parts = [self.keys[0]] | ||
for key in self.keys[1:]: | ||
parts.append(sa.text("'{}'".format(self.separator))) | ||
parts.append(key) | ||
return sa.func.concat(*parts).label(self.label) | ||
|
||
def __str__(self): | ||
return self.separator.join(str(k) for k in self.keys) | ||
|
||
def __repr__(self): | ||
return '<CompositeId {}>'.format(repr(self.keys)) |
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