sails: columnType 'bigint' not working

Waterline version: 0.13 Node version: 7.10 NPM version: 4.2.0 Operating system: Mac OS El Capitan

Hello guys ! I’m currently facing a strange issue using columnType: ‘bigint’ which is raising a warning (see attachment). Currently using sails-postgresql 1.0.0

capture d ecran 2017-05-15 a 18 02 32

Here is my Model.js

module.exports = {
  attributes: {
    lastActivity: {
      type: 'number',
      columnType: 'bigint',
      defaultsTo: +new Date()
    }
  }
}
  • I tried to clean my database but the warning still appears
  • I tried on a fresh new sails project

Any ideas what’s going on ?

Best,

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (6 by maintainers)

Commits related to this issue

Most upvoted comments

@sgress454 I am having a very similar data transformation issue, but I am concerned that our data-science team will have some issues with unix timestamp stored in bigint columns.

When I use the timestamp data type it seems to be getting converted to a Date object before the validation check when processing all selected records. The value then fails the _.isString || _.isNumber test (the attribute value is resolves as an [object Date]).

Warning: After transforming columnNames back to attribute names, a record in the result has a value with an unexpected data type for property updatedAt. The model’s updatedAt attribute declares itself an auto timestamp with type: 'string', but instead of a valid timestamp, the actual value in the record is:

2017-05-31T16:48:17.886Z

That looks like a string, but I think it’s actually some kind of Date -> String conversion that is happening in util.inspect().

Would it be a safe workaround to develop my own createdAt and updatedAt functionality using beforeCreate/beforeUpdate lifecycle callbacks using the ref type? (I am still not 100% confident that I understand what the ref type is.) For example…

    createdAt: {
      type: 'ref',
      columnType: 'timestamp'
    },
    updatedAt: {
      type: 'ref',
      columnType: 'timestamp'
    }

Thanks!

@billyshena @edencorbin The issue is that the max “bigint” value is larger than the max JavaScript integer value, so it needs to be stored as a string. See https://github.com/balderdashy/sails/issues/4064. You’ll need to define your attribute like so:

module.exports = {
  attributes: {
    lastActivity: {
      type: 'string',
      columnType: 'bigint',
      defaultsTo: +new Date()
    }
  }
}