Fluent Query Builder Library
Project description
Moschitta Query Documentation
The moschitta-query package provides a Fluent Query Builder for the Moschitta Framework, enabling developers to generate SQL queries programmatically using a fluent interface.
Installation
You can install moschitta-query via pip:
pip install moschitta-query
Or use it with Poetry:
poetry add moschitta-query
Usage
Basic Query Construction
To use moschitta-query, you need to initialize an instance of the Query class.
from moschitta_query.query import Query
# Create a basic select query
query = Query().select('id', 'name').from_('users')
print(query.to_sql())
# Output: SELECT id, name FROM users
Adding Conditions
You can add conditions to your query using the where method.
# Add a where clause to the query
query = Query().select('*').from_('users').where('age > 21')
print(query.to_sql())
# Output: SELECT * FROM users WHERE age > 21
Joining Tables
Perform joins using the join method.
# Perform an inner join with another table
query = Query().select('users.id', 'users.name', 'orders.total').from_('users') \
.join('orders', 'users.id = orders.user_id')
print(query.to_sql())
# Output: SELECT users.id, users.name, orders.total FROM users JOIN orders ON users.id = orders.user_id
Ordering Results
Specify the order of the result set using the order_by method.
# Order the result set by a column
query = Query().select('name').from_('users').order_by('name')
print(query.to_sql())
# Output: SELECT name FROM users ORDER BY name
API Reference
moschitta_query.query.Query
select(*columns: str) -> Query: Specifies the columns to select in the query.from_(table: str) -> Query: Specifies the table to select data from.where(*conditions: str) -> Query: Adds conditions to filter the result set.join(table: str, on_clause: str) -> Query: Performs an inner join with another table.left_join(table: str, on_clause: str) -> Query: Performs a left outer join with another table.right_join(table: str, on_clause: str) -> Query: Performs a right outer join with another table.order_by(*columns: str) -> Query: Specifies the columns to order the result set by.group_by(*columns: str) -> Query: Groups the result set by the specified columns.having(*conditions: str) -> Query: Adds conditions to filter the grouped result set.limit(count: int) -> Query: Limits the number of rows returned by the query.offset(start: int) -> Query: Specifies the starting offset for the result set.to_sql() -> str: Returns the constructed SQL query as a string.
Contributing
Contributions to moschitta-query are welcome! You can contribute by opening issues for bugs or feature requests, submitting pull requests, or helping improve the documentation.
License
This project is licensed under the terms of the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moschitta_query-0.1.0.tar.gz.
File metadata
- Download URL: moschitta_query-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/6.5.0-13parrot1-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
573011472596b3056d5bff9386e565459decc2b86c02bd4ddd24d5060ab51662
|
|
| MD5 |
4a6fc962f2f14b5f7e00fd133ef5142a
|
|
| BLAKE2b-256 |
1034b6a5200c505b3243d08fdd2558e8568749c67081264fd268d9cb1a141a66
|
File details
Details for the file moschitta_query-0.1.0-py3-none-any.whl.
File metadata
- Download URL: moschitta_query-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/6.5.0-13parrot1-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
442477f2e06302035f62cfeb22d1d8290eb605911fc2c23e67dbee3c832d5ca8
|
|
| MD5 |
254757529d410e112ddbc60c53a8b46f
|
|
| BLAKE2b-256 |
d8a93bf6440338945c0193282da2422a7eb8886b6db7a6875e2d3003ad2939b5
|