Skip to content

Instantly share code, notes, and snippets.

@thanakijwanavit
Last active September 15, 2020 02:05
Show Gist options
  • Save thanakijwanavit/806a5daa5284587694f977f8129e6327 to your computer and use it in GitHub Desktop.
Save thanakijwanavit/806a5daa5284587694f977f8129e6327 to your computer and use it in GitHub Desktop.
Global secondary index for pynamodb
from pynamodb.indexes import GlobalSecondaryIndex, AllProjection
from pynamodb.attributes import NumberAttribute, BooleanAttribute
class Database(Model):
class Meta:
aws_access_key_id = ACCESS_KEY_ID
aws_secret_access_key = SECRET_ACCESS_KEY
table_name = DATABASE_TABLE_NAME
region = REGION
ib_prcode = UnicodeAttribute(hash_key=True, default = '')
lastUpdate = NumberAttribute( default = 0)
inventory = JSONAttribute(default={})
needUpdate = BooleanAttribute(default=False)
needUpdateIndex = Database.NeedUpdateIndex()
class NeedUpdateIndex(GlobalSecondaryIndex):
class Meta:
index_name = 'need-update'
projection = AllProjection()
# This attribute is the hash key for the index
# Note that this attribute must also exist
# in the model
needUpdate = BooleanAttribute(default=False, hash_key=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment