You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I write you because I spent almost three weeks to resolve the problem that I have, and I don't know what to do now after test every sample I have found on www ;-(
I have made a WS program in python, to serve data from a Database (MySQL) for querying data.
I'm mainly using modules Flask and Flask_SQLAlchemy among others.
The scenary is the following, this program will run on board different ships, all of them have the same architecture, the same SGBD and the schema name is the same ('SADO'), the only difference between them is the data content on the DB Tables, each ship have their data adquisition values, but the DB and schemas are de same.
An exemple of request URL onboard to query data with bind to 'SADO' schema: http://127.0.0.1:5000/api/v1/utmapi/navigation/lastPosition (the same in all ships. works isolate onboard)
Them problem comes here, every ship sincronices with a onshore centralize SGBD (MySQL), on different schemas ('SADO_RT_<ship_name>')
The program should work onship server and onshore server. But now onshore version is not working.
Onship server, is easy to use **kwargs for run the program inserting the ship name param '_ship' for use inside the program for some proposes.
The URL bind should be the same for all the ships programs:
mysql+pymysql://sadodb:xxx@localhost:3306/SADO
And a sample entry point for query data is like this one:
My problem with the onshore version is the following. The kwarg for identifying the ship, in onshore version, should be 'ALL'
Once the parameter is readed by the program, knows that should have differences binds. These binds could be configure in 'SQLALCHEMY_BINDS'.
The entry point to for client onshore to query data for a especific ship is like this: http://127.0.0.1:5000/api/v1/utmapi/navigation/lastPosition?ship=SDG
I use the decorator @app.before_request, and its function def before_request(): , in order to read the key value ship and update de engine/session to make the request to the specific selected ship on the request URL.
One more thing, I use query formats like this sample:
def get_last_position(self):
navigation: Navigation = Navigation.query.order_by(Navigation.timestamp.desc()).first()
self.shipPosition = Point(navigation.latitude,navigation.longitude)
#print('Position -> ', self.shipPosition.getPoint().format_decimal())
return self.shipPosition
Can some one help for resolve this handicap.
In few works, I need to change dynamically the engine - session bind in the scope engine inside app Flask object (Factory use), inside the function before_request().
Some one have and update sample in order to learn how to do it ?
The modules versions used are the following.
Python 3.9
Flask 3.0.3
Flask_SQLALchemy 3.1.1
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello all ;-)
I write you because I spent almost three weeks to resolve the problem that I have, and I don't know what to do now after test every sample I have found on www ;-(
I have made a WS program in python, to serve data from a Database (MySQL) for querying data.
I'm mainly using modules Flask and Flask_SQLAlchemy among others.
The scenary is the following, this program will run on board different ships, all of them have the same architecture, the same SGBD and the schema name is the same ('SADO'), the only difference between them is the data content on the DB Tables, each ship have their data adquisition values, but the DB and schemas are de same.
An exemple of request URL onboard to query data with bind to 'SADO' schema:
http://127.0.0.1:5000/api/v1/utmapi/navigation/lastPosition (the same in all ships. works isolate onboard)
Them problem comes here, every ship sincronices with a onshore centralize SGBD (MySQL), on different schemas ('SADO_RT_<ship_name>')
The program should work onship server and onshore server. But now onshore version is not working.
Onship server, is easy to use **kwargs for run the program inserting the ship name param '_ship' for use inside the program for some proposes.
The URL bind should be the same for all the ships programs:
And a sample entry point for query data is like this one:
My problem with the onshore version is the following. The kwarg for identifying the ship, in onshore version, should be 'ALL'
Once the parameter is readed by the program, knows that should have differences binds. These binds could be configure in 'SQLALCHEMY_BINDS'.
The entry point to for client onshore to query data for a especific ship is like this:
http://127.0.0.1:5000/api/v1/utmapi/navigation/lastPosition?ship=SDG
I use the decorator @app.before_request, and its function def before_request(): , in order to read the key value ship and update de engine/session to make the request to the specific selected ship on the request URL.
One more thing, I use query formats like this sample:
def get_last_position(self):
navigation: Navigation = Navigation.query.order_by(Navigation.timestamp.desc()).first()
self.shipPosition = Point(navigation.latitude,navigation.longitude)
#print('Position -> ', self.shipPosition.getPoint().format_decimal())
return self.shipPosition
Can some one help for resolve this handicap.
In few works, I need to change dynamically the engine - session bind in the scope engine inside app Flask object (Factory use), inside the function before_request().
Some one have and update sample in order to learn how to do it ?
The modules versions used are the following.
Python 3.9
Flask 3.0.3
Flask_SQLALchemy 3.1.1
Beta Was this translation helpful? Give feedback.
All reactions