Skip to main content

This python package is based from python mysql connector

Project description

Welcome to EzSQL!

This python package is based from python mysql connector. It allows you to easily consume MySQL service without doing much of the code.

Features

 - Perform Basic Secure prepared MySQL queries
 - Perform SELECT queries with your return data format of choice
	 - Get a JSON formatted result
	 - Get a List formatted result
	 - Get results in Tuple
- Supports DB Credentials from Environment Variables

Installation

pip install python-ezsql

Setting up your credentials

To set your credentials, you can set the following in your environment variable. You may also put it in your .env file

EZSQL_DBUSER=your_user
EZSQL_DBPASS=your_pass
EZSQL_DBHOST=your_host
EZSQL_DBNAME=your_db

Creating a query instance

from ezsql.EzSQL import Query

#query_string is your prepared statement.
query_string = "SELECT * FROM table_a WHERE id = %s"

#query_values is a tuple of values
query_values = (1,)

_ezsql = Query(query_string,query_values)

SELECT That returns tuple

_result = _ezsql.run_select()
print(_result)

outputs

[(1, 'foo', 18)]

SELECT That returns a list

_result = _ezsql.run_select_with_list()
print(_result)

outputs

[1, 'foo', 18]

SELECT That returns a JSON

_result = _ezsql.run_select_with_json()
print(_result)

outputs

[{'id': 1, 'name': 'foo', 'age': 18}]

INSERT

_result = _ezsql.run_insert()
print(_result)

outputs

True

UPDATE

_result = _ezsql.run_update()
print(_result)

outputs

True

DELETE

_result = _ezsql.run_delete()
print(_result)

outputs

True

Running a test

To run a test, create a table like this.

CREATE TABLE `data` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(45) DEFAULT NULL,
`age` int DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

When the table is ready, you can use the run_test() function

from ezsql.tests import test_ezsql
test_ezsql.run_tests()

Test Output

Running ezsql test.
PENDING: Testing set_query_string()
SUCCESS: Query string set.
Testing set_query_values()
SUCCESS: Query values set.
PENDING: Testing db_connection()
SUCCESS: Connection successful.
PENDING: Testing run_insert()
SUCCESS: Successfully inserted data.
PENDING: Testing run_select()
SUCCESS: Successfully retrieved result for select
SUCCESS: Result: [(47, 'John', 30)]
PENDING: Testing run_update()
SUCCESS: Successfully updated data.
PENDING: Testing run_select_with_json()
SUCCESS: Successfully retrieved result for select with JSON
Result: [{'id': 47, 'name': 'John', 'age': 31}]
PENDING: Testing run_select_with_list()
SUCCESS: Successfully retrieved result for select with list
SUCCESS: Result: [[47, 'John', 31]]
PENDING: Testing run_delete()
SUCCESS: Successfully deleted data.

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

python-ezsql-0.0.3.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

python_ezsql-0.0.3-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file python-ezsql-0.0.3.tar.gz.

File metadata

  • Download URL: python-ezsql-0.0.3.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.3

File hashes

Hashes for python-ezsql-0.0.3.tar.gz
Algorithm Hash digest
SHA256 76f6e942aa723d1aaf5de64e323e077f46a1a985b5603f82c9c960fd8325b858
MD5 5e6291c2a4184101b5d966966fb70504
BLAKE2b-256 d9f74a8535adc0fedde4a5d0b55b81ef1ce1417113e7dc736c5b0f9cae30b0ea

See more details on using hashes here.

File details

Details for the file python_ezsql-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for python_ezsql-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2ec36328468e162ea6dbe665ab09b6d3a1343ae4fcb02d3f7fad06c0f4972a5f
MD5 4a73b5e0d08ecfdbcc445607563bf2bc
BLAKE2b-256 f1290ede56b8c28296e63cb6f7aff76389f7507cab5e82b9b7472c304d44f9a1

See more details on using hashes here.

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