MCPcopy
hub / github.com/tortoise/tortoise-orm / init

Method init

tortoise/__init__.py:297–445  ·  view source on GitHub ↗

Sets up Tortoise-ORM: loads apps and models, configures database connections but does not connect to the database yet. The actual connection or connection pool is established lazily on first query execution. You can configure using only one of ``config``, ``config_f

(
        cls,
        config: dict[str, Any] | TortoiseConfig | None = None,
        config_file: str | None = None,
        _create_db: bool = False,
        db_url: str | None = None,
        modules: dict[str, Iterable[str | ModuleType]] | None = None,
        use_tz: bool = True,
        timezone: str = "UTC",
        routers: list[str | type] | None = None,
        table_name_generator: Callable[[type[Model]], str] | None = None,
        init_connections: bool = True,
        _enable_global_fallback: bool = False,
    )

Source from the content-addressed store, hash-verified

295
296 @classmethod
297 async def init(
298 cls,
299 config: dict[str, Any] | TortoiseConfig | None = None,
300 config_file: str | None = None,
301 _create_db: bool = False,
302 db_url: str | None = None,
303 modules: dict[str, Iterable[str | ModuleType]] | None = None,
304 use_tz: bool = True,
305 timezone: str = "UTC",
306 routers: list[str | type] | None = None,
307 table_name_generator: Callable[[type[Model]], str] | None = None,
308 init_connections: bool = True,
309 _enable_global_fallback: bool = False,
310 ) -> TortoiseContext:
311 """
312 Sets up Tortoise-ORM: loads apps and models, configures database connections but does not
313 connect to the database yet. The actual connection or connection pool is established
314 lazily on first query execution.
315
316 You can configure using only one of ``config``, ``config_file``
317 and ``(db_url, modules)``.
318
319 :param config:
320 Dict containing config or ``TortoiseConfig``:
321
322 .. admonition:: Example
323
324 .. code-block:: python3
325
326 {
327 'connections': {
328 # Dict format for connection
329 'default': {
330 'engine': 'tortoise.backends.asyncpg',
331 'credentials': {
332 'host': 'localhost',
333 'port': '5432',
334 'user': 'tortoise',
335 'password': 'qwerty123',
336 'database': 'test',
337 }
338 },
339 # Using a DB_URL string
340 'default': 'postgres://postgres:qwerty123@localhost:5432/test'
341 },
342 'apps': {
343 'my_app': {
344 'models': ['__main__'],
345 # If no default_connection specified, defaults to 'default'
346 'default_connection': 'default',
347 }
348 },
349 'routers': ['path.router1', 'path.router2'],
350 'use_tz': False,
351 'timezone': 'UTC'
352 }
353
354 :param config_file:

Callers 15

init_ormFunction · 0.45
tortoise_initFunction · 0.45
init_ormFunction · 0.45
init_ormFunction · 0.45
innerFunction · 0.45
init_ormMethod · 0.45
runnerFunction · 0.45
init_ormFunction · 0.45
tortoise_cli_contextFunction · 0.45
planFunction · 0.45
sqlmigrateFunction · 0.45
migrateFunction · 0.45

Calls 9

__enter__Method · 0.95
close_connectionsMethod · 0.95
initMethod · 0.95
TortoiseContextClass · 0.90
ConfigurationErrorClass · 0.90
star_passwordMethod · 0.80
getMethod · 0.45
to_dictMethod · 0.45