notheotherben / node-orm-timestamps Goto Github PK
View Code? Open in Web Editor NEWnode-orm2 plugin to provide automatic timestamping support for models
node-orm2 plugin to provide automatic timestamping support for models
I'm running node v0.10.21, orm v2.1.3, orm-timestamps v0.2.0. I'm mostly following the example code:
app.use(orm.express(config.mysql, {
define: function(db, models) {
db.use(modts);
var user = db.define('user', {
username: String,
email: String,
password: String
}, {
timestamp: true
});
user.sync(function(err) {
if (err) {
console.error("error creating user model: " + err);
}
});
}
}));
and I get the resulting exception:
ReferenceError: persist is not defined
at Object.monitor [as beforeDefine] (/Users/kevin/Documents/Projects/node/timestamp/node_modules/orm-timestamps/lib/orm-timestamps.js:48:6)
at ORM.define (/Users/kevin/Documents/Projects/node/timestamp/node_modules/orm/lib/ORM.js:213:20)
at Object.app.use.orm.express.define (/Users/kevin/Documents/Projects/node/timestamp/app.js:40:23)
at /Users/kevin/Documents/Projects/node/timestamp/node_modules/orm/lib/Express.js:38:9
at Handshake._callback (/Users/kevin/Documents/Projects/node/timestamp/node_modules/orm/lib/ORM.js:127:13)
at Handshake.Sequence.end (/Users/kevin/Documents/Projects/node/timestamp/node_modules/mysql/lib/protocol/sequences/Sequence.js:75:24)
at Handshake.Sequence.OkPacket (/Users/kevin/Documents/Projects/node/timestamp/node_modules/mysql/lib/protocol/sequences/Sequence.js:84:8)
at Protocol._parsePacket (/Users/kevin/Documents/Projects/node/timestamp/node_modules/mysql/lib/protocol/Protocol.js:172:24)
at Parser.write (/Users/kevin/Documents/Projects/node/timestamp/node_modules/mysql/lib/protocol/Parser.js:62:12)
at Protocol.write (/Users/kevin/Documents/Projects/node/timestamp/node_modules/mysql/lib/protocol/Protocol.js:37:16)
This is the line in orm-timestamps:
if(persist && options.createdProperty !== false)
I don't see 'persist' defined in the module itself, so that may be the issue here. Just for testing purposes, I added "var persist = true" after "options" is extend and that resolved the issue for me.
Thanks,
Kevin
Using package version 0.1.1, node version 0.10.17 and postgres version 9.1.9 I'm experiencing an issue with incorrect timestamps.
I changed nothing from the default configuration for the package and yet timestamps still appear to be exactly 7 hours ahead of local time. For instance, new Date()
reports the correct time at Thu Sep 05 2013 09:11:14 GMT-0700 (PDT)
. Running SELECT NOW()
on my postgres instance also returns the expected time PDT. However, creating and saving a timestamped ORM model instance and then immediately reloading it gives it a created_at
property of Thu Sep 05 2013 16:11:14 GMT-0700 (PDT)
which is not PDT but GMT-0.
If new Date()
is the default source of date and time information for timestamps, why are my timestamps in GMT-0?
Just a suggestion, maybe add functionality for 'soft deletes', which will be updated when the row is 'deleted', then excluded from further searches (unless set to include deleted entries)
Line 8 reads:
expiry: function() { var d = new Date(); d.setMinutes(d.getMinutes() + 60); return d; },
Later this is executed with options.expire()
. I presume it should also read "expiry" in line 8.
Hi
when i set persist to true orm-timestamp throws a "Maximum call stack size exceeded" error
Here is full stack trace and error:
(node:7632) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): RangeError: Maximum call stack size exceeded
(node:7632) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the
Node.js process with a non-zero exit code.
RangeError: Maximum call stack size exceeded
at Object.now (C:\actcustomer\node_modules\orm-timestamps\lib\orm-timestamps.js:7:16)
at Object.<anonymous> (C:\actcustomer\node_modules\orm-timestamps\lib\orm-timestamps.js:81:46)
at Object.exports.wait (C:\actcustomer\node_modules\orm\lib\Hook.js:19:26)
at saveInstanceProperty (C:\actcustomer\node_modules\orm\lib\Instance.js:422:10)
at Object.set [as modified_at] (C:\actcustomer\node_modules\orm\lib\Instance.js:521:11)
at Object.<anonymous> (C:\actcustomer\node_modules\orm-timestamps\lib\orm-timestamps.js:81:36)
at Object.exports.wait (C:\actcustomer\node_modules\orm\lib\Hook.js:19:26)
at saveInstanceProperty (C:\actcustomer\node_modules\orm\lib\Instance.js:422:10)
at Object.set [as modified_at] (C:\actcustomer\node_modules\orm\lib\Instance.js:521:11)
at Object.<anonymous> (C:\actcustomer\node_modules\orm-timestamps\lib\orm-timestamps.js:81:36)
at Object.exports.wait (C:\actcustomer\node_modules\orm\lib\Hook.js:19:26)
at saveInstanceProperty (C:\actcustomer\node_modules\orm\lib\Instance.js:422:10)
at Object.set [as modified_at] (C:\actcustomer\node_modules\orm\lib\Instance.js:521:11)
at Object.<anonymous> (C:\actcustomer\node_modules\orm-timestamps\lib\orm-timestamps.js:81:36)
at Object.exports.wait (C:\actcustomer\node_modules\orm\lib\Hook.js:19:26)
at saveInstanceProperty (C:\actcustomer\node_modules\orm\lib\Instance.js:422:10)
Maximum call stack size exceeded
var orm = require("orm");
var modts = require('orm-timestamps');
orm.settings.set("instance.returnAllErrors", true);
orm.settings.set("connection.reconnect", true);
orm.settings.set("connection.pool", true);
orm.settings.set("connection.debug", true);
orm.connect("mysql://root:@localhost/laser_control", function (err, db) {
if (err) throw err;
db.use(modts);
var user = db.define("users", {
id : {type: 'serial'},
name : { type: 'text', required : true},
mail : { type: 'text', unique: true, required : true},
password : { type: 'text', required : true},
crm : { type: 'integer', key: true },
city : { type: 'text', key: true, size: 2},
id_socket : { type: 'text', size: 100},
status : { type: "enum", values: [ "1", "0"], defaultValue: "1" },
}, {
timestamp: true
});
db.sync(function(err) {
if (err) throw err;
});
});
--
it create all my model including created_at and updated_at, but everytime that i insert a new user, my fields created_at and updated_at keep the value "NULL" in database, i'm doing something wrong ?
obs: my code isn't give any error, it just not fill with the values that i want.
Perhaps setting it to null.
This would be cool but not mandatory. Perhaps it needs some more integration between plugins and models/instances.
The idea would be to have the possibility to read this methods but not change them.
I'm pretty sure I know the answer to this already, but I have to ask :) Is there any way to use "timestamp" as the column type for MySQL? I prefer using that type because it is timezone independent. I've hacked orm to allow this type for MySQL, but I'd much rather use this nice plugin instead.
Thanks!
Kevin
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.