public LambdaQueryBuilder OrderByAsc <T>(params Expression <Func <T, object> >[] expressions) { foreach (var expression in expressions) { _orderBy.Asc(_parser.Parse(expression, ClauseContext.OrderBy)); } return(this); }
public static async Task Main() { LogService logService = new LogService(); string password = File.ReadAllText(@"E:\Desktop\password.txt"); QueryOptions queryOptions = new QueryOptions { DataStore = DataStore.PostgreSQL, }; queryOptions.ConnectionString = $"Server=127.0.0.1;Port=5432;Database=AutomatorTest;User ID=postgres;Password={password};"; DBAutomator postgres = new DBAutomator(queryOptions, logService); postgres.Register(new UserModel()); postgres.Register(new AddressModel()); postgres.Register(new UserAddressModel()); postgres.OnSlowQueryDetected += Postgres_OnSlowQueryDetected; UserModel newUser1 = new UserModel { UserID = 1, UserName = "******" }; UserModel newUser2 = new UserModel { UserID = 2, UserName = "******" }; UserModel newUser3 = new UserModel { UserID = 3, UserName = "******" }; UserModel newUser4 = new UserModel { UserID = 4, UserName = "******" }; UserModel newUser5 = new UserModel { UserID = 5, UserName = "******" }; UserModel newUser6 = new UserModel { UserID = 6, UserName = "******" }; OrderByClause <UserModel> orderBy = new OrderByClause <UserModel>(postgres); orderBy.Asc(nameof(UserModel.UserID)); orderBy.Asc(nameof(UserModel.UserName)); //delete the entire table var a = await postgres.DeleteAsync <UserModel>(); //insert a new row var b = await postgres.InsertAsync(newUser1); var c = await postgres.InsertAsync(newUser2); var d = await postgres.InsertAsync(newUser3); var e = await postgres.InsertAsync(newUser4); var f = await postgres.InsertAsync(newUser5); var g = await postgres.InsertAsync(newUser6); //update an existing row newUser1.UserName = "******"; var h = await postgres.UpdateAsync(newUser1); //update all matching rows var i = await postgres.UpdateAsync <UserModel>(u => u.UserName == "changed again", u => u.UserName == "changed"); //get the required rows var j = await postgres.GetAsync <UserModel>(u => u.UserID > 2); var k = await postgres.GetAsync <UserModel>(u => u.UserID < 2); var l = await postgres.GetAsync <UserModel>(u => u.UserID >= 2); var m = await postgres.GetAsync <UserModel>(u => u.UserID <= 2); var n = await postgres.GetAsync <UserModel>(u => u.UserID == 2); var o = await postgres.GetAsync <UserModel>(u => u.UserID == 2 || u.UserName == "changed again"); var p = await postgres.GetAsync(u => u.UserID == 2 || u.UserName == "changed again", orderBy); //delete all matching rows var q = await postgres.DeleteAsync <UserModel>(u => u.UserID == 6); //delete a row that matches a given item var r = await postgres.DeleteAsync(newUser5); //delete the entire table var s = await postgres.DeleteAsync <AddressModel>(); var t = new AddressModel { //AddressID = 1, //autogenerated UserAddress = "some address", UserID = 1 }; //insert a new row var u = await postgres.InsertAsync(t); var v = new AddressModel { //AddressID = 2, //autogenerated UserAddress = "some other address", UserID = 5 }; var w = await postgres.InsertAsync(v); var x = await postgres.GetAsync <UserAddressModel>(); var y = await postgres.GetAsync <UserAddressModel>(ua => ua.UserID == 1); var z = x.First(); z.UserAddress = "a new world"; z.UserName = "******"; var aa = JsonSerializer.Serialize(z); var ab = JsonSerializer.Deserialize <UserModel>(aa); var ad = await postgres.UpdateAsync(ab); var ac = JsonSerializer.Deserialize <AddressModel>(aa); var ae = await postgres.UpdateAsync(ac); var af = await postgres.UpdateAsync <AddressModel>(a => a.UserAddress == "all addresses changed"); var ag = await postgres.UpdateAsync <AddressModel>(a => a.UserAddress == "another new world", a => a.UserID == 1); await Task.Delay(-1); }