-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
create unqiue index in indexes and related children in contrib.postgres/sqlite.indexes #1642
base: develop
Are you sure you want to change the base?
create unqiue index in indexes and related children in contrib.postgres/sqlite.indexes #1642
Conversation
jun 8/related changes:
|
b1e4b8e
to
c265815
Compare
Why you decided to make it as separate class? Also CI seems to be failing due to lint, you can run |
Hi i got your point. i'll remove shared unique index and go further with driver specific implementation |
86e0643
to
3ad96ef
Compare
if self.INDEX_TYPE: | ||
self.INDEX_TYPE = f"USING {self.INDEX_TYPE}" |
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.
Sorry, I was wrong about this, I forgot that postgresql allows only default b-tree index to be unique, so it is something we don't need to support
|
||
|
||
class SqliteUniqueIndex(SqliteIndex): | ||
INDEX_TYPE = "unique".upper() |
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.
Why not just "UNIQUE"
?
fields: Optional[Tuple[str, ...]] = None, | ||
name: Optional[str] = None, | ||
condition: Optional[Dict[str, str]] = None, | ||
where_expre: Optional[str] = None, |
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.
I am a little at lost here
Why do we need both condition
and where_expre
?
return str(f"{key} {op} {cond}") | ||
|
||
def _gen_condition(self, conditions: Dict[str, str]): | ||
conditions = " AND ".join(tuple(map(self._gen_field_cond, conditions.items()))) |
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.
please use comprehensions
" AND ".join(self._gen_field_cond(k, v) for k, v in condition.items())
With that you will also be able to make better signature and typing for _gen_field_cond
self.extra = where_expre or self._gen_condition(_condition) | ||
|
||
@classmethod | ||
def _gen_field_cond(cls, kv: tuple): |
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.
Add return typing
create a postgresql unique index and consider the
nulls not distinct
Description
enhancement was started from this issue
this PR provide a manual solution for postgres driver. but i think the orm has to provide a base/shared solution.
the solution is a way to consider nulls equal in unique indexes on that drivers that consider nulls not equal.
postgres can done that by :
nulls not distinct
sqlite and sqlserver too by : index expressions
on mysql i don't know yet.