[INSTRM-1298] Add select_copy_to method Created: 22/Jun/21 Updated: 15/Jul/21 Resolved: 15/Jul/21 |
|
| Status: | Done |
| Project: | Instrument control development |
| Component/s: | spt_operational_database |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Normal |
| Reporter: | cloomis | Assignee: | Kiyoto Yabe |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
There is a new insert_copy_from method on Opdb which allows efficient copying from the user to the database, which is absolutely necessary for FPS/MCS operations. Those actors also need to copy from the database to the user – the MCS needs the FPS targets, and the FPS needs the MCS matches. So can we add select_by_copy(sqlSelect or something? I admit that I get confused by the postgres terminology of COPY_FROM and COPY_TO. We probably do not need to expose the internal postgres names that way, so insert_by_copy. select_by_copy, or insertBulk, selectBulk might be better? Also, can the opdb methods have the context manager or try-except wrapping? Leaving transactions open on failures causes all sorts of trouble later. |
| Comments |
| Comment by rhl [ 22/Jun/21 ] |
surely we should use the context managers not try/except in all new code. |
| Comment by cloomis [ 22/Jun/21 ] |
|
I strongly agree, but the sqlalchemy proxy for the psycopg2 engine does not obviously have a working context manager. New versions might. |
| Comment by Kiyoto Yabe [ 23/Jun/21 ] |
|
For select_by_copy method, I think I can implement that. Considering existing method names, is it OK to name them `insert_by_copy` and `fetch_by_copy`? For the error handling, I think I can consider the context manager, though it may be beyond my ability to design and implement. Could you make a separate ticket for this, just in case? cloomis |
| Comment by cloomis [ 14/Jul/21 ] |
|
I'm moving the request to use context managers to a separate ticket so that the copy_{to, from} work can be merged. |