S
S
Sanders Rocket2020-05-05 22:57:55
SQLite
Sanders Rocket, 2020-05-05 22:57:55

How to output values ​​from database to string?

How to output all values ​​from database to message?

if (msg.message.text.startsWith("/dostups")) {
  if (await isAdmin(msg)) {
    let sql = db.run('select dostuplvl, VKid from dostups')
    console.log(sql.toString())
    messagesend(msg.message.peer_id, 'info in console')
  } else {
    notmessage();
  }
}

My attempt is above, but if I do toString, I get the result:
uDwNA8J.png
Without toString:
IxSOXpH.png
How values ​​are stored in the database:
tWwaGqo.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sanders Rocket, 2020-05-06
@sandersik

let sql = 'select dostuplvl, VKid from dostups';
    db.all(sql, [], (err, rows) => {
      if (err) {
        throw err;
      }
      rows.forEach((row) => {
        console.log(row)
        messagesend(msg.message.peer_id, '🚫Пользователь: vk.com/id' + row.VKid + '🚫\n 🚫Уровень доступа: ' + row.dostuplvl);
      });
    });

I decided

D
Dmitry Gordinskiy, 2020-05-05
@DmitriyGordinskiy

1) The .run method does not return the result of the request, but an instance of the object on which it was called.
2) The .run method does not imply getting the result of the request, some kind of get / all / each is better for this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question