Skip to content
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

Add support SET TRANSACTION statements. #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jellelicht
Copy link

First attempt to fix #76; I went for more similarity to the existing BEGIN statement.
Please advise if I missed something, or if I've misunderstood the instructions.

@jellelicht jellelicht changed the title Add support for initial support SET TRANSACTION statements. Add support SET TRANSACTION statements. May 12, 2022
Copy link
Contributor

@janpaepke janpaepke left a comment

Choose a reason for hiding this comment

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

Good stuff.

Have you seen @oguimbal's suggestion in #76 to use toStr(matchedStatement).toLowerCase()? Might make the extraction functions more readable?

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';
Copy link
Contributor

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?

Copy link
Owner

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

might make sense to add more granular types? (see suggestion by @oguimbal in #76)

Copy link
Owner

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

@@ -247,6 +247,26 @@ describe('Simple statements', () => {
})


Copy link
Contributor

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.

Copy link
Owner

Choose a reason for hiding this comment

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

yup

Copy link
Owner

@oguimbal oguimbal left a 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

@@ -247,6 +247,26 @@ describe('Simple statements', () => {
})


checkStatement(`set transaction SNAPSHOT mysnapshot`, {
Copy link
Owner

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 {
Copy link
Owner

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';
Copy link
Owner

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):* {%
Copy link
Owner

Choose a reason for hiding this comment

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

  1. session characteristics may (optionally) be separated by commas.
  2. 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 write

AND

set session characteristics as transaction deferrable  isolation level read uncommitted read write

are 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):* {%
Copy link
Owner

Choose a reason for hiding this comment

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

same remark

@@ -247,6 +247,26 @@ describe('Simple statements', () => {
})


Copy link
Owner

Choose a reason for hiding this comment

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

yup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SET TRANSACTION ... statement not supported
3 participants