Skip to main content

Python uchun oddiy PostgreSQL wrapper

Project description

PostgresDB

Oddiy va qulay Python wrapper PostgreSQL bazasi bilan ishlash uchun.

O'rnatish

    pip install postgresdb3

Foydalanish

from postgresdb3 import PostgresDB

# Bazaga ulanish
db = PostgresDB(
    database="mydb",
    user="postgres",
    password="mypassword",
    host="localhost",
    port=5432
)

# Jadval yaratish
db.create("users", "id SERIAL PRIMARY KEY, name VARCHAR(100), age INT")

# Ma'lumot qo'shish
db.insert("users", "name, age", ("Ali", 25))

# Ma'lumotlarni olish
users = db.select("users")
print(users)

# Bitta qatorni olish
user = db.select("users", where=("name=%s", ["Ali"]), fetchone=True)
print(user)

# Shart bilan ma'lumot olish
adults = db.select("users", where=("age > %s", [18]))
print(adults)

# Bir nechta shart
specific_users = db.select("users", where=("age > %s AND name = %s", [18, "Ali"]))
print(specific_users)

# Jadvaldagi ma'lumotni yangilash
db.update("users", "age", 26, "name", "Ali")

# Ma'lumotni o'chirish
db.delete("users", "name", "Ali")

# Jadvalni o'chirish
db.drop("users")

Parametrlar va metodlar

PostgresDB(database, user, password, host="localhost", port=5432) --- bazaga ulanish.

create(table, columns) --- jadval yaratish, columns SQL sintaksisida.

drop(table) --- jadvalni o'chirish.

insert(table, columns, values) --- ma'lumot qo'shish.

select(table, columns="*", where=None, join=None, group_by=None, order_by=None, limit=None, fetchone=False) --- ma'lumotlarni olish.

where misollar:

db.select("users", where=("age > %s", [18]))
db.select("users", where=("age > %s AND name = %s", [18, "Ali"]))

join misol:

db.select("orders", join=[("INNER JOIN", "users", "users.id = orders.user_id")])

update(table, set_column, set_value, where_column, where_value) --- ma'lumotni yangilash.

delete(table, where_column, where_value) --- ma'lumotni o'chirish.

manager(sql, params=None, commit=False, fetchall=False, fetchone=False) --- barcha SQL amallarni bajaruvchi yagona metod.

Qo‘shimcha

%s bilan parametrizatsiya qilish xavfsiz va SQL injection'dan himoya qiladi.

where va join list yoki tuple yordamida murakkab so‘rovlar yozish mumkin.

limit va order_by parametrlaridan foydalanib ma'lumotlarni tartiblash va cheklash oson.

commit=True bo‘lgan amallar darhol bazaga yoziladi, select() esa hech qachon o‘zgartirish kiritmaydi.

manager() — barcha SQL buyruqlarini bajaruvchi yagona metod bo‘lib, kerak bo‘lganda to‘g‘ridan‑to‘g‘ri SQL yozish imkonini beradi.

PostgreSQL bilan ishlash uchun psycopg2 kutubxonasi talab qilinadi.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

postgresdb3-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

postgresdb3-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file postgresdb3-0.1.0.tar.gz.

File metadata

  • Download URL: postgresdb3-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for postgresdb3-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c15da6841c3cb58d31be4e215d18e508e9d1f87f39e644d62c0e294fc59b154c
MD5 04f3d9276fb53e6b2c693c46c7c2f312
BLAKE2b-256 5c1ffbafe4d90eb289ebd2e79640c3be04e66ea1cc6e1be5045c7b5f99d99fcc

See more details on using hashes here.

File details

Details for the file postgresdb3-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: postgresdb3-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for postgresdb3-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62f247a0e4e0c8e16af781a881724ed8f2e38d1fee0c29595b4e849dd3caf620
MD5 14486f744193c2d3c5c4491221e1d67b
BLAKE2b-256 42a80de7377baa96c72e7607e086f50f00daebe6f769944a732ac28596714c3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page