Develop a Python script that connects to a PostgreSQL database and performs basic CRUD operations on a table named "products" with columns: id, name, price, and quantity. Use SQLAlchemy as the ORM library.
PLAINFORMAT
from sqlalchemy import create_engine, Column, Integer, String, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

# Define the Product class based on the products table
Base = declarative_base()

class Product(Base):
    __tablename__ = 'products'
    id = Column(Integer, primary_key=True)
    name = Column(String)
    price = Column(Float)
    quantity = Column(Integer)

    def __repr__(self):
        return f"<Product(id={self.id}, name='{self.name}', price={self.price}, quantity={self.quantity})>"

# Connect to the PostgreSQL database
engine = create_engine('postgresql://username:password@localhost/dbname')
Base.metadata.create_all(engine)  # Create the products table if it doesn't exist

Session = sessionmaker(bind=engine)
session = Session()

# Insert a new product (Create)
new_product = Product(name='Sample Product', price=9.99, quantity=10)
session.add(new_product)
session.commit()

# Query all products (Read)
all_products = session.query(Product).all()
print("All products:", all_products)

# Update a product
product_to_update = session.query(Product).filter_by(name='Sample Product').first()
if product_to_update:
    product_to_update.price = 12.99
    session.commit()

# Delete a product
product_to_delete = session.query(Product).filter_by(name='Sample Product').first()
if product_to_delete:
    session.delete(product_to_delete)
    session.commit()

# Close the session
session.close()