I have a DatabaseConnection
schema with these attributes:
db_type
, db_connection_details
.
Now, for my flask app, I am supporting two database types: mysql and postgresql and I have two different schemas for both pertaining to the db_connection_details
schema which have different fields.
Now, in the DatabaseConnection
schema, is it possible to specify which schema to pick depending on the db_type
. Thanks!
Edit:
An example input is like:
"training_data": {
"source": "mysql",
"connection_details": {
"a": "",
"b": ""
}
}
DatabaseConnection
schema:
class DatabaseConnection(Schema):
source = fields.String(required=True)
connection_details = fields.Nested(ConnectionSchema, required=True)
Now the mysql schema has a
, b
fields (as shown in the example), while the postgres schema has additional fields c
, d
. If the source is a mysql database, it should pick up the MySqlConnectionSchema
, while if the source is a postgresql database, it should pick up PostgresConnectionSchema
(in place of the ConnectionSchema
field in DatabaseConnection
schema). Is this possible in marshmallow?