- class nannyml.io.db.database_writer.DatabaseWriter(connection_string: str, connection_options: Optional[Dict[str, Any]] = None, model_name: Optional[str] = None)[source]
Writerimplementation that writes a
Resultinto a database table.
Resultclass is transformed into a list of DbMetric objects by an appropriate
Mapperinstance. These DbMetrics are written into a database table, specific to the
This supports any database that is compatible with SQLAlchemy.
Creates a new
connection_string (str) – The connection string that configures the connection to the database. Might contain user credentials as well.
connection_options (Dict[str, Any], default=None) – Additional options passed along to the underlying SQLAlchemy engine.
model_name (str, default=None) – 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)