https://github.com/fbraem/sql-smith
An SQL query builder with zero dependencies and a fluent interface
https://github.com/fbraem/sql-smith
fluent python python3 query query-builder sql
Last synced: about 1 month ago
JSON representation
An SQL query builder with zero dependencies and a fluent interface
- Host: GitHub
- URL: https://github.com/fbraem/sql-smith
- Owner: fbraem
- License: mit
- Created: 2021-04-16T18:29:15.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-03-07T18:28:04.000Z (3 months ago)
- Last Synced: 2025-04-09T18:52:03.472Z (about 1 month ago)
- Topics: fluent, python, python3, query, query-builder, sql
- Language: Python
- Homepage:
- Size: 324 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
=========
sql-smith
=========**sql-smith** is an SQL query builder with zero dependencies and a fluent interface.
The sentence above is, beside the name, a copy from the website of the PHP library
Latitude_, for the simple reason that this Python module is a port of Latitude.Read the full `documentation `_.
Installation
************.. code-block:: sh
$ pip install sql-smith
Quick Start
***********QueryFactory is a factory to create a **SELECT**, **INSERT**, **UPDATE** or **DELETE** query.
Use the fluent interface of the queries to complete the query... code-block:: python
from sql_smith import QueryFactory
from sql_smith.engine import CommonEngine
from sql_smith.functions import field
factory = QueryFactory(CommonEngine())
query = factory \
.select('id', 'username') \
.from_('users') \
.where(field('id').eq(5)) \
.compile()
print(query.sql) # SELECT "id", "username" FROM "users" WHERE "id" = ?
print(query.params) # (5)When the query is ready, compile it. The return value of compile is a Query class instance
with two properties: sql and params. Use these properties to pass the query to a database... code-block:: python
import sqlite3
db = sqlite3.connect('test.db')
cur = db.cursor()for row in cur.execute(query.sql, query.params):
print(row).. _Latitude: https://latitude.shadowhand.com/