Comments (15)
Right now I'm not going to mess with the mechanism of Database Watch because I'm not familiar with it yet.
For now I'm going to focus on collection level events and validation. To solve this problem I have two solution.
VALIDATION:
- Write a wrapper around all collection methods like
insert
,update
etc. - Write
deny
rules that won't allow operation if a document is not valid.
EVENTS:
- Wrapper around all collection methods.
So I will probably implement it using wrapper, however I don't like this approach. Maybe someone would have better solution?
from meteor-astronomy.
I don't use allow/deny, but I think they work only with db operations triggered by the client. If that is the case, they cannot be used for this feature.
from meteor-astronomy.
About the other proposed solutions, what I can say is that aldeed:meteor-collection2
does the job well (although with poor usability).
from meteor-astronomy.
Yes you are right about allow/deny rules. I have to make a good decision if it goes about API. If I override collection methods, then I should have some way of accessing original methods.
In your opinion, what is the worst part of aldeed:meteor-collection2
that causes poor usability. What would you improve? I want to get as many opinions as possible.
from meteor-astronomy.
There are 3 things that annoy me in aldeed:meteor-collection2
:
- It tries to ensure database integrity, which makes it difficult to understand. See this discussion. What I need is only the validation of the arguments being passed to insert/update, nothing more.
- It manipulates data on-the-fly in a complex way (it is called "cleaning", see here), leading to painful bugs.
- Error messages are cryptic. Example here.
from meteor-astronomy.
- In fact the first point for me is a bug in SimpleSchema and could be easily fixed.
- Astronomy does two of the things that SimpleSchema does. If it does not do it's a bug :P
- Removing properties that are not in the schema
- Conversion of values to match what schema expects
- Fortunately, in Astronomy error generation mechanism is very flexible.
So, I assume that the you are happy with the API of SimpleSchema which executes validation:
Books.insert({
field: 'value'
});
I don't like idea of overriding collection's method like insert
or update
. I would propose something different:
Books.astro.insert({
field: 'value'
});
or some similar approach not messing with currently existing methods of collection.
from meteor-astronomy.
I'm not sure it is a better option, but the following API syntax might have few benefits:
Astro.insert('Books', {
field: 'value'
});
- it makes it clear that Astronomy package is used here to handle certain operations (easier for newcomers to the codebase);
- it is similar to using Underscore like
_.map(...);
Cons: someone might go looking for an "Astro" collection :)
What do you think guys?
from meteor-astronomy.
Yep, seems to be good idea. However, maybe it would be better to pass just a collection not collection name.
Astro.insert(Books, {
field: 'value'
}, callback /* optional */);
Astro.update(Books, selector, modifier, callback /* optional */);
from meteor-astronomy.
Agree, I just came back to edit "Books" to Books :)
from meteor-astronomy.
What do you think about the syntax like:
Book.insert();
Not Books
. We can insert, update etc. from the level of the Class not Collection.
from meteor-astronomy.
👍 for Book.insert();
I like it 😄
from meteor-astronomy.
Hi, I'm almost done with the direct database access methods. There is only one problem: validation. And I want to know your opinion on this subject. Let met explain the problem.
Right now, I've implemented all collection methods:
Post = Astro.Class({
name: 'Post',
collection: Posts,
fields: {
title: {
default: 'Default title'
}
}
});
Post.insert();
Post.upsert();
Post.update();
Post.remove();
Post.find();
Post.findOne();
It works great and such statement:
Post.insert({});
will insert the following document:
{
title: 'Default title'
}
All event will be called on the document, so everything works as expected. But what about validation? In fact I think that validating object on direct database access is bad thing. Let's take SimpleSchema as an example. You have to create validation context, validate query and later retrieve errors. If I would like to implement this in Astronomy I would have to do it in the following way:
Post.update(selector, modifier, {
forEach: function(post) {
if (post.validate()) {
return true;
}
// Do something with the errors.
post.getValidationErrors();
return false;
}
});
It's ugly but works. However, the problem is even more absurd on insert
or remove
. Why would I ever need to use forEach
method if I'm inserting only one document? Why don't just:
var post = new Post();
if (post.validate()) {
post.save();
}
And validating document on remove operation? I don't see the point. Validation is only for checking document's integrity, no to check if I can remove given document. For that case, we need security package.
So, my question is:
Do you need at all validation on direct collection access?
If yes
, then:
Do you need validation on direction collection insert and remove?
from meteor-astronomy.
I agree validation of a single object before insertion should be left to the programmer.
from meteor-astronomy.
I think we have deviated from the original purpose of this Issue. But I'll appreciate any comments which can help contributors to progress in their work.
from meteor-astronomy.
Ok, I decided to make validation possible only on document update. Direct database access have been implemented and @dalerka your original issue is solved by this feature.
Post.insert({field: 'value'});
will trigger all events and model logic as expected. The same is true about other collection operations.
For now I'm closing this issue. It will appear on 1.0 release.
from meteor-astronomy.
Related Issues (20)
- [Feature request] Mongo transactions HOT 2
- Class.create - create not found HOT 1
- [Feature Request] doc.save() return a promise HOT 3
- Q: is there an afterFieldSet event? HOT 1
- Feature: mongo Deciamal type HOT 6
- Strange behaviour of the method 'save' within the helper
- Updating "sub class" isn't working HOT 1
- advice on indexes on 'type' HOT 2
- This package is still maintenance? HOT 2
- Getting field definition HOT 2
- findOne with fields causes insert on optional field HOT 1
- delete field on subtype? HOT 1
- Integrating Astro class with meteor/ostrio:files HOT 9
- Is there a way to use the validator without a document/model? HOT 1
- Method "Astronomy/execute" not found 404 HOT 3
- Trigger another field validation error HOT 4
- Detect if a field was hidden in afterInit event HOT 3
- How to mock meteor method call when declaring method in class? HOT 2
- Issues with latest Meteor versions & oplog converter
- Standalone version HOT 1
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 meteor-astronomy.