Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: API to get connection string from backend #10373

Closed
1 task done
NickCrews opened this issue Oct 25, 2024 · 5 comments
Closed
1 task done

feat: API to get connection string from backend #10373

NickCrews opened this issue Oct 25, 2024 · 5 comments
Labels
feature Features or general enhancements

Comments

@NickCrews
Copy link
Contributor

Is your feature request related to a problem?

This may be out of scope for ibis, but I'm curious if you have any suggestions. See duckdb/duckdb#14549 (comment) for the motivation and use case. I went directly upstream, since I thought it would be useful to have that functionality in duckdb by itself.

If I understand correctly, sometimes ibis backends are constructed directly from a db connection, eg ibis.duckdb.connect(duckdb.connect()) instead of ibis.duckdb.connect("db.duckdb"). In that case, we would need to rely on the upstream backend to provide a .get_connection_string() method. So maybe this is impossible to do for all backends.

What is the motivation behind your request?

No response

Describe the solution you'd like

conn.connection_string or similar.

What version of ibis are you running?

NA

What backend(s) are you using, if any?

duckdb

Code of Conduct

  • I agree to follow this project's Code of Conduct
@NickCrews NickCrews added the feature Features or general enhancements label Oct 25, 2024
@cpcloud
Copy link
Member

cpcloud commented Oct 25, 2024

Why isn't having an existing connection enough?

@NickCrews
Copy link
Contributor Author

Because I am trying to use sqlalchemy to create the tables in the database, and as far as I can see there is no way to create a sqlalchemy engine from an existing connection, only from a connection string.

@cpcloud
Copy link
Member

cpcloud commented Oct 25, 2024

There's definitely a way to do that: https://stackoverflow.com/a/23744051

@NickCrews
Copy link
Contributor Author

NickCrews commented Oct 25, 2024

Maybe is it that the DuckdbPyConnection doesn't implement the needed API? Am I passing in the wrong thing?

# python -m pip install duckdb-engine>=0.13.4
# import duckdb_engine
import duckdb
import sqlalchemy as sa
from sqlalchemy.orm import declarative_base

_base = declarative_base()


class Pet(_base):
    __tablename__ = "pets"

    id = sa.Column(sa.Integer, primary_key=True)
    name = sa.Column(sa.String)
    age = sa.Column(sa.Integer)
    species = sa.Column(sa.String)


con = duckdb.connect()
engine = sa.create_engine("duckdb://", creator=lambda: con)
_base.metadata.create_all(engine)
# AttributeError: 'duckdb.duckdb.DuckDBPyConnection' object has no attribute 'connection'

Maybe this needs to happen at the duckdb-engine level?

@cpcloud
Copy link
Member

cpcloud commented Oct 28, 2024

I don't know, but this certainly isn't an Ibis issue.

@cpcloud cpcloud closed this as not planned Won't fix, can't repro, duplicate, stale Oct 28, 2024
@github-project-automation github-project-automation bot moved this from backlog to done in Ibis planning and roadmap Oct 28, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feature Features or general enhancements
Projects
Archived in project
Development

No branches or pull requests

2 participants