-
Notifications
You must be signed in to change notification settings - Fork 6
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
add support for partial indexes #159
base: main
Are you sure you want to change the base?
Conversation
And also creating uniques in create_model() and add_field(), and removing them in remove_field().
where = query.build_where(self.condition) | ||
compiler = query.get_compiler(connection=schema_editor.connection) | ||
mql_ = where.as_mql(compiler, schema_editor.connection) | ||
# Transform aggregate() query syntax into find() syntax. |
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.
This stinks and doesn't work for multiple conditions / null conditions (but maybe could be done). I wonder if it would be better to have a separate path from as_mql()
to generate find()
compatible MQL rather than trying to convert from the aggregate syntax.
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.
As I understand it, we're pulling the index conditions from a model's field definitions using the compiler built by the schema editor? Is this schema_editor compiler different from our Mongo one?
can self.condition ever be a list of items?
Speaking more broadly, I'd say, yes, let's include the find
compatible conversions, but how many nodes/expressions would we need that for? Also, since find
is much more limited there would still be gaps.
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.
query.get_compiler()
is the same compiler we use for other queries.
condition
is a Q
object: "For example, condition=Q(pages__gt=400)
indexes records with more than 400 pages."
What doesn't currently work is multiple conditions like:
Q(
pub_date__gt=datetime.datetime(
year=2015,
month=1,
day=1,
tzinfo=timezone.get_current_timezone(),
)
)
& Q(headline__contains="China")
Maybe that can be translated without too much difficulty. I didn't think about it too much.
Obviously, we can only support conditions that MongoDB supports.
07e5a17
to
575957c
Compare
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.
Added some comments! Will circle back and ask some more tomorrow :)
if unique: | ||
kwargs["unique"] = True | ||
if field: | ||
filter_expression[field.column].update({"$type": field.db_type(self.connection)}) |
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.
do we need to maintain type? if so, why?
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.
The comment is below: "Use partialFilterExpression to allow multiple null values for a unique constraint." It's not really in the best spot and should be amended to reference $type
since partialFilterExpression is also used for condition
.
where = query.build_where(self.condition) | ||
compiler = query.get_compiler(connection=schema_editor.connection) | ||
mql_ = where.as_mql(compiler, schema_editor.connection) | ||
# Transform aggregate() query syntax into find() syntax. |
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.
As I understand it, we're pulling the index conditions from a model's field definitions using the compiler built by the schema editor? Is this schema_editor compiler different from our Mongo one?
can self.condition ever be a list of items?
Speaking more broadly, I'd say, yes, let's include the find
compatible conversions, but how many nodes/expressions would we need that for? Also, since find
is much more limited there would still be gaps.
refs #104