https://github.com/kougen/py-repositories
A library which implements the repository pattern for multiple providers
https://github.com/kougen/py-repositories
helpful json package pip postgresql python repository-pattern solid-principles
Last synced: about 1 month ago
JSON representation
A library which implements the repository pattern for multiple providers
- Host: GitHub
- URL: https://github.com/kougen/py-repositories
- Owner: kougen
- Created: 2024-03-22T22:56:55.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-16T20:57:19.000Z (11 months ago)
- Last Synced: 2025-03-16T20:48:28.378Z (about 2 months ago)
- Topics: helpful, json, package, pip, postgresql, python, repository-pattern, solid-principles
- Language: Python
- Homepage: https://pypi.org/project/pyrepositories/
- Size: 56.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Python SOLID Repository pattern implementations
This repository contains a simple implementation of the Repository pattern in Python. The implementation is based on the SOLID principles.
It supports:
- PostgreSQL
- JSON## Usage
Check the ./scripts/main.py for a full example.
```py
# main.py
# ...
# Define the fields for the table and entities
datasource = DataSource()
table = JsonTable('users', os.path.join(path_root, 'scripts', 'data'), fields)
datasource.add_table(table)datasource.clear('users')
dummy_users = [
User('John Doe', '[email protected]', 'johndoe'),
User('Jane Doe', '[email protected]', 'janedoe'),
User('Mary Poppins', '[email protected]', 'marypoppins'),
]for user in dummy_users:
datasource.insert('users', user)filters = [
Filter([
FilterCondition('name', 'Doe', FilterTypes.CONTAINS),
FilterCondition('email', '[email protected]', FilterTypes.EQUAL)
]),
Filter([
FilterCondition('name', 'Mary', FilterTypes.CONTAINS),
])
]for user in datasource.get_by_filters('users', filters):
print(user)print("Unique")
mary = datasource.get_unique('users', 'username', 'marypoppins')
print(mary)```