Skip to content

Commit

Permalink
rename config and add more info
Browse files Browse the repository at this point in the history
  • Loading branch information
alexferl committed Feb 13, 2022
1 parent 43e8fd3 commit 8744c3e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ app.config["MYSQL_PASSWORD"] = "password"
app.config["MYSQL_DB"] = "database"
# Extra configs, optional:
app.config["MYSQL_CURSORCLASS"] = "DictCursor"
app.config["MYSQL_EXTRA_KWARGS"] = {"ssl": {"ca": "/path/to/ca-file"}}
app.config["MYSQL_CUSTOM_OPTIONS"] = {"ssl": {"ca": "/path/to/ca-file"}} # https://mysqlclient.readthedocs.io/user_guide.html#functions-and-attributes

mysql = MySQL(app)

Expand Down
6 changes: 3 additions & 3 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Next, add a :class:`~flask_mysqldb.MySQL` instance to your code:
app.config["MYSQL_DB"] = "database"
# Extra configs, optional:
app.config["MYSQL_CURSORCLASS"] = "DictCursor"
app.config["MYSQL_EXTRA_KWARGS"] = {"ssl": {"ca": "/path/to/ca-file"}}
app.config["MYSQL_CUSTOM_OPTIONS"] = {"ssl": {"ca": "/path/to/ca-file"}} # https://mysqlclient.readthedocs.io/user_guide.html#functions-and-attributes
mysql = MySQL(app)
Expand Down Expand Up @@ -77,7 +77,7 @@ directives:
``MYSQL_SQL_MODE`` If present, the session SQL mode will be set to the given string.
``MYSQL_CURSORCLASS`` If present, the cursor class will be set to the given string.
``MYSQL_AUTOCOMMIT`` If enabled, will use the autocommit feature of MySQL. Default: False
``MYSQL_EXTRA_KWARGS`` Use this to pass any extra directives that are not defined here. Default: None
``MYSQL_CUSTOM_OPTIONS`` ``dict`` of options you want to set in this format: {option: value}. See all available option `here <# https://mysqlclient.readthedocs.io/user_guide.html#functions-and-attributes>`_. Default: ``None``
============================ ===================================================


Expand All @@ -99,7 +99,7 @@ Changes:
- 1.0.0: February 13, 2022

- Added option for autocommit. Thanks to `@shaunpud <https://github.com/shaunpud>`_ on GitHub.
- Added option to pass any extra configuration to mysqlclient.
- Added option to pass any extra configuration to mysqlclient with MYSQL_CUSTOM_OPTIONS.

- 0.2.0: September 5, 2015

Expand Down
6 changes: 3 additions & 3 deletions flask_mysqldb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def init_app(self, app):
app.config.setdefault("MYSQL_SQL_MODE", None)
app.config.setdefault("MYSQL_CURSORCLASS", None)
app.config.setdefault("MYSQL_AUTOCOMMIT", False)
app.config.setdefault("MYSQL_EXTRA_KWARGS", None)
app.config.setdefault("MYSQL_CUSTOM_OPTIONS", None)

if hasattr(app, "teardown_appcontext"):
app.teardown_appcontext(self.teardown)
Expand Down Expand Up @@ -82,8 +82,8 @@ def connect(self):
if current_app.config["MYSQL_AUTOCOMMIT"]:
kwargs["autocommit"] = current_app.config["MYSQL_AUTOCOMMIT"]

if current_app.config["MYSQL_EXTRA_KWARGS"]:
kwargs.update(current_app.config["MYSQL_EXTRA_KWARGS"])
if current_app.config["MYSQL_CUSTOM_OPTIONS"]:
kwargs.update(current_app.config["MYSQL_CUSTOM_OPTIONS"])

return MySQLdb.connect(**kwargs)

Expand Down

0 comments on commit 8744c3e

Please sign in to comment.