Skip to main content

A simple way to interact with a database using the SOLID principles' Repository pattern.

Project description

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.

# 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', 'test@asd.com', 'johndoe'),
    User('Jane Doe', 'test3@asd.com', 'janedoe'),
    User('Mary Poppins', 'poppinst@industry.com', 'marypoppins'),
]

for user in dummy_users:
    datasource.insert('users', user)

filters = [
    Filter([
        FilterCondition('name', 'Doe', FilterTypes.CONTAINS),
        FilterCondition('email', 'test@asd.com', 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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrepositories-2.1.1.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

pyrepositories-2.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file pyrepositories-2.1.1.tar.gz.

File metadata

  • Download URL: pyrepositories-2.1.1.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for pyrepositories-2.1.1.tar.gz
Algorithm Hash digest
SHA256 02b25e229b196bbb8ec3f42aa389fee8bdb7e2ef20ea5eec9e4d52298bee26ac
MD5 d322394ebc4e22e212db35ac7d96be7a
BLAKE2b-256 5f3e9813deaa2db385571db91b36c9cb3227ea674716e5dcee3e7b5d89bb8a24

See more details on using hashes here.

Provenance

File details

Details for the file pyrepositories-2.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pyrepositories-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4bad203fa7fbb260a2032c17550db0165382489c1cee44aefd818ac8bb1ef411
MD5 87ef4e9c4e4b324501872fac9b499054
BLAKE2b-256 e836c753623a42abc4be020625e9dceb8799adc714e1d9cf372fbe375002f205

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page