// Create instance of your Schemaletschema=Schema{tables_fields_names:tables_fields_names().clone(),tables_fields_types:tables_fields_types().clone(),};// Pass the standard functions, or your custom functions or mix of them to the envletstd_signatures=standard_functions();letstd_functions=standard_function_signatures();letaggregation_signatures=aggregation_function_signatures();letaggregation_functions=aggregation_functions();letmutenv=Environment::new(schema);env.with_standard_functions(&std_signatures,std_functions);env.with_aggregation_functions(&aggregation_signatures,aggregation_functions);// Create instance of the diagnostic reporter, to report errors, warns ...etcletmutreporter=DiagnosticReporter::default();// Pass the query to the tokenizer to get List of tokens or errorlettokensOrError=tokenizer::tokenize(query.clone());// If tokenizer return error, report it and stopiftokensOrError.is_err(){letdiagnostic=tokensOrError.err().unwrap();reporter.report_diagnostic(&query,*diagnostic);return;}// Get the list of tokenslettokens=tokensOrError.ok().unwrap();// Start the parser to get AST or errorletastOrError=parser::parse_gql(tokens,env);// Same like tokenizer if it return error, report it and stopifastOrError.is_err(){letdiagnostic=astOrError.err().unwrap();reporter.report_diagnostic(&query,*diagnostic);return;}letquery_ast=astOrError.ok().unwrap();// Create instance of your data providerletprovider:Box<dynDataProvider>=Box::new(FileDataProvider::new(repos.to_vec()));// Pass the ast and provider to the execution engine to get result or errorletevaluation_result=engine::evaluate(env,&provider,query_node);// Report Runtime exceptions if they existsifevaluation_result.is_err(){reporter.report_diagnostic(&query,Diagnostic::exception(&evaluation_result.err().unwrap()),);return;}letexecution_result=evaluation_result.ok().unwrap();// When you get result with selected groups, you can print them like table, json, csv or your custom formatifletSelectedGroups(mutgroups)=engine_result{letpagination=true;letpage_size=10;letprinter=Box::new(TablePrinter::new(pagination,page_size));printer.print(&mutgroups);}
Thats it, now you can create a customizable query language with your own schema, data, types and functions.