コード例 #1
0
 def join(self,
          table: Table,
          on: EXPRESSION_TYPE = None,
          using: Column = None,
          full_cartesian: bool = False):
     join = "join {table}".format(table=table.str())  # unsafe formatting
     assert on is None or using is None, "both 'on' and 'using' cannot be specified at the same time"
     if on is not None:
         join += " on {on}".format(on=ExpressionParser.parse(on).str())
     elif using is not None:
         join += " using ({using})".format(using=using.name)
     elif not full_cartesian:
         raise Exception(
             "Trying to create a join without adding 'on' nor 'using' clauses. "
             "This results in a full cartesian product of both tables, "
             "and that is probably not what you want to achieve. "
             "To avoid it, set either an 'on' condition or a 'using' column. "
             "If you really want to perform the full cartesian product, "
             "set the 'full_cartesian' parameter to true.")
     if self._not_none(self._join):
         self._join += " " + join
     else:
         self._join = join
     return self
コード例 #2
0
 def limit(self, expr: EXPRESSION_TYPE):
     expr = ExpressionParser.parse(expr)
     self._limit = "limit {expr}".format(
         expr=expr.str())  # unsafe formatting
     return self
コード例 #3
0
 def group_by(self, *expr: EXPRESSION_TYPE):
     expr = ExpressionParser.parse(expr)
     self._group_by = "group by {expr}".format(
         expr=expr.str())  # unsafe formatting
     return self
コード例 #4
0
 def fields(self, *fields: EXPRESSION_TYPE):
     self._fields = ExpressionParser.parse(fields).str()
     return self
コード例 #5
0
 def where(self, expr: EXPRESSION_TYPE):
     expr = ExpressionParser.parse(expr)
     self._where = "where {expr}".format(
         expr=expr.str())  # unsafe formatting
     return self
コード例 #6
0
 def parse(expr):
     return ExpressionParser.parse(expr)
コード例 #7
0
 def order_by(self, expr: EXPRESSION_TYPE, mode: OrderMode = None):
     expr = ExpressionParser.parse(expr)
     self._order_by = "order by {expr}".format(expr=expr.str())
     if mode is not None:
         self._order_by += " {mode}".format(mode=mode.str())
     return self
コード例 #8
0
 def set(self, column: Column, expr: EXPRESSION_TYPE):
     expr = ExpressionParser.parse(expr)
     self._set = "set {column_name} = {expr}".format(column_name=column.name, expr=expr.str())
     return self
コード例 #9
0
 def values(self, *values: EXPRESSION_TYPE):
     self._values = ExpressionParser.parse(values).str()
     return self