Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

refactor(db_api): cleanup the code#636

Merged
gcf-merge-on-green[bot] merged 6 commits intogoogleapis:mainfrom
MaxxleLLC:refactor
Nov 25, 2021
Merged

refactor(db_api): cleanup the code#636
gcf-merge-on-green[bot] merged 6 commits intogoogleapis:mainfrom
MaxxleLLC:refactor

Conversation

@IlyaFaer
Copy link
Copy Markdown

@IlyaFaer IlyaFaer commented Nov 2, 2021

No description provided.

@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 2, 2021
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the googleapis/python-spanner API. label Nov 2, 2021
TABLE_SCHEMA = ''
AND
TABLE_NAME = @table_name
"""
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excess cumbersome formatting

table = parts.get("table")
columns = parts.get("columns")
values = parts.get("values")
return transaction.insert(table, columns, values)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excess variables


return function(connection, *args, **kwargs)

return wrapper
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving the check into a decorator, as we planned long ago


def _do_execute_update(self, transaction, sql, params):
sql = parse_utils.ensure_where_clause(sql)
sql, params = parse_utils.sql_pyformat_args_to_spanner(sql, params)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are the same lines earlier, but under an if statement. Merging both cases into one.

statements.append(ddl)

# Only queue DDL statements if they are all correctly classified.
self.connection._ddl_statements.extend(statements)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating DDLs batching into a method

# self._run_prior_DDL_statements()
self.connection.run_prior_DDL_statements()

if not self.connection.autocommit:
Copy link
Copy Markdown
Author

@IlyaFaer IlyaFaer Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving several commands away of this if statement to avoid duplicating them in the further methods calls



def parse_values(stmt):
return expect(stmt, VALUES)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is used only once and is quite simple. Let's erase it

return "", pyfmt_str

# Otherwise we expect a function.
return expect(word, FUNC)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't find where EXPR is passed into the method, so I guess it's not actually used

:returns: A tree of the already parsed expression.
"""
_, _values = parse_values(values_stmt)
return _values
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused function

@IlyaFaer IlyaFaer marked this pull request as ready for review November 22, 2021 12:13
@IlyaFaer IlyaFaer requested review from a team and larkee November 22, 2021 12:13
@larkee larkee added the automerge Merge the pull request once unit tests and other checks pass. label Nov 25, 2021
@gcf-merge-on-green gcf-merge-on-green Bot merged commit 8e2cf04 into googleapis:main Nov 25, 2021
@gcf-merge-on-green gcf-merge-on-green Bot removed the automerge Merge the pull request once unit tests and other checks pass. label Nov 25, 2021
@IlyaFaer IlyaFaer deleted the refactor branch November 25, 2021 08:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: spanner Issues related to the googleapis/python-spanner API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants