Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding a parameter for committing select queries -- psycopg2, unless in

autocommit mode, will open a transaction for any query, including
selects.  If not comitted, leads to idle in transactions -- this fixes
and also addresses #116
  • Loading branch information...
commit 5b93c6f8e599e3b9e1ff89af35ca8c7fed83dbf6 1 parent a5ec7bb
Charles Leifer authored
Showing with 7 additions and 1 deletion.
  1. +7 −1 peewee.py
8 peewee.py
View
@@ -1454,6 +1454,7 @@ def execute(self):
class Database(object):
+ commit_select = False
compiler_class = QueryCompiler
expr_overrides = {}
field_overrides = {}
@@ -1526,7 +1527,11 @@ def get_compiler(self):
def execute(self, query):
sql, params = query.sql(self.get_compiler())
- return self.execute_sql(sql, params, query.require_commit)
+ if isinstance(query, (SelectQuery, RawQuery)):
+ commit = self.commit_select
+ else:
+ commit = query.require_commit
+ return self.execute_sql(sql, params, commit)
def execute_sql(self, sql, params=None, require_commit=True):
cursor = self.get_cursor()
@@ -1632,6 +1637,7 @@ def get_tables(self):
class PostgresqlDatabase(Database):
+ commit_select = True
field_overrides = {
'bigint': 'BIGINT',
'bool': 'BOOLEAN',
Please sign in to comment.
Something went wrong with that request. Please try again.