diff --git a/Cargo.lock b/Cargo.lock index 3c15aa7..8193abf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,15 +34,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.3.2" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bumpalo" @@ -76,14 +70,14 @@ dependencies = [ "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.0", + "windows-targets", ] [[package]] name = "comfy-table" -version = "7.1.0" +version = "7.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c64043d6c7b7a4c58e39e7efccfdea7b93d885a795d0c054a69dbbf4dd52686" +checksum = "b34115915337defe99b2aff5c2ce6771e5fbc4079f4b506301f5cf394c8452f7" dependencies = [ "crossterm", "strum", @@ -103,7 +97,7 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" dependencies = [ - "bitflags 2.4.2", + "bitflags", "crossterm_winapi", "libc", "parking_lot", @@ -140,9 +134,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "fileql" -version = "0.8.0" +version = "0.9.0" dependencies = [ "gitql-ast", "gitql-cli", @@ -165,42 +171,45 @@ dependencies = [ [[package]] name = "gitql-ast" -version = "0.25.0" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccfe61481132151fdf0878c5d9dcdc8c7a99d06fbe1ccc6538c0a5ce63c6ec20" +checksum = "d78a05238b1958b362717b8e9eab9f0bdd4af5afc4c585ea971b71de50db0038" dependencies = [ - "gitql-core", + "dyn-clone", ] [[package]] name = "gitql-cli" -version = "0.28.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef72318486c350b90cabcd5efdb7ab0c2275ba23605ff11d71c522a13545a1e8" +checksum = "f05b216a66d0180409f9f61849ab98584850a082193049a7e9417be533f13eda" dependencies = [ "comfy-table", + "csv", "gitql-ast", "gitql-core", "gitql-parser", + "serde_json", "termcolor", ] [[package]] name = "gitql-core" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfb7e49988ee709f5b61be226503f68cb3781832b625e3a990180d6c174f0367" +checksum = "353206a67ce0b10432165d3ebf87f30aac2e48eb23625902def459a7d74e76ed" dependencies = [ "chrono", - "csv", - "serde_json", + "dyn-clone", + "gitql-ast", + "indexmap", ] [[package]] name = "gitql-engine" -version = "0.28.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da75c1150718f55249af8b70fc115d9f09959661293a3af06839f8b769f1425" +checksum = "e2314639d63b3e3a496c177d210ed0cd6ca8045e0b017e4899cb27d4f998435d" dependencies = [ "chrono", "gitql-ast", @@ -210,9 +219,9 @@ dependencies = [ [[package]] name = "gitql-parser" -version = "0.27.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59af3408cec8c3f63ab7a6030be1aec980ca74c1d4c0dc870790842b291db13" +checksum = "62da24b55ac59f7421ee21c2b01e1b4ddca871c39ef602ddf4f1626a6bb099a5" dependencies = [ "gitql-ast", "gitql-core", @@ -220,22 +229,29 @@ dependencies = [ [[package]] name = "gitql-std" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3908a86eb9b8e36d44f1c716a317851feb9c9a2d8617de725f8d50d60dab4cca" +checksum = "458e07059e4279211b37d895eb96dc64db7fc0d92e3c0dc19cf37172c7bee3cc" dependencies = [ "chrono", + "gitql-ast", "gitql-core", "rand", "regex", "uuid", ] +[[package]] +name = "hashbrown" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" + [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "iana-time-zone" @@ -260,6 +276,16 @@ dependencies = [ "cc", ] +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown", +] + [[package]] name = "itoa" version = "1.0.10" @@ -283,9 +309,9 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -320,9 +346,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", @@ -330,15 +356,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-targets 0.48.5", + "windows-targets", ] [[package]] @@ -397,11 +423,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ - "bitflags 1.3.2", + "bitflags", ] [[package]] @@ -435,9 +461,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" [[package]] name = "ryu" @@ -484,21 +510,21 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.1" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "strum" -version = "0.25.0" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" [[package]] name = "strum_macros" -version = "0.25.3" +version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ "heck", "proc-macro2", @@ -535,9 +561,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "uuid" @@ -626,11 +652,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "winapi", + "windows-sys", ] [[package]] @@ -645,22 +671,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.0", + "windows-targets", ] [[package]] -name = "windows-targets" -version = "0.48.5" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -669,93 +689,51 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" dependencies = [ - "windows_aarch64_gnullvm 0.52.0", - "windows_aarch64_msvc 0.52.0", - "windows_i686_gnu 0.52.0", - "windows_i686_msvc 0.52.0", - "windows_x86_64_gnu 0.52.0", - "windows_x86_64_gnullvm 0.52.0", - "windows_x86_64_msvc 0.52.0", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 79c5b5d..68ec0c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "fileql" authors = ["AmrDeveloper"] -version = "0.8.0" +version = "0.9.0" edition = "2021" description = "A tool to run SQL-like query on local files using GitQL SDK" license = "MIT" @@ -13,9 +13,9 @@ categories = ["command-line-utilities"] exclude = [".github/**", "docs/**", "media/**", "scripts/**"] [dependencies] -gitql-core = "0.5.0" -gitql-std = "0.5.0" -gitql-cli = "0.28.0" -gitql-ast = "0.25.0" -gitql-parser = "0.27.0" -gitql-engine = "0.28.0" +gitql-core = "0.7.0" +gitql-std = "0.7.0" +gitql-ast = "0.27.0" +gitql-parser = "0.29.0" +gitql-cli = "0.30.0" +gitql-engine = "0.30.0" diff --git a/src/data_provider.rs b/src/data_provider.rs index 840f1e5..61bcc73 100644 --- a/src/data_provider.rs +++ b/src/data_provider.rs @@ -1,7 +1,11 @@ use std::path::Path; use gitql_core::object::Row; -use gitql_core::value::Value; +use gitql_core::values::base::Value; +use gitql_core::values::boolean::BoolValue; +use gitql_core::values::integer::IntValue; +use gitql_core::values::null::NullValue; +use gitql_core::values::text::TextValue; use gitql_engine::data_provider::DataProvider; pub struct FileDataProvider { @@ -32,13 +36,14 @@ fn select_files( let files = collect_paths_nested_files(paths, excludes); let mut rows: Vec = Vec::with_capacity(paths.len()); for file in files.iter() { - let mut values: Vec = Vec::with_capacity(selected_columns.len()); + let mut values: Vec> = Vec::with_capacity(selected_columns.len()); let path = Path::new(&file); for column_name in selected_columns { if column_name == "path" { let file_path_string = path.to_str().unwrap_or(""); - values.push(Value::Text(file_path_string.to_string())); + let value = file_path_string.to_string(); + values.push(Box::new(TextValue { value })); continue; } @@ -48,23 +53,30 @@ fn select_files( } else { "" }; - values.push(Value::Text(parent_path.to_string())); + let value = parent_path.to_string(); + values.push(Box::new(TextValue { value })); continue; } if column_name == "extension" { - let extension = path.extension().and_then(|ext| ext.to_str()).unwrap_or(""); - values.push(Value::Text(extension.to_string())); + let value = path + .extension() + .and_then(|ext| ext.to_str()) + .unwrap_or("") + .to_string(); + values.push(Box::new(TextValue { value })); continue; } if column_name == "is_dir" { - values.push(Value::Boolean(path.is_dir())); + let value = path.is_dir(); + values.push(Box::new(BoolValue { value })); continue; } if column_name == "is_file" { - values.push(Value::Boolean(path.is_file())); + let value = path.is_file(); + values.push(Box::new(BoolValue { value })); continue; } @@ -74,11 +86,11 @@ fn select_files( } else { 0 }; - values.push(Value::Integer(file_size)); + values.push(Box::new(IntValue { value: file_size })); continue; } - values.push(Value::Null); + values.push(Box::new(NullValue)); } rows.push(Row { values }); diff --git a/src/functions.rs b/src/functions.rs index 34aa686..651d714 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -1,7 +1,9 @@ +use gitql_ast::types::integer::IntType; +use gitql_ast::types::text::TextType; use gitql_core::signature::Function; use gitql_core::signature::Signature; -use gitql_core::types::DataType; -use gitql_core::value::Value; +use gitql_core::values::base::Value; +use gitql_core::values::integer::IntValue; use gitql_std::function::standard_function_signatures; use gitql_std::function::standard_functions; use std::collections::HashMap; @@ -16,26 +18,25 @@ pub fn fileql_std_functions() -> &'static HashMap<&'static str, Function> { }) } -pub fn fileql_std_signatures() -> &'static HashMap<&'static str, Signature> { - static HASHMAP: OnceLock> = OnceLock::new(); - HASHMAP.get_or_init(|| { - let mut map: HashMap<&'static str, Signature> = standard_function_signatures().to_owned(); - map.insert( - "files_count", - Signature { - parameters: vec![DataType::Text], - return_type: DataType::Integer, - }, - ); - map - }) +pub fn fileql_std_signatures() -> HashMap<&'static str, Signature> { + let mut map: HashMap<&'static str, Signature> = standard_function_signatures().to_owned(); + map.insert( + "files_count", + Signature { + parameters: vec![Box::new(TextType)], + return_type: Box::new(IntType), + }, + ); + map } -fn files_count(values: &[Value]) -> Value { - let path = values[0].as_text(); +fn files_count(values: &[Box]) -> Box { + let path = values[0].as_text().unwrap(); if let Ok(entries) = std::fs::read_dir(path) { let count = entries.flatten().count(); - return Value::Integer(count as i64); + return Box::new(IntValue { + value: count as i64, + }); } - Value::Integer(0) + Box::new(IntValue { value: 0 }) } diff --git a/src/main.rs b/src/main.rs index d409070..bea9d35 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,10 @@ use data_provider::FileDataProvider; use gitql_cli::arguments::OutputFormat; use gitql_cli::diagnostic_reporter; use gitql_cli::diagnostic_reporter::DiagnosticReporter; -use gitql_cli::render; +use gitql_cli::printer::base::OutputPrinter; +use gitql_cli::printer::csv_printer::CSVPrinter; +use gitql_cli::printer::json_printer::JSONPrinter; +use gitql_cli::printer::table_printer::TablePrinter; use gitql_core::environment::Environment; use gitql_core::schema::Schema; use gitql_engine::data_provider::DataProvider; @@ -56,8 +59,8 @@ fn main() { let aggregation_functions = aggregation_functions(); let mut env = Environment::new(schema); - env.with_standard_functions(std_signatures, std_functions); - env.with_aggregation_functions(aggregation_signatures, aggregation_functions); + env.with_standard_functions(&std_signatures, std_functions); + env.with_aggregation_functions(&aggregation_signatures, aggregation_functions); execute_fileql_query(query, &arguments, files, &mut env, &mut reporter); } @@ -93,8 +96,8 @@ fn launch_fileql_repl(arguments: Arguments) { let aggregation_functions = aggregation_functions(); let mut global_env = Environment::new(schema); - global_env.with_standard_functions(std_signatures, std_functions); - global_env.with_aggregation_functions(aggregation_signatures, aggregation_functions); + global_env.with_standard_functions(&std_signatures, std_functions); + global_env.with_aggregation_functions(&aggregation_signatures, aggregation_functions); let mut input = String::new(); @@ -190,21 +193,14 @@ fn execute_fileql_query( // Render the result only if they are selected groups not any other statement let engine_result = evaluation_result.ok().unwrap(); if let SelectedGroups(mut groups) = engine_result { - match arguments.output_format { + let printer: Box = match arguments.output_format { OutputFormat::Render => { - render::render_objects(&mut groups, arguments.pagination, arguments.page_size); + Box::new(TablePrinter::new(arguments.pagination, arguments.page_size)) } - OutputFormat::JSON => { - if let Ok(json) = groups.as_json() { - println!("{}", json); - } - } - OutputFormat::CSV => { - if let Ok(csv) = groups.as_csv() { - println!("{}", csv); - } - } - } + OutputFormat::JSON => Box::new(JSONPrinter {}), + OutputFormat::CSV => Box::new(CSVPrinter {}), + }; + printer.print(&mut groups); } let engine_duration = engine_start.elapsed(); diff --git a/src/schema.rs b/src/schema.rs index 57a1e85..99bc8c0 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,19 +1,20 @@ -use gitql_core::types::DataType; use std::collections::HashMap; use std::sync::OnceLock; -pub fn tables_fields_types() -> &'static HashMap<&'static str, DataType> { - static HASHMAP: OnceLock> = OnceLock::new(); - HASHMAP.get_or_init(|| { - let mut map = HashMap::new(); - map.insert("path", DataType::Text); - map.insert("parent", DataType::Text); - map.insert("extension", DataType::Text); - map.insert("is_dir", DataType::Boolean); - map.insert("is_file", DataType::Boolean); - map.insert("size", DataType::Integer); - map - }) +use gitql_ast::types::base::DataType; +use gitql_ast::types::boolean::BoolType; +use gitql_ast::types::integer::IntType; +use gitql_ast::types::text::TextType; + +pub fn tables_fields_types() -> HashMap<&'static str, Box> { + let mut map: HashMap<&'static str, Box> = HashMap::new(); + map.insert("path", Box::new(TextType)); + map.insert("parent", Box::new(TextType)); + map.insert("extension", Box::new(TextType)); + map.insert("is_dir", Box::new(BoolType)); + map.insert("is_file", Box::new(BoolType)); + map.insert("size", Box::new(IntType)); + map } pub fn tables_fields_names() -> &'static HashMap<&'static str, Vec<&'static str>> {