Use of SQL Spitter
Use YAML files to strip SQL statements from the program, and implement dynamic SQL through Jinja2.
Specify sql folder
from sql_splitter import SqlLoader
# Configure the path of the sql folder
SqlLoader.SQL_FILE_PATH = "/Users/kela/Program/open-sources/sql-splitter/sql_splitter/example/sql"
loader = SqlLoader()
Load all sql statements
# All sql statements are loaded while the application is running
loader.preload_all_sqls()
print(f'All sqls: {loader.sqls}')
Gets the specified sql statement
# Obtain sql based on sql_id
sql = loader.get(
"user.index.query_user_info", options={}
)
print(f"current sql: {sql}")
Write sql statements sql/user/index.yml
SELECT
user.id,
user.account_id,
user.account_name,
user.user_name,
user.password,
user.phone,
user.is_delete,
user.enable_flag,
user.register_datetime,
group.name AS group_name
FROM user
JOIN group ON user.group_id = group.id
WHERE user.id = :user_id
Generate dynamic sql with the option parameter
SELECT
user.id,
user.account_id,
user.account_name,
user.user_name,
user.password,
user.phone,
user.is_delete,
user.enable_flag,
user.register_datetime,
group.name AS group_name
FROM user
JOIN group ON user.group_id = group.id
{% if user_id > 0 %}
WHERE user.id = :user_id
{% endif %}
# Obtain sql based on sql_id with option
# Dynamic sql requires passing in parameters to be filtered
sql = loader.get(
"user.index.query_user_info",
options={
'user_id': 1
}
)
print(f"current sql: {sql}")
# 生成的sql语句
"""
SELECT
user.id,
user.account_id,
user.account_name,
user.user_name,
user.password,
user.phone,
user.is_delete,
user.enable_flag,
user.register_datetime,
group.name AS group_name
FROM user
JOIN group ON user.group_id = group.id
WHERE user.id = :user_id
"""
Metadata
Release files for sql-spliter 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sql-spliter-0.0.2.tar.gz | 3.7 kB | Without provenance | Details for sql-spliter-0.0.2.tar.gz |
Release files / sql-spliter-0.0.2.tar.gz
| Download URL | sql-spliter-0.0.2.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a951ebe708cca33fbf8e541ce21ce472be53645e966f04fc7fea3d4b8d8d680
|
|
BLAKE2b-256 checksum How to use checksums |
1bcb8de9237fccdf2436d1521a361630ce8a13ecfdf31cfef0d2f6c78953bacd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.16
|
Security for sql-spliter 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.