Skip to content

Commit

Permalink
Repository Name
Browse files Browse the repository at this point in the history
  • Loading branch information
thefyk committed Nov 28, 2022
0 parents commit 9f5a831
Show file tree
Hide file tree
Showing 9 changed files with 1,195 additions and 0 deletions.
16 changes: 16 additions & 0 deletions django_redshift_backend/__init__.py
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.
1,120 changes: 1,120 additions & 0 deletions django_redshift_backend/base.py

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions django_redshift_backend/distkey.py
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
45 changes: 45 additions & 0 deletions django_redshift_backend/meta.py
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
11 changes: 11 additions & 0 deletions setup.py
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()
)

0 comments on commit 9f5a831

Please sign in to comment.