mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] base_external_dbsource: black, isort, prettier
This commit is contained in:
@@ -15,7 +15,7 @@ _logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class BaseExternalDbsource(models.Model):
|
class BaseExternalDbsource(models.Model):
|
||||||
""" It provides logic for connection to an external data source
|
"""It provides logic for connection to an external data source
|
||||||
|
|
||||||
Classes implementing this interface must provide the following methods
|
Classes implementing this interface must provide the following methods
|
||||||
suffixed with the adapter type. See the method definitions and examples
|
suffixed with the adapter type. See the method definitions and examples
|
||||||
@@ -95,7 +95,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
self.current_table = name
|
self.current_table = name
|
||||||
|
|
||||||
def connection_close(self, connection):
|
def connection_close(self, connection):
|
||||||
""" It closes the connection to the data source.
|
"""It closes the connection to the data source.
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -106,7 +106,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def connection_open(self):
|
def connection_open(self):
|
||||||
""" It provides a context manager for the data source.
|
"""It provides a context manager for the data source.
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -123,23 +123,23 @@ class BaseExternalDbsource(models.Model):
|
|||||||
_logger.exception("Connection close failure.")
|
_logger.exception("Connection close failure.")
|
||||||
|
|
||||||
def execute(self, query=None, execute_params=None, metadata=False, **kwargs):
|
def execute(self, query=None, execute_params=None, metadata=False, **kwargs):
|
||||||
""" Executes a query and returns a list of rows.
|
"""Executes a query and returns a list of rows.
|
||||||
|
|
||||||
"execute_params" can be a dict of values, that can be referenced
|
"execute_params" can be a dict of values, that can be referenced
|
||||||
in the SQL statement using "%(key)s" or, in the case of Oracle,
|
in the SQL statement using "%(key)s" or, in the case of Oracle,
|
||||||
":key".
|
":key".
|
||||||
Example:
|
Example:
|
||||||
query = "SELECT * FROM mytable WHERE city = %(city)s AND
|
query = "SELECT * FROM mytable WHERE city = %(city)s AND
|
||||||
date > %(dt)s"
|
date > %(dt)s"
|
||||||
execute_params = {
|
execute_params = {
|
||||||
'city': 'Lisbon',
|
'city': 'Lisbon',
|
||||||
'dt': datetime.datetime(2000, 12, 31),
|
'dt': datetime.datetime(2000, 12, 31),
|
||||||
}
|
}
|
||||||
|
|
||||||
If metadata=True, it will instead return a dict containing the
|
If metadata=True, it will instead return a dict containing the
|
||||||
rows list and the columns list, in the format:
|
rows list and the columns list, in the format:
|
||||||
{ 'cols': [ 'col_a', 'col_b', ...]
|
{ 'cols': [ 'col_a', 'col_b', ...]
|
||||||
, 'rows': [ (a0, b0, ...), (a1, b1, ...), ...] }
|
, 'rows': [ (a0, b0, ...), (a1, b1, ...), ...] }
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Old API compatibility
|
# Old API compatibility
|
||||||
@@ -163,7 +163,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return rows
|
return rows
|
||||||
|
|
||||||
def connection_test(self):
|
def connection_test(self):
|
||||||
""" It tests the connection
|
"""It tests the connection
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ConnectionSuccessError: On connection success
|
ConnectionSuccessError: On connection success
|
||||||
@@ -182,7 +182,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def remote_browse(self, record_ids, *args, **kwargs):
|
def remote_browse(self, record_ids, *args, **kwargs):
|
||||||
""" It browses for and returns the records from remote by ID
|
"""It browses for and returns the records from remote by ID
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -200,7 +200,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return method(record_ids, *args, **kwargs)
|
return method(record_ids, *args, **kwargs)
|
||||||
|
|
||||||
def remote_create(self, vals, *args, **kwargs):
|
def remote_create(self, vals, *args, **kwargs):
|
||||||
""" It creates a record on the remote data source.
|
"""It creates a record on the remote data source.
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -218,7 +218,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return method(vals, *args, **kwargs)
|
return method(vals, *args, **kwargs)
|
||||||
|
|
||||||
def remote_delete(self, record_ids, *args, **kwargs):
|
def remote_delete(self, record_ids, *args, **kwargs):
|
||||||
""" It deletes records by ID on remote
|
"""It deletes records by ID on remote
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -236,7 +236,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return method(record_ids, *args, **kwargs)
|
return method(record_ids, *args, **kwargs)
|
||||||
|
|
||||||
def remote_search(self, query, *args, **kwargs):
|
def remote_search(self, query, *args, **kwargs):
|
||||||
""" It searches the remote for the query.
|
"""It searches the remote for the query.
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -254,7 +254,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return method(query, *args, **kwargs)
|
return method(query, *args, **kwargs)
|
||||||
|
|
||||||
def remote_update(self, record_ids, vals, *args, **kwargs):
|
def remote_update(self, record_ids, vals, *args, **kwargs):
|
||||||
""" It updates the remote records with the vals
|
"""It updates the remote records with the vals
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -295,7 +295,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
# Compatibility & Private
|
# Compatibility & Private
|
||||||
|
|
||||||
def conn_open(self):
|
def conn_open(self):
|
||||||
""" It opens and returns a connection to the remote data source.
|
"""It opens and returns a connection to the remote data source.
|
||||||
|
|
||||||
This method calls adapter method of this same name, suffixed with
|
This method calls adapter method of this same name, suffixed with
|
||||||
the adapter type.
|
the adapter type.
|
||||||
@@ -308,7 +308,7 @@ class BaseExternalDbsource(models.Model):
|
|||||||
return connection
|
return connection
|
||||||
|
|
||||||
def _get_adapter_method(self, method_prefix):
|
def _get_adapter_method(self, method_prefix):
|
||||||
""" It returns the connector adapter method for ``method_prefix``.
|
"""It returns the connector adapter method for ``method_prefix``.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
method_prefix: (str) Prefix of adapter method (such as
|
method_prefix: (str) Prefix of adapter method (such as
|
||||||
|
|||||||
Reference in New Issue
Block a user