aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Plugins.Extensions.Data/src/Abstractions
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-01-09 15:09:13 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2023-01-09 15:09:13 -0500
commita46c3bf452d287b50b2e7dd5a24f5995c9fd26f6 (patch)
tree3a978b2dd2887b5c0e25f595516594a647d8e880 /lib/VNLib.Plugins.Extensions.Data/src/Abstractions
parent189c6714057bf45553847eaeb9ce97eb7272eb8c (diff)
Restructure
Diffstat (limited to 'lib/VNLib.Plugins.Extensions.Data/src/Abstractions')
-rw-r--r--lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IBulkDataStore.cs65
-rw-r--r--lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IDataStore.cs123
-rw-r--r--lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IPaginatedDataStore.cs56
-rw-r--r--lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IUserEntity.cs39
4 files changed, 283 insertions, 0 deletions
diff --git a/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IBulkDataStore.cs b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IBulkDataStore.cs
new file mode 100644
index 0000000..b644ec3
--- /dev/null
+++ b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IBulkDataStore.cs
@@ -0,0 +1,65 @@
+/*
+* Copyright (c) 2022 Vaughn Nugent
+*
+* Library: VNLib
+* Package: VNLib.Plugins.Extensions.Data
+* File: IBulkDataStore.cs
+*
+* IBulkDataStore.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 General Public License as published
+* by the Free Software Foundation, either version 2 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
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with VNLib.Plugins.Extensions.Data. If not, see http://www.gnu.org/licenses/.
+*/
+
+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/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IDataStore.cs b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IDataStore.cs
new file mode 100644
index 0000000..4ab62bf
--- /dev/null
+++ b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IDataStore.cs
@@ -0,0 +1,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 General Public License as published
+* by the Free Software Foundation, either version 2 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
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with VNLib.Plugins.Extensions.Data. If not, see http://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);
+ }
+}
diff --git a/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IPaginatedDataStore.cs b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IPaginatedDataStore.cs
new file mode 100644
index 0000000..4a9cb89
--- /dev/null
+++ b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IPaginatedDataStore.cs
@@ -0,0 +1,56 @@
+/*
+* Copyright (c) 2022 Vaughn Nugent
+*
+* Library: VNLib
+* Package: VNLib.Plugins.Extensions.Data
+* File: IPaginatedDataStore.cs
+*
+* IPaginatedDataStore.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 General Public License as published
+* by the Free Software Foundation, either version 2 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
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with VNLib.Plugins.Extensions.Data. If not, see http://www.gnu.org/licenses/.
+*/
+
+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/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IUserEntity.cs b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IUserEntity.cs
new file mode 100644
index 0000000..aaca7c0
--- /dev/null
+++ b/lib/VNLib.Plugins.Extensions.Data/src/Abstractions/IUserEntity.cs
@@ -0,0 +1,39 @@
+/*
+* Copyright (c) 2022 Vaughn Nugent
+*
+* Library: VNLib
+* Package: VNLib.Plugins.Extensions.Data
+* File: IUserEntity.cs
+*
+* IUserEntity.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 General Public License as published
+* by the Free Software Foundation, either version 2 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
+* General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with VNLib.Plugins.Extensions.Data. If not, see http://www.gnu.org/licenses/.
+*/
+
+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; }
+ }
+}