Example #1
0
 private void Init(Stream stream, string collectionName = "Default")
 {
     dbStream   = stream;
     bsonMapper = new BsonMapper();
     bsonMapper.IncludeFields = true;
     db         = new UltraLiteDatabase(dbStream, bsonMapper);
     collection = db.GetCollection(collectionName);
 }
 private void Init(FileEntry dbFile, string collectionName = "Default")
 {
     bsonMapper = new BsonMapper();
     bsonMapper.IncludeFields = true;
     dbStream   = dbFile.OpenOrCreateForReadWrite();
     db         = new UltraLiteDatabase(dbStream, bsonMapper);
     collection = db.GetCollection(collectionName);
 }
        private void MinMaxCommon(UltraLiteCollection <DateTimeTest> coll)
        {
            var searchdatetime = new DateTime(2018, 02, 22, 0, 0, 10);

            var min = coll.Min("Date").AsDateTime;
            var max = coll.Max("Date").AsDateTime;

            var smaller = coll.FindOne(Query.LT("Date", searchdatetime));
            var greater = coll.FindOne(Query.GT("Date", searchdatetime));

            var all = coll.FindAll().ToList();

            var linqmin = all.Min(x => x.Date);
            var linqmax = all.Max(x => x.Date);

            Assert.AreEqual(min, linqmin);
            Assert.AreEqual(max, linqmax);
        }
Example #4
0
        public LiteDBStorageItem(UltraLiteDatabase db, string key)
        {
            Key         = key;
            _database   = db;
            _collection = _database.GetCollection <Definition>(TableName);
            _filter     = Query.EQ("Key", new BsonValue(key));
            var doc = _collection.FindOne(_filter);

            if (doc == null)
            {
                _collection.Insert(new Definition {
                    Key = key
                });
            }
            else if (!string.IsNullOrWhiteSpace(doc.Json))
            {
                data = JsonConvert.DeserializeObject <T>(doc.Json);
            }
        }