sql server - sequelize hex column values auto conversion to buffer -


i have mssql database id in form of hex values.

for example, when viewed in management studio, typical id column looks like

id,                                  | username 0x8189cf203dea4a44b8adeff1c8246866,  | john 0xaf4845c8a34a48ef8b6d481f2d20d561,  | peter 0x70b1f5e3b3f8417bbb99912640c54520,  | alan 

to query user table, need write like

select * users id = 0x8189cf203dea4a44b8adeff1c8246866 

i use lot of sequelize.query run bunch of sql statements directly.

when such table read in sequelize, id gets converted buffer type in sequelize. question is, how can keep hex value? there config keep string hex value of these ids? did have convert these buffer type manually hex string hand, , attach 0x in front?

for example, when viewed in management studio, typical id column looks like

for me, typical id not this, i'm quite sure, hex-values uniqueidentifiers (=guid) (see option 2).

option 1: hex-string

you might store hex string string representation:

select sys.fn_varbintohexstr(0x8189cf203dea4a44b8adeff1c8246866) 

returns "0x8189cf203dea4a44b8adeff1c8246866" (which string now)

but - how ever - function meant opposite truncates part of this

select sys.fn_cdc_hexstrtobin(n'0x8189cf203dea4a44b8adeff1c8246866') 

returns 0x8189cf203dea4a44b8ad (which short!!!)

option 2: guid

i cast these values guids (if none of them wider 16 bytes!) , store them typesafe. easy , out-of-the-box guid string representation (e.g. write in xml) , cast guid.

select cast(0x8189cf203dea4a44b8adeff1c8246866 uniqueidentifier); 

returns 20cf8981-ea3d-444a-b8ad-eff1c8246866

select cast('20cf8981-ea3d-444a-b8ad-eff1c8246866' uniqueidentifier) 

returns same above, show, string value casted real guid

select cast(cast('20cf8981-ea3d-444a-b8ad-eff1c8246866' uniqueidentifier) varbinary(max)) 

returns 0x8189cf203dea4a44b8adeff1c8246866

now have original hex-string again.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -