Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
ops_sdk
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PublicSource
ops_sdk
Commits
aa73eaf0
Commit
aa73eaf0
authored
Jan 10, 2019
by
shenshuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改db连接
parent
cd7d726c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
db_context.py
websdk/db_context.py
+7
-4
No files found.
websdk/db_context.py
View file @
aa73eaf0
...
...
@@ -8,6 +8,7 @@ role : 数据库连接
import
pymysql
from
urllib.parse
import
quote_plus
from
sqlalchemy
import
create_engine
from
sqlalchemy.pool
import
NullPool
from
sqlalchemy.orm
import
sessionmaker
from
.consts
import
const
from
.configs
import
configs
...
...
@@ -28,7 +29,8 @@ def init_engine(**settings):
dbname
=
db_conf
[
const
.
DBNAME_KEY
]
engine
=
create_engine
(
'mysql+pymysql://{user}:{pwd}@{host}:{port}/{dbname}?charset=utf8'
.
format
(
user
=
dbuser
,
pwd
=
quote_plus
(
dbpwd
),
host
=
dbhost
,
port
=
dbport
,
dbname
=
dbname
),
logging_name
=
dbkey
)
# logging_name=dbkey)
logging_name
=
dbkey
,
poolclass
=
NullPool
)
engines
[
dbkey
]
=
engine
...
...
@@ -58,9 +60,9 @@ class DBContext(object):
self
.
__engine
=
engine
self
.
need_commit
=
need_commit
@
property
def
db_key
(
self
):
return
self
.
__db_key
#
@property
#
def db_key(self):
#
return self.__db_key
@
staticmethod
def
__get_db_engine
(
db_key
,
**
settings
):
...
...
@@ -77,6 +79,7 @@ class DBContext(object):
return
self
.
__session
def
__exit__
(
self
,
exc_type
,
exc_val
,
exc_tb
):
print
(
exc_type
,
exc_val
,
exc_tb
)
if
self
.
need_commit
:
if
exc_type
:
self
.
__session
.
rollback
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment