Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
add engine_arams to parametrise sqlalchemy engine creation, change me…
Browse files Browse the repository at this point in the history
…tadata_kwargs to metadata_params, add a customization example in engine documentation (#23)
  • Loading branch information
mjalo authored and villebro committed Jan 23, 2020
1 parent f6eefd6 commit 97065f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 7 additions & 0 deletions docs/engines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ following engines have dedicated support for the following insert modes:

Engines not listed above will default to using multirow inserts if supported,
falling back to single row inserts as a last resort.

Engine customization
####################

engine_params: Optional dict of parameter that get destructured as keyword arguments for create_engine call in the engine. Allows customization of engine connection pool and such.

For example, to set engine to use a connection pool size of one, pass engine_params = {"pool_size": 1}
9 changes: 5 additions & 4 deletions sqltask/base/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ class EngineContext:
def __init__(self,
name: str,
url: str,
metadata_kwargs: Optional[Dict[str, Any]] = None,
engine_params: Optional[Dict[str, Any]] = None,
metadata_params: Optional[Dict[str, Any]] = None,
):
self.name = name
self.engine = create_engine(url)
self.engine = create_engine(url, **engine_params)
self.engine_spec = get_engine_spec(self.engine.name)
url_params = self.engine_spec.get_url_params(self.engine.url)
self.database, self.schema = url_params
self.metadata_kwargs = metadata_kwargs or {}
self.metadata_params = metadata_params or {}
self.metadata = MetaData(
bind=self.engine,
schema=url_params.schema,
**self.metadata_kwargs,
**self.metadata_params,
)
if url_params.database and url_params.schema:
url_str = url_params.database + "/" + url_params.schema
Expand Down

0 comments on commit 97065f7

Please sign in to comment.