using System; using System.Threading.Tasks; using System.Collections.Generic; using VNLib.Utils; namespace VNLib.Plugins.Extensions.Data.Abstractions { /// /// An abstraction that defines a Data-Store and common /// operations that retrieve or manipulate records of data /// /// The data-model type public interface IDataStore { /// /// Gets the total number of records in the current store /// /// A task that resolves the number of records in the store Task GetCountAsync(); /// /// Gets the number of records that belong to the specified constraint /// /// A specifier to constrain the reults /// The number of records that belong to the specifier Task GetCountAsync(string specifier); /// /// Gets a record from its key /// /// The key identifying the unique record /// A promise that resolves the record identified by the specified key Task GetSingleAsync(string key); /// /// Gets a record from its key /// /// A variable length specifier arguemnt array for retreiving a single application /// Task GetSingleAsync(params string[] specifiers); /// /// Gets a record from the store with a partial model, intended to complete the model /// /// The partial model used to query the store /// A task the resolves the completed data-model Task GetSingleAsync(T record); /// /// Fills a collection with enires retireved from the store using the specifer /// /// The collection to add entires to /// A specifier argument to constrain results /// The maximum number of elements to retrieve /// A Task the resolves to the number of items added to the collection Task GetCollectionAsync(ICollection collection, string specifier, int limit); /// /// Fills a collection with enires retireved from the store using a variable length specifier /// parameter /// /// The collection to add entires to /// The maximum number of elements to retrieve /// /// A Task the resolves to the number of items added to the collection Task GetCollectionAsync(ICollection collection, int limit, params string[] args); /// /// Updates an entry in the store with the specified record /// /// The record to update /// A task the resolves an error code (should evaluate to false on failure, and true on success) Task UpdateAsync(T record); /// /// Creates a new entry in the store representing the specified record /// /// The record to add to the store /// A task the resolves an error code (should evaluate to false on failure, and true on success) Task CreateAsync(T record); /// /// Deletes one or more entrires from the store matching the specified record /// /// The record to remove from the store /// A task the resolves the number of records removed(should evaluate to false on failure, and deleted count on success) Task DeleteAsync(T record); /// /// Deletes one or more entires from the store matching the specified unique key /// /// The unique key that identifies the record /// A task the resolves the number of records removed(should evaluate to false on failure, and deleted count on success) Task DeleteAsync(string key); /// /// Deletes one or more entires from the store matching the supplied specifiers /// /// A variable length array of specifiers used to delete one or more entires /// A task the resolves the number of records removed(should evaluate to false on failure, and deleted count on success) Task DeleteAsync(params string[] specifiers); /// /// Updates an entry in the store if it exists, or creates a new entry if one does not already exist /// /// The record to add to the store /// A task the resolves the result of the operation Task AddOrUpdateAsync(T record); } }