public async Task QueryTest() { 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; var subquery2 = db.Query(() => Guid.Parse("c0cac2b4-4821-4135-900b-4a36b46f0122").DbValue().Value()).Value; var from = db.Query(() => new { Id = Guid.Parse("c0cac2b4-4821-4135-900b-4a36b46f0122").DbValue().Value() }).Value; var query = db.Query(() => new { Id = organisations.Id.NullValue(), Name = organisations.Name.ToLower().Value(), //IdName = (organisations.Id + organisations.Name).Value(), }) .From(organisations) //.InnerJoin(from, from.Value().Id == organisations.Id) .Where(organisations.Id == subquery.DbValue()); //.InnerJoin(organisations, organisations.Id == organisations.Id) //.Where(organisations.Name == "") //.GroupBy(organisations.Id); var sql = query.ToString(); var result = await db.ExecuteAsync(query); } }
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 async Task QueryTest() { var services = new ServiceCollection() .AddRoscoeSqlServer("Server=localhost;Database=test;"); using (var provider = services.BuildServiceProvider()) { var db = new RoscoeDb(provider); var organisations = new OrganisationTable("o"); var query = db.Query(() => new { Id = organisations.Id.Value(), Name = Elvis(organisations.Name.Value(), x => x.ToUpper()), NameIsFoo = db.Functions .Case() .When(organisations.Name == new Foo().Value(), 1.DbValue()) .Else(0) .EndCase().Value(), }) .From(organisations) .ForJsonPath(); var result = await db.ExecuteAsync(query); } }