-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Index Support #51
Index Support #51
Conversation
def __init__(self, doc_spec, **kwargs): | ||
super(Schema, self).__init__(doc_spec, **kwargs) | ||
super(Schema, self).__init__(doc_spec, **{k:v for k,v in kwargs.iteritems() if k != 'indexes'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aware this is hackish... is there a better way to do it? I want to pass an extra kwarg
here that the underlying class doesn't support.
@tleach I know kids and stuff, but I will keep working on this if you give me feedback. 😗 |
Sorry got sidetracked by selenium bullshit. Will take a look tonight if I can. Tom LeachPrincipal Engineer, GameChanger Media On Tue, Jul 7, 2015 at 6:20 PM, Kiril Savino [email protected]
|
def __init__(self, doc_spec, **kwargs): | ||
indexes = [] | ||
|
||
def __init__(self, doc_spec, indexes=[], **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set indexes=None
. See http://effbot.org/zone/default-values.htm
I was pondering this on the way home. I've realized there is a problem with adding indexes to the Though it conceptually makes sense to declare indexes with the The use cases are obvious ( Furthermore, this is a useful simplifying assumption which So, what's the alternative? We could declare them with the One possibility is some kind of special my_thing_schema = IndexedSchema(Schema({
'name': {'type': basestring},
...
}))
my_thing_schema.add_index({'name': 1})
MyThing = create_model(db.my_thing, my_thing_schema) Nice things about this:
We could even make the constructor take a my_thing_schema_1 = IndexedSchema(Schema({
'name': {'type': basestring},
}))
my_thing_schema_2 = IndexedSchema({ # creates a wrapped `Schema` instance internally
'name': {'type': basestring},
}) So, yeah. Probably want to mull this over a little more, but I think that seems like a better direction. Thoughts? |
Why do the indexes need to be coupled to |
I think there is something to be gained by schemas and index declarations being co-located. Indexes do indirectly depend on the data model declared in a schema. In my mind, declaring indexes alongside a collection-level schema is a light-touch way to prod the user to keep the two consistent. If you declare your schema in one place and your indexes somewhere else then I can see the two diverging over time. I may even be veering towards mandating that we actually validate index specs against their associated schemas to ensure they make sense (though could probably be persuaded that that's overkill). So yeah - definitely don't want schemas to know about indexes, but I think it's desirable for indexes to know about schemas. |
I have an idea. Sent from my Enormous iPhone On Jul 8, 2015, at 10:15 AM, Tom Leach [email protected] wrote: I think there is something to be gained by schemas and index declarations Indexes do indirectly depend on the data model declared in a schema. In my I may even be veering towards mandating that we actually validate index So yeah - definitely don't want schemas to know about indexes, but I think — |
Hi @tleach !
I couldn't help but want to fix #1 , because I am trying to use Mongothon for a side project during vacation, and I want to be able to create indexes in a good way like this.
I'm opening this pull request before it's done, because I want to start the dialogue here.
indexes
support inmongothon.schema.Schema
"index":True
support to the Schema tooTODO:
IndexSpec
class and use those rather than dicts DONEOpen to feedback!