| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,13 +13,18 @@ | |||
| 13 | 13 | # See the License for the specific language governing permissions and | |
| 14 | 14 | # limitations under the License. | |
| 15 | 15 | """Sets up shorcuts for imports from the library.""" | |
| 16 | + import logging | ||
| 16 | 17 | ||
| 17 | 18 | from spanner_orm import api | |
| 18 | 19 | from spanner_orm import condition | |
| 19 | 20 | from spanner_orm import field | |
| 20 | 21 | from spanner_orm import model | |
| 21 | 22 | from spanner_orm import relationship | |
| 22 | 23 | ||
| 24 | + # add NullHandler to root-module logger so that individual modules | ||
| 25 | + # won't have to. | ||
| 26 | + logging.getLogger(__name__).addHandler(logging.NullHandler()) | ||
| 27 | + | ||
| 23 | 28 | # pylint: disable=invalid-name | |
| 24 | 29 | SpannerApi = api.SpannerApi | |
| 25 | 30 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,11 +15,14 @@ | |||
| 15 | 15 | """Class that handles API calls to Spanner.""" | |
| 16 | 16 | ||
| 17 | 17 | import abc | |
| 18 | + import logging | ||
| 18 | 19 | ||
| 19 | 20 | from spanner_orm import error | |
| 20 | 21 | ||
| 21 | 22 | from google.cloud import spanner | |
| 22 | 23 | ||
| 24 | + _logger = logging.getLogger(__name__) | ||
| 25 | + | ||
| 23 | 26 | ||
| 24 | 27 | class SpannerReadApi(abc.ABC): | |
| 25 | 28 | """Handles sending read requests to Spanner""" | |
@@ -39,13 +42,17 @@ def run_read_only(cls, method, *args, **kwargs): | |||
| 39 | 42 | @staticmethod | |
| 40 | 43 | def find(transaction, table_name, columns, keyset): | |
| 41 | 44 | """Obtains rows with primary_keys from the given table.""" | |
| 45 | + _logger.debug('Find table=%s columns=%s keys=%s', | ||
| 46 | + table_name, columns, keyset.keys) | ||
| 42 | 47 | stream_results = transaction.read( | |
| 43 | 48 | table=table_name, columns=columns, keyset=keyset) | |
| 44 | 49 | return list(stream_results) | |
| 45 | 50 | ||
| 46 | 51 | @staticmethod | |
| 47 | 52 | def sql_query(transaction, query, parameters, parameter_types): | |
| 48 | 53 | """Runs a read only SQL query.""" | |
| 54 | + _logger.debug('Executing SQL:\n%s\n%s\n%s', | ||
| 55 | + query, parameters, parameter_types) | ||
| 49 | 56 | stream_results = transaction.execute_sql( | |
| 50 | 57 | query, params=parameters, param_types=parameter_types) | |
| 51 | 58 | return list(stream_results) | |
@@ -68,16 +75,22 @@ def run_write(cls, *args, **kwargs): | |||
| 68 | 75 | @staticmethod | |
| 69 | 76 | def insert(transaction, table_name, columns, values): | |
| 70 | 77 | """Add rows to a table.""" | |
| 78 | + _logger.debug('Insert table=%s columns=%s values=%s', | ||
| 79 | + table_name, columns, values) | ||
| 71 | 80 | transaction.insert(table=table_name, columns=columns, values=values) | |
| 72 | 81 | ||
| 73 | 82 | @staticmethod | |
| 74 | 83 | def update(transaction, table_name, columns, values): | |
| 75 | 84 | """Updates rows of a table.""" | |
| 85 | + _logger.debug('Update table=%s columns=%s values=%s', | ||
| 86 | + table_name, columns, values) | ||
| 76 | 87 | transaction.update(table=table_name, columns=columns, values=values) | |
| 77 | 88 | ||
| 78 | 89 | @staticmethod | |
| 79 | 90 | def upsert(transaction, table_name, columns, values): | |
| 80 | 91 | """Updates existing rows of a table or adds rows if they don't exist.""" | |
| 92 | + _logger.debug('Upsert table=%s columns=%s values=%s', | ||
| 93 | + table_name, columns, values) | ||
| 81 | 94 | transaction.insert_or_update( | |
| 82 | 95 | table=table_name, columns=columns, values=values) | |
| 83 | 96 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,7 @@ | |||
| 12 | 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | 13 | # See the License for the specific language governing permissions and | |
| 14 | 14 | # limitations under the License. | |
| 15 | - | ||
| 15 | + import logging | ||
| 16 | 16 | import unittest | |
| 17 | 17 | from unittest import mock | |
| 18 | 18 | ||
@@ -86,4 +86,5 @@ def test_metadata(self, columns, index_columns, indexes): | |||
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | 88 | if __name__ == '__main__': | |
| 89 | + logging.basicConfig() | ||
| 89 | 90 | unittest.main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,6 +13,7 @@ | |||
| 13 | 13 | # See the License for the specific language governing permissions and | |
| 14 | 14 | # limitations under the License. | |
| 15 | 15 | ||
| 16 | + import logging | ||
| 16 | 17 | import unittest | |
| 17 | 18 | from unittest import mock | |
| 18 | 19 | ||
@@ -57,4 +58,5 @@ def mock_connection(self, client): | |||
| 57 | 58 | ||
| 58 | 59 | ||
| 59 | 60 | if __name__ == '__main__': | |
| 61 | + logging.basicConfig() | ||
| 60 | 62 | unittest.main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ | |||
| 14 | 14 | # limitations under the License. | |
| 15 | 15 | ||
| 16 | 16 | import datetime | |
| 17 | + import logging | ||
| 17 | 18 | import unittest | |
| 18 | 19 | ||
| 19 | 20 | from spanner_orm import error | |
@@ -131,4 +132,5 @@ def test_error_on_unretrieved_relation_get(self): | |||
| 131 | 132 | ||
| 132 | 133 | ||
| 133 | 134 | if __name__ == '__main__': | |
| 135 | + logging.basicConfig() | ||
| 134 | 136 | unittest.main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ | |||
| 14 | 14 | # limitations under the License. | |
| 15 | 15 | ||
| 16 | 16 | import datetime | |
| 17 | + import logging | ||
| 17 | 18 | import unittest | |
| 18 | 19 | from unittest import mock | |
| 19 | 20 | ||
@@ -255,4 +256,5 @@ def test_includes_error_on_invalid_subconditions(self): | |||
| 255 | 256 | ||
| 256 | 257 | ||
| 257 | 258 | if __name__ == '__main__': | |
| 259 | + logging.basicConfig() | ||
| 258 | 260 | unittest.main() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments