feat: add FOR UPDATE/FOR SHARE clause (#418)

* feat: add FOR UPDATE/FOR SHARE clause

* refactor: LockType enum variant name

Co-authored-by: gamife <gamife9886@gmail.com>
This commit is contained in:
gamife 2022-02-24 13:39:38 +08:00 committed by GitHub
parent 899f91b1f6
commit 0b5178d7e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 4 deletions

View file

@ -2649,6 +2649,12 @@ impl<'a> Parser<'a> {
None
};
let lock = if self.parse_keyword(Keyword::FOR) {
Some(self.parse_lock()?)
} else {
None
};
Ok(Query {
with,
body,
@ -2656,6 +2662,7 @@ impl<'a> Parser<'a> {
limit,
offset,
fetch,
lock,
})
} else {
let insert = self.parse_insert()?;
@ -2667,6 +2674,7 @@ impl<'a> Parser<'a> {
order_by: vec![],
offset: None,
fetch: None,
lock: None,
})
}
}
@ -3639,6 +3647,15 @@ impl<'a> Parser<'a> {
})
}
/// Parse a FOR UPDATE/FOR SHARE clause
pub fn parse_lock(&mut self) -> Result<LockType, ParserError> {
match self.expect_one_of_keywords(&[Keyword::UPDATE, Keyword::SHARE])? {
Keyword::UPDATE => Ok(LockType::Update),
Keyword::SHARE => Ok(LockType::Share),
_ => unreachable!(),
}
}
pub fn parse_values(&mut self) -> Result<Values, ParserError> {
let values = self.parse_comma_separated(|parser| {
parser.expect_token(&Token::LParen)?;