Skip to content

Commit

Permalink
Merge branch 'release/1.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyue92tree committed Dec 24, 2018
2 parents 62217db + a2ecac7 commit 165bbc3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Crwy

[![PyPI Version](https://img.shields.io/pypi/v/Crwy.svg)](https://pypi.python.org/pypi/Crwy)
[![Build Status](https://travis-ci.org/wuyue92tree/crwy.svg?branch=1.3.1)](https://travis-ci.org/wuyue92tree/crwy)
[![Build Status](https://travis-ci.org/wuyue92tree/crwy.svg?branch=1.3.2)](https://travis-ci.org/wuyue92tree/crwy)

# 简介

Expand Down Expand Up @@ -34,7 +34,7 @@ pip install crwy
```

or
前往下载: https://pypi.python.org/pypi/Crwy/1.3.1/
前往下载: https://pypi.python.org/pypi/Crwy/1.3.2/

# 使用手册

Expand Down
2 changes: 1 addition & 1 deletion crwy/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.1
1.3.2
17 changes: 14 additions & 3 deletions crwy/utils/sql/pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
raise CrwyImportException("You should install PyGreSQL first! try: pip "
"install PyGreSQL")
try:
from DBUtils.PersistentPg import PersistentPg
from DBUtils.PersistentDB import PersistentDB
except ImportError:
raise CrwyImportException(
"You should install DBUtils first! try: pip install "
Expand All @@ -29,7 +29,7 @@
@cls2singleton
class PgHandle(object):
def __init__(self, **kwargs):
self._pg_pool = PersistentPg(pgdb, **kwargs)
self._pg_pool = PersistentDB(pgdb, **kwargs)

def query_by_sql(self, sql):
conn = self._pg_pool.connection()
Expand All @@ -44,14 +44,25 @@ def query_by_sql(self, sql):
cur.close()
conn.close()

def save(self, sql, data, many=False):
def save(self, sql, data, many=False, get_last_insert_id=False):
conn = self._pg_pool.connection()
cur = conn.cursor()
try:
if get_last_insert_id is True:
sql = sql.strip(';')
sql = sql + ' returning id'

if many is False:
cur.execute(sql, data)
else:
cur.executemany(sql, data)

conn.commit()

if get_last_insert_id is True:
res = cur.fetchone()
return res.id

except Exception as e:
raise CrwyDbException(e)
finally:
Expand Down

0 comments on commit 165bbc3

Please sign in to comment.