How to use the pynamodb.indexes.GlobalSecondaryIndex function in pynamodb

To help you get started, we’ve selected a few pynamodb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pynamodb / PynamoDB / tests / test_model.py View on Github external
player_id = UnicodeAttribute(hash_key=True)
    created_time = UTCDateTimeAttribute(range_key=True)
    winner_id = UnicodeAttribute()
    loser_id = UnicodeAttribute(null=True)

    player_opponent_index = GamePlayerOpponentIndex()
    opponent_time_index = GameOpponentTimeIndex()


class OldStyleModel(Model):
    _table_name = 'IndexedModel'
    user_name = UnicodeAttribute(hash_key=True)


class EmailIndex(GlobalSecondaryIndex):
    """
    A global secondary index for email addresses
    """

    class Meta:
        index_name = 'custom_idx_name'
        read_capacity_units = 2
        write_capacity_units = 1
        projection = AllProjection()

    email = UnicodeAttribute(hash_key=True)
    alt_numbers = NumberSetAttribute(range_key=True, attr_name='numbers')


class LocalEmailIndex(LocalSecondaryIndex):
    """
github yfilali / graphql-pynamodb / examples / flask_auth_pynamodb / models.py View on Github external
method, salt, hashval = pwhash.split('$', 2)

    return method.startswith('pbkdf2:') and len(method[7:].split(':')) in (1, 2)


class PasswordAttribute(UnicodeAttribute):
    def serialize(self, value):
        if is_password_hash(value):
            return value
        return generate_password_hash(value)

    def deserialize(self, value):
        return value


class UserEmailIndex(GlobalSecondaryIndex):
    class Meta:
        read_capacity_units = 1
        write_capacity_units = 1
        projection = AllProjection()

    email = UnicodeAttribute(hash_key=True)


class User(Model):
    class Meta:
        table_name = "users"
        host = "http://localhost:8000"

    def __init__(self, hash_key=None, range_key=None, **args):
        Model.__init__(self, hash_key, range_key, **args)
        if not self.id:
github communitybridge / easycla / cla-backend / cla / models / dynamo_models.py View on Github external
"""

    class Meta:
        """Meta class for external ID repository index."""

        index_name = "external-repository-index"
        write_capacity_units = int(cla.conf["DYNAMO_WRITE_UNITS"])
        read_capacity_units = int(cla.conf["DYNAMO_READ_UNITS"])
        # All attributes are projected - not sure if this is necessary.
        projection = AllProjection()

    # This attribute is the hash key for the index.
    repository_external_id = UnicodeAttribute(hash_key=True)


class SFDCRepositoryIndex(GlobalSecondaryIndex):
    """
    This class represents a global secondary index for querying repositories by external ID.
    """

    class Meta:
        """Meta class for external ID repository index."""

        index_name = "sfdc-repository-index"
        write_capacity_units = int(cla.conf["DYNAMO_WRITE_UNITS"])
        read_capacity_units = int(cla.conf["DYNAMO_READ_UNITS"])
        # All attributes are projected - not sure if this is necessary.
        projection = AllProjection()

    # This attribute is the hash key for the index.
    repository_sfdc_id = UnicodeAttribute(hash_key=True)
github communitybridge / easycla / cla-backend / cla / models / dynamo_models.py View on Github external
class LFUsernameIndex(GlobalSecondaryIndex):
    """
    This class represents a global secondary index for querying users by LF Username.
    """
    class Meta:
        """Meta class for LF Username index."""
        index_name = 'lf-username-index'
        write_capacity_units = int(cla.conf['DYNAMO_WRITE_UNITS'])
        read_capacity_units = int(cla.conf['DYNAMO_READ_UNITS'])
        # All attributes are projected - not sure if this is necessary.
        projection = AllProjection()

    # This attribute is the hash key for the index.
    lf_username = UnicodeAttribute(hash_key=True)

class ProjectRepositoryIndex(GlobalSecondaryIndex):
    """
    This class represents a global secondary index for querying repositories by project ID.
    """
    class Meta:
        """Meta class for project repository index."""
        index_name = 'project-repository-index'
        write_capacity_units = int(cla.conf['DYNAMO_WRITE_UNITS'])
        read_capacity_units = int(cla.conf['DYNAMO_READ_UNITS'])
        # All attributes are projected - not sure if this is necessary.
        projection = AllProjection()

    # This attribute is the hash key for the index.
    repository_project_id = UnicodeAttribute(hash_key=True)


class ExternalRepositoryIndex(GlobalSecondaryIndex):
github pynamodb / PynamoDB / examples / indexes.py View on Github external
"""
Examples using DynamoDB indexes
"""
import datetime
from pynamodb.models import Model
from pynamodb.indexes import GlobalSecondaryIndex, AllProjection, LocalSecondaryIndex
from pynamodb.attributes import UnicodeAttribute, NumberAttribute, UTCDateTimeAttribute


class ViewIndex(GlobalSecondaryIndex):
    """
    This class represents a global secondary index
    """
    class Meta:
        # You can override the index name by setting it below
        index_name = "viewIdx"
        read_capacity_units = 1
        write_capacity_units = 1
        # All attributes are projected
        projection = AllProjection()
    # This attribute is the hash key for the index
    # Note that this attribute must also exist
    # in the model
    view = NumberAttribute(default=0, hash_key=True)
github communitybridge / easycla / cla-backend / cla / models / dynamo_models.py View on Github external
def delete_database():
    """
    Named "delete_database" instead of "delete_tables" because delete_database
    is expected to exist in all database storage wrappers.

    WARNING: This will delete all existing table data.
    """
    tables = [RepositoryModel, ProjectModel, SignatureModel, \
              CompanyModel, UserModel, StoreModel, GitHubOrgModel, GerritModel]
    # Delete all existing tables.
    for table in tables:
        if table.exists():
            table.delete_table()

class GitHubUserIndex(GlobalSecondaryIndex):
    """
    This class represents a global secondary index for querying users by GitHub ID.
    """
    class Meta:
        """Meta class for GitHub User index."""
        index_name = 'github-user-index'
        write_capacity_units = int(cla.conf['DYNAMO_WRITE_UNITS'])
        read_capacity_units = int(cla.conf['DYNAMO_READ_UNITS'])
        # All attributes are projected - not sure if this is necessary.
        projection = AllProjection()

    # This attribute is the hash key for the index.
    user_github_id = NumberAttribute(hash_key=True)

class LFUsernameIndex(GlobalSecondaryIndex):
    """
github communitybridge / easycla / cla-backend / cla / models / dynamo_models.py View on Github external
"""

    class Meta:
        """ Meta class for Signature Project External Index """

        index_name = "project-signature-external-id-index"
        write_capacity_units = int(cla.conf["DYNAMO_WRITE_UNITS"])
        read_capacity_units = int(cla.conf["DYNAMO_READ_UNITS"])
        # All attributes are projected - not sure if this is necessary.
        projection = AllProjection()

    # This attribute is the hash key for the index
    signature_project_external_id = UnicodeAttribute(hash_key=True)


class SignatureCompanySignatoryIndex(GlobalSecondaryIndex):
    """
    This class represents a global secondary index for querying signatures by signature company signatory ID
    """

    class Meta:
        """ Meta class for Signature Company Signatory Index """

        index_name = "signature-company-signatory-index"
        write_capacity_units = int(cla.conf["DYNAMO_WRITE_UNITS"])
        read_capacity_units = int(cla.conf["DYNAMO_READ_UNITS"])
        projection = AllProjection()

    signature_company_signatory_id = UnicodeAttribute(hash_key=True)


class SignatureCompanyInitialManagerIndex(GlobalSecondaryIndex):
github communitybridge / easycla / cla-backend / cla / models / dynamo_models.py View on Github external
"""

    class Meta:
        """Meta class for reference Signature index."""

        index_name = "project-signature-index"
        write_capacity_units = int(cla.conf["DYNAMO_WRITE_UNITS"])
        read_capacity_units = int(cla.conf["DYNAMO_READ_UNITS"])
        # All attributes are projected - not sure if this is necessary.
        projection = AllProjection()

    # This attribute is the hash key for the index.
    signature_project_id = UnicodeAttribute(hash_key=True)


class ReferenceSignatureIndex(GlobalSecondaryIndex):
    """
    This class represents a global secondary index for querying signatures by reference.
    """

    class Meta:
        """Meta class for reference Signature index."""

        index_name = "reference-signature-index"
        write_capacity_units = int(cla.conf["DYNAMO_WRITE_UNITS"])
        read_capacity_units = int(cla.conf["DYNAMO_READ_UNITS"])
        # All attributes are projected - not sure if this is necessary.
        projection = AllProjection()

    # This attribute is the hash key for the index.
    signature_reference_id = UnicodeAttribute(hash_key=True)
github communitybridge / easycla / cla-backend / cla / models / dynamo_models.py View on Github external
"""

    class Meta:
        """Meta class for external ID company index."""

        index_name = "external-company-index"
        write_capacity_units = int(cla.conf["DYNAMO_WRITE_UNITS"])
        read_capacity_units = int(cla.conf["DYNAMO_READ_UNITS"])
        # All attributes are projected - not sure if this is necessary.
        projection = AllProjection()

    # This attribute is the hash key for the index.
    company_external_id = UnicodeAttribute(hash_key=True)


class GithubOrgSFIndex(GlobalSecondaryIndex):
    """
    This class represents a global secondary index for querying github organizations by a Salesforce ID.
    """

    class Meta:
        """Meta class for external ID github org index."""

        index_name = "github-org-sfid-index"
        write_capacity_units = int(cla.conf["DYNAMO_WRITE_UNITS"])
        read_capacity_units = int(cla.conf["DYNAMO_READ_UNITS"])
        projection = AllProjection()

    organization_sfid = UnicodeAttribute(hash_key=True)


class ProjectSignatureIndex(GlobalSecondaryIndex):
github pynamodb / PynamoDB / examples / indexes.py View on Github external
for item in TestModel.view_index.query(1):
    print("Item queried from index: {0}".format(item))


class GamePlayerOpponentIndex(LocalSecondaryIndex):
    class Meta:
        read_capacity_units = 1
        write_capacity_units = 1
        table_name = "GamePlayerOpponentIndex"
        host = "http://localhost:8000"
        projection = AllProjection()
    player_id = UnicodeAttribute(hash_key=True)
    winner_id = UnicodeAttribute(range_key=True)


class GameOpponentTimeIndex(GlobalSecondaryIndex):
    class Meta:
        read_capacity_units = 1
        write_capacity_units = 1
        table_name = "GameOpponentTimeIndex"
        host = "http://localhost:8000"
        projection = AllProjection()
    winner_id = UnicodeAttribute(hash_key=True)
    created_time = UnicodeAttribute(range_key=True)


class GameModel(Model):
    class Meta:
        read_capacity_units = 1
        write_capacity_units = 1
        table_name = "GameModel"
        host = "http://localhost:8000"