Skip to content

Instantly share code, notes, and snippets.

@cnolanminich
Created December 11, 2024 20:39
Show Gist options
  • Save cnolanminich/3ff622566d0f9d0ddf84a4477aa575fd to your computer and use it in GitHub Desktop.
Save cnolanminich/3ff622566d0f9d0ddf84a4477aa575fd to your computer and use it in GitHub Desktop.
example postgres resource
import pandas as pd
from dagster import asset, ResourceParam
from sqlalchemy import create_engine
# Define the PostgreSQL resource
class PostgresResource:
def __init__(self, connection_string):
self.connection_string = connection_string
def get_connection(self):
return create_engine(self.connection_string).connect()
# Define the asset that ingests data from PostgreSQL
@asset
def ingest_data_from_postgres(postgres: ResourceParam[PostgresResource]):
with postgres.get_connection() as conn:
query = "SELECT * FROM your_table"
df = pd.read_sql_query(query, conn)
# Perform any additional data processing here
return df
# Example of how to configure the resource
postgres_resource = PostgresResource(connection_string="postgresql://user:password@localhost:5432/your_database")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment