Skip to content

Commit

Permalink
Merge pull request #60 from VianneyMI/57-expressions-and-operators-up…
Browse files Browse the repository at this point in the history
…grades

57-expressions-and-operators-upgrades
  • Loading branch information
VianneyMI committed Aug 29, 2023
2 parents aa9634b + 467f263 commit 750f3b8
Show file tree
Hide file tree
Showing 88 changed files with 2,894 additions and 904 deletions.
32 changes: 32 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
# Release Notes

## 0.16.0


### New Features

* Created S object (represents $ sign since it is not a valid variable name in python) to store all MongoDB operators and to create references to fields
* Created SS object (represents $$) to store aggregation variables and referenes to user variables
* Interfaced a chunk of new operators(add, divide, multiply, pow, substract, cond, if_null, switch, millisecond, date_from_string, date_to_string, type_)
* Integrated new operators in Expressions class


### Refactoring

* Redefined Expressions completely. Simplified and clarified how they can be used when using this package.
* Removed index module that was at the root of the package (monggregate.index.py -> ø)
* Removed expressions subpackage (monggregate.expression -> ø)
* Moved expressions fields module to the root of the package (monggregate.expressions.fields.py -> monggregate.fields.py)
* Removed expressions aggregation_variables module (monggregate.expression.aggregation_variables.py -> ø)
* Moved the enums that were defined in index to a more relevant place. Ex OperatorEnum is now in monggregate.operators.py

### Breaking Changes

* Operators now return python objects rather than expressions/statements.
NOTE: The wording might change for clarification purposes.
statement might be renamed expression and resolve might renamed express
To do so, some arguments might need to be renamed in the operators
* Expressions subpackage has been exploded and some parts have been deleted

### Documentation

* Updated readme to reflect changes in the packge. Readme now focuses on the recommended way to use the package and clarifies how to use MongoDB operators.

## 0.15.0

### Fixes
Expand Down
4 changes: 3 additions & 1 deletion monggregate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""App Package"""

from monggregate.expressions import Expression
from monggregate.dollar import S, SS
from monggregate.pipeline import Pipeline
from monggregate.expressions.expressions import Expression


__version__ = "0.15.0"
__author__ = "Vianney Mixtur"
Expand Down
19 changes: 15 additions & 4 deletions monggregate/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""Module defining the base class of the package"""
"""
Module defining the base classes of the package.
All the classes of the package inherit from one of the classes defined in this module.
"""

# Standard Library imports
#----------------------------
from abc import ABC, abstractmethod
from typing import Any
from typing import Any, TypeGuard

# 3rd Party imports
# ---------------------------
Expand All @@ -15,7 +19,14 @@

from humps.main import camelize

class Singleton:
"""Singleton metaclass"""

_instance = None
def __new__(cls, *args, **kwargs):
if not isinstance(cls._instance, cls):
cls._instance = object.__new__(cls, *args, **kwargs)
return cls._instance

class BaseModel(pyd.BaseModel, ABC):
"""Mongreggate base class"""
Expand Down Expand Up @@ -45,10 +56,10 @@ class Config(pyd.BaseConfig):
allow_population_by_field_name = True
underscore_attrs_are_private = True
smart_union = True
#alias_generator = camelize
alias_generator = camelize


def isbasemodel(instance:Any)->bool:
def isbasemodel(instance:Any)->TypeGuard[BaseModel]:
"""Returns true if instance is an instance of BaseModel"""

return isinstance(instance, BaseModel)
Expand Down
Loading

0 comments on commit 750f3b8

Please sign in to comment.