aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IDataStore.cs
blob: 4e2d68263d96e57cff4cfce780a481dc537ce65b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* Copyright (c) 2022 Vaughn Nugent
* 
* Library: VNLib
* Package: VNLib.Plugins.Extensions.Data
* File: IDataStore.cs 
*
* IDataStore.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.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);
    }
}