Skip to content

Commit

Permalink
fix: readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ale-Cas committed Jan 21, 2024
1 parent c723262 commit 5e01c53
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 66 deletions.
48 changes: 46 additions & 2 deletions README.md
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

Expand Down
124 changes: 85 additions & 39 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ version = "0.0.0"
version_files = ["pyproject.toml:version"]

[tool.poetry.dependencies] # https://python-poetry.org/docs/dependency-specification/
pydantic = "^1.8.2"
pydantic = {extras = ["email"], version = "^1.8.2"}
python = ">=3.8,<4.0"

[tool.poetry.group.test.dependencies] # https://python-poetry.org/docs/master/managing-dependencies/
Expand Down
Loading

0 comments on commit 5e01c53

Please sign in to comment.