Skip to content

MarkTLite/interfaces-databases

Repository files navigation

Interfaces (Databases)

codecov Test status Build Status

Description

This project involves the application of design patterns to develop a phonebook cli with the following advantages:

  • High extensibility (Providers' function definitions can be added without complicating the codebase at all)
  • Dependency change does not fail the system.

Concepts applied

  • Databases: PostgreSQL, mongoDB, firestore, sqlalchemy, filesystem
  • Interfaces
  • Dependency Injection
  • Singleton pattern
  • db versioning with alembic

Adding Providers

add commandline argument for the new provider in the tests file Make sure the test_databases.py tests even when unchanged pass for your newly added providers' logic

Running Tests

pip install coverage
Run tests for each provider in this format:
coverage run tests\test_databases.py postgres
where "postgres" is one of:

  • postgres
  • mongoDB
  • firestore
  • sqlite
  • filesystem

Getting coverage

use -a to append individual tests
coverage run tests\test_databases.py filesystem && coverage run -a tests\test_databases.py sqlite && coverage run -a tests\test_databases.py postgres && coverage run -a tests\test_databases.py mongoDB && coverage run -a tests\test_databases.py firestore
then
coverage report
add this to the testcov.yml file too

Environment files

Add these files in the /providers folder before running.

dbconfig.ini for postgres

[postgresql]
host=****
database=****
port=5432
user=user
password=****

.env for mongo

MONGO_URI=****

The service account json for firestore

{
}

alembic

Used for db change mgt and versioning to have reversible changes and avoid loss of data during db restructuring. Run:
alembic init alembic
in a virtual env to create the missing alembic.ini in the root dir and then in it, edit the:
sqlalchemy.url = driver://user:pass@localhost/dbname

About

Applied interfaces and dependency injection to create a phonebook cli with better code quality. Providers include PostgreSQL, MongoDB, Firestore

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published