mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] base_external_dbsource_mysql: Don't depend on SQLite
The amount of shared code is so insignificant, that it doesn't worth to depend on base_external_dbsource_sqlite.
This commit is contained in:
@@ -40,7 +40,6 @@ To install this module, you need to:
|
|||||||
|
|
||||||
* Install ``libmysqlclient-dev`` package (``default-libmysqlclient-dev`` on Debian)
|
* Install ``libmysqlclient-dev`` package (``default-libmysqlclient-dev`` on Debian)
|
||||||
* Install ``sqlalchemy`` and ``mysqlclient`` python libraries
|
* Install ``sqlalchemy`` and ``mysqlclient`` python libraries
|
||||||
* Install ``base_external_dbsource_sqlite`` Odoo module
|
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
=============
|
=============
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
'website': 'https://github.com/OCA/server-backend',
|
'website': 'https://github.com/OCA/server-backend',
|
||||||
'license': 'LGPL-3',
|
'license': 'LGPL-3',
|
||||||
'depends': [
|
'depends': [
|
||||||
'base_external_dbsource_sqlite',
|
'base_external_dbsource',
|
||||||
],
|
],
|
||||||
'external_dependencies': {
|
'external_dependencies': {
|
||||||
'python': [
|
'python': [
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from odoo import api, models
|
from odoo import models
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -20,6 +20,11 @@ try:
|
|||||||
except (ImportError, AssertionError):
|
except (ImportError, AssertionError):
|
||||||
_logger.info('MySQLdb not available. Please install "mysqlclient" '
|
_logger.info('MySQLdb not available. Please install "mysqlclient" '
|
||||||
'python package.')
|
'python package.')
|
||||||
|
try:
|
||||||
|
import sqlalchemy
|
||||||
|
except ImportError:
|
||||||
|
_logger.info('SQLAlchemy library not available. Please '
|
||||||
|
'install "sqlalchemy" python package.')
|
||||||
except ImportError:
|
except ImportError:
|
||||||
_logger.info('base_external_dbsource Odoo module not found.')
|
_logger.info('base_external_dbsource Odoo module not found.')
|
||||||
|
|
||||||
@@ -29,14 +34,22 @@ class BaseExternalDbsource(models.Model):
|
|||||||
|
|
||||||
_inherit = "base.external.dbsource"
|
_inherit = "base.external.dbsource"
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def connection_close_mysql(self, connection):
|
def connection_close_mysql(self, connection):
|
||||||
return connection.close()
|
return connection.close()
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def connection_open_mysql(self):
|
def connection_open_mysql(self):
|
||||||
return self._connection_open_sqlalchemy()
|
return sqlalchemy.create_engine(self.conn_string_full).connect()
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def execute_mysql(self, sqlquery, sqlparams, metadata):
|
def execute_mysql(self, sqlquery, sqlparams, metadata):
|
||||||
return self._execute_sqlalchemy(sqlquery, sqlparams, metadata)
|
# FIXME: Duplicated method in modules to be consolidated in base
|
||||||
|
rows, cols = list(), list()
|
||||||
|
for record in self:
|
||||||
|
with record.connection_open() as connection:
|
||||||
|
if sqlparams is None:
|
||||||
|
cur = connection.execute(sqlquery)
|
||||||
|
else:
|
||||||
|
cur = connection.execute(sqlquery, sqlparams)
|
||||||
|
if metadata:
|
||||||
|
cols = list(cur.keys())
|
||||||
|
rows = [r for r in cur]
|
||||||
|
return rows, cols
|
||||||
|
|||||||
@@ -2,4 +2,3 @@ To install this module, you need to:
|
|||||||
|
|
||||||
* Install ``libmysqlclient-dev`` package (``default-libmysqlclient-dev`` on Debian)
|
* Install ``libmysqlclient-dev`` package (``default-libmysqlclient-dev`` on Debian)
|
||||||
* Install ``sqlalchemy`` and ``mysqlclient`` python libraries
|
* Install ``sqlalchemy`` and ``mysqlclient`` python libraries
|
||||||
* Install ``base_external_dbsource_sqlite`` Odoo module
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
<meta name="generator" content="Docutils 0.12: http://docutils.sourceforge.net/" />
|
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
|
||||||
<title>External Database Source - MySQL</title>
|
<title>External Database Source - MySQL</title>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
|
|
||||||
/*
|
/*
|
||||||
:Author: David Goodger (goodger@python.org)
|
:Author: David Goodger (goodger@python.org)
|
||||||
:Id: $Id: html4css1.css 7614 2013-02-21 15:55:51Z milde $
|
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||||
:Copyright: This stylesheet has been placed in the public domain.
|
:Copyright: This stylesheet has been placed in the public domain.
|
||||||
|
|
||||||
Default cascading style sheet for the HTML output of Docutils.
|
Default cascading style sheet for the HTML output of Docutils.
|
||||||
@@ -37,6 +37,14 @@ table.borderless td, table.borderless th {
|
|||||||
.hidden {
|
.hidden {
|
||||||
display: none }
|
display: none }
|
||||||
|
|
||||||
|
.subscript {
|
||||||
|
vertical-align: sub;
|
||||||
|
font-size: smaller }
|
||||||
|
|
||||||
|
.superscript {
|
||||||
|
vertical-align: super;
|
||||||
|
font-size: smaller }
|
||||||
|
|
||||||
a.toc-backref {
|
a.toc-backref {
|
||||||
text-decoration: none ;
|
text-decoration: none ;
|
||||||
color: black }
|
color: black }
|
||||||
@@ -161,12 +169,12 @@ h2.subtitle {
|
|||||||
hr.docutils {
|
hr.docutils {
|
||||||
width: 75% }
|
width: 75% }
|
||||||
|
|
||||||
img.align-left, .figure.align-left, object.align-left {
|
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||||
clear: left ;
|
clear: left ;
|
||||||
float: left ;
|
float: left ;
|
||||||
margin-right: 1em }
|
margin-right: 1em }
|
||||||
|
|
||||||
img.align-right, .figure.align-right, object.align-right {
|
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||||
clear: right ;
|
clear: right ;
|
||||||
float: right ;
|
float: right ;
|
||||||
margin-left: 1em }
|
margin-left: 1em }
|
||||||
@@ -177,6 +185,11 @@ img.align-center, .figure.align-center, object.align-center {
|
|||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table.align-center {
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.align-left {
|
.align-left {
|
||||||
text-align: left }
|
text-align: left }
|
||||||
|
|
||||||
@@ -194,6 +207,15 @@ div.align-right {
|
|||||||
/* div.align-center * { */
|
/* div.align-center * { */
|
||||||
/* text-align: left } */
|
/* text-align: left } */
|
||||||
|
|
||||||
|
.align-top {
|
||||||
|
vertical-align: top }
|
||||||
|
|
||||||
|
.align-middle {
|
||||||
|
vertical-align: middle }
|
||||||
|
|
||||||
|
.align-bottom {
|
||||||
|
vertical-align: bottom }
|
||||||
|
|
||||||
ol.simple, ul.simple {
|
ol.simple, ul.simple {
|
||||||
margin-bottom: 1em }
|
margin-bottom: 1em }
|
||||||
|
|
||||||
@@ -370,7 +392,6 @@ foreign MySQL databases using SQLAlchemy.</p>
|
|||||||
<ul class="simple">
|
<ul class="simple">
|
||||||
<li>Install <tt class="docutils literal"><span class="pre">libmysqlclient-dev</span></tt> package (<tt class="docutils literal"><span class="pre">default-libmysqlclient-dev</span></tt> on Debian)</li>
|
<li>Install <tt class="docutils literal"><span class="pre">libmysqlclient-dev</span></tt> package (<tt class="docutils literal"><span class="pre">default-libmysqlclient-dev</span></tt> on Debian)</li>
|
||||||
<li>Install <tt class="docutils literal">sqlalchemy</tt> and <tt class="docutils literal">mysqlclient</tt> python libraries</li>
|
<li>Install <tt class="docutils literal">sqlalchemy</tt> and <tt class="docutils literal">mysqlclient</tt> python libraries</li>
|
||||||
<li>Install <tt class="docutils literal">base_external_dbsource_sqlite</tt> Odoo module</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="section" id="configuration">
|
<div class="section" id="configuration">
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
def test_connection_open_mysql(self):
|
def test_connection_open_mysql(self):
|
||||||
""" It should call SQLAlchemy open """
|
""" It should call SQLAlchemy open """
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
self.dbsource, '_connection_open_sqlalchemy'
|
self.dbsource, 'connection_open_mysql'
|
||||||
) as parent_method:
|
) as parent_method:
|
||||||
self.dbsource.connection_open_mysql()
|
self.dbsource.connection_open_mysql()
|
||||||
parent_method.assert_called_once_with()
|
parent_method.assert_called_once_with()
|
||||||
@@ -35,7 +35,7 @@ class TestBaseExternalDbsource(common.TransactionCase):
|
|||||||
""" It should pass args to SQLAlchemy execute """
|
""" It should pass args to SQLAlchemy execute """
|
||||||
expect = 'sqlquery', 'sqlparams', 'metadata'
|
expect = 'sqlquery', 'sqlparams', 'metadata'
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
self.dbsource, '_execute_sqlalchemy'
|
self.dbsource, 'execute_mysql'
|
||||||
) as parent_method:
|
) as parent_method:
|
||||||
self.dbsource.execute_mysql(*expect)
|
self.dbsource.execute_mysql(*expect)
|
||||||
parent_method.assert_called_once_with(*expect)
|
parent_method.assert_called_once_with(*expect)
|
||||||
|
|||||||
Reference in New Issue
Block a user