Home > Software design >  js number limit
js number limit

Time:04-22

Good afternoon, the data is sent to the database: channel:966735614273806457 message: 966735619332136962

They show up correctly in the database. but when i try to get them i get an object with rounded numbers like:

{ id: 29, channel: 966735614273806500, message: 966735619332137000 } 

I am getting data with the following query:

  const sqlq = `SELECT * FROM report`
await data.db.all(sqlq,[],(err,row)=>{
console.log(row[row.length-1])
})

In general, my task is to get the last element of the database every time, if there is still the possibility of obtaining it without adding all the elements to the array, then I would like to know this. I am using the sqlite library

CodePudding user response:

A BIGINT can store integers up to 10 times those values, so it's possible that they are, in fact, numeric. You may want to inspect the data type to determine if they are strings.

Those values are over 100 times JavaScript's MAX_SAFE_INTEGER. You'll probably want to handle the output as strings, regardless of the type that's stored in the database. Based on the context, that looks like an attribute, so I can't imagine you'll need to perform any math on it.

Don't use SELECT *. Be deliberate. Changes to the database could easily break your code. You'll probably want something like

  const sqlq = `SELECT id, cast(channel as varchar(25)) as channel, cast(message as varchar(25)) as message FROM report`
await data.db.all(sqlq,[],(err,row)=>{
console.log(row[row.length-1])
})
  • Related