Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
e8e5a20
Enhance `BsonAutoId` XML documentation
TyKonKet Nov 15, 2025
224a053
Improve XML documentation for LiteDatabase class
TyKonKet Nov 15, 2025
0e9a9e4
Improve XML documentation for BsonMapper class
TyKonKet Nov 15, 2025
51bb079
Improve documentation for EntityBuilder<T> API
TyKonKet Nov 15, 2025
b40b0b2
Add XML docs for ConnectionType enum and clean up placeholders
TyKonKet Nov 15, 2025
aa801e3
Improve Collation and LCID XML comments
TyKonKet Nov 15, 2025
5b18679
Improve XML docs for EngineSettings and SharedMutexName
TyKonKet Nov 15, 2025
99a2347
Enhance `BsonDocument` and `BsonValue` with XML docs
TyKonKet Nov 15, 2025
71f2719
Enhanced the `LiteException` class by adding detailed XML
TyKonKet Nov 15, 2025
fdca589
Improve documentation and readability in BsonExpression
TyKonKet Nov 15, 2025
1c1ac87
Improve documentation and code clarity in LiteDB API
TyKonKet Nov 15, 2025
ca63660
Improve documentation for ConnectionString class
TyKonKet Nov 15, 2025
9c8715f
Add SharedDataReader and enhance BsonDataReader docs
TyKonKet Nov 15, 2025
8923ceb
Improve LiteDB documentation
TyKonKet Nov 15, 2025
fdf806f
Add XML docs to `Pragmas` class
TyKonKet Nov 15, 2025
0775936
Expanded XML documentation across `SharedEngine`, `LiteEngine` and `I…
TyKonKet Nov 16, 2025
0402e53
Improve documentation for RebuildOptions class
TyKonKet Nov 16, 2025
5e1a818
Improve XML documentation for ILiteDatabase interface
TyKonKet Nov 16, 2025
9656857
Refactor and enhance XML documentation
TyKonKet Nov 16, 2025
cee0651
Enhanced `ILiteQueryable<T>` and `ILiteQueryableResult<T>` with detai…
TyKonKet Nov 16, 2025
97ed841
Refactored XML documentation for clarity and consistency, adding deta…
TyKonKet Nov 16, 2025
0fbfd0f
Improve ObjectId documentation
TyKonKet Nov 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 23 additions & 69 deletions LiteDB/Client/Database/Collections/Aggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,128 +9,92 @@ public partial class LiteCollection<T>
{
#region Count

/// <summary>
/// Get document count in collection
/// </summary>
/// <inheritdoc/>
public int Count()
{
// do not use indexes - collections has DocumentCount property
return this.Query().Count();
}

/// <summary>
/// Get document count in collection using predicate filter expression
/// </summary>
/// <inheritdoc/>
public int Count(BsonExpression predicate)
{
if (predicate == null) throw new ArgumentNullException(nameof(predicate));

return this.Query().Where(predicate).Count();
}

/// <summary>
/// Get document count in collection using predicate filter expression
/// </summary>
/// <inheritdoc/>
public int Count(string predicate, BsonDocument parameters) => this.Count(BsonExpression.Create(predicate, parameters));

/// <summary>
/// Get document count in collection using predicate filter expression
/// </summary>
/// <inheritdoc/>
public int Count(string predicate, params BsonValue[] args) => this.Count(BsonExpression.Create(predicate, args));

/// <summary>
/// Count documents matching a query. This method does not deserialize any documents. Needs indexes on query expression
/// </summary>
/// <inheritdoc/>
public int Count(Expression<Func<T, bool>> predicate) => this.Count(_mapper.GetExpression(predicate));

/// <summary>
/// Get document count in collection using predicate filter expression
/// </summary>
/// <inheritdoc/>
public int Count(Query query) => new LiteQueryable<T>(_engine, _mapper, _collection, query).Count();

#endregion

#region LongCount

/// <summary>
/// Get document count in collection
/// </summary>
/// <inheritdoc/>
public long LongCount()
{
return this.Query().LongCount();
}

/// <summary>
/// Get document count in collection using predicate filter expression
/// </summary>
/// <inheritdoc/>
public long LongCount(BsonExpression predicate)
{
if (predicate == null) throw new ArgumentNullException(nameof(predicate));

return this.Query().Where(predicate).LongCount();
}

/// <summary>
/// Get document count in collection using predicate filter expression
/// </summary>
/// <inheritdoc/>
public long LongCount(string predicate, BsonDocument parameters) => this.LongCount(BsonExpression.Create(predicate, parameters));

/// <summary>
/// Get document count in collection using predicate filter expression
/// </summary>
/// <inheritdoc/>
public long LongCount(string predicate, params BsonValue[] args) => this.LongCount(BsonExpression.Create(predicate, args));

/// <summary>
/// Get document count in collection using predicate filter expression
/// </summary>
/// <inheritdoc/>
public long LongCount(Expression<Func<T, bool>> predicate) => this.LongCount(_mapper.GetExpression(predicate));

/// <summary>
/// Get document count in collection using predicate filter expression
/// </summary>
/// <inheritdoc/>
public long LongCount(Query query) => new LiteQueryable<T>(_engine, _mapper, _collection, query).Count();

#endregion

#region Exists

/// <summary>
/// Get true if collection contains at least 1 document that satisfies the predicate expression
/// </summary>
/// <inheritdoc/>
public bool Exists(BsonExpression predicate)
{
if (predicate == null) throw new ArgumentNullException(nameof(predicate));

return this.Query().Where(predicate).Exists();
}

/// <summary>
/// Get true if collection contains at least 1 document that satisfies the predicate expression
/// </summary>
/// <inheritdoc/>
public bool Exists(string predicate, BsonDocument parameters) => this.Exists(BsonExpression.Create(predicate, parameters));

/// <summary>
/// Get true if collection contains at least 1 document that satisfies the predicate expression
/// </summary>
/// <inheritdoc/>
public bool Exists(string predicate, params BsonValue[] args) => this.Exists(BsonExpression.Create(predicate, args));

/// <summary>
/// Get true if collection contains at least 1 document that satisfies the predicate expression
/// </summary>
/// <inheritdoc/>
public bool Exists(Expression<Func<T, bool>> predicate) => this.Exists(_mapper.GetExpression(predicate));

/// <summary>
/// Get true if collection contains at least 1 document that satisfies the predicate expression
/// </summary>
/// <inheritdoc/>
public bool Exists(Query query) => new LiteQueryable<T>(_engine, _mapper, _collection, query).Exists();

#endregion

#region Min/Max

/// <summary>
/// Returns the min value from specified key value in collection
/// </summary>
/// <inheritdoc/>
public BsonValue Min(BsonExpression keySelector)
{
if (string.IsNullOrEmpty(keySelector)) throw new ArgumentNullException(nameof(keySelector));
Expand All @@ -145,14 +109,10 @@ public BsonValue Min(BsonExpression keySelector)
return doc[doc.Keys.First()];
}

/// <summary>
/// Returns the min value of _id index
/// </summary>
/// <inheritdoc/>
public BsonValue Min() => this.Min("_id");

/// <summary>
/// Returns the min value from specified key value in collection
/// </summary>
/// <inheritdoc/>
public K Min<K>(Expression<Func<T, K>> keySelector)
{
if (keySelector == null) throw new ArgumentNullException(nameof(keySelector));
Expand All @@ -164,9 +124,7 @@ public K Min<K>(Expression<Func<T, K>> keySelector)
return (K)_mapper.Deserialize(typeof(K), value);
}

/// <summary>
/// Returns the max value from specified key value in collection
/// </summary>
/// <inheritdoc/>
public BsonValue Max(BsonExpression keySelector)
{
if (string.IsNullOrEmpty(keySelector)) throw new ArgumentNullException(nameof(keySelector));
Expand All @@ -181,14 +139,10 @@ public BsonValue Max(BsonExpression keySelector)
return doc[doc.Keys.First()];
}

/// <summary>
/// Returns the max _id index key value
/// </summary>
/// <inheritdoc/>
public BsonValue Max() => this.Max("_id");

/// <summary>
/// Returns the last/max field using a linq expression
/// </summary>
/// <inheritdoc/>
public K Max<K>(Expression<Func<T, K>> keySelector)
{
if (keySelector == null) throw new ArgumentNullException(nameof(keySelector));
Expand Down
24 changes: 6 additions & 18 deletions LiteDB/Client/Database/Collections/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,35 @@ namespace LiteDB
{
public partial class LiteCollection<T>
{
/// <summary>
/// Delete a single document on collection based on _id index. Returns true if document was deleted
/// </summary>
/// <inheritdoc/>
public bool Delete(BsonValue id)
{
if (id == null || id.IsNull) throw new ArgumentNullException(nameof(id));

return _engine.Delete(_collection, new [] { id }) == 1;
}

/// <summary>
/// Delete all documents inside collection. Returns how many documents was deleted. Run inside current transaction
/// </summary>
/// <inheritdoc/>
public int DeleteAll()
{
return _engine.DeleteMany(_collection, null);
}

/// <summary>
/// Delete all documents based on predicate expression. Returns how many documents was deleted
/// </summary>
/// <inheritdoc/>
public int DeleteMany(BsonExpression predicate)
{
if (predicate == null) throw new ArgumentNullException(nameof(predicate));

return _engine.DeleteMany(_collection, predicate);
}

/// <summary>
/// Delete all documents based on predicate expression. Returns how many documents was deleted
/// </summary>
/// <inheritdoc/>
public int DeleteMany(string predicate, BsonDocument parameters) => this.DeleteMany(BsonExpression.Create(predicate, parameters));

/// <summary>
/// Delete all documents based on predicate expression. Returns how many documents was deleted
/// </summary>
/// <inheritdoc/>
public int DeleteMany(string predicate, params BsonValue[] args) => this.DeleteMany(BsonExpression.Create(predicate, args));

/// <summary>
/// Delete all documents based on predicate expression. Returns how many documents was deleted
/// </summary>
/// <inheritdoc/>
public int DeleteMany(Expression<Func<T, bool>> predicate) => this.DeleteMany(_mapper.GetExpression(predicate));
}
}
44 changes: 11 additions & 33 deletions LiteDB/Client/Database/Collections/Find.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ namespace LiteDB
{
public partial class LiteCollection<T>
{
/// <summary>
/// Return a new LiteQueryable to build more complex queries
/// </summary>
/// <inheritdoc/>
public ILiteQueryable<T> Query()
{
return new LiteQueryable<T>(_engine, _mapper, _collection, new Query()).Include(_includes);
}

#region Find

/// <summary>
/// Find documents inside a collection using predicate expression.
/// </summary>
/// <inheritdoc/>
public IEnumerable<T> Find(BsonExpression predicate, int skip = 0, int limit = int.MaxValue)
{
if (predicate == null) throw new ArgumentNullException(nameof(predicate));
Expand All @@ -34,9 +30,7 @@ public IEnumerable<T> Find(BsonExpression predicate, int skip = 0, int limit = i
.ToEnumerable();
}

/// <summary>
/// Find documents inside a collection using query definition.
/// </summary>
/// <inheritdoc/>
public IEnumerable<T> Find(Query query, int skip = 0, int limit = int.MaxValue)
{
if (query == null) throw new ArgumentNullException(nameof(query));
Expand All @@ -48,53 +42,37 @@ public IEnumerable<T> Find(Query query, int skip = 0, int limit = int.MaxValue)
.ToEnumerable();
}

/// <summary>
/// Find documents inside a collection using predicate expression.
/// </summary>
/// <inheritdoc/>
public IEnumerable<T> Find(Expression<Func<T, bool>> predicate, int skip = 0, int limit = int.MaxValue) => this.Find(_mapper.GetExpression(predicate), skip, limit);

#endregion

#region FindById + One + All

/// <summary>
/// Find a document using Document Id. Returns null if not found.
/// </summary>
/// <inheritdoc/>
public T FindById(BsonValue id)
{
if (id == null || id.IsNull) throw new ArgumentNullException(nameof(id));

return this.Find(BsonExpression.Create("_id = @0", id)).FirstOrDefault();
}

/// <summary>
/// Find the first document using predicate expression. Returns null if not found
/// </summary>
/// <inheritdoc/>
public T FindOne(BsonExpression predicate) => this.Find(predicate).FirstOrDefault();

/// <summary>
/// Find the first document using predicate expression. Returns null if not found
/// </summary>
/// <inheritdoc/>
public T FindOne(string predicate, BsonDocument parameters) => this.FindOne(BsonExpression.Create(predicate, parameters));

/// <summary>
/// Find the first document using predicate expression. Returns null if not found
/// </summary>
/// <inheritdoc/>
public T FindOne(BsonExpression predicate, params BsonValue[] args) => this.FindOne(BsonExpression.Create(predicate, args));

/// <summary>
/// Find the first document using predicate expression. Returns null if not found
/// </summary>
/// <inheritdoc/>
public T FindOne(Expression<Func<T, bool>> predicate) => this.FindOne(_mapper.GetExpression(predicate));

/// <summary>
/// Find the first document using defined query structure. Returns null if not found
/// </summary>
/// <inheritdoc/>
public T FindOne(Query query) => this.Find(query).FirstOrDefault();

/// <summary>
/// Returns all documents inside collection order by _id index.
/// </summary>
/// <inheritdoc/>
public IEnumerable<T> FindAll() => this.Query().Include(_includes).ToEnumerable();

#endregion
Expand Down
10 changes: 2 additions & 8 deletions LiteDB/Client/Database/Collections/Include.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ namespace LiteDB
{
public partial class LiteCollection<T>
{
/// <summary>
/// Run an include action in each document returned by Find(), FindById(), FindOne() and All() methods to load DbRef documents
/// Returns a new Collection with this action included
/// </summary>
/// <inheritdoc/>
public ILiteCollection<T> Include<K>(Expression<Func<T, K>> keySelector)
{
if (keySelector == null) throw new ArgumentNullException(nameof(keySelector));
Expand All @@ -20,10 +17,7 @@ public ILiteCollection<T> Include<K>(Expression<Func<T, K>> keySelector)
return this.Include(path);
}

/// <summary>
/// Run an include action in each document returned by Find(), FindById(), FindOne() and All() methods to load DbRef documents
/// Returns a new Collection with this action included
/// </summary>
/// <inheritdoc/>
public ILiteCollection<T> Include(BsonExpression keySelector)
{
if (string.IsNullOrEmpty(keySelector)) throw new ArgumentNullException(nameof(keySelector));
Expand Down
Loading