Last active
May 25, 2016 09:25
-
-
Save bookercodes/4900b3cfc284cab0510ca17088fbfcc5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In an attempt to reproduce http://stackoverflow.com/questions/37432676/node-js-sequelize-orm-date-issue... | |
const Sequelize = require('sequelize') | |
const connection = new Sequelize('so_schema', 'root', '') | |
const customer = connection.define('customer', { | |
dob: Sequelize.DATE | |
}) | |
connection.sync({ | |
force: true | |
}).then(() => { | |
const dob = new Date('1990-10-27') | |
console.log(`Creating customer with dob: ${dob}`) | |
return customer.create({ | |
dob: new Date('1990-10-27') | |
}) | |
}).then(createdCustomer => { | |
const {id} = createdCustomer.dataValues | |
return customer.findOne({ | |
where: { | |
id | |
} | |
}) | |
}).then(foundCustomer => { | |
const {dob} = foundCustomer.dataValues | |
console.log(`Found customer with dob: ${dob}`) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Creating customer with dob: Sat Oct 27 1990 01:00:00 GMT+0100 (BST) | |
Executing (default): INSERT INTO `customers` (`id`,`dob`,`createdAt`,`updatedAt`) VALUES (DEFAULT,'1990-10-27 00:00:00','2016-05-25 09:24:41','2016-05-25 09:24:41'); | |
Executing (default): SELECT `id`, `dob`, `createdAt`, `updatedAt` FROM `customers` AS `customer` WHERE `customer`.`id` = 1; | |
Found customer with dob: Sat Oct 27 1990 01:00:00 GMT+0100 (BST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment