Add support SET TRANSACTION statements.#81
Add support SET TRANSACTION statements.#81jellelicht wants to merge 1 commit intooguimbal:masterfrom
SET TRANSACTION statements.#81Conversation
SET TRANSACTION statements.SET TRANSACTION statements.
| 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.
Should this maybe be a boolean?
There was a problem hiding this comment.
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.
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
| @@ -247,6 +247,26 @@ describe('Simple statements', () => { | |||
| }) | |||
|
|
|||
|
|
|||
There was a problem hiding this comment.
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.
oguimbal
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
- 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):* {% |
| @@ -247,6 +247,26 @@ describe('Simple statements', () => { | |||
| }) | |||
|
|
|||
|
|
|||
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.