9
9
10
10
11
11
class QuerySetAsync (QuerySet ):
12
-
13
12
def __init__ (self , model = None , query = None , using = None , hints = None ):
14
13
super ().__init__ (model , query , using , hints )
15
14
@@ -20,18 +19,24 @@ async def async_create(self, **kwargs):
20
19
return await sync_to_async (self .create , thread_sensitive = True )(** kwargs )
21
20
22
21
async def async_bulk_create (self , obs , batch_size = None , ignore_conflicts = False ):
23
- return await sync_to_async (self .bulk_create , thread_sensitive = True )(obs , batch_size = batch_size ,
24
- ignore_conflicts = ignore_conflicts )
22
+ return await sync_to_async (self .bulk_create , thread_sensitive = True )(
23
+ obs , batch_size = batch_size , ignore_conflicts = ignore_conflicts
24
+ )
25
25
26
26
async def async_bulk_update (self , objs , fields , batch_size = None ):
27
- return await sync_to_async (self .bulk_update , thread_sensitive = True )(objs = objs , fields = fields ,
28
- batch_size = batch_size )
27
+ return await sync_to_async (self .bulk_update , thread_sensitive = True )(
28
+ objs = objs , fields = fields , batch_size = batch_size
29
+ )
29
30
30
31
async def async_get_or_create (self , defaults = None , ** kwargs ):
31
- return await sync_to_async (self .get_or_create , thread_sensitive = True )(defaults = defaults , ** kwargs )
32
+ return await sync_to_async (self .get_or_create , thread_sensitive = True )(
33
+ defaults = defaults , ** kwargs
34
+ )
32
35
33
36
async def async_update_or_create (self , defaults = None , ** kwargs ):
34
- return await sync_to_async (self .update_or_create , thread_sensitive = True )(defaults = defaults , ** kwargs )
37
+ return await sync_to_async (self .update_or_create , thread_sensitive = True )(
38
+ defaults = defaults , ** kwargs
39
+ )
35
40
36
41
async def async_earliest (self , * fields ):
37
42
return await sync_to_async (self .earliest , thread_sensitive = True )(* fields )
@@ -48,8 +53,10 @@ async def async_none(self):
48
53
async def async_last (self ):
49
54
return await sync_to_async (self .last , thread_sensitive = True )()
50
55
51
- async def async_in_bulk (self , id_list = None , * _ , field_name = 'pk' ):
52
- return await sync_to_async (self .in_bulk , thread_sensitive = True )(id_list = id_list , * _ , field_name = field_name )
56
+ async def async_in_bulk (self , id_list = None , * _ , field_name = "pk" ):
57
+ return await sync_to_async (self .in_bulk , thread_sensitive = True )(
58
+ id_list = id_list , * _ , field_name = field_name
59
+ )
53
60
54
61
async def async_delete (self ):
55
62
return await sync_to_async (self .delete , thread_sensitive = True )()
@@ -64,11 +71,14 @@ async def async_count(self):
64
71
return await sync_to_async (self .count , thread_sensitive = True )()
65
72
66
73
async def async_explain (self , * _ , format = None , ** options ):
67
- return await sync_to_async (self .explain , thread_sensitive = True )(* _ , format = format , ** options )
74
+ return await sync_to_async (self .explain , thread_sensitive = True )(
75
+ * _ , format = format , ** options
76
+ )
68
77
69
78
async def async_raw (self , raw_query , params = None , translations = None , using = None ):
70
- return await sync_to_async (self .raw , thread_sensitive = True )(raw_query , params = params , translations = translations ,
71
- using = using )
79
+ return await sync_to_async (self .raw , thread_sensitive = True )(
80
+ raw_query , params = params , translations = translations , using = using
81
+ )
72
82
73
83
def __aiter__ (self ):
74
84
self ._fetch_all ()
@@ -78,9 +88,6 @@ def _fetch_all(self):
78
88
with concurrent .futures .ThreadPoolExecutor (max_workers = 1 ) as executor :
79
89
future_fetch_all = executor .submit (super (QuerySetAsync , self )._fetch_all )
80
90
81
-
82
-
83
-
84
91
##################################################################
85
92
# PUBLIC METHODS THAT ALTER ATTRIBUTES AND RETURN A NEW QUERYSET #
86
93
##################################################################
@@ -95,10 +102,14 @@ async def async_exclude(self, *args, **kwargs):
95
102
return await sync_to_async (self .exclude , thread_sensitive = True )(* args , ** kwargs )
96
103
97
104
async def async_complex_filter (self , filter_obj ):
98
- return await sync_to_async (self .complex_filter , thread_sensitive = True )(filter_obj )
105
+ return await sync_to_async (self .complex_filter , thread_sensitive = True )(
106
+ filter_obj
107
+ )
99
108
100
109
async def async_union (self , * other_qs , all = False ):
101
- return await sync_to_async (self .union , thread_sensitive = True )(* other_qs , all = all )
110
+ return await sync_to_async (self .union , thread_sensitive = True )(
111
+ * other_qs , all = all
112
+ )
102
113
103
114
async def async_intersection (self , * other_qs ):
104
115
return await sync_to_async (self .intersection , thread_sensitive = True )(* other_qs )
@@ -107,24 +118,38 @@ async def async_difference(self, *other_qs):
107
118
return await sync_to_async (self .difference , thread_sensitive = True )(* other_qs )
108
119
109
120
async def async_select_for_update (self , nowait = False , skip_locked = False , of = ()):
110
- return await sync_to_async (self .select_for_update , thread_sensitive = True )(nowait = nowait ,
111
- skip_locked = skip_locked , of = of )
121
+ return await sync_to_async (self .select_for_update , thread_sensitive = True )(
122
+ nowait = nowait , skip_locked = skip_locked , of = of
123
+ )
112
124
113
125
async def async_prefetch_related (self , * lookups ):
114
- return await sync_to_async (self .prefetch_related , thread_sensitive = True )(* lookups )
126
+ return await sync_to_async (self .prefetch_related , thread_sensitive = True )(
127
+ * lookups
128
+ )
115
129
116
130
async def async_annotate (self , * args , ** kwargs ):
117
- return await sync_to_async (self .annotate , thread_sensitive = True )(* args , ** kwargs )
131
+ return await sync_to_async (self .annotate , thread_sensitive = True )(
132
+ * args , ** kwargs
133
+ )
118
134
119
135
async def async_order_by (self , * field_names ):
120
136
return await sync_to_async (self .order_by , thread_sensitive = True )(* field_names )
121
137
122
138
async def async_distinct (self , * field_names ):
123
139
return await sync_to_async (self .distinct , thread_sensitive = True )(* field_names )
124
140
125
- async def async_extra (self , select = None , where = None , params = None , tables = None , order_by = None , select_params = None ):
126
- return await sync_to_async (self .extra , thread_sensitive = True )(select , where , params , tables , order_by ,
127
- select_params )
141
+ async def async_extra (
142
+ self ,
143
+ select = None ,
144
+ where = None ,
145
+ params = None ,
146
+ tables = None ,
147
+ order_by = None ,
148
+ select_params = None ,
149
+ ):
150
+ return await sync_to_async (self .extra , thread_sensitive = True )(
151
+ select , where , params , tables , order_by , select_params
152
+ )
128
153
129
154
async def async_reverse (self ):
130
155
return await sync_to_async (self .reverse , thread_sensitive = True )()
@@ -139,11 +164,13 @@ async def async_using(self, alias):
139
164
return await sync_to_async (self .using , thread_sensitive = True )(alias )
140
165
141
166
async def async_resolve_expression (self , * args , ** kwargs ):
142
- return await sync_to_async (self .resolve_expression , thread_sensitive = True )(* args , ** kwargs )
167
+ return await sync_to_async (self .resolve_expression , thread_sensitive = True )(
168
+ * args , ** kwargs
169
+ )
143
170
144
171
@property
145
172
async def async_ordered (self ):
146
173
def _ordered ():
147
174
return super (QuerySetAsync , self ).ordered
148
- return await sync_to_async (_ordered , thread_sensitive = True )()
149
175
176
+ return await sync_to_async (_ordered , thread_sensitive = True )()
0 commit comments