Example #1
0
        public AlbumDataStore(ISettings settings)
        {
            var filePath   = Path.Combine(Directory.GetCurrentDirectory(), "data", settings.Database);
            var folderPath = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }
            var connectionString = new ConnectionString {
                Mode = LiteDB.FileMode.Exclusive, Filename = filePath
            };

            _db = new LiteDatabase(connectionString);

            Albums = _db.GetCollection <Album>(nameof(Album));
            Albums.EnsureIndex(x => x.Name, true);
            Albums.EnsureIndex(x => x.TimeCreated, false);
        }