database.py 690 B

1234567891011121314
  1. def conn_string(dsn):
  2. if dsn["driver"] == "mssql":
  3. return f"mssql+pyodbc://{dsn['user']}:{dsn['password']}@{dsn['server']}/{dsn['database']}?driver=SQL+Server+Native+Client+11.0"
  4. if dsn["driver"] == "mysql":
  5. return f"mysql+pymysql://{dsn['user']}:{dsn['password']}@{dsn['server']}/{dsn['database']}?charset=utf8mb4"
  6. return f"pyodbc://{dsn['user']}:{dsn['pass']}@{dsn['server']}/{dsn['database']}?driver={dsn['driver']}"
  7. def bcp_conn_params(dsn):
  8. return f"-S {dsn['server']} -d {dsn['database']} -U {dsn['user']} -P {dsn['password']}"
  9. def mysql_conn_params(dsn):
  10. return f"-h {dsn['server']} -D {dsn['database']} -u {dsn['user']} -p {dsn['password']}"