postgresdb3 0.1.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.1.0/PKG-INFO +126 -0
- postgresdb3-0.1.0/README.md +105 -0
- postgresdb3-0.1.0/postgresdb3/__init__.py +1 -0
- postgresdb3-0.1.0/postgresdb3/core.py +149 -0
- postgresdb3-0.1.0/postgresdb3.egg-info/PKG-INFO +126 -0
- postgresdb3-0.1.0/postgresdb3.egg-info/SOURCES.txt +10 -0
- postgresdb3-0.1.0/postgresdb3.egg-info/dependency_links.txt +1 -0
- postgresdb3-0.1.0/postgresdb3.egg-info/requires.txt +1 -0
- postgresdb3-0.1.0/postgresdb3.egg-info/top_level.txt +1 -0
- postgresdb3-0.1.0/pyproject.toml +3 -0
- postgresdb3-0.1.0/setup.cfg +4 -0
- postgresdb3-0.1.0/setup.py +24 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: postgresdb3
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python uchun oddiy PostgreSQL wrapper
|
|
5
|
+
Home-page: https://github.com/AlijonovUz/PostgresDB
|
|
6
|
+
Author: Abdulbosit Alijonov
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: psycopg2>=2.9
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: description
|
|
16
|
+
Dynamic: description-content-type
|
|
17
|
+
Dynamic: home-page
|
|
18
|
+
Dynamic: requires-dist
|
|
19
|
+
Dynamic: requires-python
|
|
20
|
+
Dynamic: summary
|
|
21
|
+
|
|
22
|
+
# PostgresDB
|
|
23
|
+
|
|
24
|
+
Oddiy va qulay Python wrapper PostgreSQL bazasi bilan ishlash uchun.
|
|
25
|
+
|
|
26
|
+
## O'rnatish
|
|
27
|
+
|
|
28
|
+
``` bash
|
|
29
|
+
pip install postgresdb3
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Foydalanish
|
|
33
|
+
|
|
34
|
+
``` python
|
|
35
|
+
from postgresdb3 import PostgresDB
|
|
36
|
+
|
|
37
|
+
# Bazaga ulanish
|
|
38
|
+
db = PostgresDB(
|
|
39
|
+
database="mydb",
|
|
40
|
+
user="postgres",
|
|
41
|
+
password="mypassword",
|
|
42
|
+
host="localhost",
|
|
43
|
+
port=5432
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Jadval yaratish
|
|
47
|
+
db.create("users", "id SERIAL PRIMARY KEY, name VARCHAR(100), age INT")
|
|
48
|
+
|
|
49
|
+
# Ma'lumot qo'shish
|
|
50
|
+
db.insert("users", "name, age", ("Ali", 25))
|
|
51
|
+
|
|
52
|
+
# Ma'lumotlarni olish
|
|
53
|
+
users = db.select("users")
|
|
54
|
+
print(users)
|
|
55
|
+
|
|
56
|
+
# Bitta qatorni olish
|
|
57
|
+
user = db.select("users", where=("name=%s", ["Ali"]), fetchone=True)
|
|
58
|
+
print(user)
|
|
59
|
+
|
|
60
|
+
# Shart bilan ma'lumot olish
|
|
61
|
+
adults = db.select("users", where=("age > %s", [18]))
|
|
62
|
+
print(adults)
|
|
63
|
+
|
|
64
|
+
# Bir nechta shart
|
|
65
|
+
specific_users = db.select("users", where=("age > %s AND name = %s", [18, "Ali"]))
|
|
66
|
+
print(specific_users)
|
|
67
|
+
|
|
68
|
+
# Jadvaldagi ma'lumotni yangilash
|
|
69
|
+
db.update("users", "age", 26, "name", "Ali")
|
|
70
|
+
|
|
71
|
+
# Ma'lumotni o'chirish
|
|
72
|
+
db.delete("users", "name", "Ali")
|
|
73
|
+
|
|
74
|
+
# Jadvalni o'chirish
|
|
75
|
+
db.drop("users")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Parametrlar va metodlar
|
|
79
|
+
|
|
80
|
+
**PostgresDB(database, user, password, host="localhost", port=5432)**
|
|
81
|
+
--- bazaga ulanish.
|
|
82
|
+
|
|
83
|
+
**create(table, columns)** --- jadval yaratish, `columns` SQL
|
|
84
|
+
sintaksisida.
|
|
85
|
+
|
|
86
|
+
**drop(table)** --- jadvalni o'chirish.
|
|
87
|
+
|
|
88
|
+
**insert(table, columns, values)** --- ma'lumot qo'shish.
|
|
89
|
+
|
|
90
|
+
**select(table, columns="\*", where=None, join=None, group_by=None,
|
|
91
|
+
order_by=None, limit=None, fetchone=False)** --- ma'lumotlarni olish.
|
|
92
|
+
|
|
93
|
+
### where misollar:
|
|
94
|
+
|
|
95
|
+
``` python
|
|
96
|
+
db.select("users", where=("age > %s", [18]))
|
|
97
|
+
db.select("users", where=("age > %s AND name = %s", [18, "Ali"]))
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### join misol:
|
|
101
|
+
|
|
102
|
+
``` python
|
|
103
|
+
db.select("orders", join=[("INNER JOIN", "users", "users.id = orders.user_id")])
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**update(table, set_column, set_value, where_column, where_value)** ---
|
|
107
|
+
ma'lumotni yangilash.
|
|
108
|
+
|
|
109
|
+
**delete(table, where_column, where_value)** --- ma'lumotni o'chirish.
|
|
110
|
+
|
|
111
|
+
**manager(sql, params=None, commit=False, fetchall=False,
|
|
112
|
+
fetchone=False)** --- barcha SQL amallarni bajaruvchi yagona metod.
|
|
113
|
+
|
|
114
|
+
## Qo‘shimcha
|
|
115
|
+
|
|
116
|
+
`%s` bilan parametrizatsiya qilish xavfsiz va SQL injection'dan himoya qiladi.
|
|
117
|
+
|
|
118
|
+
`where` va `join` `list` yoki `tuple` yordamida murakkab so‘rovlar yozish mumkin.
|
|
119
|
+
|
|
120
|
+
`limit` va `order_by` parametrlaridan foydalanib ma'lumotlarni tartiblash va cheklash oson.
|
|
121
|
+
|
|
122
|
+
`commit=True` bo‘lgan amallar darhol bazaga yoziladi, select() esa hech qachon o‘zgartirish kiritmaydi.
|
|
123
|
+
|
|
124
|
+
`manager()` — barcha SQL buyruqlarini bajaruvchi yagona metod bo‘lib, kerak bo‘lganda to‘g‘ridan‑to‘g‘ri SQL yozish imkonini beradi.
|
|
125
|
+
|
|
126
|
+
PostgreSQL bilan ishlash uchun `psycopg2` kutubxonasi talab qilinadi.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# PostgresDB
|
|
2
|
+
|
|
3
|
+
Oddiy va qulay Python wrapper PostgreSQL bazasi bilan ishlash uchun.
|
|
4
|
+
|
|
5
|
+
## O'rnatish
|
|
6
|
+
|
|
7
|
+
``` bash
|
|
8
|
+
pip install postgresdb3
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Foydalanish
|
|
12
|
+
|
|
13
|
+
``` python
|
|
14
|
+
from postgresdb3 import PostgresDB
|
|
15
|
+
|
|
16
|
+
# Bazaga ulanish
|
|
17
|
+
db = PostgresDB(
|
|
18
|
+
database="mydb",
|
|
19
|
+
user="postgres",
|
|
20
|
+
password="mypassword",
|
|
21
|
+
host="localhost",
|
|
22
|
+
port=5432
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
# Jadval yaratish
|
|
26
|
+
db.create("users", "id SERIAL PRIMARY KEY, name VARCHAR(100), age INT")
|
|
27
|
+
|
|
28
|
+
# Ma'lumot qo'shish
|
|
29
|
+
db.insert("users", "name, age", ("Ali", 25))
|
|
30
|
+
|
|
31
|
+
# Ma'lumotlarni olish
|
|
32
|
+
users = db.select("users")
|
|
33
|
+
print(users)
|
|
34
|
+
|
|
35
|
+
# Bitta qatorni olish
|
|
36
|
+
user = db.select("users", where=("name=%s", ["Ali"]), fetchone=True)
|
|
37
|
+
print(user)
|
|
38
|
+
|
|
39
|
+
# Shart bilan ma'lumot olish
|
|
40
|
+
adults = db.select("users", where=("age > %s", [18]))
|
|
41
|
+
print(adults)
|
|
42
|
+
|
|
43
|
+
# Bir nechta shart
|
|
44
|
+
specific_users = db.select("users", where=("age > %s AND name = %s", [18, "Ali"]))
|
|
45
|
+
print(specific_users)
|
|
46
|
+
|
|
47
|
+
# Jadvaldagi ma'lumotni yangilash
|
|
48
|
+
db.update("users", "age", 26, "name", "Ali")
|
|
49
|
+
|
|
50
|
+
# Ma'lumotni o'chirish
|
|
51
|
+
db.delete("users", "name", "Ali")
|
|
52
|
+
|
|
53
|
+
# Jadvalni o'chirish
|
|
54
|
+
db.drop("users")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Parametrlar va metodlar
|
|
58
|
+
|
|
59
|
+
**PostgresDB(database, user, password, host="localhost", port=5432)**
|
|
60
|
+
--- bazaga ulanish.
|
|
61
|
+
|
|
62
|
+
**create(table, columns)** --- jadval yaratish, `columns` SQL
|
|
63
|
+
sintaksisida.
|
|
64
|
+
|
|
65
|
+
**drop(table)** --- jadvalni o'chirish.
|
|
66
|
+
|
|
67
|
+
**insert(table, columns, values)** --- ma'lumot qo'shish.
|
|
68
|
+
|
|
69
|
+
**select(table, columns="\*", where=None, join=None, group_by=None,
|
|
70
|
+
order_by=None, limit=None, fetchone=False)** --- ma'lumotlarni olish.
|
|
71
|
+
|
|
72
|
+
### where misollar:
|
|
73
|
+
|
|
74
|
+
``` python
|
|
75
|
+
db.select("users", where=("age > %s", [18]))
|
|
76
|
+
db.select("users", where=("age > %s AND name = %s", [18, "Ali"]))
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### join misol:
|
|
80
|
+
|
|
81
|
+
``` python
|
|
82
|
+
db.select("orders", join=[("INNER JOIN", "users", "users.id = orders.user_id")])
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**update(table, set_column, set_value, where_column, where_value)** ---
|
|
86
|
+
ma'lumotni yangilash.
|
|
87
|
+
|
|
88
|
+
**delete(table, where_column, where_value)** --- ma'lumotni o'chirish.
|
|
89
|
+
|
|
90
|
+
**manager(sql, params=None, commit=False, fetchall=False,
|
|
91
|
+
fetchone=False)** --- barcha SQL amallarni bajaruvchi yagona metod.
|
|
92
|
+
|
|
93
|
+
## Qo‘shimcha
|
|
94
|
+
|
|
95
|
+
`%s` bilan parametrizatsiya qilish xavfsiz va SQL injection'dan himoya qiladi.
|
|
96
|
+
|
|
97
|
+
`where` va `join` `list` yoki `tuple` yordamida murakkab so‘rovlar yozish mumkin.
|
|
98
|
+
|
|
99
|
+
`limit` va `order_by` parametrlaridan foydalanib ma'lumotlarni tartiblash va cheklash oson.
|
|
100
|
+
|
|
101
|
+
`commit=True` bo‘lgan amallar darhol bazaga yoziladi, select() esa hech qachon o‘zgartirish kiritmaydi.
|
|
102
|
+
|
|
103
|
+
`manager()` — barcha SQL buyruqlarini bajaruvchi yagona metod bo‘lib, kerak bo‘lganda to‘g‘ridan‑to‘g‘ri SQL yozish imkonini beradi.
|
|
104
|
+
|
|
105
|
+
PostgreSQL bilan ishlash uchun `psycopg2` kutubxonasi talab qilinadi.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .core import PostgresDB
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import psycopg2
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class PostgresDB:
|
|
5
|
+
|
|
6
|
+
def __init__(self, database, user, password, host="localhost", port=5432):
|
|
7
|
+
"""
|
|
8
|
+
PostgreSQL bazasiga ulanish.
|
|
9
|
+
|
|
10
|
+
Parametrlar:
|
|
11
|
+
database (str): Bazaning nomi
|
|
12
|
+
user (str): Foydalanuvchi
|
|
13
|
+
password (str): Parol
|
|
14
|
+
host (str): Server manzili (standart = localhost)
|
|
15
|
+
port (int): Port (standart = 5432)
|
|
16
|
+
"""
|
|
17
|
+
self.connect = psycopg2.connect(
|
|
18
|
+
database=database, user=user, password=password, host=host, port=port
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
def manager(
|
|
22
|
+
self,
|
|
23
|
+
sql=None,
|
|
24
|
+
params=None,
|
|
25
|
+
*,
|
|
26
|
+
commit=False,
|
|
27
|
+
fetchall=False,
|
|
28
|
+
fetchone=False,
|
|
29
|
+
):
|
|
30
|
+
"""
|
|
31
|
+
Barcha SQL amallarni boshqaruvchi yagona metod.
|
|
32
|
+
|
|
33
|
+
Parametrlar:
|
|
34
|
+
sql (str | None): Bajariladigan SQL so'rov.
|
|
35
|
+
params (tuple | list | None): Parametrlar.
|
|
36
|
+
commit (bool): Tranzaksiyani tasdiqlash.
|
|
37
|
+
fetchall (bool): Barcha natijalarni olish.
|
|
38
|
+
fetchone (bool): Bitta natija olish.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
with self.connect as connect:
|
|
42
|
+
result = None
|
|
43
|
+
with connect.cursor() as cursor:
|
|
44
|
+
cursor.execute(sql, params)
|
|
45
|
+
|
|
46
|
+
if commit:
|
|
47
|
+
connect.commit()
|
|
48
|
+
elif fetchall:
|
|
49
|
+
result = cursor.fetchall()
|
|
50
|
+
elif fetchone:
|
|
51
|
+
result = cursor.fetchone()
|
|
52
|
+
|
|
53
|
+
return result
|
|
54
|
+
|
|
55
|
+
def create(self, table, columns):
|
|
56
|
+
"""
|
|
57
|
+
table: str - jadval nomi
|
|
58
|
+
columns: str - ustunlar va turlari, misol: "id SERIAL PRIMARY KEY, name VARCHAR(100)"
|
|
59
|
+
"""
|
|
60
|
+
sql = f"CREATE TABLE IF NOT EXISTS {table} ({columns})"
|
|
61
|
+
self.manager(sql, commit=True)
|
|
62
|
+
|
|
63
|
+
def drop(self, table):
|
|
64
|
+
"""
|
|
65
|
+
table: str - o'chiriladigan jadval nomi
|
|
66
|
+
"""
|
|
67
|
+
sql = f"DROP TABLE IF EXISTS {table} CASCADE"
|
|
68
|
+
self.manager(sql, commit=True)
|
|
69
|
+
|
|
70
|
+
def select(
|
|
71
|
+
self,
|
|
72
|
+
table,
|
|
73
|
+
columns="*",
|
|
74
|
+
where=None,
|
|
75
|
+
join=None,
|
|
76
|
+
group_by=None,
|
|
77
|
+
order_by=None,
|
|
78
|
+
limit=None,
|
|
79
|
+
fetchone=False,
|
|
80
|
+
):
|
|
81
|
+
"""
|
|
82
|
+
table: str — asosiy jadval
|
|
83
|
+
columns: str — tanlanadigan ustunlar ("id, name")
|
|
84
|
+
where: tuple | None — ("age > %s", [18])
|
|
85
|
+
join: list | None — [("INNER JOIN", "orders", "users.id = orders.user_id")]
|
|
86
|
+
group_by: str | None — "age"
|
|
87
|
+
order_by: str | None — "age DESC"
|
|
88
|
+
limit: int | None
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
sql = f"SELECT {columns} FROM {table}"
|
|
92
|
+
params = []
|
|
93
|
+
|
|
94
|
+
if join:
|
|
95
|
+
for join_type, join_table, on_condition in join:
|
|
96
|
+
sql += f" {join_type} {join_table} ON {on_condition}"
|
|
97
|
+
|
|
98
|
+
if where:
|
|
99
|
+
condition, values = where
|
|
100
|
+
sql += f" WHERE {condition}"
|
|
101
|
+
params.extend(values)
|
|
102
|
+
|
|
103
|
+
if group_by:
|
|
104
|
+
sql += f" GROUP BY {group_by}"
|
|
105
|
+
|
|
106
|
+
if order_by:
|
|
107
|
+
sql += f" ORDER BY {order_by}"
|
|
108
|
+
|
|
109
|
+
if limit:
|
|
110
|
+
sql += f" LIMIT %s"
|
|
111
|
+
params.append(limit)
|
|
112
|
+
|
|
113
|
+
if fetchone:
|
|
114
|
+
return self.manager(sql, params, fetchone=True)
|
|
115
|
+
return self.manager(sql, params, fetchall=True)
|
|
116
|
+
|
|
117
|
+
def insert(self, table, columns, values):
|
|
118
|
+
"""
|
|
119
|
+
table: str - jadval nomi
|
|
120
|
+
columns: str - ustunlar, misol: "name, email, age"
|
|
121
|
+
values: tuple yoki list - ustun qiymatlari, misol: ("Ali", "ali@mail.com", 25)
|
|
122
|
+
"""
|
|
123
|
+
placeholders = ", ".join(["%s"] * len(values))
|
|
124
|
+
sql = f"INSERT INTO {table} ({columns}) VALUES ({placeholders})"
|
|
125
|
+
self.manager(sql, values, commit=True)
|
|
126
|
+
|
|
127
|
+
def update(self, table, set_column, set_value, where_column, where_value):
|
|
128
|
+
"""
|
|
129
|
+
Jadvaldagi ma'lumotni yangilash.
|
|
130
|
+
|
|
131
|
+
Parametrlar:
|
|
132
|
+
table (str): Jadval nomi.
|
|
133
|
+
set_column (str): O'zgartiriladigan ustun.
|
|
134
|
+
set_value (Any): Yangi qiymat.
|
|
135
|
+
where_column (str): Filtrlash ustuni.
|
|
136
|
+
where_value (Any): Qaysi qatorda o'zgarish bo'lishi.
|
|
137
|
+
|
|
138
|
+
Izoh:
|
|
139
|
+
Faqat WHERE shartiga mos kelgan qatorlar yangilanadi.
|
|
140
|
+
"""
|
|
141
|
+
sql = f"UPDATE {table} SET {set_column} = %s WHERE {where_column} = %s"
|
|
142
|
+
return self.manager(sql, (set_value, where_value), commit=True)
|
|
143
|
+
|
|
144
|
+
def delete(self, table, where_column, where_value):
|
|
145
|
+
"""
|
|
146
|
+
Jadvaldan qator o'chirish.
|
|
147
|
+
"""
|
|
148
|
+
sql = f"DELETE FROM {table} WHERE {where_column} = %s"
|
|
149
|
+
return self.manager(sql, (where_value,), commit=True)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: postgresdb3
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python uchun oddiy PostgreSQL wrapper
|
|
5
|
+
Home-page: https://github.com/AlijonovUz/PostgresDB
|
|
6
|
+
Author: Abdulbosit Alijonov
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.7
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: psycopg2>=2.9
|
|
13
|
+
Dynamic: author
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: description
|
|
16
|
+
Dynamic: description-content-type
|
|
17
|
+
Dynamic: home-page
|
|
18
|
+
Dynamic: requires-dist
|
|
19
|
+
Dynamic: requires-python
|
|
20
|
+
Dynamic: summary
|
|
21
|
+
|
|
22
|
+
# PostgresDB
|
|
23
|
+
|
|
24
|
+
Oddiy va qulay Python wrapper PostgreSQL bazasi bilan ishlash uchun.
|
|
25
|
+
|
|
26
|
+
## O'rnatish
|
|
27
|
+
|
|
28
|
+
``` bash
|
|
29
|
+
pip install postgresdb3
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Foydalanish
|
|
33
|
+
|
|
34
|
+
``` python
|
|
35
|
+
from postgresdb3 import PostgresDB
|
|
36
|
+
|
|
37
|
+
# Bazaga ulanish
|
|
38
|
+
db = PostgresDB(
|
|
39
|
+
database="mydb",
|
|
40
|
+
user="postgres",
|
|
41
|
+
password="mypassword",
|
|
42
|
+
host="localhost",
|
|
43
|
+
port=5432
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# Jadval yaratish
|
|
47
|
+
db.create("users", "id SERIAL PRIMARY KEY, name VARCHAR(100), age INT")
|
|
48
|
+
|
|
49
|
+
# Ma'lumot qo'shish
|
|
50
|
+
db.insert("users", "name, age", ("Ali", 25))
|
|
51
|
+
|
|
52
|
+
# Ma'lumotlarni olish
|
|
53
|
+
users = db.select("users")
|
|
54
|
+
print(users)
|
|
55
|
+
|
|
56
|
+
# Bitta qatorni olish
|
|
57
|
+
user = db.select("users", where=("name=%s", ["Ali"]), fetchone=True)
|
|
58
|
+
print(user)
|
|
59
|
+
|
|
60
|
+
# Shart bilan ma'lumot olish
|
|
61
|
+
adults = db.select("users", where=("age > %s", [18]))
|
|
62
|
+
print(adults)
|
|
63
|
+
|
|
64
|
+
# Bir nechta shart
|
|
65
|
+
specific_users = db.select("users", where=("age > %s AND name = %s", [18, "Ali"]))
|
|
66
|
+
print(specific_users)
|
|
67
|
+
|
|
68
|
+
# Jadvaldagi ma'lumotni yangilash
|
|
69
|
+
db.update("users", "age", 26, "name", "Ali")
|
|
70
|
+
|
|
71
|
+
# Ma'lumotni o'chirish
|
|
72
|
+
db.delete("users", "name", "Ali")
|
|
73
|
+
|
|
74
|
+
# Jadvalni o'chirish
|
|
75
|
+
db.drop("users")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Parametrlar va metodlar
|
|
79
|
+
|
|
80
|
+
**PostgresDB(database, user, password, host="localhost", port=5432)**
|
|
81
|
+
--- bazaga ulanish.
|
|
82
|
+
|
|
83
|
+
**create(table, columns)** --- jadval yaratish, `columns` SQL
|
|
84
|
+
sintaksisida.
|
|
85
|
+
|
|
86
|
+
**drop(table)** --- jadvalni o'chirish.
|
|
87
|
+
|
|
88
|
+
**insert(table, columns, values)** --- ma'lumot qo'shish.
|
|
89
|
+
|
|
90
|
+
**select(table, columns="\*", where=None, join=None, group_by=None,
|
|
91
|
+
order_by=None, limit=None, fetchone=False)** --- ma'lumotlarni olish.
|
|
92
|
+
|
|
93
|
+
### where misollar:
|
|
94
|
+
|
|
95
|
+
``` python
|
|
96
|
+
db.select("users", where=("age > %s", [18]))
|
|
97
|
+
db.select("users", where=("age > %s AND name = %s", [18, "Ali"]))
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### join misol:
|
|
101
|
+
|
|
102
|
+
``` python
|
|
103
|
+
db.select("orders", join=[("INNER JOIN", "users", "users.id = orders.user_id")])
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**update(table, set_column, set_value, where_column, where_value)** ---
|
|
107
|
+
ma'lumotni yangilash.
|
|
108
|
+
|
|
109
|
+
**delete(table, where_column, where_value)** --- ma'lumotni o'chirish.
|
|
110
|
+
|
|
111
|
+
**manager(sql, params=None, commit=False, fetchall=False,
|
|
112
|
+
fetchone=False)** --- barcha SQL amallarni bajaruvchi yagona metod.
|
|
113
|
+
|
|
114
|
+
## Qo‘shimcha
|
|
115
|
+
|
|
116
|
+
`%s` bilan parametrizatsiya qilish xavfsiz va SQL injection'dan himoya qiladi.
|
|
117
|
+
|
|
118
|
+
`where` va `join` `list` yoki `tuple` yordamida murakkab so‘rovlar yozish mumkin.
|
|
119
|
+
|
|
120
|
+
`limit` va `order_by` parametrlaridan foydalanib ma'lumotlarni tartiblash va cheklash oson.
|
|
121
|
+
|
|
122
|
+
`commit=True` bo‘lgan amallar darhol bazaga yoziladi, select() esa hech qachon o‘zgartirish kiritmaydi.
|
|
123
|
+
|
|
124
|
+
`manager()` — barcha SQL buyruqlarini bajaruvchi yagona metod bo‘lib, kerak bo‘lganda to‘g‘ridan‑to‘g‘ri SQL yozish imkonini beradi.
|
|
125
|
+
|
|
126
|
+
PostgreSQL bilan ishlash uchun `psycopg2` kutubxonasi talab qilinadi.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
setup.py
|
|
4
|
+
postgresdb3/__init__.py
|
|
5
|
+
postgresdb3/core.py
|
|
6
|
+
postgresdb3.egg-info/PKG-INFO
|
|
7
|
+
postgresdb3.egg-info/SOURCES.txt
|
|
8
|
+
postgresdb3.egg-info/dependency_links.txt
|
|
9
|
+
postgresdb3.egg-info/requires.txt
|
|
10
|
+
postgresdb3.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
psycopg2>=2.9
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
postgresdb3
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
with open("README.md", "r", encoding="utf-8") as f:
|
|
4
|
+
long_description = f.read()
|
|
5
|
+
|
|
6
|
+
setup(
|
|
7
|
+
name="postgresdb3",
|
|
8
|
+
version="0.1.0",
|
|
9
|
+
packages=find_packages(),
|
|
10
|
+
install_requires=[
|
|
11
|
+
"psycopg2>=2.9"
|
|
12
|
+
],
|
|
13
|
+
author="Abdulbosit Alijonov",
|
|
14
|
+
description="Python uchun oddiy PostgreSQL wrapper",
|
|
15
|
+
long_description=long_description,
|
|
16
|
+
long_description_content_type="text/markdown",
|
|
17
|
+
url="https://github.com/AlijonovUz/PostgresDB",
|
|
18
|
+
classifiers=[
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"License :: OSI Approved :: MIT License",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
],
|
|
23
|
+
python_requires='>=3.7',
|
|
24
|
+
)
|