Skip to content

Commit

Permalink
RC with make_index_query
Browse files Browse the repository at this point in the history
  • Loading branch information
micmurawski committed Apr 19, 2023
1 parent 0795fe9 commit 78a24e5
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 1,050 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ jobs:
python3 setup.py sdist bdist_wheel
python3 -m twine check dist/*
python3 -m twine upload --skip-existing dist/* --verbose -u ${USERNAME} -p ${PASSWORD}
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
PROJECT_NAME = pynamodb-utils
LAMBDA_PYTHON_PACKAGE_NAME = $(PROJECT_NAME)
COV = pynamodb_utils

include build/makefile/root.mk
include build/makefile/python.mk
include build/makefile/lint.mk
include makefiles/root.mk
include makefiles/python.mk
include makefiles/lint.mk
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,25 @@ from pynamodb_utils import DynamicMapAttribute, AsDictModel,
JSONQueryModel, TimestampedModel


class CategoryEnum(enum.Enum):
finance = enum.auto()
politics = enum.auto()

class PostCategoryCreatedAtGSI(GlobalSecondaryIndex):
category = EnumAttribute(hash_key=True, enum=CategoryEnum)
created_at = UTCDateTimeAttribute(range_key=True)

class Meta:
index_name = "example-index-name"
projection = AllProjection

class Post(AsDictModel, JSONQueryModel, TimestampedModel):
name = UnicodeAttribute(hash_key=True)
sub_name = UnicodeAttribute(range_key=True)
category = EnumAttribute(enum=CategoryEnum, default=CategoryEnum.finance)
content = UnicodeAttribute()
tags = DynamicMapAttribute(default={})
category_created_at_gsi = PostCategoryCreatedAtGSI()

class Meta:
table_name = 'example-table-name'
Expand All @@ -37,20 +52,24 @@ Post.create_table(read_capacity_units=10, write_capacity_units=10)

post = Post(
name='A weekly news.',
sub_name='Shocking revelations',
content='Last week took place...',
category=CategoryEnum.finance,
tags={
"type": "news",
"topics": ["stock exchange", "NYSE"]
}
)
post.save()

condition = Post.get_conditions_from_json(query={
"created_at__lte": str(datetime.now()),
"tags.type__equals": "news",
"tags.topics__contains": ["NYSE"]
})
results = Post.scan(filter_condition=condition)
condition = Post.make_index_query(
query={
"created_at__lte": str(datetime.now()),
"sub_name__exists": None,
"category__equals": "finance",
"OR": {"tags.type__equals": "news", "tags.topics__contains": ["NYSE"]},
}
) # class method executes query on the most optimal index
print(next(results).as_dict())
```
That lines of code should result with following output
Expand All @@ -71,4 +90,4 @@ That lines of code should result with following output

## Links
* https://github.com/pynamodb/PynamoDB
* https://pypi.org/project/pynamodb-utils/
* https://pypi.org/project/pynamodb-utils/
11 changes: 0 additions & 11 deletions build/makefile/lint.mk

This file was deleted.

59 changes: 0 additions & 59 deletions build/makefile/python.mk

This file was deleted.

128 changes: 0 additions & 128 deletions build/makefile/root.mk

This file was deleted.

2 changes: 0 additions & 2 deletions pynamodb_utils/__init__.py

This file was deleted.

98 changes: 0 additions & 98 deletions pynamodb_utils/attributes.py

This file was deleted.

10 changes: 0 additions & 10 deletions pynamodb_utils/exceptions.py

This file was deleted.

Loading

0 comments on commit 78a24e5

Please sign in to comment.