You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is some basic boilerplate for connecting to Materialize via SQLalchemy.
fromsqlalchemyimportcreate_engine, textfromsqlalchemy.ormimportsessionmakerfromdotenvimportdotenv_valuesfrompathlibimportPathfromsqlalchemyimportURLpath_to_env=Path(__file__).parent.absolute() /".env"# Load values from .env file into config dictionary.# See example.env for what variables you need to define.config=dotenv_values(path_to_env)
config["options"] =''ifconfig["MZ_CLUSTER"]:
config["options"] +=f'--cluster={config["MZ_CLUSTER"]}'else:
config["options"] +='--cluster=quickstart'ifconfig["MZ_TRANSACTION_ISOLATION"]:
config["options"] +=f' -c transaction_isolation={config["MZ_TRANSACTION_ISOLATION"]}'ifconfig["MZ_SCHEMA"]:
config["options"] +=f' -c search_path={config["MZ_SCHEMA"]}'url=URL.create(
"postgresql+psycopg2",
database=config["MZ_DB"],
username=config["MZ_USER"],
password=config["MZ_PASSWORD"],
host=config["MZ_HOST"],
port=6875,
query={
"sslmode": "require",
"application_name": "sqlalchemy app",
"options": config["options"]
}
)
# Create an engine and metadataengine=create_engine(
url=url,
# avoid wrapping queries in transactionsisolation_level="AUTOCOMMIT")
# Create a new sessionSession=sessionmaker(bind=engine)
session=Session()
conn=session.connection()
result=conn.execute(text('select * from t'))
# Fetch all rows from the result (if you want to print the rows)rows=result.fetchall()
forrowinrows:
print(row)
# Close the sessionsession.close()
The text was updated successfully, but these errors were encountered:
Here is some basic boilerplate for connecting to Materialize via SQLalchemy.
The text was updated successfully, but these errors were encountered: