private static async Task TestQuery <T>(RedisSqlClient client, Expression <Func <T, bool> > expr) { var stopwatch = new Stopwatch(); stopwatch.Start(); var query = await client.Query(expr); stopwatch.Stop(); Console.WriteLine($"Fetched {query.Count()} entities in {stopwatch.ElapsedMilliseconds} MS"); }
private static async Task MainAsync() { var client = new RedisSqlClient(); Console.WriteLine("Type -h for help\n"); while (true) { Console.Write("> "); var input = Console.ReadLine(); if (string.Equals(input?.Trim(), "-h", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Welcome to Redis.SQL Manager. Use Redis.SQL Manager to manage your Redis data store using SQL-like statements." + "\n\n-To create a new entity type use the format:\n\ncreate ENTITY (property:type)\n\nExample:\n\ncreate user (name:string, id:int64)" + "\n\n-Currently Supported types in Redis.SQL are: \n\n-string\n-int32\n-int64\n-char\n-boolean\n-datetime\n-timespan" + "\n\n-To insert a new entity type use the format:\n\ninsert ENTITY (property) values (value)\n\nExample:\n\ninsert user (name, id) values ('Ahmed', 1)" + "\n\n-To project entities from your data store, use the format: \n\nselect [*/comma separated properties] from ENTITY where property [=/!=/>=/<=/</>] value [and/or] ..., note that providing the where condition is not obligatory\n\nExample:\n\nselect * from user where name='ahmed' or (age=30 and verified = true)" + "\n\n-To delete an entity from your data store, use the format: \n\ndelete ENTITY where [condition], note that providing the where condition is not obligatory.\n\nExample:\n\ndelete from user where id = 1" + "\n\n-To update an entity use the format: \n\nupdate ENTITY set property=value where [condition], note that providing the where condition is not obligatory.\n\nExample:\n\nupdate user set name='John', age=40 where id = 3\n\n"); } else { IList <IDictionary <string, string> > result; try { result = (await client.ExecuteSql(input)).ToList(); } catch (Exception e) { Console.WriteLine($"\n{e.Message}\n"); continue; } Console.WriteLine("\nExecuted Successfully\n"); var counter = 0; foreach (var item in result) { Console.WriteLine($"Row #{++counter}"); foreach (var property in item) { Console.WriteLine($"-{property.Key}: {property.Value}"); } Console.WriteLine("\n"); } } } }
private static async Task MainAsync() { var client = new RedisSqlClient(); await client.Create <Employee>(); //Creating an entity type in the data store Console.WriteLine("Entity Type Created"); var employees = GetEmployees().ToList(); foreach (var employee in employees) { await client.Insert(employee); //Inserting data in the data store } Console.WriteLine($"{employees.Count} Entities Inserted"); var rnd = new Random(); int GetRandom() => rnd.Next(0, employees.Count - 1); var randomEmployee1 = employees[GetRandom()]; var randomEmployee2 = employees[GetRandom()]; var randomEmployee3 = employees[GetRandom()]; //Warming Up await client.Query <Employee>(x => (x.Name == randomEmployee1.Name || x.Age >= randomEmployee2.Age) && x.Insured == !randomEmployee3.Insured && x.Department <= 'c'); var timespan = TimeSpan.FromHours(5); //Querying data await TestQuery <Employee>(client, x => x.Name == randomEmployee3.Name || (x.Joined >= randomEmployee1.Joined && x.ShiftStartTime == timespan)); await TestQuery <Employee>(client, x => (x.Age > randomEmployee3.Age && x.ShiftStartTime < timespan) || x.Name == randomEmployee2.Name); await TestQuery <Employee>(client, x => !x.Insured); await TestQuery <Employee>(client, x => (x.Joined < randomEmployee2.Joined && !x.Insured && x.Age < randomEmployee1.Age) || x.Id == randomEmployee3.Id); //Deleting an entity await client.Delete(randomEmployee1); //Updating an entity randomEmployee2.Name = Guid.NewGuid().ToString(); await client.Update(randomEmployee2); }