public static IEnumerable <Versioned <T> > GetLatests <T>(this LiteRevisionsDB <T> revDb) { using (var db = revDb.OpenRead()) return(db.Version1 <T>() .FindAll() .GroupBy(_ => _.GroupId) .Select(_ => _.Last())); }
public static LiteDatabase OpenRead <T>(this LiteRevisionsDB <T> revDb) { if (revDb._mem == null && !File.Exists(revDb.DbPath)) { var db = revDb.Connect(LiteDB.FileMode.Shared); db.Dispose(); } return(revDb.Connect(LiteDB.FileMode.ReadOnly)); }
public static T GetById <T>(this LiteRevisionsDB <T> revDb, long groupId) where T : class { using (var db = revDb.OpenRead()) { var vers = db.Version1 <T>() .Find(_ => _.GroupId == groupId) .OrderBy(_ => _.Id); return(vers.LastOrDefault()?.Content); } }
public static Versioned <T> Insert <T>(this LiteRevisionsDB <T> revDb, T doc, string author, string changeLog = null) { using (var db = revDb.OpenWrite()) return(db.InsertVersioned(new Versioned <T> { GroupId = db.CountLatests <T>() + 1, Content = doc, ChangeLog = changeLog, ChangedBy = author, ChangeDate = DateTime.Now })); }
public static Versioned <T> Update <T>(this LiteRevisionsDB <T> revDb, long groupId, T newDTO, string updatedBy, string changeLog) { var newVer = new Versioned <T> { GroupId = groupId, Content = newDTO, ChangeLog = changeLog, ChangedBy = updatedBy, ChangeDate = DateTime.Now }; using (var db = revDb.OpenWrite()) return(db.InsertVersioned(newVer)); }
private static LiteDatabase Connect <T>(this LiteRevisionsDB <T> revDb, LiteDB.FileMode fileMode) { var db = revDb._mem != null ? new LiteDatabase(revDb._mem) : new LiteDatabase(new ConnectionString { Filename = revDb.DbPath, Journal = false, Mode = fileMode, LimitSize = long.MaxValue }); if (fileMode != LiteDB.FileMode.ReadOnly) { db.Version1 <T>().EnsureIndex(nameof(Versioned <T> .GroupId)); } return(db); }
public static LiteDatabase OpenWrite <T>(this LiteRevisionsDB <T> revDb) => revDb.Connect(LiteDB.FileMode.Shared);
public static long CountAll <T>(this LiteRevisionsDB <T> revDb) { using (var db = revDb.OpenRead()) return(db.CountLatests <T>()); }
public static long NextDocID <T>(this LiteRevisionsDB <T> revDb) => revDb.CountAll() + 1;