diff options
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.Data/src/Abstractions')
-rw-r--r-- | lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IDataStore.cs | 34 | ||||
-rw-r--r-- | lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IPaginatedDataStore.cs | 8 |
2 files changed, 28 insertions, 14 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IDataStore.cs b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IDataStore.cs index 4e2d682..1c8174c 100644 --- a/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IDataStore.cs +++ b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IDataStore.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.Data @@ -23,11 +23,13 @@ */ using System; +using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; using VNLib.Utils; + namespace VNLib.Plugins.Extensions.Data.Abstractions { /// <summary> @@ -40,20 +42,23 @@ namespace VNLib.Plugins.Extensions.Data.Abstractions /// <summary> /// Gets the total number of records in the current store /// </summary> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>A task that resolves the number of records in the store</returns> - Task<long> GetCountAsync(); + Task<long> GetCountAsync(CancellationToken cancellation = default); /// <summary> /// Gets the number of records that belong to the specified constraint /// </summary> /// <param name="specifier">A specifier to constrain the reults</param> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>The number of records that belong to the specifier</returns> - Task<long> GetCountAsync(string specifier); + Task<long> GetCountAsync(string specifier, CancellationToken cancellation = default); /// <summary> /// Gets a record from its key /// </summary> /// <param name="key">The key identifying the unique record</param> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>A promise that resolves the record identified by the specified key</returns> - Task<T?> GetSingleAsync(string key); + Task<T?> GetSingleAsync(string key, CancellationToken cancellation = default); /// <summary> /// Gets a record from its key /// </summary> @@ -64,16 +69,18 @@ namespace VNLib.Plugins.Extensions.Data.Abstractions /// Gets a record from the store with a partial model, intended to complete the model /// </summary> /// <param name="record">The partial model used to query the store</param> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>A task the resolves the completed data-model</returns> - Task<T?> GetSingleAsync(T record); + Task<T?> GetSingleAsync(T record, CancellationToken cancellation = default); /// <summary> /// Fills a collection with enires retireved from the store using the specifer /// </summary> /// <param name="collection">The collection to add entires to</param> /// <param name="specifier">A specifier argument to constrain results</param> /// <param name="limit">The maximum number of elements to retrieve</param> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>A Task the resolves to the number of items added to the collection</returns> - Task<ERRNO> GetCollectionAsync(ICollection<T> collection, string specifier, int limit); + Task<ERRNO> GetCollectionAsync(ICollection<T> collection, string specifier, int limit, CancellationToken cancellation = default); /// <summary> /// Fills a collection with enires retireved from the store using a variable length specifier /// parameter @@ -87,26 +94,30 @@ namespace VNLib.Plugins.Extensions.Data.Abstractions /// Updates an entry in the store with the specified record /// </summary> /// <param name="record">The record to update</param> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>A task the resolves an error code (should evaluate to false on failure, and true on success)</returns> - Task<ERRNO> UpdateAsync(T record); + Task<ERRNO> UpdateAsync(T record, CancellationToken cancellation = default); /// <summary> /// Creates a new entry in the store representing the specified record /// </summary> /// <param name="record">The record to add to the store</param> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>A task the resolves an error code (should evaluate to false on failure, and true on success)</returns> - Task<ERRNO> CreateAsync(T record); + Task<ERRNO> CreateAsync(T record, CancellationToken cancellation = default); /// <summary> /// Deletes one or more entrires from the store matching the specified record /// </summary> /// <param name="record">The record to remove from the store</param> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>A task the resolves the number of records removed(should evaluate to false on failure, and deleted count on success)</returns> - Task<ERRNO> DeleteAsync(T record); + Task<ERRNO> DeleteAsync(T record, CancellationToken cancellation = default); /// <summary> /// Deletes one or more entires from the store matching the specified unique key /// </summary> /// <param name="key">The unique key that identifies the record</param> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>A task the resolves the number of records removed(should evaluate to false on failure, and deleted count on success)</returns> - Task<ERRNO> DeleteAsync(string key); + Task<ERRNO> DeleteAsync(string key, CancellationToken cancellation = default); /// <summary> /// Deletes one or more entires from the store matching the supplied specifiers /// </summary> @@ -117,7 +128,8 @@ namespace VNLib.Plugins.Extensions.Data.Abstractions /// Updates an entry in the store if it exists, or creates a new entry if one does not already exist /// </summary> /// <param name="record">The record to add to the store</param> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>A task the resolves the result of the operation</returns> - Task<ERRNO> AddOrUpdateAsync(T record); + Task<ERRNO> AddOrUpdateAsync(T record, CancellationToken cancellation = default); } } diff --git a/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IPaginatedDataStore.cs b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IPaginatedDataStore.cs index 2ccb5ab..7c271eb 100644 --- a/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IPaginatedDataStore.cs +++ b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IPaginatedDataStore.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.Data @@ -22,8 +22,9 @@ * along with this program. If not, see https://www.gnu.org/licenses/. */ -using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; +using System.Collections.Generic; namespace VNLib.Plugins.Extensions.Data.Abstractions { @@ -40,8 +41,9 @@ namespace VNLib.Plugins.Extensions.Data.Abstractions /// <param name="collection">The collection to add records to</param> /// <param name="page">Pagination page to get records from</param> /// <param name="limit">The maximum number of items to retrieve from the store</param> + /// <param name="cancellation">A cancellation token to cancel the operation</param> /// <returns>A task that resolves the number of items added to the collection</returns> - Task<int> GetPageAsync(ICollection<T> collection, int page, int limit); + Task<int> GetPageAsync(ICollection<T> collection, int page, int limit, CancellationToken cancellation = default); /// <summary> /// Gets a collection of records using a pagination style query with constraint arguments, and adds the records to the collecion /// </summary> |