-
Notifications
You must be signed in to change notification settings - Fork 47
Add support SET TRANSACTION statements.
#81
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
base: master
Are you sure you want to change the base?
Conversation
SET TRANSACTION statements.SET TRANSACTION statements.
janpaepke
left a comment
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.
| export interface SetTransactionMode extends PGNode { | ||
| type: 'set transaction' | 'set session characteristics as transaction'; | ||
| isolationLevel: 'serializable' | 'repeatable read' | 'read committed' | 'read uncommitted'; | ||
| writeable?: 'read write' | 'read only'; |
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.
Should this maybe be a boolean?
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.
I agree, if you use deferable as boolean, it would make more sense to have a writeable as boolean as well.
In fact, given that "writeable" is the default behaviour, it would perhaps be more relevent to have a readonlyMode: boolean or something like that ?
That would allow code like:
if (!node.readonlyMode) {
// do something if writeable
}to behave as expected when the writeability is not explicitely provided
| snapshotId: Name; | ||
| } | ||
|
|
||
| export interface SetTransactionMode extends PGNode { |
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.
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.
yes, it should: this typing suggests that set session characteristics as transaction deferrable , isolation level read uncommitted , isolation level read committed , read write is not a valid statement... but it is 🤷♂️ try it
=> The fact that my typing suggestion involves an array of characteristics reflects that
| deferrable: false, | ||
| }) | ||
|
|
||
|
|
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.
From what I understand, in both SET TRANSACTION as well as SET SESSION CHARACTERISTICS [...] the transaction_modes can be separated with a comma. I think there was also one in your initial example? 🤔
If true, this version should be added to the tests.
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.
yup
oguimbal
left a comment
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.
Good job on this first PR :) Thanks !
Not bad at all.
There are several fixes to make this mergeable though
| }) | ||
|
|
||
|
|
||
| checkStatement(`set transaction SNAPSHOT mysnapshot`, { |
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.
the snapshot ID is supposed to be a string (this statement is not parsable against a real db)
set transaction SNAPSHOT 'mysnapshot'is OK
| snapshotId: Name; | ||
| } | ||
|
|
||
| export interface SetTransactionMode extends PGNode { |
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.
yes, it should: this typing suggests that set session characteristics as transaction deferrable , isolation level read uncommitted , isolation level read committed , read write is not a valid statement... but it is 🤷♂️ try it
=> The fact that my typing suggestion involves an array of characteristics reflects that
| export interface SetTransactionMode extends PGNode { | ||
| type: 'set transaction' | 'set session characteristics as transaction'; | ||
| isolationLevel: 'serializable' | 'repeatable read' | 'read committed' | 'read uncommitted'; | ||
| writeable?: 'read write' | 'read only'; |
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.
I agree, if you use deferable as boolean, it would make more sense to have a writeable as boolean as well.
In fact, given that "writeable" is the default behaviour, it would perhaps be more relevent to have a readonlyMode: boolean or something like that ?
That would allow code like:
if (!node.readonlyMode) {
// do something if writeable
}to behave as expected when the writeability is not explicitely provided
|
|
||
| simplestatements_set_session | ||
| -> kw_session kw_characteristics %kw_as kw_transaction | ||
| (simplestatements_begin_isol | simplestatements_begin_writ | simplestatements_begin_def):* {% |
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.
- session characteristics may (optionally) be separated by commas.
- providing no transaction characteristic should not be valid (it is with this implementation)
i.e.
set session characteristics as transaction deferrable , isolation level read uncommitted, read writeAND
set session characteristics as transaction deferrable isolation level read uncommitted read writeare both valid.
=> there shouldb be some kind of %comma:? somewhere :)
For instance, something like this should fix both issues
%kw_as kw_transaction sess_characteristics (%comma:? sess_characteristics):*
(please add UTs to check that the syntax with commas is OK too)
| %} | ||
|
|
||
| simplestatements_set_transaction | ||
| -> kw_transaction (simplestatements_begin_isol | simplestatements_begin_writ | simplestatements_begin_def):* {% |
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.
same remark
| deferrable: false, | ||
| }) | ||
|
|
||
|
|
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.
yup
First attempt to fix #76; I went for more similarity to the existing
BEGINstatement.Please advise if I missed something, or if I've misunderstood the instructions.