SQL connector for lazy people
Project description
LazySql: SQL connector for lazy people
Installation
pip3 install lazysql
Testing
python3 -m unittest
Usage
Connecting
#Import your db connector
import sqlite3
import psycopg2
from lazysql import LazySql
read_db = LazySql(sqlite3, 'read.db', max_conn=3)
write_db = LazySql(psycopg2, "dbname='write_db' user='postgres' host='localhost' password='UnsafePassword' port=5432")
Reading
query1 = f"SELECT * FROM read_table LIMIT 5;"
#Returns selection from DB
res = read_db.query(query1)
Writing
query2 = f"INSERT INTO write_table(value1, value2, value3) VALUES(%s, %s, %s)"
write_db.query(query2, , data=(test, 1, 2.3), commit=True)
Batch Writing
query3 = f"INSERT INTO write_table(value1, value2, value3) VALUES(%s, %s, %s)"
for i in range(0,100):
write_db.batch(query3, data=(f"test{i}", i, i+1.5))
write_db.commit()
#Alternatives
write_db.batch(None, commit=True) #Commits directly
write_db.close() #Close without committing
write_db.batch(None, close=True) #Close without committing
Async
test1res, test2res, test3res = read_db.async_query([
{"query":"SELECT * FROM test WHERE _str=?", "data":"test1"},
{"query":"SELECT * FROM test WHERE _str=?", "data":"test2"},
{"query":"SELECT * FROM test WHERE _str=?", "data":"test3"}
])
#Result will be in list of order of query sent
#i.e
[
[
{'id': 5, '_str': 'test1', '_int': 1, '_flt': 2.5},
{'id': 15, '_str': 'test1', '_int': 1, '_flt': 2.5},
{'id': 25, '_str': 'test1', '_int': 1, '_flt': 2.5}
],
[
{'id': 6, '_str': 'test2', '_int': 2, '_flt': 3.5},
{'id': 16, '_str': 'test2', '_int': 2, '_flt': 3.5},
{'id': 26, '_str': 'test2', '_int': 2, '_flt': 3.5}
],
[
{'id': 7, '_str': 'test3', '_int': 3, '_flt': 4.5},
{'id': 17, '_str': 'test3', '_int': 3, '_flt': 4.5},
{'id': 27, '_str': 'test3', '_int': 3, '_flt': 4.5}]
]
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
lazysql-0.0.5.tar.gz
(4.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lazysql-0.0.5.tar.gz.
File metadata
- Download URL: lazysql-0.0.5.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
471b75dcb2abcfe7f3b1c9f7ac6dcacb0c8b68b2927157fa535109c6aa93b04f
|
|
| MD5 |
7e6f9a18128869262fa887a1683d255e
|
|
| BLAKE2b-256 |
7114e657693b521d05f8aa057d15e84b5bf516f4c24d81ef30f1a7aec2c17b6b
|
File details
Details for the file lazysql-0.0.5-py3-none-any.whl.
File metadata
- Download URL: lazysql-0.0.5-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97c3f50d0cc4b8334f2866ee93e457a368f01a8c9674b181ad61a6c2cb18e355
|
|
| MD5 |
292e0f674ce42826d0cd12fd487b881d
|
|
| BLAKE2b-256 |
6830d005c7b03abd05d3fd7601e4370b3b796200a0d573d919900b83ea94ee20
|