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 prefect/server/schemas/sorting.py
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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 prefect/server/schemas/sorting.py
164
165
166
167
168
169
170
171
172
173
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 prefect/server/schemas/sorting.py
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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 prefect/server/schemas/sorting.py
143
144
145
146
147
148
149
150
151
152
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]

BlockDocumentSort

Bases: AutoEnum

Defines block document sorting options.

Source code in prefect/server/schemas/sorting.py
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
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, db: "PrefectDBInterface") -> "ColumnElement":
        """Return an expression used to sort block documents"""
        sort_mapping = {
            "NAME_DESC": db.BlockDocument.name.desc(),
            "NAME_ASC": db.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 prefect/server/schemas/sorting.py
202
203
204
205
206
207
208
209
def as_sql_sort(self, db: "PrefectDBInterface") -> "ColumnElement":
    """Return an expression used to sort block documents"""
    sort_mapping = {
        "NAME_DESC": db.BlockDocument.name.desc(),
        "NAME_ASC": db.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 prefect/server/schemas/sorting.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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 prefect/server/schemas/sorting.py
123
124
125
126
127
128
129
130
131
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 prefect/server/schemas/sorting.py
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
53
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 prefect/server/schemas/sorting.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
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 prefect/server/schemas/sorting.py
104
105
106
107
108
109
110
111
112
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 prefect/server/schemas/sorting.py
81
82
83
84
85
86
87
88
89
90
91
92
93
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 prefect/server/schemas/sorting.py
87
88
89
90
91
92
93
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 prefect/server/schemas/sorting.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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 prefect/server/schemas/sorting.py
67
68
69
70
71
72
73
74
75
76
77
78
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 prefect/server/schemas/sorting.py
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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 prefect/server/schemas/sorting.py
184
185
186
187
188
189
190
191
192
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]