Giter Club home page Giter Club logo

sqlalchemy-tds's People

Contributors

cclauss avatar eshirazi avatar jackwotherspoon avatar m32 avatar mariusdkm avatar ununnilium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sqlalchemy-tds's Issues

Allow for `host` to be optional in DB URI

Currently the host param seems to be required as part of the DB URI when creating a SQLAlchemy engine with sqlalchemy.create_engine:

# create connection pool
pool = sqlalchemy.create_engine(
    "mssql+pytds://<HOST>",
    creator=getconn,
)

However, some libraries that leverage SQLAlchemy's creator argument do not need a host param in order to successfully make a connection such as the Cloud SQL Python Connector. It seems that when the creator argument is used to establish the connection it does not even look at the host field, allowing you to put any dummy value for <HOST> and connections will still be established. This makes me believe that the param should be made optional.

Currently for MySQL and Postgres, connection with the Cloud SQL Python Connector are made as follows without the need for host:

from google.cloud.sql.connector import Connector
import sqlalchemy

# initialize Connector object
connector = Connector()

# function to return the database connection
def getconn() -> pymysql.connections.Connection:
    conn: pymysql.connections.Connection = connector.connect(
        "project:region:instance",
        "pymysql",
        user="my-user",
        password="my-password",
        db="my-db-name"
    )
    return conn

# create connection pool
pool = sqlalchemy.create_engine(
    "mysql+pymysql://",
    creator=getconn,
)

Ideal behavior for pytds would be as follows:

# create connection pool
pool = sqlalchemy.create_engine(
    "mssql+pytds://",
    creator=getconn,
)

If you try the above currently you get the following error:

File "/layers/google.python.pip/pip/lib/python3.10/site-packages/sqlalchemy_pytds/connector.py", line 99, in create_connect_args
  connect_args["dsn"] = connect_args["host"]
    KeyError: 'host'

Because of this we are currently telling users to pass in a dummy value as the host field to satisfy it being required:

# create connection pool
pool = sqlalchemy.create_engine(
    "mssql+pytds://dummy-value",
    creator=getconn,
)

is there any issue you see if we make it so that having a host field is not required?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.