mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-18 01:45:59 +08:00
Adjust Postgres indexes for Django 3.2 (#616)
This commit is contained in:
@@ -1,82 +1,90 @@
|
|||||||
from typing import Optional, Sequence
|
from typing import Optional, Sequence, Union
|
||||||
|
|
||||||
from django.db.models.query_utils import Q
|
from django.db.models.query_utils import Q
|
||||||
|
|
||||||
from django.db.models import Index
|
from django.db.models import Index
|
||||||
|
from django.db.models.expressions import BaseExpression, Combinable
|
||||||
|
|
||||||
|
|
||||||
class PostgresIndex(Index): ...
|
class PostgresIndex(Index): ...
|
||||||
|
|
||||||
class BrinIndex(PostgresIndex):
|
class BrinIndex(PostgresIndex):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*expressions: Union[BaseExpression, Combinable, str],
|
||||||
autosummarize: Optional[bool] = ...,
|
autosummarize: Optional[bool] = ...,
|
||||||
pages_per_range: Optional[int] = ...,
|
pages_per_range: Optional[int] = ...,
|
||||||
fields: Sequence[str] = ...,
|
fields: Sequence[str] = ...,
|
||||||
name: Optional[str] = ...,
|
name: Optional[str] = ...,
|
||||||
db_tablespace: Optional[str] = ...,
|
db_tablespace: Optional[str] = ...,
|
||||||
opclasses: Sequence[str] = ...,
|
opclasses: Sequence[str] = ...,
|
||||||
condition: Optional[Q] = ...
|
condition: Optional[Q] = ...,
|
||||||
|
include: Optional[Sequence[str]] = ...,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
class BTreeIndex(PostgresIndex):
|
class BTreeIndex(PostgresIndex):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*expressions: Union[BaseExpression, Combinable, str],
|
||||||
fillfactor: Optional[int] = ...,
|
fillfactor: Optional[int] = ...,
|
||||||
fields: Sequence[str] = ...,
|
fields: Sequence[str] = ...,
|
||||||
name: Optional[str] = ...,
|
name: Optional[str] = ...,
|
||||||
db_tablespace: Optional[str] = ...,
|
db_tablespace: Optional[str] = ...,
|
||||||
opclasses: Sequence[str] = ...,
|
opclasses: Sequence[str] = ...,
|
||||||
condition: Optional[Q] = ...
|
condition: Optional[Q] = ...,
|
||||||
|
include: Optional[Sequence[str]] = ...,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
class GinIndex(PostgresIndex):
|
class GinIndex(PostgresIndex):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*expressions: Union[BaseExpression, Combinable, str],
|
||||||
fastupdate: Optional[bool] = ...,
|
fastupdate: Optional[bool] = ...,
|
||||||
gin_pending_list_limit: Optional[int] = ...,
|
gin_pending_list_limit: Optional[int] = ...,
|
||||||
fields: Sequence[str] = ...,
|
fields: Sequence[str] = ...,
|
||||||
name: Optional[str] = ...,
|
name: Optional[str] = ...,
|
||||||
db_tablespace: Optional[str] = ...,
|
db_tablespace: Optional[str] = ...,
|
||||||
opclasses: Sequence[str] = ...,
|
opclasses: Sequence[str] = ...,
|
||||||
condition: Optional[Q] = ...
|
condition: Optional[Q] = ...,
|
||||||
|
include: Optional[Sequence[str]] = ...,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
class GistIndex(PostgresIndex):
|
class GistIndex(PostgresIndex):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*expressions: Union[BaseExpression, Combinable, str],
|
||||||
buffering: Optional[bool] = ...,
|
buffering: Optional[bool] = ...,
|
||||||
fillfactor: Optional[int] = ...,
|
fillfactor: Optional[int] = ...,
|
||||||
fields: Sequence[str] = ...,
|
fields: Sequence[str] = ...,
|
||||||
name: Optional[str] = ...,
|
name: Optional[str] = ...,
|
||||||
db_tablespace: Optional[str] = ...,
|
db_tablespace: Optional[str] = ...,
|
||||||
opclasses: Sequence[str] = ...,
|
opclasses: Sequence[str] = ...,
|
||||||
condition: Optional[Q] = ...
|
condition: Optional[Q] = ...,
|
||||||
|
include: Optional[Sequence[str]] = ...,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
class HashIndex(PostgresIndex):
|
class HashIndex(PostgresIndex):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*expressions: Union[BaseExpression, Combinable, str],
|
||||||
fillfactor: Optional[int] = ...,
|
fillfactor: Optional[int] = ...,
|
||||||
fields: Sequence[str] = ...,
|
fields: Sequence[str] = ...,
|
||||||
name: Optional[str] = ...,
|
name: Optional[str] = ...,
|
||||||
db_tablespace: Optional[str] = ...,
|
db_tablespace: Optional[str] = ...,
|
||||||
opclasses: Sequence[str] = ...,
|
opclasses: Sequence[str] = ...,
|
||||||
condition: Optional[Q] = ...
|
condition: Optional[Q] = ...,
|
||||||
|
include: Optional[Sequence[str]] = ...,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|
||||||
class SpGistIndex(PostgresIndex):
|
class SpGistIndex(PostgresIndex):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
*expressions: Union[BaseExpression, Combinable, str],
|
||||||
fillfactor: Optional[int] = ...,
|
fillfactor: Optional[int] = ...,
|
||||||
fields: Sequence[str] = ...,
|
fields: Sequence[str] = ...,
|
||||||
name: Optional[str] = ...,
|
name: Optional[str] = ...,
|
||||||
db_tablespace: Optional[str] = ...,
|
db_tablespace: Optional[str] = ...,
|
||||||
opclasses: Sequence[str] = ...,
|
opclasses: Sequence[str] = ...,
|
||||||
condition: Optional[Q] = ...
|
condition: Optional[Q] = ...,
|
||||||
|
include: Optional[Sequence[str]] = ...,
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|||||||
18
tests/typecheck/contrib/postgres/test_indexes.yml
Normal file
18
tests/typecheck/contrib/postgres/test_indexes.yml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
- case: can_instantiate_index
|
||||||
|
main: |
|
||||||
|
from django.db import models
|
||||||
|
from django.db.models.functions import Lower
|
||||||
|
from django.contrib.postgres.indexes import {{ index }}
|
||||||
|
{{ index }}(fields=["foo"])
|
||||||
|
{{ index }}(models.F("bar"), name="test")
|
||||||
|
{{ index }}("foo", models.F("bar"), Lower("baz"), name="test")
|
||||||
|
{{ index }}("foo", name="test", opclasses=["bar"])
|
||||||
|
{{ index }}("foo", name="test", condition=models.Q(foo=1))
|
||||||
|
{{ index }}("foo", name="test", include=["bar"])
|
||||||
|
parametrized:
|
||||||
|
- index: BrinIndex
|
||||||
|
- index: BTreeIndex
|
||||||
|
- index: GinIndex
|
||||||
|
- index: GistIndex
|
||||||
|
- index: HashIndex
|
||||||
|
- index: SpGistIndex
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models.functions import Lower
|
from django.db.models.functions import Lower
|
||||||
models.Index(fields=["foo"])
|
models.Index(fields=["foo"])
|
||||||
|
models.Index(models.F("bar"), name="test")
|
||||||
models.Index("foo", models.F("bar"), Lower("baz"), name="test")
|
models.Index("foo", models.F("bar"), Lower("baz"), name="test")
|
||||||
models.Index("foo", name="test", opclasses=["bar"])
|
models.Index("foo", name="test", opclasses=["bar"])
|
||||||
models.Index("foo", name="test", condition=models.Q(foo=1))
|
models.Index("foo", name="test", condition=models.Q(foo=1))
|
||||||
|
|||||||
Reference in New Issue
Block a user