A Python library for dynamically generating SQL queries.
Project description
Pysqlizer
Pysqlizer is a Python library for dynamically generating SQL queries based on tuple length and optimizing query generation efficiency.
Installation
Install via pip:
pip install pysqlizer
Usage
sqlify
Function Signature:
sqlify(keyColumn: str, data: list, raiseException: bool = False, how: str = "IN", condition: str = "OR") -> str
Parameters:
- keyColumn (str): The column name on which the condition will be applied.
- data (list): List of values to be used in the query.
- raiseException (bool, optional): If
True, raises an error for an empty data list. Default isFalse. - how (str, optional): SQL condition type (
IN,NOT IN,LIKE,NOT LIKE). Default isIN. - condition (str, optional): Logical condition between multiple statements (
AND,OR). Default isOR.
Examples:
from pysqlizer import sqlify
# Case 1: Basic IN condition
print(sqlify("product_id", [101, 102, 103]))
# Output: "product_id IN (101, 102, 103)"
# Case 2: NOT IN condition
print(sqlify("category_id", [5, 6], how="NOT IN"))
# Output: "category_id NOT IN (5, 6)"
# Case 3: LIKE condition
print(sqlify("product_name", ["phone", "laptop"], how="LIKE", condition="AND"))
# Output: "(product_name LIKE '%phone%' AND product_name LIKE '%laptop%')"
# Case 4: NOT LIKE condition
print(sqlify("product_name", ["tablet", "watch"], how="NOT LIKE", condition="OR"))
# Output: "(product_name NOT LIKE '%tablet%' OR product_name NOT LIKE '%watch%')"
# Case 5: Empty list without exception
print(sqlify("user_id", [], how="IN"))
# Output: "(1=0)" (safe fallback for empty lists)
# Case 6: Empty list with exception
print(sqlify("user_id", [], raiseException=True))
# Raises ValueError: "data list cannot be empty when raiseException=True"
sqlifylike
Function Signature:
sqlifylike(keyColumn: str, data: list, how: str = "LIKE", condition: str = "OR") -> str
Parameters:
- keyColumn (str): The column name on which the condition will be applied.
- data (list): List of values to be used in the LIKE conditions.
- how (str, optional): SQL condition type (
LIKEorNOT LIKE). Default isLIKE. - condition (str, optional): Logical condition between multiple statements (
AND,OR). Default isOR.
Examples:
from pysqlizer import sqlifylike
# Case 1: LIKE condition with OR
print(sqlifylike("product_name", ["phone", "laptop"]))
# Output: "(product_name LIKE '%phone%' OR product_name LIKE '%laptop%')"
# Case 2: LIKE condition with AND
print(sqlifylike("product_name", ["phone", "laptop"], condition="AND"))
# Output: "(product_name LIKE '%phone%' AND product_name LIKE '%laptop%')"
# Case 3: NOT LIKE condition with OR
print(sqlifylike("product_name", ["tablet", "watch"], how="NOT LIKE"))
# Output: "(product_name NOT LIKE '%tablet%' OR product_name NOT LIKE '%watch%')"
# Case 4: NOT LIKE condition with AND
print(sqlifylike("product_name", ["tablet", "watch"], how="NOT LIKE", condition="AND"))
# Output: "(product_name NOT LIKE '%tablet%' AND product_name NOT LIKE '%watch%')"
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
pysqlizer-1.0.0.tar.gz
(3.5 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 pysqlizer-1.0.0.tar.gz.
File metadata
- Download URL: pysqlizer-1.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
354fd4851cf7b2fd80ce58046a2c0165d07b48ce6e4deae3ec1878c16d9c6f37
|
|
| MD5 |
8e49e045a1a2ced25f7a82a93e19c9aa
|
|
| BLAKE2b-256 |
41a3af563bbb33da9fb694193f03502fa1edb28fc6a7e2698a7be6f510546a28
|
File details
Details for the file pysqlizer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pysqlizer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
966e6823c6f8d66e2e08e1aaa6bed7a747706c78a1c06c723b18782abd4f1b09
|
|
| MD5 |
4f6afd874a4c501fbfa2f26337c33b39
|
|
| BLAKE2b-256 |
67055af2bc58a175bd9880bbd3ca80aa6793ad620fb7daf36d61ed8bf77124f7
|