I am working on a REST API so I am trying to implement a way for users to create a new service ticket.
Everything is working fine except for when it comes to storing things in the db (postgres).
Here's a snippet of the transaction once it is generated:
BEGIN;
INSERT INTO service_request (id, ...)
VALUES (...);
INSERT INTO media (id, filename, ...)
VALUES (...),
(...),
(...);
INSERT INTO servicerequest_media(service_request_id, media_id)
values (..., ...),
(..., ...),
(...,...);
COMMIT;
Using sqlx prepared statements, I know that the result contains some metadata such as the last inserted id. However, how can I add a select
query to my transaction and get the results of that query?
stmt, err := s.db.Prepare(CREATE_SERVICE_REQUEST)
if err != nil {
////
}
res, err := stmt.Exec()
if err != nil {
////
}
Or, do I need to do a 2nd query to get the result?
I am pretty new to this, so please let me know if I need to give more context.