📅  最后修改于: 2023-12-03 14:48:40.693000             🧑  作者: Mango
Yesql is a lightweight library that allows programmers to write and manage SQL statements in external files. With Yesql, SQL code is kept separate from application code, making queries easier to read, maintain, and test.
To install Yesql, use pip:
pip install yesql
queries.sql
in your application directory:-- queries.sql
-- Example of a SQL query for Yesql to handle
-- :name parameter can be replaced at runtime
SELECT * FROM users WHERE name = :name;
import yesql
with open("queries.sql", "r") as file:
queries = yesql.load(file)
result = queries.get_user_by_name(name="John")
print(result)
Output:
[{'id': 1, 'name': 'John', 'age': 25}]
Yesql can make writing and managing SQL code easier and more maintainable. If you're tired of keeping SQL code mixed in with your application code, give Yesql a try!