We have a database library in C# that we can use like this:
DatabaseConnection conn = DatabaseConnection.FromConnectionString("...");
this library hides many of the differences between different database engines, like sql function names, parameter names and specifications, etc.
Internally, the DatabaseConnection class is an abstract class implementing some of the basic methods, but the .FromConnectionString method runs through a list of registered specialized types that handles the actual differences, and constructs an object of the right class. In other words, I don't get a DatabaseConnection object back, I get a MSSQLDatabaseConnection or OracleDatabaseConnection object back instead, which of course inherit from DatabaseConnection.
The connection string contains information about what kind of database engine and version this connection is for.
I'd like to create a similar library in python.
Is the right approach to make something that can be constructed like this:
conn = DatabaseConnection("...")
or through a class method:
conn = DatabaseConnection.FromConnectionString("...")
is the first even possible, that is... constructing an object like this and getting back something else, a specialized object, depending on data in the passed string?
Ok, let me ask a different question... What is the pythonic way of doing this?
I basically want to have the DatabaseConnection base class in Python as well, implementing the common methods, and specialize in derived classes, and have a method or function somewhere that based on the connection string constructs and returns the right type of object.