Skip to content

prefect.server.schemas.sorting

Schemas for sorting Prefect REST API objects.

ArtifactCollectionSort

Bases: AutoEnum

Defines artifact collection sorting options.

Source code in src/prefect/server/schemas/sorting.py
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
class ArtifactCollectionSort(AutoEnum):
    """Defines artifact collection sorting options."""

    CREATED_DESC = AutoEnum.auto()
    UPDATED_DESC = AutoEnum.auto()
    ID_DESC = AutoEnum.auto()
    KEY_DESC = AutoEnum.auto()
    KEY_ASC = AutoEnum.auto()

    def as_sql_sort(self) -> "ColumnElement":
        """Return an expression used to sort artifact collections"""
        sort_mapping = {
            "CREATED_DESC": orm_models.ArtifactCollection.created.desc(),
            "UPDATED_DESC": orm_models.ArtifactCollection.updated.desc(),
            "ID_DESC": orm_models.ArtifactCollection.id.desc(),
            "KEY_DESC": orm_models.ArtifactCollection.key.desc(),
            "KEY_ASC": orm_models.ArtifactCollection.key.asc(),
        }
        return sort_mapping[self.value]

as_sql_sort()

Return an expression used to sort artifact collections

Source code in src/prefect/server/schemas/sorting.py
163
164
165
166
167
168
169
170
171
172
def as_sql_sort(self) -> "ColumnElement":
    """Return an expression used to sort artifact collections"""
    sort_mapping = {
        "CREATED_DESC": orm_models.ArtifactCollection.created.desc(),
        "UPDATED_DESC": orm_models.ArtifactCollection.updated.desc(),
        "ID_DESC": orm_models.ArtifactCollection.id.desc(),
        "KEY_DESC": orm_models.ArtifactCollection.key.desc(),
        "KEY_ASC": orm_models.ArtifactCollection.key.asc(),
    }
    return sort_mapping[self.value]

ArtifactSort

Bases: AutoEnum

Defines artifact sorting options.

Source code in src/prefect/server/schemas/sorting.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
class ArtifactSort(AutoEnum):
    """Defines artifact sorting options."""

    CREATED_DESC = AutoEnum.auto()
    UPDATED_DESC = AutoEnum.auto()
    ID_DESC = AutoEnum.auto()
    KEY_DESC = AutoEnum.auto()
    KEY_ASC = AutoEnum.auto()

    def as_sql_sort(self) -> "ColumnElement":
        """Return an expression used to sort artifacts"""
        sort_mapping = {
            "CREATED_DESC": orm_models.Artifact.created.desc(),
            "UPDATED_DESC": orm_models.Artifact.updated.desc(),
            "ID_DESC": orm_models.Artifact.id.desc(),
            "KEY_DESC": orm_models.Artifact.key.desc(),
            "KEY_ASC": orm_models.Artifact.key.asc(),
        }
        return sort_mapping[self.value]

as_sql_sort()

Return an expression used to sort artifacts

Source code in src/prefect/server/schemas/sorting.py
142
143
144
145
146
147
148
149
150
151
def as_sql_sort(self) -> "ColumnElement":
    """Return an expression used to sort artifacts"""
    sort_mapping = {
        "CREATED_DESC": orm_models.Artifact.created.desc(),
        "UPDATED_DESC": orm_models.Artifact.updated.desc(),
        "ID_DESC": orm_models.Artifact.id.desc(),
        "KEY_DESC": orm_models.Artifact.key.desc(),
        "KEY_ASC": orm_models.Artifact.key.asc(),
    }
    return sort_mapping[self.value]

BlockDocumentSort

Bases: AutoEnum

Defines block document sorting options.

Source code in src/prefect/server/schemas/sorting.py
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
class BlockDocumentSort(AutoEnum):
    """Defines block document sorting options."""

    NAME_DESC = "NAME_DESC"
    NAME_ASC = "NAME_ASC"
    BLOCK_TYPE_AND_NAME_ASC = "BLOCK_TYPE_AND_NAME_ASC"

    def as_sql_sort(self) -> "ColumnElement":
        """Return an expression used to sort block documents"""
        sort_mapping = {
            "NAME_DESC": orm_models.BlockDocument.name.desc(),
            "NAME_ASC": orm_models.BlockDocument.name.asc(),
            "BLOCK_TYPE_AND_NAME_ASC": sa.text("block_type_name asc, name asc"),
        }
        return sort_mapping[self.value]

as_sql_sort()

Return an expression used to sort block documents

Source code in src/prefect/server/schemas/sorting.py
201
202
203
204
205
206
207
208
def as_sql_sort(self) -> "ColumnElement":
    """Return an expression used to sort block documents"""
    sort_mapping = {
        "NAME_DESC": orm_models.BlockDocument.name.desc(),
        "NAME_ASC": orm_models.BlockDocument.name.asc(),
        "BLOCK_TYPE_AND_NAME_ASC": sa.text("block_type_name asc, name asc"),
    }
    return sort_mapping[self.value]

DeploymentSort

Bases: AutoEnum

Defines deployment sorting options.

Source code in src/prefect/server/schemas/sorting.py
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
class DeploymentSort(AutoEnum):
    """Defines deployment sorting options."""

    CREATED_DESC = AutoEnum.auto()
    UPDATED_DESC = AutoEnum.auto()
    NAME_ASC = AutoEnum.auto()
    NAME_DESC = AutoEnum.auto()

    def as_sql_sort(self) -> "ColumnElement":
        """Return an expression used to sort deployments"""
        sort_mapping = {
            "CREATED_DESC": orm_models.Deployment.created.desc(),
            "UPDATED_DESC": orm_models.Deployment.updated.desc(),
            "NAME_ASC": orm_models.Deployment.name.asc(),
            "NAME_DESC": orm_models.Deployment.name.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort()

Return an expression used to sort deployments

Source code in src/prefect/server/schemas/sorting.py
122
123
124
125
126
127
128
129
130
def as_sql_sort(self) -> "ColumnElement":
    """Return an expression used to sort deployments"""
    sort_mapping = {
        "CREATED_DESC": orm_models.Deployment.created.desc(),
        "UPDATED_DESC": orm_models.Deployment.updated.desc(),
        "NAME_ASC": orm_models.Deployment.name.asc(),
        "NAME_DESC": orm_models.Deployment.name.desc(),
    }
    return sort_mapping[self.value]

FlowRunSort

Bases: AutoEnum

Defines flow run sorting options.

Source code in src/prefect/server/schemas/sorting.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class FlowRunSort(AutoEnum):
    """Defines flow run sorting options."""

    ID_DESC = AutoEnum.auto()
    START_TIME_ASC = AutoEnum.auto()
    START_TIME_DESC = AutoEnum.auto()
    EXPECTED_START_TIME_ASC = AutoEnum.auto()
    EXPECTED_START_TIME_DESC = AutoEnum.auto()
    NAME_ASC = AutoEnum.auto()
    NAME_DESC = AutoEnum.auto()
    NEXT_SCHEDULED_START_TIME_ASC = AutoEnum.auto()
    END_TIME_DESC = AutoEnum.auto()

    def as_sql_sort(self) -> "ColumnElement":
        from sqlalchemy.sql.functions import coalesce

        """Return an expression used to sort flow runs"""
        sort_mapping = {
            "ID_DESC": orm_models.FlowRun.id.desc(),
            "START_TIME_ASC": coalesce(
                orm_models.FlowRun.start_time, orm_models.FlowRun.expected_start_time
            ).asc(),
            "START_TIME_DESC": coalesce(
                orm_models.FlowRun.start_time, orm_models.FlowRun.expected_start_time
            ).desc(),
            "EXPECTED_START_TIME_ASC": orm_models.FlowRun.expected_start_time.asc(),
            "EXPECTED_START_TIME_DESC": orm_models.FlowRun.expected_start_time.desc(),
            "NAME_ASC": orm_models.FlowRun.name.asc(),
            "NAME_DESC": orm_models.FlowRun.name.desc(),
            "NEXT_SCHEDULED_START_TIME_ASC": orm_models.FlowRun.next_scheduled_start_time.asc(),
            "END_TIME_DESC": orm_models.FlowRun.end_time.desc(),
        }
        return sort_mapping[self.value]

FlowSort

Bases: AutoEnum

Defines flow sorting options.

Source code in src/prefect/server/schemas/sorting.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
class FlowSort(AutoEnum):
    """Defines flow sorting options."""

    CREATED_DESC = AutoEnum.auto()
    UPDATED_DESC = AutoEnum.auto()
    NAME_ASC = AutoEnum.auto()
    NAME_DESC = AutoEnum.auto()

    def as_sql_sort(self) -> "ColumnElement":
        """Return an expression used to sort flows"""
        sort_mapping = {
            "CREATED_DESC": orm_models.Flow.created.desc(),
            "UPDATED_DESC": orm_models.Flow.updated.desc(),
            "NAME_ASC": orm_models.Flow.name.asc(),
            "NAME_DESC": orm_models.Flow.name.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort()

Return an expression used to sort flows

Source code in src/prefect/server/schemas/sorting.py
103
104
105
106
107
108
109
110
111
def as_sql_sort(self) -> "ColumnElement":
    """Return an expression used to sort flows"""
    sort_mapping = {
        "CREATED_DESC": orm_models.Flow.created.desc(),
        "UPDATED_DESC": orm_models.Flow.updated.desc(),
        "NAME_ASC": orm_models.Flow.name.asc(),
        "NAME_DESC": orm_models.Flow.name.desc(),
    }
    return sort_mapping[self.value]

LogSort

Bases: AutoEnum

Defines log sorting options.

Source code in src/prefect/server/schemas/sorting.py
80
81
82
83
84
85
86
87
88
89
90
91
92
class LogSort(AutoEnum):
    """Defines log sorting options."""

    TIMESTAMP_ASC = AutoEnum.auto()
    TIMESTAMP_DESC = AutoEnum.auto()

    def as_sql_sort(self) -> "ColumnElement":
        """Return an expression used to sort task runs"""
        sort_mapping = {
            "TIMESTAMP_ASC": orm_models.Log.timestamp.asc(),
            "TIMESTAMP_DESC": orm_models.Log.timestamp.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort()

Return an expression used to sort task runs

Source code in src/prefect/server/schemas/sorting.py
86
87
88
89
90
91
92
def as_sql_sort(self) -> "ColumnElement":
    """Return an expression used to sort task runs"""
    sort_mapping = {
        "TIMESTAMP_ASC": orm_models.Log.timestamp.asc(),
        "TIMESTAMP_DESC": orm_models.Log.timestamp.desc(),
    }
    return sort_mapping[self.value]

TaskRunSort

Bases: AutoEnum

Defines task run sorting options.

Source code in src/prefect/server/schemas/sorting.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class TaskRunSort(AutoEnum):
    """Defines task run sorting options."""

    ID_DESC = AutoEnum.auto()
    EXPECTED_START_TIME_ASC = AutoEnum.auto()
    EXPECTED_START_TIME_DESC = AutoEnum.auto()
    NAME_ASC = AutoEnum.auto()
    NAME_DESC = AutoEnum.auto()
    NEXT_SCHEDULED_START_TIME_ASC = AutoEnum.auto()
    END_TIME_DESC = AutoEnum.auto()

    def as_sql_sort(self) -> "ColumnElement":
        """Return an expression used to sort task runs"""
        sort_mapping = {
            "ID_DESC": orm_models.TaskRun.id.desc(),
            "EXPECTED_START_TIME_ASC": orm_models.TaskRun.expected_start_time.asc(),
            "EXPECTED_START_TIME_DESC": orm_models.TaskRun.expected_start_time.desc(),
            "NAME_ASC": orm_models.TaskRun.name.asc(),
            "NAME_DESC": orm_models.TaskRun.name.desc(),
            "NEXT_SCHEDULED_START_TIME_ASC": orm_models.TaskRun.next_scheduled_start_time.asc(),
            "END_TIME_DESC": orm_models.TaskRun.end_time.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort()

Return an expression used to sort task runs

Source code in src/prefect/server/schemas/sorting.py
66
67
68
69
70
71
72
73
74
75
76
77
def as_sql_sort(self) -> "ColumnElement":
    """Return an expression used to sort task runs"""
    sort_mapping = {
        "ID_DESC": orm_models.TaskRun.id.desc(),
        "EXPECTED_START_TIME_ASC": orm_models.TaskRun.expected_start_time.asc(),
        "EXPECTED_START_TIME_DESC": orm_models.TaskRun.expected_start_time.desc(),
        "NAME_ASC": orm_models.TaskRun.name.asc(),
        "NAME_DESC": orm_models.TaskRun.name.desc(),
        "NEXT_SCHEDULED_START_TIME_ASC": orm_models.TaskRun.next_scheduled_start_time.asc(),
        "END_TIME_DESC": orm_models.TaskRun.end_time.desc(),
    }
    return sort_mapping[self.value]

VariableSort

Bases: AutoEnum

Defines variables sorting options.

Source code in src/prefect/server/schemas/sorting.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
class VariableSort(AutoEnum):
    """Defines variables sorting options."""

    CREATED_DESC = "CREATED_DESC"
    UPDATED_DESC = "UPDATED_DESC"
    NAME_DESC = "NAME_DESC"
    NAME_ASC = "NAME_ASC"

    def as_sql_sort(self) -> "ColumnElement":
        """Return an expression used to sort variables"""
        sort_mapping = {
            "CREATED_DESC": orm_models.Variable.created.desc(),
            "UPDATED_DESC": orm_models.Variable.updated.desc(),
            "NAME_DESC": orm_models.Variable.name.desc(),
            "NAME_ASC": orm_models.Variable.name.asc(),
        }
        return sort_mapping[self.value]

as_sql_sort()

Return an expression used to sort variables

Source code in src/prefect/server/schemas/sorting.py
183
184
185
186
187
188
189
190
191
def as_sql_sort(self) -> "ColumnElement":
    """Return an expression used to sort variables"""
    sort_mapping = {
        "CREATED_DESC": orm_models.Variable.created.desc(),
        "UPDATED_DESC": orm_models.Variable.updated.desc(),
        "NAME_DESC": orm_models.Variable.name.desc(),
        "NAME_ASC": orm_models.Variable.name.asc(),
    }
    return sort_mapping[self.value]