MCPcopy
hub / github.com/MagicStack/asyncpg / _get_statement

Method _get_statement

asyncpg/connection.py:403–503  ·  view source on GitHub ↗
(
        self,
        query,
        timeout,
        *,
        named: typing.Union[str, bool, None] = False,
        use_cache=True,
        ignore_custom_codec=False,
        record_class=None
    )

Source from the content-addressed store, hash-verified

401 return await self._executemany(command, args, timeout)
402
403 async def _get_statement(
404 self,
405 query,
406 timeout,
407 *,
408 named: typing.Union[str, bool, None] = False,
409 use_cache=True,
410 ignore_custom_codec=False,
411 record_class=None
412 ):
413 if record_class is None:
414 record_class = self._protocol.get_record_class()
415 else:
416 _check_record_class(record_class)
417
418 if use_cache:
419 statement = self._stmt_cache.get(
420 (query, record_class, ignore_custom_codec)
421 )
422 if statement is not None:
423 return statement
424
425 # Only use the cache when:
426 # * `statement_cache_size` is greater than 0;
427 # * query size is less than `max_cacheable_statement_size`.
428 use_cache = (
429 self._stmt_cache_enabled
430 and (
431 not self._config.max_cacheable_statement_size
432 or len(query) <= self._config.max_cacheable_statement_size
433 )
434 )
435
436 if isinstance(named, str):
437 stmt_name = named
438 elif use_cache or named:
439 stmt_name = self._get_unique_id('stmt')
440 else:
441 stmt_name = ''
442
443 statement = await self._protocol.prepare(
444 stmt_name,
445 query,
446 timeout,
447 record_class=record_class,
448 ignore_custom_codec=ignore_custom_codec,
449 )
450 need_reprepare = False
451 types_with_missing_codecs = statement._init_types()
452 tries = 0
453 while types_with_missing_codecs:
454 settings = self._protocol.get_settings()
455
456 # Introspect newly seen types and populate the
457 # codec cache.
458 types, intro_stmt = await self._introspect_types(
459 types_with_missing_codecs, timeout)
460

Callers 4

_prepareMethod · 0.95
_do_executeMethod · 0.95
__anext__Method · 0.45
_initMethod · 0.45

Calls 8

_get_unique_idMethod · 0.95
_introspect_typesMethod · 0.95
_cleanup_stmtsMethod · 0.95
_check_record_classFunction · 0.85
getMethod · 0.80
prepareMethod · 0.80
get_settingsMethod · 0.80
putMethod · 0.80

Tested by

no test coverage detected