create_database_context

felis.db.database_context.create_database_context(engine_url, metadata, output_file=None, dry_run=False, echo=None)

Create a DatabaseContext object based on the engine URL.

Parameters:
  • engine_url (str | URL) – The database URL for the database connection.

  • metadata (MetaData) – The SQLAlchemy MetaData representing the database objects.

  • output_file (Optional[IO[str]], default: None) – Output file for writing generated SQL commands.

  • dry_run (bool, default: False) – If True, configure the context to perform a dry run, where operations will not be executed. If False, use a normal context where operations are executed.

  • echo (bool | None, default: None) – If True, the SQLAlchemy engine will log all statements to the console.

Returns:

A database context appropriate for the given engine URL. This will be a MockContext if the URL appears like a mock URL or if dry_run is True, otherwise it will be a context based on the dialect using the factory pattern.

Return type:

DatabaseContext

Raises:

DatabaseContextError – If the dialect is not supported or if there’s an issue creating the context.