Skip to main content

说明

简单的数据库连接

用法

pip install myally_database

推荐搭配包 python-decouple 以便可以直接在 .env 中写配置

创建个 database.py

pip install python-decouple

from decouple import config
from myally_database import Database
db_config = {
    'user': config('DB_USER'),
    'password': config('DB_PASSWORD'),
    'host': config('DB_HOST'),
    'port': config('DB_PORT', default=3306, cast=int),
    'database': config('DB_DATABASE')
}
# 创建一个全局的Database实例,可以在其他文件中直接使用
database = Database(db_config)

.env 配置

DB_USER=名
DB_PASSWORD=数据库密码
DB_HOST=ip
DB_PORT=端口
DB_DATABASE=数据库

调用后用法与包 SQLAlchemy 一致

from database import database
# 获取数据库会话
session = database.get_session()
# 提交事务
session.commit()
# 关闭会话
session.close()

Metadata

Release files for myally_database 1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for myally_database 1.3
File Size Uploaded
myally_database-1.3.tar.gz 1.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for myally_database 1.3
File Interpreter ABI Platform
myally_database-1.3-py3-none-any.whl Python 3 none any Details

Total release size: 3.7 kB

Release files / myally_database-1.3.tar.gz

Download URL myally_database-1.3.tar.gz
Size 1.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3bc1f717d313122eec9f2cc5533b3b56a6fad04043b3bd0050995a8eeb5286b8
BLAKE2b-256 checksum
How to use checksums
7cc5f852ec9b596b7dd9f68fd2427e7e4c6d0639e4dbf0b5d813844dc5003870
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.0 CPython/3.10.6 Windows/10

Release files / myally_database-1.3-py3-none-any.whl

Download URL myally_database-1.3-py3-none-any.whl
Size 2.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f28925df4553ae0bcfdac98d0bb39c95d2b1b79b755e41ec08f6e001aaa1bc16
BLAKE2b-256 checksum
How to use checksums
b4b90767da4f2ba9eaa1750f10074afb32bcd1b2409cff9138989a7f717f38ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.0 CPython/3.10.6 Windows/10

Release history Release notifications | RSS feed

This release

1.3 This release

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page