Package: querytyper
QuerytyperQuerytyper 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.FeaturesConstruct 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.UsingTo add and install this package as a dependency of your project, runpoetry add querytyper.A simple example:frompydanticimportBaseModel,EmailStrfromquerytyperimportMongoFilterMeta,MongoQueryclassUser(BaseModel):"""User database model."""id:intname:strage:intemail:EmailStrclassUserFilter(User,metaclass=MongoFilterMeta):"""User query filter."""query=MongoQuery((UserFilter.name=="John")&(UserFilter.age>=10)&(UserFilter.emailin["john@example.com","john@gmail.com",]))print(query){"name":"John","age":{"$gte":10},"email":["john@example.com","john@gmail.com",],}ContributingPrerequisites1. Set up Git to use SSHGenerate an SSH keyandadd the SSH key to your GitHub account.Configure SSH to automatically load your SSH keys:cat<< EOF >> ~/.ssh/configHost *AddKeysToAgent yesIgnoreUnknown UseKeychainUseKeychain yesEOF2. Install DockerInstall Docker Desktop.EnableUse Docker Compose V2in Docker Desktop's preferences window.Linux only:Export your user's user id and group id so thatfiles created in the Dev Container are owned by your user:cat<< EOF >> ~/.bashrcexport UID=$(id --user)export GID=$(id --group)EOF3. Install VS Code or PyCharmInstall VS CodeandVS Code's Dev Containers extension. Alternatively, installPyCharm.Optional:install aNerd Fontsuch asFiraCode Nerd Fontandconfigure VS Codeorconfigure PyCharmto use it.Development environmentsThe following development environments are supported:⭐️GitHub Codespaces: click onCodeand selectCreate codespaceto start a Dev Container withGitHub Codespaces.⭐️Dev Container (with container volume): click onOpen in Dev Containersto clone this repository in a container volume and create a Dev Container with VS Code.Dev Container: clone this repository, open it with VS Code, and runCtrl/⌘+⇧+P→Dev Containers: Reopen in Container.PyCharm: clone this repository, open it with PyCharm, andconfigure Docker Compose as a remote interpreterwith thedevservice.Terminal: clone this repository, open it with your terminal, and rundocker compose up --detach devto start a Dev Container in the background, and then rundocker compose exec dev zshto open a shell prompt in the Dev Container.DevelopingThis project follows theConventional Commitsstandard to automateSemantic VersioningandKeep A ChangelogwithCommitizen.Runpoefrom within the development environment to print a list ofPoe the Poettasks available to run on this project.Runpoetry add {package}from within the development environment to install a run time dependency and add it topyproject.tomlandpoetry.lock. Add--group testor--group devto install a CI or development dependency, respectively.Runpoetry updatefrom within the development environment to upgrade all dependencies to the latest versions allowed bypyproject.toml.Runcz bumpto bump the package's version, update theCHANGELOG.md, and create a git tag.