From 38615fb27ffae8bc187e9778ab6c0d817c89650e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E5=B2=B3?= Date: Mon, 24 Dec 2018 14:45:26 +0800 Subject: [PATCH 1/2] fix pg connect issue --- crwy/utils/sql/pg.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crwy/utils/sql/pg.py b/crwy/utils/sql/pg.py index 76a1320..28c4962 100644 --- a/crwy/utils/sql/pg.py +++ b/crwy/utils/sql/pg.py @@ -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 " @@ -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() @@ -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: From a2ecac7296d375961f8c024748d15d309e64eefc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E5=B2=B3?= Date: Mon, 24 Dec 2018 14:46:36 +0800 Subject: [PATCH 2/2] update version to 1.3.2 --- README.md | 4 ++-- crwy/VERSION | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4e4d717..b0a7e7d 100644 --- a/README.md +++ b/README.md @@ -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) # 简介 @@ -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/ # 使用手册 diff --git a/crwy/VERSION b/crwy/VERSION index 6261a05..d5e98f7 100644 --- a/crwy/VERSION +++ b/crwy/VERSION @@ -1 +1 @@ -1.3.1 \ No newline at end of file +1.3.2 \ No newline at end of file