{"library":"pgdb","title":"PostgreSQL Database Wrapper","description":"pgdb is a lightweight Python wrapper around `psycopg2-binary` designed to simplify basic interactions with PostgreSQL databases. It provides a simple API for connecting, executing queries, and fetching results. The library, currently at version 0.0.11, appears to be in maintenance mode with its last update over two years ago.","language":"python","status":"maintenance","last_verified":"Fri Apr 17","install":{"commands":["pip install pgdb"],"cli":null},"imports":["import pgdb"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import pgdb\nimport os\n\nDB_HOST = os.environ.get('PGDB_HOST', 'localhost')\nDB_NAME = os.environ.get('PGDB_DATABASE', 'test_db')\nDB_USER = os.environ.get('PGDB_USER', 'postgres')\nDB_PASS = os.environ.get('PGDB_PASSWORD', 'mysecretpassword') # REMEMBER to change in prod\n\nconn = None\ntry:\n    conn = pgdb.connect(host=DB_HOST, database=DB_NAME, user=DB_USER, password=DB_PASS)\n    cursor = conn.cursor()\n\n    # Cleanup for re-runs and create table\n    cursor.execute(\"DROP TABLE IF EXISTS example_data;\")\n    cursor.execute(\"CREATE TABLE example_data (id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL);\")\n    conn.commit()\n\n    # Insert data\n    cursor.execute(\"INSERT INTO example_data (name) VALUES ('Alice'), ('Bob'), ('Charlie');\")\n    conn.commit()\n\n    # Fetch and print data\n    cursor.execute(\"SELECT id, name FROM example_data;\")\n    print(\"Fetched data:\")\n    for row in cursor.fetchall():\n        print(row)\n\nexcept pgdb.Error as e:\n    print(f\"Database error: {e}\")\n    if conn:\n        conn.rollback() # Rollback on error\nfinally:\n    if conn:\n        conn.close()","lang":"python","description":"This quickstart demonstrates how to establish a connection, create a table, insert data, and fetch results using `pgdb`. It utilizes environment variables for database credentials, falling back to common defaults for local testing. It also includes basic error handling and resource cleanup.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}