DatabaseRepository<T>
Namespace: SlottyMedia.Database.Repository
This interface provides the basic CRUD operations for a database repository.
public abstract class DatabaseRepository<T> : IDatabaseRepository`1
Type Parameters
T
Inheritance Object → DatabaseRepository<T>
Implements IDatabaseRepository<T>
Methods
GetElementById(Guid)
public Task<T> GetElementById(Guid entityId)
Parameters
entityId Guid
Returns
Task<T>
GetElementById(Guid, Expression<Func<T, Object[]>>)
public Task<T> GetElementById(Guid entityId, Expression<Func<T, Object[]>> selector)
Parameters
entityId Guid
selector Expression<Func<T, Object[]>>
Returns
Task<T>
GetElementByField(String, String)
public Task<T> GetElementByField(string fieldName, string fieldValue)
Parameters
fieldName String
fieldValue String
Returns
Task<T>
GetAllElements()
public Task<List<T>> GetAllElements()
Returns
Task<List<T>>
GetAllElements(PageRequest)
public Task<IPage<T>> GetAllElements(PageRequest pageRequest)
Parameters
pageRequest PageRequest
Returns
Task<IPage<T>>
AddElement(T)
public Task<T> AddElement(T entity)
Parameters
entity T
Returns
Task<T>
UpdateElement(T)
public Task UpdateElement(T entity)
Parameters
entity T
Returns
DeleteElement(T)
public Task DeleteElement(T entity)
Parameters
entity T
Returns
ExecuteQuery(IPostgrestTable<T>)
Executes a query on the specified table.
protected Task<List<T>> ExecuteQuery(IPostgrestTable<T> query)
Parameters
query IPostgrestTable<T>
The query to execute.
Returns
Task<List<T>>
A task that represents the asynchronous operation. The task result contains a list of entities.
Exceptions
GeneralDatabaseException
Thrown when an unexpected error occurs.
ExecuteSingleQuery(IPostgrestTable<T>)
Executes a single query on the specified table.
public Task<T> ExecuteSingleQuery(IPostgrestTable<T> query)
Parameters
query IPostgrestTable<T>
The query to execute.
Returns
Task<T>
A task that represents the asynchronous operation. The task result contains a single entity.
Exceptions
DatabaseMissingItemException
Thrown when the entity is not found in the database.
GeneralDatabaseException
Thrown when an unexpected error occurs.
ExecuteCountQuery(IPostgrestTable<T>, CountType)
Executes a single query on the specified table.
public Task<int> ExecuteCountQuery(IPostgrestTable<T> query, CountType countType)
Parameters
query IPostgrestTable<T>
The query to execute.
countType CountType
Determines how exact the Count will be
Returns
Task<Int32>
A task that represents the asynchronous operation. The task result contains a single entity.
Exceptions
DatabaseMissingItemException
Thrown when the entity is not found in the database.
GeneralDatabaseException
Thrown when an unexpected error occurs.
ExecuteFunction(String)
Executes a function on the database.
protected Task<object> ExecuteFunction(string nameOfFunction)
Parameters
nameOfFunction String
The name of the function to execute.
Returns
Task<Object>
A task that represents the asynchronous operation. The task result contains the result of the function.
Exceptions
DatabaseMissingItemException
Thrown when the items could not be retrieved from the database.
GeneralDatabaseException
Thrown when an unexpected error occurs.
ExecuteFunction(String, Dictionary<String, Object>)
Executes a function on the database with parameters.
protected Task<object> ExecuteFunction(string nameOfFunction, Dictionary<string, object> parameters)
Parameters
nameOfFunction String
The name of the function to execute.
parameters Dictionary<String, Object>
The parameters to pass to the function.
Returns
Task<Object>
A task that represents the asynchronous operation. The task result contains the result of the function.
Exceptions
DatabaseMissingItemException
Thrown when the items could not be retrieved from the database.
GeneralDatabaseException
Thrown when an unexpected error occurs.
ApplyPagination(Func<IPostgrestTable<T>>, PageRequest)
This method applies pagination to a query.
protected Task<IPage<T>> ApplyPagination(Func<IPostgrestTable<T>> queryBuilder, PageRequest pageRequest)
Parameters
queryBuilder Func<IPostgrestTable<T>>
A function that builds the needed query. This function needs to return a different
object on each invocation, otherwise the pagination will break!
pageRequest PageRequest
The page request
Returns
Task<IPage<T>>
The IPage<T> that corresponds to the given request
Exceptions
DatabasePaginationFailedException
This exception will be thrown, when an error occurs during the
Process of Applying the Pagination