sequelize / sequelize

Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.
https://sequelize.org/
MIT License
29.62k stars 4.28k forks source link

MariaDB incorrectly outputs BigInt value #12390

Open Venefilyn opened 4 years ago

Venefilyn commented 4 years ago

Issue Description

Accessing a BigInt Unsigned field with mariadb driver will not display the value, instead it will display a Long object with low, high, and unsigned fields.

Changing to MySQL driver works, but not ideal given the changes between MySQL and MariaDB

What are you doing?

Accessing a BigInt

const ServerConfig = sequelize => {
  const attributes = {
    serverid: {
      type: DataTypes.BIGINT.UNSIGNED,
      allowNull: false,
      defaultValue: null,
      primaryKey: true,
      autoIncrement: false,
      comment: null,
      field: "serverid",
      unique: "serverid"
    }
  };
  const options = {
    tableName: "server_config",
    comment: "",
    indexes: []
  };
  const ServerConfigModel = sequelize.define("server_config_model", attributes, options);
  return ServerConfigModel;
};
const sequelize = new Sequelize('db', 'root', 'root', {
    host: 'localhost',
    dialect: 'mariadb',
});
let configs = ServerConfig(sequelize)
configs.findOne()
    .then(config => {
        console.log(config.get('serverid'))
    })

What do you expect to happen?

It outputs the value of the BigInt

> 9223372036854775807

What is actually happening?

It outputs the object's properties

> Long { low: -1, high: 2147483647, unsigned: true }

Additional context

This means serializing to JSON does not work as intended.

Environment

Issue Template Checklist

How does this problem relate to dialects?

Would you be willing to resolve this issue by submitting a Pull Request?

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

pbstriker38 commented 2 years ago

Can this be reopened? Shouldn't MariaDB behave like Postgres, where bigints are returned as strings.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

Tchekda commented 1 year ago

Just had the same issue, except changing the driver (which isn't ideal, as you mentioned), is there any solution that manually applying .toString() to all the BIGINT fields?