execute a query into AfterInsert subscriber hook - typeorm

There is a way to execute a query in a method with #AfterInsert decorator?
I want update a column in insert transaction.
I tried, but the execution did freaze.

Related

Is Query.Close necessary after Query.ExecSQL?

In Delphi, whenever I use a TQuery to perform a SELECT on a database, I follow the Query.Open with a try..finally, with Query.Close in the finally section. This makes sense to me, as the Query would still be storing data (using memory) unnecessarily otherwise.
But my question has to do with when I use a Query to perform an INSERT or DELETE, thus requiring the execution of the SQL with Query.ExecSQL
My question is, must I use Query.Close after Query.ExecSQL?
My thoughts are, because this is a command to be executed on the database, which presumably does not return any data to the Query, there is no need to do a Query.Close
But maybe someone out there has more in-depth knowledge of what, if anything, might be returned and stored in a Query after a Query.ExecSQL is called, for which a Query.Close would be beneficial?
Thank you.
No it is not needed as ExecSQL does not maintain a recordset.
from the documentation (emphasis mine):
Executes the SQL statement for the query. Call ExecSQL to execute the
SQL statement currently assigned to the SQL property. Use ExecSQL to
execute queries that do not return a cursor to data (such as INSERT,
UPDATE, DELETE, and CREATE TABLE).
Note: For SELECT statements, call Open instead of ExecSQL.
ExecSQL prepares the statement in SQL property for execution if it has not already been prepared. To speed performance, an application should ordinarily call Prepare before calling ExecSQL for the first time.

Grails Domain Class Not Saving without Groovy.Sql first

I'm using Hibernate 3 and Grails 2.2.5.
I have an AJAX call in one of my views that is supposed to look up some data and provide a text result. In the methods used to generate the text result, I have a method call to a service to save the text result to its own domain.
The problem is that the .save(flush: true) will not persist to the database. However, if I add a Groovy SQL instance and perform an .executeInsert() with any insertion the insert in the Groovy SQL will be inserted AND the .save(flush: true) method will work as expected... I've tried various different ways, but as soon as I comment out the .executeInsert("...") the domain class will not be persisted.
I've checked common problems: validation checks out (returns true), I turned deepValidate to false and I used flush in case Hibernate was trying to save the insertion statement to a later time. I also turned on logSql = true in DataSource.groovy and the SQL insert statement does get logged when I comment the .executeInsert("...") out but is never persisted to the table.
-EDIT/UPDATE-
The Hibernate log has the insert statement as:
insert into TextDomain (version, text, ... , id) values (?,?,?,?,?)
Are the question marks supposed to be there? Not too experienced with Hibernate so I'm not sure if that's the actual SQL statement it is executing or if it is filling the values in?
Also, the method I'm trying to call .save() in is in src/groovy .
EDIT/UPDATE -> TEST:
I setup a test as a single action in a controller. I simply called a service method that filled the textDomain with some test values and then did a .save(). When calling the controller action (i.e. going to the url my-app:8080/test/text) the textDomain is persisted correctly. However, I tried adding the service that has the actual textDomain instantiation and test values from another service and it will not persist...

is there any way to forcefully imply validation on update_all

I have a Rails application I am using update_all to updates but as we know it is skipping the validations how can I forcefully apply validation on this update_all
From the API docs (emphasis my own).
Updates all records with details given if they match a set of conditions supplied, limits and order can also be supplied. This method constructs a single SQL UPDATE statement and sends it straight to the database. It does not instantiate the involved models and it does not trigger Active Record callbacks or validations.
No, there is not a way to force validations when calling update_all. The purpose of update_all is to modify records in bulk without instantiating model instances for each record. A model instance must exist for a record to have validations called against it.

PostgreSQL Stored Procedure Name of User

I was wondering if there was a way to detect the log in name of the user executing the query which triggers a stored procedure? Say, I have a trigger on table_a that fires when a particular column is changed. I would like to retrieve the name of the logged in user who executed the query which triggered the stored procedure running.
Is this possible?
Turns out there is a recognized keyword called current_user that does the exact thing I want - holds the username of the current user executing the query.

How to insert a new record after successful update of a record in grails

i am trying to insert a new record into a table when admin approves someones request in grails. What is the right method to achieve this? When admin approves a request a table get updated with a Boolean isapprove true and on success of this insert records in another table.
Thanks in advance
You should create a service and service method to handle the use case. That method should
Take input and decide whether to do the update
Update the record with the isapprove variable.
Create a new record and insert it. See this documentation for how to do it; it's really easy.
Creating the service and service method ensures that the above steps are transactional, so if one step fails the database is in a consistent state. Also, it is a nice unit of functionality for testing, so the code will be more maintainable.

Resources