balderdashy / balderdashy/sails
MSSQL db - datetime null attribute
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 22.8k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Node version: >8.x
Sails version (sails): 1.2.3
ORM hook version (sails-hook-orm): 2.1.1
Sockets hook version (sails-hook-sockets): 1.5.5
Organics hook version (sails-hook-organics): not installed
Grunt hook version (sails-hook-grunt): 3.1.1
Uploads hook version (sails-hook-uploads): not installed
DB adapter & version (e.g. sails-mysql@5.55.5): sails-mssql@2.0.2, sails-mongo@1.0.1
Skipper adapter & version (e.g. skipper-s3@5.55.5): 0.9.0-4
I'm having difficulties retrieving a datetime column with null values from MS SQL. The setup in SQL or Sails is quite simple:
SQL: User table with a column MyDate (datetime, null)
SAILS:
model User.js with attribute set as
MyDate:{
type: 'ref',
columnType: 'datetime'
}
When I use the blueprint REST call http://localhost:1337/user, I am getting the following results:
- Invalid Date when the value is null in the database
- The expected value when the value is not null in the database
I have tried below attribute settings in the User model and got the following results:
- MyDate:{ type: 'ref', columnType: 'datetime' }: Invalid date when null, expected value when not null
- MyDate:{ type: 'json', columnType: 'datetime' }: Invalid date when null, expected value when not null
- MyDate:{ type: 'string', columnType: 'datetime' }: Invalid date when null, expected value when not null
- MyDate:{ type: 'string', columnType: 'datetime', allowNull: true }: Invalid date when null, expected value when not null
- MyDate:{ type: 'string', allowNull: true }: null value when null, datetime value as a JS ISO date when not null, and with the following warning generated in Sails logs:
Warning: After transforming columnNames back to attribute names for model
user,
a record in the result has a value with an unexpected data type for propertyMyDate.
The corresponding attribute declarestype: 'string'but instead
of that, the actual value is:2019-12-01T09:35:05.967Z
Would you know what would be the correct way to get null values a null, datetime values as datetime and not get a SAILS warning ?
thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the User.js model attribute and reproduce the issue through the blueprint REST call at http://localhost:1337/user using the reported sails-mssql setup. Compare records where MyDate is null and non-null, and review the warning about transforming columnNames back to attribute names. Done means null remains null, datetime values retain their expected representation, and Sails emits no unexpected-data-type warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100