我有这个查询:
SELECT
username AS email,
optin AS optional
FROM user AS ua
INNER JOIN user_preferences AS up ON up.user_id = ua.id
WHERE ua.id = ${id}
我收到了预期的数据,但是看起来像这样:
let queryResult = await MySQLQueryBuilder.getBasicUserData(userId);
返回的queryResult
是:
{
email: 'someuser@email';
optional: { type: 'Buffer', data: [1] }
}
我希望得到这样的东西:
{
email: 'someuser@email.com',
optional: 1
}
请注意,optin
列的数据类型为bit
。
答案 0 :(得分:1)
您可以在SQL查询中解决此问题,方法是将位类型转换为int类型,例如,将位类型加0:
SELECT
username AS email,
optin+0 AS optional
FROM user AS ua
INNER JOIN user_preferences AS up ON up.user_id = ua.id
WHERE ua.id = ${id}
即使在this fiddle中,您也可以看到您描述的行为。