Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 6 additions & 12 deletions codegen/src/worktable/generator/table/select_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,7 @@ use syn::Type;
fn is_numeric_type(ty: &Type) -> bool {
matches!(
ty.to_token_stream().to_string().as_str(),
"i8" | "i16"
| "i32"
| "i64"
| "i128"
| "u8"
| "u16"
| "u32"
| "u64"
| "u128"
| "f32"
| "f64"
"i8" | "i16" | "i32" | "i64" | "i128" | "u8" | "u16" | "u32" | "u64" | "u128"
)
}

Expand Down Expand Up @@ -66,7 +56,11 @@ impl Generator {
}
impl From<std::ops::Range<#type_ident>> for #column_range_type {
fn from(range: std::ops::Range<#type_ident>) -> Self {
let end = range.end.saturating_sub(1);
let end = if range.end > range.start {
range.end.saturating_sub(1)
} else {
range.end
};
Self::#variant_ident(range.start..=end)
}
}
Expand Down
2 changes: 2 additions & 0 deletions examples/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn main() {
test: u8,
attr: String,
attr2: i16,
attr_float: f64,

},
indexes: {
Expand Down Expand Up @@ -41,6 +42,7 @@ fn main() {
attr2: 345,
test: 1,
id: 0,
attr_float: 100.0,
};

// insert
Expand Down
50 changes: 50 additions & 0 deletions tests/worktable/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ worktable! (
}
);

worktable! (
name: TestFloat,
columns: {
id: u64 primary_key autoincrement,
test: i64,
another: f64,
exchange: String
},
indexes: {
test_idx: test unique,
exchnage_idx: exchange,
}
);

#[test]
fn table_name() {
let table = TestWorkTable::default();
Expand Down Expand Up @@ -645,6 +659,42 @@ fn select_all_where_by_eq_string_test() {
assert_eq!(equal.len(), 1);
}

#[test]
fn select_all_range_float_test() {
let table = TestFloatWorkTable::default();

let row1 = TestFloatRow {
id: table.get_next_pk().into(),
test: 3,
another: 100.0,
exchange: "M".to_string(),
};
let row2 = TestFloatRow {
id: table.get_next_pk().into(),
test: 1,
another: 200.0,
exchange: "N".to_string(),
};
let row3 = TestFloatRow {
id: table.get_next_pk().into(),
test: 2,
another: 300.0,
exchange: "P".to_string(),
};

let _ = table.insert(row1.clone()).unwrap();
let _ = table.insert(row2.clone()).unwrap();
let _ = table.insert(row3.clone()).unwrap();

let all = table
.select_all()
.where_by(|row| row.another > 99.0 && row.another < 300.0)
.execute()
.unwrap();

assert_eq!(all.len(), 2);
}

#[test]
fn select_all_where_by_contains_string_test() {
let table = TestWorkTable::default();
Expand Down
Loading