Compiles the template ready for the engine - keeping the arguments separate from the template.
(
self, engine_type: str = "postgres"
)
| 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( |