Skip to main content

Path base SQL Query

Project description

SQLRaw

SQLRaw is a library that makes it easy to run .sql files that work with a SQLAlchemy.

First of all, SQLAlchemy connection definition are made

connstr = "postgresql://user:psw@host/database"
engine = create_engine(connstr, echo=False)
conn = engine.connect()

Read & Execute Current Sub Folders SQL File

sql = SqlRaw.current()
sql.load("person").connect(conn)
list = sql.fetchone({"id": 1})

In this example, the file "person.sql" is searched and executed in the current folder or subfolders. If there is a parameter definition such as ":id" in SQL, a value can be assigned to the "fetchone" method as a parameter.

Also Note that "fetchone" can be used instead of "fetchall"

Reading a file in a specific folder

sql = SqlRaw.paths(["/model"])

Use Cache

sql.cache_prefix = "app-name-prefix"
sql.cache(host='', port=6379, password='')

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

sqlraw-0.1.4.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

sqlraw-0.1.4-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page