-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9f5a831
Showing
9 changed files
with
1,195 additions
and
0 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,16 @@ | ||
try: # py38 or later | ||
from importlib.metadata import version, PackageNotFoundError | ||
try: | ||
__version__ = version("package-name") | ||
except PackageNotFoundError: | ||
# package is not installed | ||
pass | ||
except ImportError: # py36, py37 | ||
from pkg_resources import get_distribution, DistributionNotFound | ||
try: | ||
__version__ = get_distribution(__name__).version | ||
except DistributionNotFound: | ||
# package is not installed | ||
pass | ||
|
||
from django_redshift_backend.meta import DistKey, SortKey # noqa |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
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,3 @@ | ||
# flake8: noqa | ||
# for backward compatibility before 3.0.0 | ||
from .meta import DistKey |
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,45 @@ | ||
from django.db.models import Index | ||
|
||
|
||
class DistKey(Index): | ||
"""A single-field index denoting the distkey for a model. | ||
Use as follows: | ||
class MyModel(models.Model): | ||
... | ||
class Meta: | ||
indexes = [DistKey(fields=['customer_id'])] | ||
""" | ||
def deconstruct(self): | ||
path, expressions, kwargs = super().deconstruct() | ||
path = path.replace('django_redshift_backend.meta', 'django_redshift_backend') | ||
return (path, expressions, kwargs) | ||
|
||
|
||
class SortKey(str): | ||
"""A SORTKEY in Redshift, also valid as ordering in Django. | ||
https://docs.djangoproject.com/en/dev/ref/models/options/#django.db.models.Options.ordering | ||
Use as follows: | ||
class MyModel(models.Model): | ||
... | ||
class Meta: | ||
ordering = [SortKey('created_at'), SortKey('-id')] | ||
""" | ||
def __hash__(self): | ||
return hash(str(self)) | ||
|
||
def deconstruct(self): | ||
path = '%s.%s' % (self.__class__.__module__, self.__class__.__name__) | ||
path = path.replace('django_redshift_backend.meta', 'django_redshift_backend') | ||
return (path, [str(self)], {}) | ||
|
||
def __eq__(self, other): | ||
if self.__class__ == other.__class__: | ||
return self.deconstruct() == other.deconstruct() | ||
return NotImplemented |
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,11 @@ | ||
from setuptools import setup, find_packages | ||
import django_redshift_backend | ||
|
||
setup( | ||
name='django_redshift', | ||
version=1, | ||
url='https://github.com/thefyk/django-redshift', | ||
author='Michael Fyk', | ||
author_email='michael.fyk@vizio.com', | ||
py_modules=find_packages() | ||
) |