A high-level sql command utility. Currently, only MySQL is supported. PYPI Package
For a detailed usage example see example.py.
First, you need to install the library using pip:
$ pip install high_sql
Then, import it and initialize it like so:
from high_sql import HighMySQL
db_conf = {'hostname': 'your hostname', 'username': 'your username', 'password': 'your password',
'db_name': 'your db name', 'port': 3306}
mysql_obj = HighMySQL(config=db_conf)
If you want to use a yml file to load the configuration, you can use the HighConfig
class:
from high_sql import HighConfig
import os
config_path = str(os.path.join('confs', 'conf.yml'))
config = HighConfig(config_src=config_path)
db_conf = config.get_db_config()
Two example YAML files can be found in the confs folder. For more details on how to use this YAML configuration loader see this Readme.
The currently supported operations are the following:
- Inserts, Updates, Deletes, Select
- Create, Truncate, Drop table
- Show all tables
Insert
mysql_obj.insert_into_table('test_table', data={'firstname': 'Mr Name', 'lastname': 'surname'})
Update
mysql_obj.update_table('test_table', set_data={'lastname': 'New Last Name'},
where='firstname="Mr Name"')
Delete
mysql_obj.delete_from_table('test_table', where='firstname="Mr Name"')
Select
res = mysql_obj.select_from_table('test_table', columns='*', where='firstname="Mr Name"',
order_by='firstname', asc_or_desc='ASC', limit=5)
Truncate
mysql_obj.truncate_table('test_table')
Create
mysql_obj.create_table(table='test_table', schema=table_schema)
Drop
mysql_obj.drop_table('test_table')
Show Tables
mysql_obj.show_tables()
All of these examples can be found in example.py.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
You need to have a machine with anaconda installed and any Bash based shell (e.g. zsh) installed.
$ conda -V
conda 4.10.1
$ echo $SHELL
/usr/bin/zsh
All the installation steps are being handled by the Makefile.
First, modify the python version (min_python
) and everything else you need in
the settings.ini.
Then, execute the following commands:
$ make create_env
$ conda activate high_sql
$ make dist
Now you are ready to use and modify the library.
If you want to run the unit tests, execute the following command:
$ make tests
For the continuous integration, the CircleCI service is being used. For more information you can check the setup guide.
For any modifications, edit the circleci config.
This is mainly for future reference for the developers of this project. First,
create a file called ~/.pypirc
with your pypi login details, as follows:
[pypi]
username = your_pypi_username
password = your_pypi_password
Then, modify the python version (min_python
), project status (status
), release version (version
)
and everything else you need in
the settings.ini.
Finally, execute the following commands:
$ make create_env
$ conda activate high_sql
$ make release
For a dev release, change the testing_version
and instead of make release
, run make release_test
.
This project is licensed under the Apache License - see the LICENSE file for details.