Skip to content

Commit db9eb90

Browse files
committed
feat: Support selecting is_dir and is_file
1 parent f2403ab commit db9eb90

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ SELECT DISTINCT parent AS folders FROM files
4444

4545
### Files table structure
4646

47-
| Name | Type | Description |
48-
| --------- | ------- | --------------------- |
49-
| path | Text | File path |
50-
| parent | Text | File parent path |
51-
| extension | Text | Extension of the file |
52-
| size | Integer | Size of the file |
47+
| Name | Type | Description |
48+
| --------- | ------- | ------------------------ |
49+
| path | Text | File path |
50+
| parent | Text | File parent path |
51+
| extension | Text | Extension of the file |
52+
| is_dir | Boolean | True if it's a directory |
53+
| is_file | Boolean | True if it's a file |
54+
| size | Integer | Size of the file |
5355

5456
---
5557

src/data_provider.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl DataProvider for FileDataProvider {
6262

6363
for file in files {
6464
let mut values: Vec<Value> = vec![];
65+
let path = Path::new(&file);
6566

6667
for index in 0..names_len {
6768
let field_name = &fields_names[index as usize];
@@ -76,14 +77,12 @@ impl DataProvider for FileDataProvider {
7677
}
7778

7879
if field_name == "path" {
79-
let path = Path::new(&file);
8080
let file_path_string = path.to_str().unwrap_or("");
8181
values.push(Value::Text(file_path_string.to_string()));
8282
continue;
8383
}
8484

8585
if field_name == "parent" {
86-
let path = Path::new(&file);
8786
let parent_path = if let Some(parent) = path.parent() {
8887
parent.to_str().unwrap_or("")
8988
} else {
@@ -94,12 +93,21 @@ impl DataProvider for FileDataProvider {
9493
}
9594

9695
if field_name == "extension" {
97-
let path = Path::new(&file);
9896
let extension = path.extension().and_then(|ext| ext.to_str()).unwrap_or("");
9997
values.push(Value::Text(extension.to_string()));
10098
continue;
10199
}
102100

101+
if field_name == "is_dir" {
102+
values.push(Value::Boolean(path.is_dir()));
103+
continue;
104+
}
105+
106+
if field_name == "is_file" {
107+
values.push(Value::Boolean(path.is_file()));
108+
continue;
109+
}
110+
103111
if field_name == "size" {
104112
let file_size = if let Ok(meta_data) = std::fs::metadata(&file) {
105113
meta_data.len() as i64

src/schema.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ lazy_static! {
88
map.insert("path", DataType::Text);
99
map.insert("parent", DataType::Text);
1010
map.insert("extension", DataType::Text);
11+
map.insert("is_dir", DataType::Boolean);
12+
map.insert("is_file", DataType::Boolean);
1113
map.insert("size", DataType::Integer);
1214
map
1315
};
@@ -16,7 +18,10 @@ lazy_static! {
1618
lazy_static! {
1719
pub static ref TABLES_FIELDS_NAMES: HashMap<&'static str, Vec<&'static str>> = {
1820
let mut map = HashMap::new();
19-
map.insert("files", vec!["path", "parent", "extension", "size"]);
21+
map.insert(
22+
"files",
23+
vec!["path", "parent", "extension", "is_dir", "is_file", "size"],
24+
);
2025
map
2126
};
2227
}

0 commit comments

Comments
 (0)