Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Carlos Ramos Carreño
neoppod
Commits
fd007f5d
Commit
fd007f5d
authored
Dec 26, 2016
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: code refactoring for backends to connect to the database
parent
dd1d6b30
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
12 deletions
+12
-12
neo/storage/database/importer.py
neo/storage/database/importer.py
+3
-0
neo/storage/database/manager.py
neo/storage/database/manager.py
+7
-1
neo/storage/database/mysqldb.py
neo/storage/database/mysqldb.py
+1
-6
neo/storage/database/sqlite.py
neo/storage/database/sqlite.py
+1
-5
No files found.
neo/storage/database/importer.py
View file @
fd007f5d
...
@@ -308,6 +308,9 @@ class ImporterDatabaseManager(DatabaseManager):
...
@@ -308,6 +308,9 @@ class ImporterDatabaseManager(DatabaseManager):
"""
.
split
():
"""
.
split
():
setattr
(
self
,
x
,
getattr
(
self
.
db
,
x
))
setattr
(
self
,
x
,
getattr
(
self
.
db
,
x
))
def
_connect
(
self
):
pass
def
commit
(
self
):
def
commit
(
self
):
self
.
db
.
commit
()
self
.
db
.
commit
()
self
.
_last_commit
=
time
.
time
()
self
.
_last_commit
=
time
.
time
()
...
...
neo/storage/database/manager.py
View file @
fd007f5d
...
@@ -52,6 +52,8 @@ class DatabaseManager(object):
...
@@ -52,6 +52,8 @@ class DatabaseManager(object):
ENGINES
=
()
ENGINES
=
()
_deferred
=
0
def
__init__
(
self
,
database
,
engine
=
None
,
wait
=
0
):
def
__init__
(
self
,
database
,
engine
=
None
,
wait
=
0
):
"""
"""
Initialize the object.
Initialize the object.
...
@@ -62,8 +64,8 @@ class DatabaseManager(object):
...
@@ -62,8 +64,8 @@ class DatabaseManager(object):
%
(
engine
,
self
.
ENGINES
))
%
(
engine
,
self
.
ENGINES
))
self
.
_engine
=
engine
self
.
_engine
=
engine
self
.
_wait
=
wait
self
.
_wait
=
wait
self
.
_deferred
=
0
self
.
_parse
(
database
)
self
.
_parse
(
database
)
self
.
_connect
()
def
__getattr__
(
self
,
attr
):
def
__getattr__
(
self
,
attr
):
if
attr
==
"_getPartition"
:
if
attr
==
"_getPartition"
:
...
@@ -78,6 +80,10 @@ class DatabaseManager(object):
...
@@ -78,6 +80,10 @@ class DatabaseManager(object):
def
_parse
(
self
,
database
):
def
_parse
(
self
,
database
):
"""Called during instantiation, to process database parameter."""
"""Called during instantiation, to process database parameter."""
@
abstract
def
_connect
(
self
):
"""Connect to the database"""
def
setup
(
self
,
reset
=
0
):
def
setup
(
self
,
reset
=
0
):
"""Set up a database, discarding existing data first if reset is True
"""Set up a database, discarding existing data first if reset is True
"""
"""
...
...
neo/storage/database/mysqldb.py
View file @
fd007f5d
...
@@ -56,12 +56,6 @@ class MySQLDatabaseManager(DatabaseManager):
...
@@ -56,12 +56,6 @@ class MySQLDatabaseManager(DatabaseManager):
_max_allowed_packet
=
32769
*
1024
_max_allowed_packet
=
32769
*
1024
def
__init__
(
self
,
*
args
,
**
kw
):
super
(
MySQLDatabaseManager
,
self
).
__init__
(
*
args
,
**
kw
)
self
.
conn
=
None
self
.
_config
=
{}
self
.
_connect
()
def
_parse
(
self
,
database
):
def
_parse
(
self
,
database
):
""" Get the database credentials (username, password, database) """
""" Get the database credentials (username, password, database) """
# expected pattern : [user[:password]@]database[(~|.|/)unix_socket]
# expected pattern : [user[:password]@]database[(~|.|/)unix_socket]
...
@@ -93,6 +87,7 @@ class MySQLDatabaseManager(DatabaseManager):
...
@@ -93,6 +87,7 @@ class MySQLDatabaseManager(DatabaseManager):
logging
.
exception
(
'Connection to MySQL failed, retrying.'
)
logging
.
exception
(
'Connection to MySQL failed, retrying.'
)
time
.
sleep
(
1
)
time
.
sleep
(
1
)
self
.
_active
=
0
self
.
_active
=
0
self
.
_config
=
{}
conn
=
self
.
conn
conn
=
self
.
conn
conn
.
autocommit
(
False
)
conn
.
autocommit
(
False
)
conn
.
query
(
"SET SESSION group_concat_max_len = %u"
%
(
2
**
32
-
1
))
conn
.
query
(
"SET SESSION group_concat_max_len = %u"
%
(
2
**
32
-
1
))
...
...
neo/storage/database/sqlite.py
View file @
fd007f5d
...
@@ -69,11 +69,6 @@ class SQLiteDatabaseManager(DatabaseManager):
...
@@ -69,11 +69,6 @@ class SQLiteDatabaseManager(DatabaseManager):
VERSION
=
1
VERSION
=
1
def
__init__
(
self
,
*
args
,
**
kw
):
super
(
SQLiteDatabaseManager
,
self
).
__init__
(
*
args
,
**
kw
)
self
.
_config
=
{}
self
.
_connect
()
def
_parse
(
self
,
database
):
def
_parse
(
self
,
database
):
self
.
db
=
os
.
path
.
expanduser
(
database
)
self
.
db
=
os
.
path
.
expanduser
(
database
)
...
@@ -83,6 +78,7 @@ class SQLiteDatabaseManager(DatabaseManager):
...
@@ -83,6 +78,7 @@ class SQLiteDatabaseManager(DatabaseManager):
def
_connect
(
self
):
def
_connect
(
self
):
logging
.
info
(
'connecting to SQLite database %r'
,
self
.
db
)
logging
.
info
(
'connecting to SQLite database %r'
,
self
.
db
)
self
.
conn
=
sqlite3
.
connect
(
self
.
db
,
check_same_thread
=
False
)
self
.
conn
=
sqlite3
.
connect
(
self
.
db
,
check_same_thread
=
False
)
self
.
_config
=
{}
def
_commit
(
self
):
def
_commit
(
self
):
retry_if_locked
(
self
.
conn
.
commit
)
retry_if_locked
(
self
.
conn
.
commit
)
...
...
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