コード例 #1
0
 def test_distill_multi_list_tuple(self):
     self.assertEqual(
         _distill_params(
             ([("foo", "bar")], [("bar", "bat")]),
             {}
         ),
         ([('foo', 'bar')], [('bar', 'bat')])
     )
コード例 #2
0
 def test_distill_single_list_dicts(self):
     self.assertEqual(
         _distill_params(([{
             "foo": "bar"
         }, {
             "foo": "hoho"
         }], ), {}), [{
             'foo': 'bar'
         }, {
             'foo': 'hoho'
         }])
コード例 #3
0
ファイル: query.py プロジェクト: tinybees/fessql
    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_}
コード例 #4
0
 def test_distill_no_multi_no_param(self):
     self.assertEqual(_distill_params((), {}), [])
コード例 #5
0
 def test_distill_dict_multi_none_param(self):
     self.assertEqual(
         _distill_params(None, {"foo": "bar"}),
         [{"foo": "bar"}]
     )
コード例 #6
0
 def test_distill_multi_string_tuple(self):
     self.assertEqual(_distill_params((("arg", "arg"), ), {}),
                      [("arg", "arg")])
コード例 #7
0
 def test_distill_multi_list_tuple(self):
     self.assertEqual(
         _distill_params(([("foo", "bar")], [("bar", "bat")]), {}),
         ([('foo', 'bar')], [('bar', 'bat')]))
コード例 #8
0
 def test_distill_single_list_tuples(self):
     self.assertEqual(
         _distill_params(([("foo", "bar"), ("bat", "hoho")], ), {}),
         [('foo', 'bar'), ('bat', 'hoho')])
コード例 #9
0
 def test_distill_single_dict(self):
     self.assertEqual(_distill_params(({
         "foo": "bar"
     }, ), {}), [{
         "foo": "bar"
     }])
コード例 #10
0
 def test_distill_single_list_tuple(self):
     self.assertEqual(
         _distill_params(([("foo", "bar")],), {}),
         [('foo', 'bar')]
     )
コード例 #11
0
 def test_distill_single_list_tuples(self):
     self.assertEqual(
         _distill_params(([("foo", "bar"), ("bat", "hoho")],), {}),
         [('foo', 'bar'), ('bat', 'hoho')]
     )
コード例 #12
0
 def test_distill_single_list_strings(self):
     self.assertEqual(
         _distill_params((["foo", "bar"],), {}),
         [["foo", "bar"]]
     )
コード例 #13
0
 def test_distill_single_dict(self):
     self.assertEqual(
         _distill_params(({"foo": "bar"},), {}),
         [{"foo": "bar"}]
     )
コード例 #14
0
 def test_distill_dict_multi_empty_param(self):
     self.assertEqual(
         _distill_params((), {"foo": "bar"}),
         [{"foo": "bar"}]
     )
コード例 #15
0
 def test_distill_dict_multi_none_param(self):
     self.assertEqual(_distill_params(None, {"foo": "bar"}), [{
         "foo": "bar"
     }])
コード例 #16
0
 def test_distill_dict_multi_empty_param(self):
     self.assertEqual(_distill_params((), {"foo": "bar"}), [{"foo": "bar"}])
コード例 #17
0
 def test_distill_multi_strings(self):
     self.assertEqual(
         _distill_params(("foo", "bar"), {}),
         [('foo', 'bar')]
     )
コード例 #18
0
 def test_distill_single_list_strings(self):
     self.assertEqual(_distill_params((["foo", "bar"], ), {}),
                      [["foo", "bar"]])
コード例 #19
0
 def test_distill_none(self):
     self.assertEqual(
         _distill_params(None, None),
         []
     )
コード例 #20
0
 def test_distill_single_list_tuple(self):
     self.assertEqual(_distill_params(([("foo", "bar")], ), {}),
                      [('foo', 'bar')])
コード例 #21
0
 def test_distill_single_list_dicts(self):
     self.assertEqual(
         _distill_params(([{"foo": "bar"}, {"foo": "hoho"}],), {}),
         [{'foo': 'bar'}, {'foo': 'hoho'}]
     )
コード例 #22
0
 def test_distill_multi_strings(self):
     self.assertEqual(_distill_params(("foo", "bar"), {}), [('foo', 'bar')])
コード例 #23
0
 def test_distill_single_string(self):
     self.assertEqual(
         _distill_params(("arg",), {}),
         [["arg"]]
     )
コード例 #24
0
 def test_distill_single_string(self):
     self.assertEqual(_distill_params(("arg", ), {}), [["arg"]])
コード例 #25
0
 def test_distill_multi_string_tuple(self):
     self.assertEqual(
         _distill_params((("arg", "arg"),), {}),
         [("arg", "arg")]
     )
コード例 #26
0
 def test_distill_none(self):
     self.assertEqual(_distill_params(None, None), [])
コード例 #27
0
 def test_distill_no_multi_no_param(self):
     self.assertEqual(
         _distill_params((), {}),
         []
     )