S
S
Sedbol2020-02-24 23:47:02
Laravel
Sedbol, 2020-02-24 23:47:02

Is it possible to immediately get an array from the database when inserting into the database?

How to immediately get the answer from the database when inserting into the database? Whether not to do SELECT to check there is such record or not? It is necessary to receive at an insertion record not that that is interposed and already from a DB. What is the best way to do this? It is necessary to insert or update a record, but not update all the fields except for two and immediately get a row from the database in response to an already prepared record.

The code below is an example, in the example only INSERT. But it is not important. What is important is how to make such a request?

function user(val) {
    return new Promise(function (resolve, reject) {
        const connection = mysql.createConnection(query);
        const win="INSERT INTO `test`(`id`, `vas`, `sas`, `nas`) VALUES (3,2,2,2)";
        const par = [];
        connection.query(win, par,
            function(err, results) {
                if (err) reject(err);
                resolve(results);
            });
        connection.end();        
    })
}

Code for understanding only (JUST EXAMPLE)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2019-07-02
@NubasLol

Because it create's a method Eloquent\Builder, but it's updateproxied to Query\Builder.
PS You seem to have been taught to read the documentation, now we will teach you to study the framework code?

I
ince, 2020-02-26
@Sedbol

const win="INSERT INTO `test`(`id`, `vas`, `sas`, `nas`) VALUES (3,2,2,2) RETURNING :id, :vas, :sas, :nas";
par = {
  id: {type: BIND_OUT}, 
  vas: {type: BIND_OUT}, 
  sas: {type: BIND_OUT}, 
  nas: {type: BIND_OUT}
}

Something like this may differ depending on which library you are using.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question