Skip to content

Commit

Permalink
Merge pull request #24 from shaunpud/master
Browse files Browse the repository at this point in the history
Added autocommit configuration
  • Loading branch information
alexferl authored Feb 13, 2022
2 parents b1b6d22 + 6a22202 commit d3e763e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ directives:
if they are not equal. Default: 'utf-8'
``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
============================ ===================================================


Expand All @@ -85,6 +86,9 @@ History

Changes:

- 0.2.1: September 4, 2020
- Added option for autocommit.

- 0.2.0: September 5, 2015
- Added option to change the cursor. Thanks to `@Sp1tF1r3 <https://github.com/Sp1tF1r3>`_ on GitHub.

Expand Down
7 changes: 6 additions & 1 deletion flask_mysqldb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def init_app(self, app):
app.config.setdefault('MYSQL_CHARSET', 'utf8')
app.config.setdefault('MYSQL_SQL_MODE', None)
app.config.setdefault('MYSQL_CURSORCLASS', None)
app.config.setdefault('MYSQL_AUTOCOMMIT', False)

if hasattr(app, 'teardown_appcontext'):
app.teardown_appcontext(self.teardown)
Expand Down Expand Up @@ -76,7 +77,11 @@ def connect(self):
kwargs['sql_mode'] = current_app.config['MYSQL_SQL_MODE']

if current_app.config['MYSQL_CURSORCLASS']:
kwargs['cursorclass'] = getattr(cursors, current_app.config['MYSQL_CURSORCLASS'])
kwargs['cursorclass'] = \
getattr(cursors, current_app.config['MYSQL_CURSORCLASS'])

if current_app.config['MYSQL_AUTOCOMMIT']:
kwargs['autocommit'] = current_app.config['MYSQL_AUTOCOMMIT']

return MySQLdb.connect(**kwargs)

Expand Down

0 comments on commit d3e763e

Please sign in to comment.