postgresdb3 0.5.0__tar.gz → 0.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- postgresdb3-0.6.0/PKG-INFO +251 -0
- postgresdb3-0.6.0/README.md +229 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/core/async_db.py +1 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/core/sync_db.py +1 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/models.py +96 -0
- postgresdb3-0.6.0/postgresdb3/orm/query.py +283 -0
- postgresdb3-0.6.0/postgresdb3.egg-info/PKG-INFO +251 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/setup.py +1 -1
- postgresdb3-0.5.0/PKG-INFO +0 -255
- postgresdb3-0.5.0/README.md +0 -233
- postgresdb3-0.5.0/postgresdb3/orm/query.py +0 -119
- postgresdb3-0.5.0/postgresdb3.egg-info/PKG-INFO +0 -255
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/__init__.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/core/__init__.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/__init__.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/base.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/fields/__init__.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/fields/base.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/fields/datetime.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/fields/misc.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/fields/numeric.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/fields/relations.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/fields/text.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3/orm/meta.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3.egg-info/SOURCES.txt +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3.egg-info/dependency_links.txt +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3.egg-info/requires.txt +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/postgresdb3.egg-info/top_level.txt +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/pyproject.toml +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.6.0}/setup.cfg +0 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: postgresdb3
|
|
3
|
+
Version: 0.6.0
|
|
4
|
+
Summary: Python uchun oddiy PostgreSQL wrapper
|
|
5
|
+
Author: Abdulbosit Alijonov
|
|
6
|
+
Project-URL: Source Code, https://github.com/AlijonovUz/PostgresDB
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: psycopg2>=2.9
|
|
13
|
+
Requires-Dist: asyncpg>=0.31.0
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: classifier
|
|
16
|
+
Dynamic: description
|
|
17
|
+
Dynamic: description-content-type
|
|
18
|
+
Dynamic: project-url
|
|
19
|
+
Dynamic: requires-dist
|
|
20
|
+
Dynamic: requires-python
|
|
21
|
+
Dynamic: summary
|
|
22
|
+
|
|
23
|
+
# PostgresDB3
|
|
24
|
+
|
|
25
|
+

|
|
26
|
+

|
|
27
|
+

|
|
28
|
+
|
|
29
|
+
**PostgresDB3** — PostgreSQL bilan ishlash uchun oddiy, qulay va yengil Python wrapper.
|
|
30
|
+
|
|
31
|
+
Kutubxona quyidagilarni qo‘llab-quvvatlaydi:
|
|
32
|
+
|
|
33
|
+
- Sync va Async ishlash
|
|
34
|
+
- CRUD operatsiyalari
|
|
35
|
+
- Query builder (`where`, `join`, `group_by`, `order_by`, `limit`, `offset`)
|
|
36
|
+
- Kengaytirilgan filterlar (`gt`, `lt`, `like`, `ilike`, `in`, `isnull`)
|
|
37
|
+
- Raw SQL bajarish
|
|
38
|
+
- Sodda ORM tizimi
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
# O‘rnatish
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install postgresdb3
|
|
46
|
+
````
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
# Sync foydalanish
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from postgresdb3 import PostgresDB
|
|
54
|
+
|
|
55
|
+
db = PostgresDB(
|
|
56
|
+
database="mydb",
|
|
57
|
+
user="postgres",
|
|
58
|
+
password="mypassword"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
# Jadval yaratish
|
|
62
|
+
db.create("users", "id SERIAL PRIMARY KEY, name VARCHAR(100), age INT")
|
|
63
|
+
|
|
64
|
+
# Qator qo‘shish
|
|
65
|
+
db.insert("users", "name, age", ("Ali", 25))
|
|
66
|
+
|
|
67
|
+
# Barcha ma'lumotlar
|
|
68
|
+
users = db.select("users")
|
|
69
|
+
|
|
70
|
+
# Shart bilan qidirish
|
|
71
|
+
adults = db.select("users", where={"age__gt": 18})
|
|
72
|
+
|
|
73
|
+
# Tartiblash
|
|
74
|
+
users = db.select("users", order_by="age DESC")
|
|
75
|
+
|
|
76
|
+
# Yangilash
|
|
77
|
+
db.update("users", "age", 26, "name", "Ali")
|
|
78
|
+
|
|
79
|
+
# O‘chirish
|
|
80
|
+
db.delete("users", "name", "Ali")
|
|
81
|
+
|
|
82
|
+
db.close()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
# Async foydalanish
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import asyncio
|
|
91
|
+
from postgresdb3 import AsyncPostgresDB
|
|
92
|
+
|
|
93
|
+
async def main():
|
|
94
|
+
|
|
95
|
+
db = AsyncPostgresDB(
|
|
96
|
+
database="mydb",
|
|
97
|
+
user="postgres",
|
|
98
|
+
password="mypassword"
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
await db.create("users", "id SERIAL PRIMARY KEY, name VARCHAR(100), age INT")
|
|
102
|
+
|
|
103
|
+
await db.insert("users", "name, age", ["Ali", 25])
|
|
104
|
+
|
|
105
|
+
users = await db.select("users")
|
|
106
|
+
|
|
107
|
+
adults = await db.select("users", where={"age__gt": 18})
|
|
108
|
+
|
|
109
|
+
await db.update("users", "age", 26, "name", "Ali")
|
|
110
|
+
|
|
111
|
+
await db.delete("users", "name", "Ali")
|
|
112
|
+
|
|
113
|
+
await db.close_pool()
|
|
114
|
+
|
|
115
|
+
asyncio.run(main())
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
# ORM foydalanish
|
|
121
|
+
|
|
122
|
+
PostgresDB3 oddiy ORM tizimini ham taqdim etadi.
|
|
123
|
+
|
|
124
|
+
## Sync ORM
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from postgresdb3 import PostgresDB
|
|
128
|
+
from postgresdb3.orm import Model
|
|
129
|
+
from postgresdb3.orm.fields import Serial, String, Integer
|
|
130
|
+
|
|
131
|
+
db = PostgresDB(
|
|
132
|
+
database="mydb",
|
|
133
|
+
user="postgres",
|
|
134
|
+
password="mypassword"
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
class User(Model):
|
|
138
|
+
db = db
|
|
139
|
+
table = "users"
|
|
140
|
+
|
|
141
|
+
id = Serial(primary_key=True)
|
|
142
|
+
name = String()
|
|
143
|
+
age = Integer()
|
|
144
|
+
|
|
145
|
+
User.create_table()
|
|
146
|
+
|
|
147
|
+
# create
|
|
148
|
+
user = User.create(name="Ali", age=20)
|
|
149
|
+
|
|
150
|
+
# all
|
|
151
|
+
users = User.all()
|
|
152
|
+
|
|
153
|
+
# find
|
|
154
|
+
user = User.find(1)
|
|
155
|
+
|
|
156
|
+
# filter
|
|
157
|
+
users = User.filter(age__gt=18).all()
|
|
158
|
+
|
|
159
|
+
# get
|
|
160
|
+
user = User.get(id=1)
|
|
161
|
+
|
|
162
|
+
# exclude
|
|
163
|
+
users = User.exclude(name="Ali").all()
|
|
164
|
+
|
|
165
|
+
# update
|
|
166
|
+
user.update(name="Valijon")
|
|
167
|
+
|
|
168
|
+
# delete
|
|
169
|
+
user.delete()
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Async ORM
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from postgresdb3 import AsyncPostgresDB
|
|
178
|
+
from postgresdb3.orm import AsyncModel
|
|
179
|
+
from postgresdb3.orm.fields import Serial, String, Integer
|
|
180
|
+
|
|
181
|
+
db = AsyncPostgresDB(
|
|
182
|
+
database="mydb",
|
|
183
|
+
user="postgres",
|
|
184
|
+
password="mypassword"
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
class User(AsyncModel):
|
|
188
|
+
db = db
|
|
189
|
+
table = "users"
|
|
190
|
+
|
|
191
|
+
id = Serial(primary_key=True)
|
|
192
|
+
name = String()
|
|
193
|
+
age = Integer()
|
|
194
|
+
|
|
195
|
+
await User.create_table()
|
|
196
|
+
|
|
197
|
+
user = await User.create(name="Ali", age=20)
|
|
198
|
+
|
|
199
|
+
users = await User.all()
|
|
200
|
+
|
|
201
|
+
user = await User.find(1)
|
|
202
|
+
|
|
203
|
+
users = await User.filter(age__gt=18).all()
|
|
204
|
+
|
|
205
|
+
user = await User.get(id=1)
|
|
206
|
+
|
|
207
|
+
users = await User.exclude(name="Ali").all()
|
|
208
|
+
|
|
209
|
+
await user.update(name="Valijon")
|
|
210
|
+
|
|
211
|
+
await user.delete()
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
# Filter operatorlari
|
|
217
|
+
|
|
218
|
+
| Operator | Tavsif |
|
|
219
|
+
| -------- | ---------------- |
|
|
220
|
+
| eq | teng |
|
|
221
|
+
| ne | teng emas |
|
|
222
|
+
| gt | katta |
|
|
223
|
+
| gte | katta yoki teng |
|
|
224
|
+
| lt | kichik |
|
|
225
|
+
| lte | kichik yoki teng |
|
|
226
|
+
| like | LIKE |
|
|
227
|
+
| ilike | ILIKE |
|
|
228
|
+
| in | IN |
|
|
229
|
+
| not_in | NOT IN |
|
|
230
|
+
| isnull | NULL tekshirish |
|
|
231
|
+
|
|
232
|
+
Misol:
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
User.filter(age__gt=18)
|
|
236
|
+
User.filter(name__ilike="%ali%")
|
|
237
|
+
User.filter(id__in=[1,2,3])
|
|
238
|
+
User.filter(name__ne="Ali")
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
# Raw SQL
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
result = db.raw(
|
|
247
|
+
"SELECT name FROM users WHERE age > %s",
|
|
248
|
+
[18],
|
|
249
|
+
fetchall=True
|
|
250
|
+
)
|
|
251
|
+
```
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# PostgresDB3
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
**PostgresDB3** — PostgreSQL bilan ishlash uchun oddiy, qulay va yengil Python wrapper.
|
|
8
|
+
|
|
9
|
+
Kutubxona quyidagilarni qo‘llab-quvvatlaydi:
|
|
10
|
+
|
|
11
|
+
- Sync va Async ishlash
|
|
12
|
+
- CRUD operatsiyalari
|
|
13
|
+
- Query builder (`where`, `join`, `group_by`, `order_by`, `limit`, `offset`)
|
|
14
|
+
- Kengaytirilgan filterlar (`gt`, `lt`, `like`, `ilike`, `in`, `isnull`)
|
|
15
|
+
- Raw SQL bajarish
|
|
16
|
+
- Sodda ORM tizimi
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
# O‘rnatish
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install postgresdb3
|
|
24
|
+
````
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
# Sync foydalanish
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from postgresdb3 import PostgresDB
|
|
32
|
+
|
|
33
|
+
db = PostgresDB(
|
|
34
|
+
database="mydb",
|
|
35
|
+
user="postgres",
|
|
36
|
+
password="mypassword"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# Jadval yaratish
|
|
40
|
+
db.create("users", "id SERIAL PRIMARY KEY, name VARCHAR(100), age INT")
|
|
41
|
+
|
|
42
|
+
# Qator qo‘shish
|
|
43
|
+
db.insert("users", "name, age", ("Ali", 25))
|
|
44
|
+
|
|
45
|
+
# Barcha ma'lumotlar
|
|
46
|
+
users = db.select("users")
|
|
47
|
+
|
|
48
|
+
# Shart bilan qidirish
|
|
49
|
+
adults = db.select("users", where={"age__gt": 18})
|
|
50
|
+
|
|
51
|
+
# Tartiblash
|
|
52
|
+
users = db.select("users", order_by="age DESC")
|
|
53
|
+
|
|
54
|
+
# Yangilash
|
|
55
|
+
db.update("users", "age", 26, "name", "Ali")
|
|
56
|
+
|
|
57
|
+
# O‘chirish
|
|
58
|
+
db.delete("users", "name", "Ali")
|
|
59
|
+
|
|
60
|
+
db.close()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
# Async foydalanish
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
import asyncio
|
|
69
|
+
from postgresdb3 import AsyncPostgresDB
|
|
70
|
+
|
|
71
|
+
async def main():
|
|
72
|
+
|
|
73
|
+
db = AsyncPostgresDB(
|
|
74
|
+
database="mydb",
|
|
75
|
+
user="postgres",
|
|
76
|
+
password="mypassword"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
await db.create("users", "id SERIAL PRIMARY KEY, name VARCHAR(100), age INT")
|
|
80
|
+
|
|
81
|
+
await db.insert("users", "name, age", ["Ali", 25])
|
|
82
|
+
|
|
83
|
+
users = await db.select("users")
|
|
84
|
+
|
|
85
|
+
adults = await db.select("users", where={"age__gt": 18})
|
|
86
|
+
|
|
87
|
+
await db.update("users", "age", 26, "name", "Ali")
|
|
88
|
+
|
|
89
|
+
await db.delete("users", "name", "Ali")
|
|
90
|
+
|
|
91
|
+
await db.close_pool()
|
|
92
|
+
|
|
93
|
+
asyncio.run(main())
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
# ORM foydalanish
|
|
99
|
+
|
|
100
|
+
PostgresDB3 oddiy ORM tizimini ham taqdim etadi.
|
|
101
|
+
|
|
102
|
+
## Sync ORM
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from postgresdb3 import PostgresDB
|
|
106
|
+
from postgresdb3.orm import Model
|
|
107
|
+
from postgresdb3.orm.fields import Serial, String, Integer
|
|
108
|
+
|
|
109
|
+
db = PostgresDB(
|
|
110
|
+
database="mydb",
|
|
111
|
+
user="postgres",
|
|
112
|
+
password="mypassword"
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
class User(Model):
|
|
116
|
+
db = db
|
|
117
|
+
table = "users"
|
|
118
|
+
|
|
119
|
+
id = Serial(primary_key=True)
|
|
120
|
+
name = String()
|
|
121
|
+
age = Integer()
|
|
122
|
+
|
|
123
|
+
User.create_table()
|
|
124
|
+
|
|
125
|
+
# create
|
|
126
|
+
user = User.create(name="Ali", age=20)
|
|
127
|
+
|
|
128
|
+
# all
|
|
129
|
+
users = User.all()
|
|
130
|
+
|
|
131
|
+
# find
|
|
132
|
+
user = User.find(1)
|
|
133
|
+
|
|
134
|
+
# filter
|
|
135
|
+
users = User.filter(age__gt=18).all()
|
|
136
|
+
|
|
137
|
+
# get
|
|
138
|
+
user = User.get(id=1)
|
|
139
|
+
|
|
140
|
+
# exclude
|
|
141
|
+
users = User.exclude(name="Ali").all()
|
|
142
|
+
|
|
143
|
+
# update
|
|
144
|
+
user.update(name="Valijon")
|
|
145
|
+
|
|
146
|
+
# delete
|
|
147
|
+
user.delete()
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Async ORM
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from postgresdb3 import AsyncPostgresDB
|
|
156
|
+
from postgresdb3.orm import AsyncModel
|
|
157
|
+
from postgresdb3.orm.fields import Serial, String, Integer
|
|
158
|
+
|
|
159
|
+
db = AsyncPostgresDB(
|
|
160
|
+
database="mydb",
|
|
161
|
+
user="postgres",
|
|
162
|
+
password="mypassword"
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
class User(AsyncModel):
|
|
166
|
+
db = db
|
|
167
|
+
table = "users"
|
|
168
|
+
|
|
169
|
+
id = Serial(primary_key=True)
|
|
170
|
+
name = String()
|
|
171
|
+
age = Integer()
|
|
172
|
+
|
|
173
|
+
await User.create_table()
|
|
174
|
+
|
|
175
|
+
user = await User.create(name="Ali", age=20)
|
|
176
|
+
|
|
177
|
+
users = await User.all()
|
|
178
|
+
|
|
179
|
+
user = await User.find(1)
|
|
180
|
+
|
|
181
|
+
users = await User.filter(age__gt=18).all()
|
|
182
|
+
|
|
183
|
+
user = await User.get(id=1)
|
|
184
|
+
|
|
185
|
+
users = await User.exclude(name="Ali").all()
|
|
186
|
+
|
|
187
|
+
await user.update(name="Valijon")
|
|
188
|
+
|
|
189
|
+
await user.delete()
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
# Filter operatorlari
|
|
195
|
+
|
|
196
|
+
| Operator | Tavsif |
|
|
197
|
+
| -------- | ---------------- |
|
|
198
|
+
| eq | teng |
|
|
199
|
+
| ne | teng emas |
|
|
200
|
+
| gt | katta |
|
|
201
|
+
| gte | katta yoki teng |
|
|
202
|
+
| lt | kichik |
|
|
203
|
+
| lte | kichik yoki teng |
|
|
204
|
+
| like | LIKE |
|
|
205
|
+
| ilike | ILIKE |
|
|
206
|
+
| in | IN |
|
|
207
|
+
| not_in | NOT IN |
|
|
208
|
+
| isnull | NULL tekshirish |
|
|
209
|
+
|
|
210
|
+
Misol:
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
User.filter(age__gt=18)
|
|
214
|
+
User.filter(name__ilike="%ali%")
|
|
215
|
+
User.filter(id__in=[1,2,3])
|
|
216
|
+
User.filter(name__ne="Ali")
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
# Raw SQL
|
|
222
|
+
|
|
223
|
+
```python
|
|
224
|
+
result = db.raw(
|
|
225
|
+
"SELECT name FROM users WHERE age > %s",
|
|
226
|
+
[18],
|
|
227
|
+
fetchall=True
|
|
228
|
+
)
|
|
229
|
+
```
|
|
@@ -28,6 +28,54 @@ class Model(BaseModel, metaclass=ModelMeta):
|
|
|
28
28
|
qs = qs.filter(**kwargs)
|
|
29
29
|
return qs.first()
|
|
30
30
|
|
|
31
|
+
@classmethod
|
|
32
|
+
def get(cls, **kwargs):
|
|
33
|
+
results = cls.filter(**kwargs).limit(2).all()
|
|
34
|
+
|
|
35
|
+
if not results:
|
|
36
|
+
raise ValueError("Obyekt topilmadi")
|
|
37
|
+
|
|
38
|
+
if len(results) > 1:
|
|
39
|
+
raise ValueError("Bir nechta obyekt topildi")
|
|
40
|
+
|
|
41
|
+
return results[0]
|
|
42
|
+
|
|
43
|
+
@classmethod
|
|
44
|
+
def order_by(cls, value):
|
|
45
|
+
return cls.query().order_by(value)
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def limit(cls, value):
|
|
49
|
+
return cls.query().limit(value)
|
|
50
|
+
|
|
51
|
+
@classmethod
|
|
52
|
+
def offset(cls, value):
|
|
53
|
+
return cls.query().offset(value)
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def columns(cls, value):
|
|
57
|
+
return cls.query().columns(value)
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def join(cls, value):
|
|
61
|
+
return cls.query().join(value)
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def group_by(cls, value):
|
|
65
|
+
return cls.query().group_by(value)
|
|
66
|
+
|
|
67
|
+
@classmethod
|
|
68
|
+
def exclude(cls, **kwargs):
|
|
69
|
+
return cls.query().exclude(**kwargs)
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def count(cls):
|
|
73
|
+
return cls.query().count()
|
|
74
|
+
|
|
75
|
+
@classmethod
|
|
76
|
+
def exists(cls):
|
|
77
|
+
return cls.query().exists()
|
|
78
|
+
|
|
31
79
|
@classmethod
|
|
32
80
|
def create(cls, **kwargs):
|
|
33
81
|
cls._check_setup()
|
|
@@ -165,6 +213,54 @@ class AsyncModel(BaseModel, metaclass=ModelMeta):
|
|
|
165
213
|
qs = qs.filter(**kwargs)
|
|
166
214
|
return await qs.first()
|
|
167
215
|
|
|
216
|
+
@classmethod
|
|
217
|
+
async def get(cls, **kwargs):
|
|
218
|
+
results = await cls.filter(**kwargs).limit(2).all()
|
|
219
|
+
|
|
220
|
+
if not results:
|
|
221
|
+
raise ValueError("Obyekt topilmadi")
|
|
222
|
+
|
|
223
|
+
if len(results) > 1:
|
|
224
|
+
raise ValueError("Bir nechta obyekt topildi")
|
|
225
|
+
|
|
226
|
+
return results[0]
|
|
227
|
+
|
|
228
|
+
@classmethod
|
|
229
|
+
def order_by(cls, value):
|
|
230
|
+
return cls.query().order_by(value)
|
|
231
|
+
|
|
232
|
+
@classmethod
|
|
233
|
+
def limit(cls, value):
|
|
234
|
+
return cls.query().limit(value)
|
|
235
|
+
|
|
236
|
+
@classmethod
|
|
237
|
+
def offset(cls, value):
|
|
238
|
+
return cls.query().offset(value)
|
|
239
|
+
|
|
240
|
+
@classmethod
|
|
241
|
+
def columns(cls, value):
|
|
242
|
+
return cls.query().columns(value)
|
|
243
|
+
|
|
244
|
+
@classmethod
|
|
245
|
+
def join(cls, value):
|
|
246
|
+
return cls.query().join(value)
|
|
247
|
+
|
|
248
|
+
@classmethod
|
|
249
|
+
def group_by(cls, value):
|
|
250
|
+
return cls.query().group_by(value)
|
|
251
|
+
|
|
252
|
+
@classmethod
|
|
253
|
+
def exclude(cls, **kwargs):
|
|
254
|
+
return cls.query().exclude(**kwargs)
|
|
255
|
+
|
|
256
|
+
@classmethod
|
|
257
|
+
def count(cls):
|
|
258
|
+
return cls.query().count()
|
|
259
|
+
|
|
260
|
+
@classmethod
|
|
261
|
+
def exists(cls):
|
|
262
|
+
return cls.query().exists()
|
|
263
|
+
|
|
168
264
|
@classmethod
|
|
169
265
|
async def create(cls, **kwargs):
|
|
170
266
|
cls._check_setup()
|