diff options
Diffstat (limited to 'VNLib.Plugins.Extensions.Data/Abstractions')
4 files changed, 187 insertions, 0 deletions
diff --git a/VNLib.Plugins.Extensions.Data/Abstractions/IBulkDataStore.cs b/VNLib.Plugins.Extensions.Data/Abstractions/IBulkDataStore.cs new file mode 100644 index 0000000..3b6ab62 --- /dev/null +++ b/VNLib.Plugins.Extensions.Data/Abstractions/IBulkDataStore.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +using VNLib.Utils; + +namespace VNLib.Plugins.Extensions.Data.Abstractions +{ + /// <summary> + /// An abstraction that defines a Data-Store that supports + /// bulk data operations + /// </summary> + /// <typeparam name="T">The data-model type</typeparam> + public interface IBulkDataStore<T> + { + /// <summary> + /// Deletes a collection of records from the store + /// </summary> + /// <param name="records">A collection of records to delete</param> + ///<returns>A task the resolves the number of entires removed from the store</returns> + Task<ERRNO> DeleteBulkAsync(ICollection<T> records); + /// <summary> + /// Updates a collection of records + /// </summary> + /// <param name="records">The collection of records to update</param> + /// <returns>A task the resolves an error code (should evaluate to false on failure, and true on success)</returns> + Task<ERRNO> UpdateBulkAsync(ICollection<T> records); + /// <summary> + /// Creates a bulk collection of records as entries in the store + /// </summary> + /// <param name="records">The collection of records to add</param> + /// <returns>A task the resolves an error code (should evaluate to false on failure, and true on success)</returns> + Task<ERRNO> CreateBulkAsync(ICollection<T> records); + /// <summary> + /// Creates or updates individual records from a bulk collection of records + /// </summary> + /// <param name="records">The collection of records to add</param> + /// <returns>A task the resolves an error code (should evaluate to false on failure, and true on success)</returns> + Task<ERRNO> AddOrUpdateBulkAsync(ICollection<T> records); + } + +} diff --git a/VNLib.Plugins.Extensions.Data/Abstractions/IDataStore.cs b/VNLib.Plugins.Extensions.Data/Abstractions/IDataStore.cs new file mode 100644 index 0000000..f923891 --- /dev/null +++ b/VNLib.Plugins.Extensions.Data/Abstractions/IDataStore.cs @@ -0,0 +1,99 @@ +using System; +using System.Threading.Tasks; +using System.Collections.Generic; + +using VNLib.Utils; + +namespace VNLib.Plugins.Extensions.Data.Abstractions +{ + /// <summary> + /// An abstraction that defines a Data-Store and common + /// operations that retrieve or manipulate records of data + /// </summary> + /// <typeparam name="T">The data-model type</typeparam> + public interface IDataStore<T> + { + /// <summary> + /// Gets the total number of records in the current store + /// </summary> + /// <returns>A task that resolves the number of records in the store</returns> + Task<long> GetCountAsync(); + /// <summary> + /// Gets the number of records that belong to the specified constraint + /// </summary> + /// <param name="specifier">A specifier to constrain the reults</param> + /// <returns>The number of records that belong to the specifier</returns> + Task<long> GetCountAsync(string specifier); + /// <summary> + /// Gets a record from its key + /// </summary> + /// <param name="key">The key identifying the unique record</param> + /// <returns>A promise that resolves the record identified by the specified key</returns> + Task<T?> GetSingleAsync(string key); + /// <summary> + /// Gets a record from its key + /// </summary> + /// <param name="specifiers">A variable length specifier arguemnt array for retreiving a single application</param> + /// <returns></returns> + Task<T?> GetSingleAsync(params string[] specifiers); + /// <summary> + /// 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> + /// <returns>A task the resolves the completed data-model</returns> + Task<T?> GetSingleAsync(T record); + /// <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> + /// <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); + /// <summary> + /// Fills a collection with enires retireved from the store using a variable length specifier + /// parameter + /// </summary> + /// <param name="collection">The collection to add entires to</param> + /// <param name="limit">The maximum number of elements to retrieve</param> + /// <param name="args"></param> + /// <returns>A Task the resolves to the number of items added to the collection</returns> + Task<ERRNO> GetCollectionAsync(ICollection<T> collection, int limit, params string[] args); + /// <summary> + /// Updates an entry in the store with the specified record + /// </summary> + /// <param name="record">The record to update</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); + /// <summary> + /// Creates a new entry in the store representing the specified record + /// </summary> + /// <param name="record">The record to add to the store</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); + /// <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> + /// <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); + /// <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> + /// <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); + /// <summary> + /// Deletes one or more entires from the store matching the supplied specifiers + /// </summary> + /// <param name="specifiers">A variable length array of specifiers used to delete one or more entires</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(params string[] specifiers); + /// <summary> + /// 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> + /// <returns>A task the resolves the result of the operation</returns> + Task<ERRNO> AddOrUpdateAsync(T record); + } +} diff --git a/VNLib.Plugins.Extensions.Data/Abstractions/IPaginatedDataStore.cs b/VNLib.Plugins.Extensions.Data/Abstractions/IPaginatedDataStore.cs new file mode 100644 index 0000000..44c11f8 --- /dev/null +++ b/VNLib.Plugins.Extensions.Data/Abstractions/IPaginatedDataStore.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace VNLib.Plugins.Extensions.Data.Abstractions +{ + /// <summary> + /// Defines a Data-Store that can retirieve and manipulate paginated + /// data + /// </summary> + /// <typeparam name="T">The data-model type</typeparam> + public interface IPaginatedDataStore<T> + { + /// <summary> + /// Gets a collection of records using a pagination style query, and adds the records to the collecion + /// </summary> + /// <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> + /// <returns>A task that resolves the number of items added to the collection</returns> + Task<int> GetPageAsync(ICollection<T> collection, int page, int limit); + /// <summary> + /// Gets a collection of records using a pagination style query with constraint arguments, and adds the records to the collecion + /// </summary> + /// <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="constraints">A params array of strings to constrain the result set from the db</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, params string[] constraints); + } + +} diff --git a/VNLib.Plugins.Extensions.Data/Abstractions/IUserEntity.cs b/VNLib.Plugins.Extensions.Data/Abstractions/IUserEntity.cs new file mode 100644 index 0000000..6026f85 --- /dev/null +++ b/VNLib.Plugins.Extensions.Data/Abstractions/IUserEntity.cs @@ -0,0 +1,15 @@ +using System; + +namespace VNLib.Plugins.Extensions.Data.Abstractions +{ + /// <summary> + /// Defines an entity base that has an owner, identified by its user-id + /// </summary> + public interface IUserEntity + { + /// <summary> + /// The user-id of the owner of the entity + /// </summary> + string? UserId { get; set; } + } +} |