MCPcopy Create free account
hub / github.com/piccolo-orm/piccolo / compile_string

Method compile_string

piccolo/querystring.py:206–235  ·  view source on GitHub ↗

Compiles the template ready for the engine - keeping the arguments separate from the template.

(
        self, engine_type: str = "postgres"
    )

Source from the content-addressed store, hash-verified

204 return (start_index, bundled, combined_args)
205
206 def compile_string(
207 self, engine_type: str = "postgres"
208 ) -> tuple[str, list[Any]]:
209 """
210 Compiles the template ready for the engine - keeping the arguments
211 separate from the template.
212 """
213 if self._frozen_compiled_strings is not None:
214 return self._frozen_compiled_strings
215
216 _, bundled, combined_args = self.bundle(
217 start_index=1, bundled=[], combined_args=[]
218 )
219 if engine_type in ("postgres", "cockroach"):
220 string = "".join(
221 fragment.prefix
222 + ("" if fragment.no_arg else f"${fragment.index}")
223 for fragment in bundled
224 )
225
226 elif engine_type == "sqlite":
227 string = "".join(
228 fragment.prefix + ("" if fragment.no_arg else "?")
229 for fragment in bundled
230 )
231
232 else:
233 raise Exception("Engine type not recognised")
234
235 return (string, combined_args)
236
237 def freeze(self, engine_type: str = "postgres"):
238 self._frozen_compiled_strings = self.compile_string(

Callers 15

freezeMethod · 0.95
__aenter__Method · 0.80
run_querystringMethod · 0.80
__aenter__Method · 0.80
run_querystringMethod · 0.80
test_compile_stringMethod · 0.80
test_addMethod · 0.80
test_multiplyMethod · 0.80
test_divideMethod · 0.80
test_powerMethod · 0.80
test_subtractMethod · 0.80

Calls 1

bundleMethod · 0.95

Tested by 15

test_compile_stringMethod · 0.64
test_addMethod · 0.64
test_multiplyMethod · 0.64
test_divideMethod · 0.64
test_powerMethod · 0.64
test_subtractMethod · 0.64
test_modulusMethod · 0.64
test_likeMethod · 0.64
test_ilikeMethod · 0.64
test_greater_thanMethod · 0.64