-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
200 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,56 @@ | ||
[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/investsuite/querytyper) | ||
|
||
# querytyper | ||
# Querytyper | ||
|
||
A Python package to queryy databases using a fully typed syntax. | ||
Querytyper is a Python package to query MongoDB using a fully typed syntax. | ||
It leverages the Pydantic library for defining and validating data models, providing a seamless and type-safe experience. | ||
|
||
## Features | ||
- Construct MongoDB queries using Python's native syntax with type hints. | ||
- Leverage Pydantic models to define your MongoDB document structure and query filters efficiently. | ||
- Build complex queries using logical operators and comparisons in a natural and expressive way. | ||
|
||
## Using | ||
|
||
To add and install this package as a dependency of your project, run `poetry add querytyper`. | ||
### A simple example: | ||
```python | ||
from pydantic import BaseModel, EmailStr | ||
from querytyper import MongoModelMetaclass, MongoQuery | ||
|
||
class User(BaseModel): | ||
"""User database model.""" | ||
id: int | ||
name: str | ||
age: int | ||
email: EmailStr | ||
|
||
class UserFilter(User, metaclass=MongoModelMetaclass): | ||
"""User query filter.""" | ||
|
||
query = MongoQuery( | ||
(UserFilter.name == "John") | ||
& (UserFilter.age >= 10) | ||
& ( | ||
UserFilter.email | ||
in [ | ||
"[email protected]", | ||
"[email protected]", | ||
] | ||
) | ||
) | ||
print(query) | ||
``` | ||
```python | ||
{ | ||
"name": "John", | ||
"age": {"$gte": 10}, | ||
"email": [ | ||
"[email protected]", | ||
"[email protected]", | ||
], | ||
} | ||
``` | ||
|
||
## Contributing | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.