2. Quickstart

This guide will help you get started with wpostgresql in minutes.

2.1. Basic Usage

Create a Pydantic model and initialize the database connection:

from pydantic import BaseModel
from wpostgresql import WPostgreSQL

class User(BaseModel):
    id: int
    name: str
    email: str

db_config = {
    "dbname": "mydatabase",
    "user": "myuser",
    "password": "mypassword",
    "host": "localhost",
    "port": 5432,
}

db = WPostgreSQL(User, db_config)

2.2. CRUD Operations

Create:

db.insert(User(id=1, name="John Doe", email="john@example.com"))

Read:

all_users = db.get_all()
john = db.get_by_field(name="John Doe")

Update:

db.update(1, User(id=1, name="John Smith", email="john.smith@example.com"))

Delete:

db.delete(1)

2.3. Async Operations

import asyncio

async def main():
    await db.insert_async(User(id=2, name="Jane", email="jane@example.com"))
    users = await db.get_all_async()

asyncio.run(main())

2.4. Next Steps