V
V
vetsmen2018-03-02 13:20:49
JavaScript
vetsmen, 2018-03-02 13:20:49

How to get immediately the first element of an array in a sql async/await query?

There is a request:

let userData = await connection.query('SELECT ...', [id]);

In it, I make a selection by one user, by his id. At the output I get: [ RowDataPacket { ... } ]
To get access immediately to the object, I use an extra construction:
if (userData && userData[0]) {
        userData = userData[0];
      }

How can I make life easier?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Skibin, 2018-03-02
@megafax

Use an ORM like sequelize

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question