I have a use case implementation for which I am trying to identify the solution, the implementation is as follows :
- User defines the SQL server connection parameters like DATABASE_TYPE ( like MySQL, pgsql, sqlite or any db supported by SQLAlchemy), HOST, PORT, SCHEMA_NAME, USER_NAME and PASSWORD
- User then does the TEST CONNECTION to validate the connection parameters provided, and provides SUCCESS and FAILURE feedback
- On SUCCESS, user will type in the sql query ( following SQLAlchemy’s SQL Expression Language more details here ) the which needs to be executed.
If you notice above all the parameters for SQLAlchemy to work are user defined at run time, I am trying to implement the function in python which consumes the above connection parameters and sql query, executes the query on successful connection and returns the query result. Any point of direction or help on this would be great.
Thanks
I’m having something like this as part of a larger project, so far only for sqlite and postgres but this can be generalized.
For start if you expect the user to know DATABASE_TYPE ( like MySQL, pgsql, sqlite or any db supported by SQLAlchemy), HOST, PORT, SCHEMA_NAME, USER_NAME and PASSWORD you could just ask for the DB URL to make your life a little easier.
After that you can test the connection by:
Cusom sql queries can be executed using the text() construct as shown here.