Esempio n. 1
0
 def __init__(self, derive: str, from_parent: str):
     super(Copy, self).__init__(derive)
     names = from_parent.split('.')
     self._from_parent_role = names[0]
     self._from_column = names[1]
     rb = RuleBank()
     rb.deposit_rule(self)
Esempio n. 2
0
    def __init__(self, derive: InstrumentedAttribute, from_parent: any):
        super(Copy, self).__init__(derive)
        if isinstance(from_parent, str):
            names = from_parent.split('.')
            self._from_parent_role = names[0]
            self._from_column = names[1]
        elif isinstance(from_parent, InstrumentedAttribute):
            self._from_column = from_parent.key
            table_class = from_parent.class_
            parent_class_name = self.get_class_name(table_class)
            pass
            attrs = self._derive.parent.attrs
            found_attr = None
            for each_attr in attrs:
                if isinstance(each_attr, RelationshipProperty):
                    each_parent_class_nodal_name = each_attr.entity.class_
                    each_parent_class_name = self.get_class_name(
                        each_parent_class_nodal_name)
                    if each_parent_class_name == parent_class_name:
                        if found_attr is not None:
                            raise Exception(
                                "TODO / copy - disambiguate relationship")
                        found_attr = each_attr
            if found_attr is None:
                raise Exception("Invalid 'as_sum_of' - not a reference to: " +
                                self.table + " in " + self.__str__())
            else:
                self._from_parent_role = found_attr.key

        else:
            pass
        rb = RuleBank()
        rb.deposit_rule(self)
Esempio n. 3
0
 def __init__(self, derive: str, as_count_of: str, where: str):
     super(Count, self).__init__(derive)
     self._as_count_of = as_count_of  # could probably super-ize parent accessor
     self._from_parent_role = as_count_of
     self._where = where
     rb = RuleBank()
     rb.deposit_rule(self)
Esempio n. 4
0
 def __init__(self, derive: str, as_sum_of: str, where: str):
     super(Sum, self).__init__(derive)
     self._as_sum_of = as_sum_of  # could probably super-ize parent accessor
     self._from_parent_role = self._as_sum_of.split(".")[0]
     self._where = where
     rb = RuleBank()
     rb.deposit_rule(self)
Esempio n. 5
0
 def __init__(self, derive: InstrumentedAttribute, as_sum_of: any,
              where: any):
     super(Sum, self).__init__(derive)
     self._as_sum_of = as_sum_of  # could probably super-ize parent accessor
     self._where = where
     if isinstance(as_sum_of, str):
         self._child_role_name = self._as_sum_of.split(".")[
             0]  # child role retrieves children
         self._child_summed_field = self._as_sum_of.split(".")[1]
     elif isinstance(as_sum_of, InstrumentedAttribute):
         self._child_summed_field = as_sum_of.key
         attrs = as_sum_of.parent.attrs
         found_attr = None
         for each_attr in attrs:
             if isinstance(each_attr, RelationshipProperty):
                 pass
                 parent_class_nodal_name = each_attr.entity.class_
                 parent_class_name = self.get_class_name(
                     parent_class_nodal_name)
                 if parent_class_name == self.table:
                     if found_attr is not None:
                         raise Exception("TODO - disambiguate relationship")
                     found_attr = each_attr
         if found_attr is None:
             raise Exception("Invalid 'as_sum_of' - not a reference to: " +
                             self.table + " in " + self.__str__())
         else:
             self._child_role_name = found_attr.back_populates
     else:
         raise Exception(
             "as_sum_of must be either string, or <mapped-class.column>: " +
             str(as_sum_of))
     if where is None:
         self._where_cond = lambda row: True
     elif isinstance(where, str):
         self._where_cond = lambda row: eval(where)
     elif isinstance(where, Callable):
         self._where_cond = where
     else:
         raise Exception("'where' must be string, or lambda: " +
                         self.__str__())
     rb = RuleBank()
     rb.deposit_rule(self)
Esempio n. 6
0
 def __init__(
         self,
         validate: object,
         error_msg: str,
         calling: Callable = None,
         as_condition: object = None):  # str or lambda boolean expression
     super(Constraint, self).__init__(validate)
     # self.table = validate  # setter finds object
     self._error_msg = error_msg
     self._as_condition = as_condition
     self._calling = calling
     if calling is None and as_condition is None:
         raise Exception(
             f'Constraint {str} requires calling or as_expression')
     if calling is not None and as_condition is not None:
         raise Exception(
             f'Constraint {str} either calling or as_expression')
     if calling is not None:
         self._function = calling
     elif isinstance(as_condition, str):
         self._as_condition = lambda row: eval(as_condition)
     ll = RuleBank()
     ll.deposit_rule(self)
Esempio n. 7
0
    def __init__(self, derive: InstrumentedAttribute,
                 as_exp: str = None,              # for very short expressions
                 as_expression: Callable = None,  # short, with type checking
                 calling: Callable = None         # complex formula
                 ):
        """
        Specify rep
          * as_exp - string (for very short expressions - price * quantity)
          * ex_expression - lambda (for type checking)
          * calling - function (for more complex formula, with old_row)

        """
        super(Formula, self).__init__(derive)

        self._as_exp = as_exp
        self._as_expression = as_expression
        self._function = calling

        self._as_exp_lambda = None   # we exec this, or _function

        valid_count = 0
        if as_exp is not None:
            self._as_exp_lambda = lambda row: eval(as_exp)
            valid_count += 1
        if as_expression is not None:
            self._as_exp_lambda = as_expression
            valid_count += 1
        if calling is not None:
            valid_count += 1
        if valid_count != 1:
            raise Exception(f'Formula requires one of as_exp, as_expression or calling')
        self._dependencies = []
        text = self.get_rule_text()
        self.parse_dependencies(rule_text=text)
        self._exec_order = -1  # will be computed in rule_bank_setup (all rules loaded)
        rb = RuleBank()
        rb.deposit_rule(self)
Esempio n. 8
0
 def __init__(self, validate: str, calling):
     super(Constraint, self).__init__(validate)
     # self.table = validate  # setter finds object
     self._function = calling
     ll = RuleBank()
     ll.deposit_rule(self)
Esempio n. 9
0
 def __init__(self, on_class: object, calling: Callable = None):
     super(AbstractRowEvent, self).__init__(on_class)
     self._function = calling
     ll = RuleBank()
     ll.deposit_rule(self)
Esempio n. 10
0
 def __init__(self, derive: str, calling: Callable):
     super(Formula, self).__init__(derive)
     self._function = calling
     rb = RuleBank()
     rb.deposit_rule(self)