📜  yesql (1)

📅  最后修改于: 2023-12-03 14:48:40.693000             🧑  作者: Mango

Yesql

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.

Features
  • Separation of concerns: Keep SQL code separate from application code.
  • Ease of use: Yesql is easy to use and understand.
  • Flexibility: Use with any language that can read files, including Python, Ruby, and JavaScript.
Installation

To install Yesql, use pip:

pip install yesql
Usage
  1. Create a new SQL file called 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;
  1. Use Yesql in your application by importing it and loading the SQL file:
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}]
Conclusion

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!