-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation for connecting to a database over ssh #2238
base: devel
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for dlt-hub-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
||
# Close the SSH tunnel to release resources | ||
tunnel.close() | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would be more pythonic:
ssh_creds = dlt.secrets["ssh"]
db_creds = dlt.secrets["destination.sqlalchemy.credentials"]
with SSHTunnelForwarder(
(ssh_creds["server_ip_address"], 22),
ssh_username=ssh_creds["username"],
ssh_pkey=ssh_creds["private_key_path"],
ssh_private_key_password=ssh_creds.get("private_key_password"),
remote_bind_address=("127.0.0.1", 5432),
) as tunnel:
engine = create_engine(
f"postgresql://{db_creds['username']}:{db_creds['password']}"
f"@127.0.0.1:{tunnel.local_bind_port}/{db_creds['database']}"
)
# Access database table as a dlt resource
table_resource = sql_table(engine, table="employees", schema="public")
# Define and run the pipeline
pipeline = dlt.pipeline(
pipeline_name="remote_db_pipeline",
destination="duckdb",
dataset_name="remote_dataset"
)
print(pipeline.run(table_resource))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated as per the above code
|
||
#### Using SqlAlchemy Engine as credentials | ||
### Using SqlAlchemy Engine as credentials | ||
|
||
You are able to pass an instance of SqlAlchemy Engine instead of credentials: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are able to pass an instance of SqlAlchemy Engine instead of credentials: | |
You are able to pass an instance of SQLAlchemy Engine instead of credentials: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
@@ -160,9 +160,9 @@ source = sql_database(credentials).with_resources("family") | |||
It is recommended to configure credentials in `.dlt/secrets.toml` and to not include any sensitive information in the pipeline code. | |||
::: | |||
|
|||
### Other connection options | |||
## Other connection options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Other connection options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
8a46bac
to
8d61c8a
Compare
bbdd9f7
to
c04284c
Compare
Description
This PR updates the SQL database configuration documentation to explain how to connect to a database using an SSH tunnel. Key additions include:
These changes aim to help users securely access remote databases behind firewalls or requiring SSH.