/* * Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.Data * File: IDbContextHandle.cs * * IDbContextHandle.cs is part of VNLib.Plugins.Extensions.Data which is part of the larger * VNLib collection of libraries and utilities. * * VNLib.Plugins.Extensions.Data is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * VNLib.Plugins.Extensions.Data is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ using System; using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; using VNLib.Utils; namespace VNLib.Plugins.Extensions.Data.Abstractions { /// /// Represents an open database connection and interfaces with the database, /// allows queries, and modifications of the set /// public interface IDbContextHandle : IAsyncDisposable { /// /// Gets a supported set of the desired entity type within the context /// /// The entity model type /// A querriable instance to execute queries on IQueryable Set() where T : class; /// /// Adds a new entity to the set /// /// /// The entity instance to add to the set void Add(T entity) where T : class; /// /// Adds a range of entities to the set of the given type /// /// /// The range of entitites to add to the set void AddRange(IEnumerable entities) where T : class; /// /// Removes an entity of a given type from the set /// /// The entity type to remove /// The entity instance containing required information to remove void Remove(T entity) where T : class; /// /// Removes a range of entities of a given type from the set /// /// /// The range of entities to remove void RemoveRange(IEnumerable entities) where T : class; /// /// Commits saves changes on the context and optionally commits changes to the database /// /// A value that indicates whether the changes should be commited to the database /// A token to cancel the operation /// The result of the database commit Task SaveAndCloseAsync(bool commit, CancellationToken cancellation = default); } }