googleapis / python-spanner-sqlalchemy

Apache License 2.0
38 stars 28 forks source link

readme out of date with metadata function? #328

Open sam-hoffman opened 1 year ago

sam-hoffman commented 1 year ago

Environment details

Steps to reproduce

Following the directions in the README, I wrote the following:

from sqlalchemy import create_engine, Table
from sqlalchemy.schema import MetaData

engine = create_engine(
    f"spanner+spanner:///projects/{project}/instances/{instance}/databases/{database}"
)
        metadata = MetaData(bind=engine)

and got the error:

    metadata = MetaData(bind=engine)
TypeError: __init__() got an unexpected keyword argument 'bind'

It seems the README might be out of date - what is the new way of connecting to tables? I was hoping to insert data.

alexjolig commented 2 months ago

For a fix, you should remove the bind parameter from Metadata instance and add it to your main action method. E.g: for creating a table do this:

metadata = MetaData()

table = Table(
    table_id,
    metadata,
    Column("user_id", Integer, primary_key=True),
    Column("user_name", String(16), nullable=False),
)
table.create(bind=engine)