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 /home/runner/work/docs/docs/prefect_source/src/prefect/server/schemas/sorting.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort artifact collections"""
        sort_mapping = {
            "CREATED_DESC": db.ArtifactCollection.created.desc(),
            "UPDATED_DESC": db.ArtifactCollection.updated.desc(),
            "ID_DESC": db.ArtifactCollection.id.desc(),
            "KEY_DESC": db.ArtifactCollection.key.desc(),
            "KEY_ASC": db.ArtifactCollection.key.asc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort artifact collections

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

ArtifactSort

Bases: AutoEnum

Defines artifact sorting options.

Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/server/schemas/sorting.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort artifacts"""
        sort_mapping = {
            "CREATED_DESC": db.Artifact.created.desc(),
            "UPDATED_DESC": db.Artifact.updated.desc(),
            "ID_DESC": db.Artifact.id.desc(),
            "KEY_DESC": db.Artifact.key.desc(),
            "KEY_ASC": db.Artifact.key.asc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort artifacts

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

DeploymentSort

Bases: AutoEnum

Defines deployment sorting options.

Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/server/schemas/sorting.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort deployments"""
        sort_mapping = {
            "CREATED_DESC": db.Deployment.created.desc(),
            "UPDATED_DESC": db.Deployment.updated.desc(),
            "NAME_ASC": db.Deployment.name.asc(),
            "NAME_DESC": db.Deployment.name.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort deployments

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

FlowRunSort

Bases: AutoEnum

Defines flow run sorting options.

Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/server/schemas/sorting.py
19
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
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, db: "PrefectDBInterface") -> "ColumnElement":
        from sqlalchemy.sql.functions import coalesce

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

FlowSort

Bases: AutoEnum

Defines flow sorting options.

Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/server/schemas/sorting.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
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, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort flows"""
        sort_mapping = {
            "CREATED_DESC": db.Flow.created.desc(),
            "UPDATED_DESC": db.Flow.updated.desc(),
            "NAME_ASC": db.Flow.name.asc(),
            "NAME_DESC": db.Flow.name.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort flows

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

LogSort

Bases: AutoEnum

Defines log sorting options.

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

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

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

as_sql_sort

Return an expression used to sort task runs

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

TaskRunSort

Bases: AutoEnum

Defines task run sorting options.

Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/server/schemas/sorting.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort task runs"""
        sort_mapping = {
            "ID_DESC": db.TaskRun.id.desc(),
            "EXPECTED_START_TIME_ASC": db.TaskRun.expected_start_time.asc(),
            "EXPECTED_START_TIME_DESC": db.TaskRun.expected_start_time.desc(),
            "NAME_ASC": db.TaskRun.name.asc(),
            "NAME_DESC": db.TaskRun.name.desc(),
            "NEXT_SCHEDULED_START_TIME_ASC": db.TaskRun.next_scheduled_start_time.asc(),
            "END_TIME_DESC": db.TaskRun.end_time.desc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort task runs

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

VariableSort

Bases: AutoEnum

Defines variables sorting options.

Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/server/schemas/sorting.py
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort variables"""
        sort_mapping = {
            "CREATED_DESC": db.Variable.created.desc(),
            "UPDATED_DESC": db.Variable.updated.desc(),
            "NAME_DESC": db.Variable.name.desc(),
            "NAME_ASC": db.Variable.name.asc(),
        }
        return sort_mapping[self.value]

as_sql_sort

Return an expression used to sort variables

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