Skip to content

The Criteria Pattern is a Python ๐Ÿ package that simplifies and standardizes criteria based filtering ๐Ÿค๐Ÿป, validation and selection.

License

Notifications You must be signed in to change notification settings

adriamontoto/criteria-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค๐Ÿป Criteria Pattern

Test Pipeline Lint Pipeline Coverage Pipeline Package Version Supported Python Versions

The Criteria Pattern is a Python ๐Ÿ package that simplifies and standardizes criteria based filtering ๐Ÿค๐Ÿป, validation and selection. This package provides a set of prebuilt ๐Ÿ‘ท๐Ÿป objects and utilities that you can drop into your existing projects and not have to implement yourself.

These utilities ๐Ÿ› ๏ธ are useful when you need complex filtering logic. It also enforces ๐Ÿ‘ฎ๐Ÿป best practices so all your filtering processes follow a uniform standard.

Easy to install and integrate, this is a must have for any Python developer looking to simplify their workflow, enforce design patterns and use the full power of modern ORMs and SQL ๐Ÿ—„๏ธ in their projects ๐Ÿš€.

Table of Contents

๐Ÿ”ผ Back to top



๐Ÿ“ฅ Installation

You can install Criteria Pattern using pip:

pip install criteria-pattern

๐Ÿ”ผ Back to top



๐Ÿ’ป Utilization

from criteria_pattern import Criteria, Filter, FilterOperator
from criteria_pattern.converter import SqlConverter

is_adult = Criteria(filters=[Filter('age', FilterOperator.GREATER_OR_EQUAL, 18)])
email_is_gmail = Criteria(filters=[Filter('email', FilterOperator.ENDS_WITH, '@gmail.com')])
email_is_yahoo = Criteria(filters=[Filter('email', FilterOperator.ENDS_WITH, '@yahoo.com')])

query = SqlConverter.convert(criteria=is_adult & (email_is_gmail | email_is_yahoo), table='user')

print(query)

# >>> SELECT * FROM user WHERE (age >= '18' AND (email LIKE '%@gmail.com' OR email LIKE '%@yahoo.com'));

๐Ÿ”ผ Back to top



๐Ÿค Contributing

We welcome contributions to Criteria Pattern! To ensure a smooth collaboration process, please follow the guidelines below.

How to Contribute

1. Fork the Repository: Click the "Fork" button at the top right of the repository page.

2. Clone Your Fork:

git clone git+ssh://[email protected]/<your-username>/criteria-pattern.git

3. Create a Branch:

git checkout -b feature/your-feature-name

4. Make Your Changes: Implement your new feature or fix a bug.

5. Run Tests: Ensure all the following tests pass before submitting your changes.

  • Run tests:
make test
  • Run tests with coverage:
make coverage
  • Run linter:
make lint
  • Run formatter:
make format

6. Commit Your Changes:

git commit -m "โœจ feature: your feature description"

7. Push to Your Fork:

git push origin feature/your-feature-name

8. Create a Pull Request: Navigate to the original repository and create a pull request from your fork.

9. Wait for Review: Your pull request will be reviewed by the maintainers. Make any necessary changes based on their feedback.

๐Ÿ”ผ Back to top



๐Ÿ”‘ License

This project is licensed under the terms of the MIT license.

๐Ÿ”ผ Back to top