node-mysql2
node-mysql2 copied to clipboard
TINYINT(1) vs BIT(1)
I believe common ways of storing booleans in MySQL are with TINYINT(1)
or BIT(1)
.
When I run queries on TINYINT(1)
, I get 1
or 0
as expected, but on BIT(1)
I seem to get <Buffer 01>
or <Buffer 00>
. Is this by design?
The buffer is returned when field character set is 'binary'. Can you post console.log(fields)
for your response?
For the BIT(1) field, it is
[ { catalog: 'def',
schema: 'koa-sample-sandbox',
name: 'Approved',
orgName: 'Approved',
table: 'Member',
orgTable: 'Member',
characterSet: 63,
columnLength: 1,
columnType: 16,
flags: 32,
decimals: 0 } ]
If I change the database schema to TINYINT(1), it is then
[ { catalog: 'def',
schema: 'koa-sample-sandbox',
name: 'Approved',
orgName: 'Approved',
table: 'Member',
orgTable: 'Member',
characterSet: 63,
columnLength: 1,
columnType: 1,
flags: 0,
decimals: 0 } ]
It falls into this default case: https://github.com/sidorares/node-mysql2/blob/aff0b1c8eca5c63566786c72d645224d5a914170/lib/compile_text_parser.js#L144
Maybe worth adding BIT type to read it as number
Sounds like that would make sense. Could it go together in the same case group with the other integer types?
Is this user comment of any relevance? dev.mysql.com/doc/refman/5.7/en/bit-type.html#comment-listing.
I guess it's better to actually try and see what's sent over the wire. I'll try to do that
Is there any progress on this?