How to access a RowDataPacket object(如何访问 RowDataPacket 对象)
问题描述
我目前正在使用 Node-webkit 开发桌面应用程序.在此过程中,我需要从本地 MySQL 数据库中获取一些数据.
I'm currently developing a desktop application with Node-webkit. During that process I need to get some data from a local MySQL-database.
查询工作正常,但我不知道如何访问结果.我将它们全部存储在一个数组中,然后传递给一个函数.在控制台中,它们看起来像这样:
The querying works fine, but I can't figure out how to access the results. I store all of them in an array that is then passed to a function. In the console they look like this:
RowDataPacket {user_id: 101, ActionsPerformed: 20}
RowDataPacket {user_id: 102, ActionsPerformed: 110}
RowDataPacket {user_id: 104, ActionsPerformed: 3}
这是查询结构:
var ret = [];
conn.query(SQLquery, function(err, rows, fields) {
if (err)
alert("...");
else {
for (var i of rows)
ret.push(i);
}
doStuffwithTheResult(ret);
}
如何在 doStuffwithTheResult 函数中检索它?值更重要,但如果我也能拿到钥匙那就太好了.
How do I retrieve this in the doStuffwithTheResult function? The values are more important, but if I could get the keys as well that would be great.
推荐答案
原来它们是普通对象,您可以通过 user_id 访问它们.
Turns out they are normal objects and you can access them through user_id.
RowDataPacket 实际上是创建对象的构造函数的名称,它看起来像这样new RowDataPacket(user_id, ...).您可以通过访问其名称 [0].constructor.name
RowDataPacket is actually the name of the constructor function that creates an object, it would look like this new RowDataPacket(user_id, ...). You can check by accessing its name [0].constructor.name
如果结果是一个数组,则必须使用[0].user_id.
If the result is an array, you would have to use [0].user_id.
这篇关于如何访问 RowDataPacket 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何访问 RowDataPacket 对象
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 无法解决整理冲突 2021-01-01
