public void CreateAndStoreManyObjectsInsideSession() { //for (int t = 0; t < 10; t++) Stopwatch swTotal = new Stopwatch(); swTotal.Start(); Parallel.For(0, 10, t => { var sw = new Stopwatch(); sw.Start(); using (var database = new CouchDatabase("http://localhost:5984/")) { using (var session = database.OpenSession("trivial")) { for (var i = 0; i < 10000; i++) { var car = new Car {Id = Guid.NewGuid().ToString(), HorsePowers = 10 + i, Make = "Audi", Model = i.ToString()}; session.Store(car); } session.SaveChanges(); } } sw.Stop(); Console.WriteLine("{0} - Elapsed: {1} ms.", t, sw.ElapsedMilliseconds); }); swTotal.Stop(); Console.WriteLine("Total - Elapsed: {0} ms.", swTotal.ElapsedMilliseconds); }
public void OpenSessionAndQueryTheDatabaseWithLinq() { using (var database = new CouchDatabase("http://localhost:5984/")) { using (var session = database.OpenSession("trivial")) { var queryable = from car in session.Query<Car>() where car.HorsePowers == 1337 select car; var cars = queryable.ToList(); Assert.That(cars != null && cars.Count > 0); } } }
public void OpenSessionAndQueryTheDatabase() { using (var database = new CouchDatabase("http://localhost:5984/")) { using (var session = database.OpenSession("trivial")) { //var queryable = session.Query<Car>().Where(x => (x.HorsePowers == 1337 || x.Model == "1337") && x.Make == "Saab"); var queryable = session.Query<Car>().Where(x => (x.HorsePowers == 123 && x.Make == "Audi")); var cars = queryable.ToList(); foreach (var car in cars) { car.Model = "Cool"; var test = session.Load<Car>(car.Id); } session.SaveChanges(); Assert.That(cars != null && cars.Any()); } } }
public HelloModule() { Get["/"] = parameters => { var indexModel = new IndexModel { Username = "******", CurrentDate = DateTime.Now }; return View["Views/index.html", indexModel]; }; Get["/cars/{hp?}"] = parameters => { var database = new CouchDatabase("http://localhost:5984/"); using (var session = database.OpenSession("trivial")) { if (parameters.hp) { var hp = (int) parameters.hp; var car = session.Query<Car>().FirstOrDefault(x => x.HorsePowers == hp); return Response.AsJson(car); } var cars = session.Query<Car>().ToList(); return Response.AsJson(cars); } }; Get["/init/{count?100}"] = parameters => { var database = new CouchDatabase("http://localhost:5984/"); using (var session = database.OpenSession("trivial")) { for (var i = 0; i < parameters.count; i++) { var car = new Car("Saab", (93 + i).ToString(), 170 + i); session.Store(car); } session.SaveChanges(); } return string.Format("Generated {0} cars.", parameters.count); }; }
public void WhenQueryingForFirstRecord_ThenOneRecordShouldBeReturned() { using (var database = new CouchDatabase("http://localhost:5984/")) { using (var session = database.OpenSession("trivial")) { var car = session.Query<Car>().FirstOrDefault(x => x.HorsePowers == 1337); Assert.That(car != null); } } }