I am trying to insert a date\time value in the format YYYY-MM-DD HH:mm:ss in MySQL DB table using Sequlize as ORM in a nodejs (Expressjs middleware). For some odd reason the time element gets stored with an incorrect time. For example, I try to insert 05:50 PM but the DB column post insert shows 06:12 pm. Any idea how to fix this?
My model has below definition for the datetime column
time_stamp: {
type: DataTypes.DATE,
allowNull: false,
},
My DB table has below definition for the field
time_stamp DATETIME NOT NULL,
Related
I need to set the default value of the appliedDate column to the current date.In MySQL there is a function CURRENT_DATE() to get the current date.But I can't seem to find an equivalent with Sequelize. Is it possible in Sequelize?
`
appliedDate: {
type: DataTypes.DATEONLY,
defaultValue: Sequelize.fn("now"),
},
`
This doesn't work since appliedDate need to be DATEONLY type.
I tried to use Sequelize.fn("now") , Sequelize.literal("CURRENT_DATE") , Sequelize.fn("CURRENT_DATE") but all of these resulted in error. I could use a workaround by setting the date using Javascript, but it would be nice to know if this feature exists in Sequelize.
defaultValue: Sequelize.literal("(CURRENT_DATE())")
defaultValue: DataTypes.NOW
Both these solve the problem
Sequelize/ MySQL table:
id: integer,
timestamp: Date
anotherField: string
I am upserting with a new document:
{ id: alreadyInTheDatabase, timestamp: reallyOldValue, anotherField: "newValue" }
I need to update timestamp but only if it is older (smaller) then the one upserting the database, anotherField needs to be always updated.
What is the best approach for it?
Thank you! :-)
My goal is to get the statistics count of data through timestamp, some what like google analytics. I'm using node.js & sequelize The timestamp field in model looks
request_timestamp: {
type: DataTypes.STRING,
allowNull: false
},
For now, I want to get data grouped by day of every timestamp. I tries date_truc but it's not working for some reason.
I have a model called Encryption which generates an AES encrypted string and saves that to a database table called encryptions. My encryption table schema is as follows:
id : bigint unsigned
user_id : bigint unsigned
encryption : VARCHAR(128) (utf8_unicode_ci)
created_at : datetime
updated_at : datetime
However, when I call .save on my encryption model instance, the value for encryption.encryption (in the database) is blank ('').
Here's the contents of the model:
ruby-1.9.2-head :005 > encryption
=> #<Encryption id: nil, user_id: 1, encryption: "\xD6\xD6\x95\x15\x0F\x92\xC6\x01\x86\x1E\x88\xD1\xB0\x1D\xE0\xEC", created_at: nil, updated_at: nil>
As you can see, it does have a value in the model. Any ideas on why the field is saving as blank in the database?
I'm using the strongbox gem to do something similar, and it requested a column type of :binary, not text, maybe you could try that...
You appear to be saving a string into a bigint column, which won't work. Switch it to a text column type.
Why am I getting the "T" and "Z" in the date when I fetch it from MongoDB and convert it to JSON using Rails3?
"date":"2011-05-12T13:51:33Z"
Thanks
Fetch:
#bs = coll.find("headers.from" => email, "date" => {"$gte" => initial_date, "$lte" => Time.now.utc})
Insert:
date : { type: Date, default: Date.now }
It's an ISO8601 formatted datetime. The 'T' separates the date from the time and the 'Z' indicates that the date is UTC (GMT). MongoDB doesn't support a Date (only) type, instead everything is converted to a timestamp.
You can drop into the mongo console and run a query you'll see date (and time) fields are stored as ISODate("2011-05-12T13:51:33Z").