TomMalkin / SimQLe

The simplest way to use SQL in Python
MIT License
30 stars 5 forks source link

Idea: load sql text from a .sql text file in a designated directory by name. #92

Open TomMalkin opened 3 years ago

TomMalkin commented 3 years ago
root/
    .connections.yaml
    /queries
        get_person.sql

where get_person.sql could be

select Id, Name, Age
from Person
where Id = :person_id

and the python code could be


cm = ConnectionManager(queries_dir="queries")  # directory called queries holds the named sql files
params = {"person_id": 5}
person_record = cm.record(
    sql=None, 
    sql_file="get_person",  # meaning the get_person.sql file in the designated queries directory
    con_name="my-database", 
    params=params
)