Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("LITE DB v5");
            Console.WriteLine("===========================================================");

            //var cn = @"filename=d:\appPWD.db; password=abc";

            File.Delete(@"d:\app.db");
            File.Delete(@"d:\app-log.db");

            //using (var repo = new LiteRepository(cn))
            //{
            //    repo.Database.UserVersion = 99;
            //}


            var sw = new Stopwatch();

            using (var e = new LiteEngine(new EngineSettings {
                Filename = @"d:\app.db"
            }))
            {
                sw.Start();

                // insert 5.000 docs
                //e.Insert("col1", Enumerable.Range(1, 5000).Select(x => new BsonDocument { ["_id"] = x }), BsonAutoId.Int32);

                foreach (var d in Enumerable.Range(1, 5000).Select(x => new BsonDocument {
                    ["_id"] = x
                }))
                {
                    e.Insert("col1", new BsonDocument[] { d }, BsonAutoId.Int32);
                }


                e.Checkpoint();
                sw.Stop();
            }


            Console.WriteLine("Time: " + sw.ElapsedMilliseconds);
            //
            //using (var repo = new LiteRepository(cn))
            //{
            //    var u = repo.Database.UserVersion;
            //
            //    Console.WriteLine(u);
            //
            //    var mau = repo.FirstOrDefault<BsonDocument>(x => x["_id"] == 1, "col1");
            //    //
            //    Console.WriteLine("dados:" + mau["n"].AsString);
            //
            //}



            Console.WriteLine(" ===========================================================");
            Console.WriteLine("End");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        private void CreateDatabase(LiteEngine engine)
        {
            engine.Insert("mycol", new[]
            {
                new BsonDocument
                {
                    ["_id"]  = 1,
                    ["name"] = "Mauricio"
                }
            }, BsonAutoId.Int32);

            // do checkpoint to use only data file
            engine.Checkpoint();
        }