- class nannyml.io.db.database_writer.DatabaseWriter(connection_string: str, connection_options: Optional[Dict[str, Any]] = None, model_name: Optional[str] = None)¶
A Writer implementation that writes a Result as a list of values into a database table.
The Result class is transformed into a list of DbMetric objects by an appropriate Mapper instance. These DbMetrics are written into a database table, specific to the Result class.
Any database that is supported by SQLAlchemy is currently supported.
Creates a new DatabaseWriter instance.
connection_string (str) – The connection string that configures the connection to the database. Might contain user credentials as well.
connection_options (Dict[str, Any]) – Additional options passed along to the underlying SQLAlchemy engine.
model_name (str) – An optional name for the model being monitored. When given this will cause a record to be created in the
modelstable and having each DbMetric link to that one. This allows easy filtering and dropdown population in data visualization tools in case of multiple models exporting into the same database structure.
>>> # write to local in-memory database >>> sqlite_writer = DatabaseWriter(connection_string='sqlite:///', model_name='car_loan_prediction') >>> sqlite_writer.write(result)
>>> postgres_writer = DatabaseWriter( ... connection_string='postgresql://postgres:mysecretpassword@localhost:5432/postgres', ... model_name='car_loan_prediction' ... ) >>> postgres_writer.write(result)