Comments (9)
Okay so I'm finally getting back to this. Thinking about it some more, I think it would be a nice inclusion, just not enabled by default. I believe features like this should be opt-in instead of opt-out.
The timestamps
property would likely have to be set using a static method. Like this:
class User extends Document {
static timestamps() {
return true;
}
}
You could also return names of the created_at/updated_at fields for more customization:
class User extends Document {
static timestamps() {
return {
created_at: 'createdTime',
updated_at: 'updatedTime'
};
}
}
Doing it in the constructor, as shown by @vfreitas-, wouldn't work because then we couldn't access the timestamps
property in any static methods (like User.findOneAndUpdate()
).
Thoughts?
from camo.
Was a pull request submitted for this yet?
from camo.
You can have a boolean variable, that will decide if the timestamp fields will be added.
class User extends Document {
constructor() {
//...
this.timestamps = false; //default = true
//...
}
}
from camo.
Maybe not to be enable by default, but that it's a way to go.
from camo.
from camo.
I'll consider it. I hesitate to add data by default to people's models, but
maybe it can be an option.
I'll leave this open for discussion for a bit to gauge interest.
Thanks!
Scott
On Jan 29, 2016 4:01 PM, "Michael De Abreu" [email protected]
wrote:
[image:
👍 ] +1—
Reply to this email directly or view it on GitHub
#40 (comment).
from camo.
What about use a timestamp decorator?
@timestamp
class User extends Document {
}
You could pass timestamp field names too:
@timestamp({
created_at: 'createdTime',
updated_at: 'updatedTime'
})
class Use extends Document {
}
from camo.
I don't think ES6 have decorators. For what I understand after googling,
decorators are suppose to come in 2016 with ES2016(ES7).
However, for a long proposal that would be a good idea.
2016-05-31 19:51 GMT-04:00 Samir El Aouar [email protected]:
What about use a timestamp decorator?
@timestamp
class User extends Document {
}You could pass timestamp field names too:
@timestamp({
created_at: 'createdTime',
updated_at: 'updatedTime'
})
class Use extends Document {
}—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#40 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AKBWABMfZIaNHx8kkcIla_N6dQQvoOE6ks5qHMmNgaJpZM4HNCJn
.
from camo.
Yep, ES6 does not have decorators. As nice as this feature would be, we'd
then have to require application code to use a transpiler like Babel, which
does not work with Camo's goal.
I'd like to implement this feature in ES6 soon, but if anyone would like to
submit a PR for it sooner, I'd be happy to accept.
On May 31, 2016 7:50 PM, "Michael De Abreu" [email protected]
wrote:
I don't think ES6 have decorators. For what I understand after googling,
decorators are suppose to come in 2016 with ES2016(ES7).However, for a long proposal that would be a good idea.
2016-05-31 19:51 GMT-04:00 Samir El Aouar [email protected]:
What about use a timestamp decorator?
@timestamp
class User extends Document {
}You could pass timestamp field names too:
@timestamp({
created_at: 'createdTime',
updated_at: 'updatedTime'
})
class Use extends Document {
}—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#40 (comment)
,
or mute the thread
<
https://github.com/notifications/unsubscribe/AKBWABMfZIaNHx8kkcIla_N6dQQvoOE6ks5qHMmNgaJpZM4HNCJn.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#40 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/ACz-bzEpoiZANjb7GPf5SLMXJkeVOpiQks5qHR2ngaJpZM4HNCJn
.
from camo.
Related Issues (20)
- Is camo still maintained? HOT 1
- Why can't there just be an upsert method on Document?
- [TypeError: Class constructor Document cannot be invoked without 'new'] when using ts-node
- Support for non-required embedded documents
- Support for reference document inside embedded document
- Info about the project HOT 3
- batch insert
- Pull request for use with react-native-local-mongodb? HOT 1
- optional modules not optional HOT 1
- RangeError: Maximum call stack size exceeded when trying to write to non-existent field HOT 1
- find() not returning all results HOT 1
- Hacktoberfest HOT 1
- Awesome Idea, Need some features HOT 1
- hasMany, hasOne, belongsTo support
- Support for "mongodb+srv" connection URL
- Double request needed to delete operation
- MongoDB collation
- Marpat: find({}, {population: true}) doesn't work HOT 1
- MongoDB's new Options format
- Raw query support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from camo.