No project description provided
Project description
dbm-database-service
Package can be used by in early stages of development to manage MySQL Database by adding and modifying tables and columns. The idea is that once we have .env file created, we can use it's mysqlpool credentials to connect into database. We are able to do it in automatic mode where .env file has to be store in same location where connector will be called, or we can use absolute path to a file.
Installation
Using pip:
pip install dbm-database-service
Using poetry:
poetry add dbm-database-service
Using pipenv:
pipenv install dbm-database-service
TESTS
Tests are automated, that means that you don't need to prepare .env files in desired places. They will be downloaded from Google Drive - feel free to inspect them. MySQL container also will be created, so no further set up is needed.
1. Make sure your docker is running and port 3306 is empty
2. Clone repository and enter main directory:
git clone https://github.com/DSmolke/DBM_DataBase_Service.git
cd DBM_DataBase_Service
3. Run tests using:
####Poetry:
poetry update
poetry shell
cd tests
poetry run pytest -vv
- update protects from decoding errors
- tests take around 15s because of database and .env files
####Pipenv:
pipenv shell
cd tests
pipenv run pytest -vv
####Pip:
pip install mysql-connector-python
pip install python-dotenv
pip install easyvalid-data-validator
pip install gdown
pip install pytest
cd tests
pytest -vv
Basic usage
Having existing database server, or mysql container, we want to create new table, add columns to existing table or do any operation on database.
###1. Step - prepare .env file Please download .env file template - > link
Edit file according to your needs.
POOL_NAME=TEST
POOL_SIZE=5
POOL_RESET_SESSION=True
HOST=localhost
DATABASE=test_db
USER=user
PASSWORD=user
PORT=3306
Copy its absolute path and keep it for later use.
###2. Step - Import all necessary objects
from dbm_database_service.models.column import Column
from dbm_database_service.models.table import Table
from dbm_database_service.models.datatype import DataType
from dbm_database_service.connectors import MySQLConnectionPoolBuilder
from dbm_database_service.managers import MySQLDatabaseManager
###3. Step - Create new MySQLConnectionPoolBuilder with prepared .env path
dbm1 = MySQLConnectionPoolBuilder(r'C:\Users\Omen i5\Desktop\PROJEKTY\dbm_database_service\tests\.env')
###4. Step - Create new MySQLDatabaseManager using object prepared in previous step
database_manager = MySQLDatabaseManager(dbm1.build())
- Step - Add new table into database:
database_manager.create_table(
Table('jeans', if_not_exists=True, columns=[
Column(name='id', datatype=DataType('int'), primary_key=True, autoincrement=True),
Column(name='brand', datatype=DataType('varchar', 255), unique=True),
Column(name='price', datatype=DataType('decimal', (6, 2)), unique=True),
])
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
Built Distribution
Hashes for dbm_database_service-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1763b12bf6487950cb973425637865b9d9d1b6cb039664f265a4970380585e3d |
|
MD5 | dac24defa169e30b56e26dc1a6f9dab6 |
|
BLAKE2b-256 | 135c821195c1f3b2bbbf411ede32dda71e66b18bf927d4c614d8fff84e25e676 |
Hashes for dbm_database_service-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed1cd0b4d069fd149de21e425a5399784a09873a2919fa34e4248ecbdd48e22b |
|
MD5 | 1b0d8ed63d2737df5b8c0486ca14184c |
|
BLAKE2b-256 | 1d64ce63c510cfa534bed649733cffbcdee1aa3adae03493fb3f247d7115d08b |