-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support stale reads #146
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0590cd0
feat: support stale reads
1de41a7
Update README.md
4796b9c
fix
493a7df
Merge branch 'stale_reads' of https://github.com/cloudspannerecosyste…
848dc58
Update README.md
094927e
Merge branch 'main' into stale_reads
skuruppu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,9 @@ | |
from sqlalchemy import ForeignKeyConstraint, types, util | ||
from sqlalchemy.engine.base import Engine | ||
from sqlalchemy.engine.default import DefaultDialect, DefaultExecutionContext | ||
from sqlalchemy.event import listens_for | ||
from sqlalchemy.ext.compiler import compiles | ||
from sqlalchemy.pool import Pool | ||
from sqlalchemy.sql.compiler import ( | ||
selectable, | ||
DDLCompiler, | ||
|
@@ -38,6 +40,13 @@ | |
from google.cloud import spanner_dbapi | ||
from google.cloud.sqlalchemy_spanner._opentelemetry_tracing import trace_call | ||
|
||
|
||
@listens_for(Pool, "reset") | ||
def reset_connection(dbapi_conn, connection_record): | ||
"""An event of returning a connection back to a pool.""" | ||
dbapi_conn.connection.staleness = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the docs, connection the hook to the |
||
|
||
|
||
# Spanner-to-SQLAlchemy types map | ||
_type_map = { | ||
"BOOL": types.Boolean, | ||
|
@@ -128,6 +137,10 @@ def pre_exec(self): | |
if read_only is not None: | ||
self._dbapi_connection.connection.read_only = read_only | ||
|
||
staleness = self.execution_options.get("staleness", None) | ||
if staleness is not None: | ||
self._dbapi_connection.connection.staleness = staleness | ||
|
||
|
||
class SpannerIdentifierPreparer(IdentifierPreparer): | ||
"""Identifiers compiler. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read timestamp and minimum read timestamp expect a
datetime.datetime
object.Maximum staleness and exact staleness expect a
datetime.timedelta
object.This should probably be documented here in some way, possibly with examples for each, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, added examples for all of them