postgresdb3 0.5.0__tar.gz → 0.7.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.7.0/PKG-INFO +251 -0
- postgresdb3-0.7.0/README.md +229 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/core/async_db.py +117 -179
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/core/sync_db.py +115 -227
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/orm/fields/__init__.py +1 -1
- postgresdb3-0.7.0/postgresdb3/orm/fields/foreign.py +31 -0
- postgresdb3-0.7.0/postgresdb3/orm/meta.py +61 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/orm/models.py +141 -19
- postgresdb3-0.7.0/postgresdb3/orm/query.py +473 -0
- postgresdb3-0.7.0/postgresdb3/orm/relations.py +44 -0
- postgresdb3-0.7.0/postgresdb3.egg-info/PKG-INFO +251 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3.egg-info/SOURCES.txt +2 -1
- {postgresdb3-0.5.0 → postgresdb3-0.7.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/fields/relations.py +0 -16
- postgresdb3-0.5.0/postgresdb3/orm/meta.py +0 -41
- 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.7.0}/postgresdb3/__init__.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/core/__init__.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/orm/__init__.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/orm/base.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/orm/fields/base.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/orm/fields/datetime.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/orm/fields/misc.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/orm/fields/numeric.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3/orm/fields/text.py +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3.egg-info/dependency_links.txt +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3.egg-info/requires.txt +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/postgresdb3.egg-info/top_level.txt +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/pyproject.toml +0 -0
- {postgresdb3-0.5.0 → postgresdb3-0.7.0}/setup.cfg +0 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: postgresdb3
|
|
3
|
+
Version: 0.7.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
|
+
```
|