public void Create_100k_Rows_DB() { using (var db = new LiteEngine(dbpath)) { var c = db.GetCollection<PerfItem>("perf"); //c.EnsureIndex("MyGuid", true); var id = 0; for (var j = 0; j < 3; j++) { var d = DateTime.Now; db.BeginTrans(); for (var i = 0; i < 10000; i++) { id++; c.Insert(id, new PerfItem { Id = id, MyGuid = Guid.NewGuid(), Nome = "Jose Silva " + id }); } db.Commit(); Debug.Print("Commits " + j + " in " + DateTime.Now.Subtract(d).TotalMilliseconds); } } }
public void Files_Store() { using (var db = new LiteEngine(dbpath)) { var c = db.GetCollection("customer"); db.BeginTrans(); for (var i = 1; i <= 500; i++) { var d = new BsonDocument(); d["Name"] = "San Jose"; c.Insert(i, d); } for (var i = 1; i <= 500; i++) { c.Delete(i); } db.Commit(); Dump.Pages(db, "before"); var meta = new Dictionary<string, string>(); meta["my-data"] = "Google LiteDB"; db.Storage.Upload("my/foto1.jpg", new MemoryStream(new byte[5000]), meta); Dump.Pages(db ,"after file"); var f = db.Storage.FindByKey("my/foto1.jpg"); Assert.AreEqual(5000, f.Length); Assert.AreEqual("Google LiteDB", f.Metadata["my-data"]); var mem = new MemoryStream(); f.OpenRead(db).CopyTo(mem); // file real size after read all bytes Assert.AreEqual(5000, mem.Length); // all bytes are 0 Assert.AreEqual(5000, mem.ToArray().Count(x => x == 0)); db.Storage.Delete("my/foto1.jpg"); Dump.Pages(db, "deleted file"); } }
public override void Update(int count) { _db.BeginTrans(); for (var id = 1; id <= count; id++) { var doc = _col.FindById(id); doc.Description = Helper.LoremIpsum(15, 15, 3, 3, 4); _col.Update(doc); } _db.Commit(); }
/// <summary> /// Bulk documents to a collection - use data chunks for most efficient insert /// </summary> public static int Bulk <T>(string connectionString, string collectionName, IEnumerable <T> docs, int buffer = 2000) where T : new() { if (string.IsNullOrEmpty(connectionString)) { throw new ArgumentNullException("connectionString"); } if (string.IsNullOrEmpty(collectionName)) { throw new ArgumentNullException("collectionName"); } if (docs == null) { throw new ArgumentNullException("collectionName"); } if (buffer < 100) { throw new ArgumentException("buffer must be bigger than 100"); } var enumerator = docs.GetEnumerator(); var count = 0; while (true) { var buff = buffer; using (var db = new LiteEngine(connectionString)) { var col = db.GetCollection <T>(collectionName); var more = true; db.BeginTrans(); while ((more = enumerator.MoveNext()) && buff > 0) { col.Insert(enumerator.Current); buff--; count++; } db.Commit(); if (more == false) { return(count); } } } }
public bool Commit() { if (_engine == null) { return(false); } try { return(_engine.Commit()); } finally { this.CloseDatabase(); } }