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

feat: add interval fields #110

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions crates/codegen/src/get_node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,9 @@ fn custom_handlers(node: &Node) -> TokenStream {
},
"interval" => {
// Adapted from https://github.com/postgres/postgres/blob/REL_15_STABLE/src/backend/utils/adt/timestamp.c#L1103
const MONTH: i32 = 1;
const YEAR: i32 = 2;
const DAY: i32 = 3;
const HOUR: i32 = 10;
const MINUTE: i32 = 11;
const SECOND: i32 = 12;
Expand All @@ -894,10 +897,41 @@ fn custom_handlers(node: &Node) -> TokenStream {

if let Some(fields) = fields {
match fields.clone() {
// YEAR TO MONTH
i if i == 1 << YEAR | 1 << MONTH => {
tokens.push(TokenProperty::from(Token::To));
tokens.push(TokenProperty::from(Token::MonthP));
},
// DAY TO HOUR
i if i == 1 << DAY | 1 << HOUR => {
tokens.push(TokenProperty::from(Token::To));
tokens.push(TokenProperty::from(Token::HourP));
},
// DAY TO MINUTE
i if i == 1 << DAY | 1 << HOUR | 1 << MINUTE => {
tokens.push(TokenProperty::from(Token::To));
tokens.push(TokenProperty::from(Token::MinuteP));
},
// DAY TO SECOND
i if i == 1 << DAY | 1 << HOUR | 1 << MINUTE | 1 << SECOND => {
tokens.push(TokenProperty::from(Token::To));
tokens.push(TokenProperty::from(Token::SecondP));
},
// HOUR TO MINUTE
i if i == 1 << HOUR | 1 << MINUTE => {
tokens.push(TokenProperty::from(Token::To));
tokens.push(TokenProperty::from(Token::MinuteP));
},
// HOUR TO SECOND
i if i == 1 << HOUR | 1 << MINUTE | 1 << SECOND => {
tokens.push(TokenProperty::from(Token::To));
tokens.push(TokenProperty::from(Token::SecondP));
},
// MINUTE TO SECOND
i if i == 1 << MINUTE | 1 << SECOND => {
tokens.push(TokenProperty::from(Token::To));
tokens.push(TokenProperty::from(Token::SecondP));
},
_ => panic!("Unknown Interval fields {:#?}", fields),
}
}
Expand Down