public async Task UpdateTest() { var services = new ServiceCollection() .AddRoscoePostgres("Host=localhost;Database=test"); using (var provider = services.BuildServiceProvider()) { var db = new RoscoeDb(provider); var organisations = new OrganisationTable("o"); var subquery = db.Query(() => Guid.Parse("c0cac2b4-4821-4135-900b-4a36b46f0122").DbValue().Value()).Value; var query = db.Update(organisations) .Set(organisations.Name, "new name".DbValue()) //.From(organisations) //.InnerJoin(organisations, organisations.Id == organisations.Id) .Where(organisations.Id == subquery.DbValue()) .Returning(() => new { Id = organisations.Id.Value(), Name = organisations.Name.Value(), }); var sql = query.ToString(); var result = await db.ExecuteAsync(query); } }
public void InsertTest() { var services = new ServiceCollection() .AddRoscoePostgres(""); using (var provider = services.BuildServiceProvider()) { var db = new RoscoeDb(provider); var organisations = new OrganisationTable("o"); var selectQuery = db.Query(() => new { Id = organisations.Id.NullValue(), Name = organisations.Name.ToLower().Value(), //IdName = (organisations.Id + organisations.Name).Value(), }) .From(organisations); var updateQuery = db.Update(organisations) .Set(organisations.Name, "new name".DbValue()) //.From(organisations) //.InnerJoin(organisations, organisations.Id == organisations.Id) .Where(organisations.Name == "") ; var query = db.InsertValues(organisations, new { organisations.Id, organisations.Name }) .Values(new { Id = Guid.NewGuid().DbValue(), Name = "org 1".DbValue() }) .OnConflict(organisations.Id, organisations.Name) //.DoNothing() .Update(x => x.Set(organisations.Name, "org 1".DbValue())) .Returning(() => new { Id = organisations.Id.Value(), }); var selectSql = selectQuery.ToString(); var updateSql = updateQuery.ToString(); var sql = query.ToString(); } }