Is it possible to access database connections programmatically in datalore notebooks?

I want to access my database connections programmatically like:

from datalore.database import list_connections

connections = list_connections()
print(connections)

Or for example,

from datalore.database import DatabaseConnection

# Define a new database connection
db_connection = DatabaseConnection.create(
    name="New Database",
    db_type="postgresql",  # Change this to match your database type (e.g., "mysql")
    host="your-db-host",
    port=5432,  # Change the port based on your database
    database="your-database-name",
    user="your-username",
    password="your-password"
)

# Attach the new database connection
db_connection.attach()
print(f"Connected to: {db_connection.name}")

Is this possible? I need to repeat and execute the same queries for a number of different databases. So the SQL cell is not viable and the connections are over ssh.

1 Like

Hello Matthew,

Thank you for your questions.
At the moment, it is not possible. You can only manipulate in Python code by an SQL connection that you had established previously in the notebook (documentation)
We are internally discussing implementing programmatic access as you described.