Simple Database Connectors
Project description
Simple Python Database Connectors
Basic Python 3 class for connecting to Databases
I recommend using this as a super class for a custom class, as shown in the quickstart, but can be used without.
Main goal
This is something I built for personal (local) projects. I'll expand this repository when I need a new type of database connection for a project. By doing it this way, I have a nice all-in one package for all my different database connections. The goal is to keep the code and package as small and lightweigth as possible.
Supported Databases
These databases are tested and working with the current build.
- AzureSQL
- SQLServer Express
These databases should work, but are not (fully) tested
- MySQL
- SQLite
Defaults
- port: 1433
- driver: ODBC Driver 17 for SQL Server
Example Code
SQLConnector
from SimpleDatabaseConnector.Connectors import SQLConnector
class CustomSQLConnector(SQLConnector):
def __init__(self,
password,
server="my-server-endpoint",
database="my-database-name",
username="my-db-username",
):
super().__init__(username, password, server, database)
# Write custom functions
db = CustomSQLConnector(password="my-db-password")
# Get a user by his/her id
id = "00000000-1234-5678-abcd-000000000001" # example uuid4
result = db.get_item_by_id("User", id)
print(result)
DatabaseCache
from SimpleDatabaseConnector.Caches import DatabaseCache
import CustomConnector # import your own custom connector
# Create new cache and db instances
cache = DatabaseCache()
db = CustomConnector()
# an example query
query = "SELECT * FROM Building WHERE FirstName = ? AND LastName = ?;"
args = ["John", "Doe"]
# example function, this would probably be integrated in your CustomConnector
def get_user():
result = cache.check(query, args=args)
if result == None:
result = db.get_all(query, args)
cache.add(query, data=result, args=args)
return result
# the first time the database will be called, the second time the cache will be used
user_sql = get_user()
user_cache = get_user()
Wanted features
- SQL Connector
- Database Cache
- MongoDB Connector
Project details
Release history Release notifications | RSS feed
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
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 SimpleDatabaseConnector-0.0.4.tar.gz.
File metadata
- Download URL: SimpleDatabaseConnector-0.0.4.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.55.2 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5e0ee69f7d3d267e4c4cb224987ef6afd856201cc83fcebe4fbdcede3add9c1
|
|
| MD5 |
0e85445ebedf0fc51e5a6f4cb2b1d786
|
|
| BLAKE2b-256 |
2f7a172c52f965b21780cbfe5c7028d247c25387f59e914207ca5331d9facd06
|
File details
Details for the file SimpleDatabaseConnector-0.0.4-py3-none-any.whl.
File metadata
- Download URL: SimpleDatabaseConnector-0.0.4-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.55.2 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
880dbe580b702cc10eb9e75922445757b194863d02850843bc61242d798f090b
|
|
| MD5 |
5bdc42b2282d69262b19d5b312a5986b
|
|
| BLAKE2b-256 |
3f2c0fe00513c6ef19d2f0a3b394ea5374f2e50d8b7f6c3093764708942f8c48
|