def test_distill_multi_list_tuple(self): self.assertEqual( _distill_params( ([("foo", "bar")], [("bar", "bat")]), {} ), ([('foo', 'bar')], [('bar', 'bat')]) )
def test_distill_single_list_dicts(self): self.assertEqual( _distill_params(([{ "foo": "bar" }, { "foo": "hoho" }], ), {}), [{ 'foo': 'bar' }, { 'foo': 'hoho' }])
def _compiled_quey( self, query: Union[Select, Insert, Update, Delete], *multiparams: Union[Dict, List[Dict]] ) -> Dict[str, Union[str, Dict, List[Dict], None]]: """ compile query to sql Args: query: multiparams: Returns: {"sql": sql, "params": params} """ bind_params = _distill_params(multiparams, {}) if len(bind_params) > 1: if isinstance(query, str): query_, params_ = query, bind_params else: compiled = query.compile(dialect=_dialect) query_ = str(compiled) params_ = [] for bind_param in bind_params: params_.append( self._base_params(query, bind_param, compiled, isinstance(query, UpdateBase))) else: if bind_params: bind_params = bind_params[0] if isinstance(query, str): query_, params_ = query, bind_params or None else: compiled = query.compile(dialect=_dialect) query_ = str(compiled) params_ = self._base_params(query, bind_params, compiled, isinstance(query, UpdateBase)) # 处理自动增加的后缀 if getattr(self._model, "__table_suffix__", None) is not None: query_ = query_.replace(getattr(self._model, "__table_suffix__"), "") return {"sql": query_, "params": params_}
def test_distill_no_multi_no_param(self): self.assertEqual(_distill_params((), {}), [])
def test_distill_dict_multi_none_param(self): self.assertEqual( _distill_params(None, {"foo": "bar"}), [{"foo": "bar"}] )
def test_distill_multi_string_tuple(self): self.assertEqual(_distill_params((("arg", "arg"), ), {}), [("arg", "arg")])
def test_distill_multi_list_tuple(self): self.assertEqual( _distill_params(([("foo", "bar")], [("bar", "bat")]), {}), ([('foo', 'bar')], [('bar', 'bat')]))
def test_distill_single_list_tuples(self): self.assertEqual( _distill_params(([("foo", "bar"), ("bat", "hoho")], ), {}), [('foo', 'bar'), ('bat', 'hoho')])
def test_distill_single_dict(self): self.assertEqual(_distill_params(({ "foo": "bar" }, ), {}), [{ "foo": "bar" }])
def test_distill_single_list_tuple(self): self.assertEqual( _distill_params(([("foo", "bar")],), {}), [('foo', 'bar')] )
def test_distill_single_list_tuples(self): self.assertEqual( _distill_params(([("foo", "bar"), ("bat", "hoho")],), {}), [('foo', 'bar'), ('bat', 'hoho')] )
def test_distill_single_list_strings(self): self.assertEqual( _distill_params((["foo", "bar"],), {}), [["foo", "bar"]] )
def test_distill_single_dict(self): self.assertEqual( _distill_params(({"foo": "bar"},), {}), [{"foo": "bar"}] )
def test_distill_dict_multi_empty_param(self): self.assertEqual( _distill_params((), {"foo": "bar"}), [{"foo": "bar"}] )
def test_distill_dict_multi_none_param(self): self.assertEqual(_distill_params(None, {"foo": "bar"}), [{ "foo": "bar" }])
def test_distill_dict_multi_empty_param(self): self.assertEqual(_distill_params((), {"foo": "bar"}), [{"foo": "bar"}])
def test_distill_multi_strings(self): self.assertEqual( _distill_params(("foo", "bar"), {}), [('foo', 'bar')] )
def test_distill_single_list_strings(self): self.assertEqual(_distill_params((["foo", "bar"], ), {}), [["foo", "bar"]])
def test_distill_none(self): self.assertEqual( _distill_params(None, None), [] )
def test_distill_single_list_tuple(self): self.assertEqual(_distill_params(([("foo", "bar")], ), {}), [('foo', 'bar')])
def test_distill_single_list_dicts(self): self.assertEqual( _distill_params(([{"foo": "bar"}, {"foo": "hoho"}],), {}), [{'foo': 'bar'}, {'foo': 'hoho'}] )
def test_distill_multi_strings(self): self.assertEqual(_distill_params(("foo", "bar"), {}), [('foo', 'bar')])
def test_distill_single_string(self): self.assertEqual( _distill_params(("arg",), {}), [["arg"]] )
def test_distill_single_string(self): self.assertEqual(_distill_params(("arg", ), {}), [["arg"]])
def test_distill_multi_string_tuple(self): self.assertEqual( _distill_params((("arg", "arg"),), {}), [("arg", "arg")] )
def test_distill_none(self): self.assertEqual(_distill_params(None, None), [])
def test_distill_no_multi_no_param(self): self.assertEqual( _distill_params((), {}), [] )