Show / Hide Table of Contents

Class SQLiteRepository<T1, T2>

Repository base class for SQLite databases. Implements the GlitchedPolygons.RepositoryPattern.IRepository<T1, T2> interface.

Inheritance
System.Object
SQLiteRepository<T1, T2>
Implements
GlitchedPolygons.RepositoryPattern.IRepository<T1, T2>
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: GlitchedPolygons.RepositoryPattern.SQLite
Assembly: GlitchedPolygons.RepositoryPattern.SQLite.dll
Syntax
public abstract class SQLiteRepository<T1, T2> : IRepository<T1, T2> where T1 : IEntity<T2>
Type Parameters
Name Description
T1

The type of entity stored in the repository. The name of this type should also exactly match the name of the db table!

T2

The type of unique id with which the entities will be identified inside the repo (typically this will be either a string containing a GUID or an auto-incremented int).

Constructors

| Improve this Doc View Source

SQLiteRepository(String, String)

Creates a new SQLite repository using a specific connection string.

Declaration
public SQLiteRepository(string connectionString, string tableName = null)
Parameters
Type Name Description
System.String connectionString

The sqlite db connection string. Ensure that this is valid!

System.String tableName

Optional custom name for the underlying SQLite database table. If left out, the entity's type name is used.

Properties

| Improve this Doc View Source

Item[T2]

Gets an entity by its unique identifier.

Declaration
public T1 this[T2 id] { get; }
Parameters
Type Name Description
T2 id

The entity's unique identifier.

Property Value
Type Description
T1

The first found GlitchedPolygons.RepositoryPattern.IEntity<T>; null if nothing was found.

| Improve this Doc View Source

TableName

The name of the underlying SQLite database table where the repository entities are stored.

Declaration
public string TableName { get; }
Property Value
Type Description
System.String

Methods

| Improve this Doc View Source

Add(T1)

Adds the specified entity to the data repository.

You need to ENSURE the uniqueness of the addendum GlitchedPolygons.RepositoryPattern.IEntity`1.Id!

Declaration
public abstract Task<bool> Add(T1 entity)
Parameters
Type Name Description
T1 entity

The entity to add.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entity could be added successfully or not.

| Improve this Doc View Source

AddRange(IEnumerable<T1>)

Adds multiple entities at once.

You need to ENSURE the uniqueness of each added GlitchedPolygons.RepositoryPattern.IEntity`1.Id!

Declaration
public abstract Task<bool> AddRange(IEnumerable<T1> entities)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T1> entities

The entities to add.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entities were added successfully or not.

| Improve this Doc View Source

Find(Expression<Func<T1, Boolean>>)

Finds all entities according to the specified predicate System.Linq.Expressions.Expression.

WARNING: Can be very slow! For specialized queries, just create a new repository! Derive from this class and create custom SQL queries that return the mapped types that you need.

Declaration
public Task<IEnumerable<T1>> Find(Expression<Func<T1, bool>> predicate)
Parameters
Type Name Description
System.Linq.Expressions.Expression<System.Func<T1, System.Boolean>> predicate

The search predicate (all entities that match the provided conditions will be added to the query's result).

Returns
Type Description
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<T1>>

The found entities (System.Collections.Generic.IEnumerable<T>).

| Improve this Doc View Source

Get(T2)

Gets an entity asynchronously by its unique identifier.

Declaration
public Task<T1> Get(T2 id)
Parameters
Type Name Description
T2 id

The entity's unique identifier.

Returns
Type Description
System.Threading.Tasks.Task<T1>

The first found GlitchedPolygons.RepositoryPattern.IEntity<T>; null if nothing was found.

| Improve this Doc View Source

GetAll()

Gets all entities from the repository.

Declaration
public Task<IEnumerable<T1>> GetAll()
Returns
Type Description
System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<T1>>

All entities inside the repo.

| Improve this Doc View Source

OpenConnection()

Opens a System.Data.IDbConnection to the SQLite database.

Does not dispose automatically: make sure to wrap your usage into a block.

Declaration
protected IDbConnection OpenConnection()
Returns
Type Description
System.Data.IDbConnection

The opened System.Data.IDbConnection (remember to dispose of it asap after you're done!).

| Improve this Doc View Source

Remove(T1)

Removes the specified entity.

Declaration
public Task<bool> Remove(T1 entity)
Parameters
Type Name Description
T1 entity

The entity to remove.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entity could be removed successfully or not.

| Improve this Doc View Source

Remove(T2)

Removes the specified entity.

Declaration
public Task<bool> Remove(T2 id)
Parameters
Type Name Description
T2 id

The unique id of the entity to remove.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entity could be removed successfully or not.

| Improve this Doc View Source

RemoveAll()

Removes all entities at once from the repository.

Declaration
public Task<bool> RemoveAll()
Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entities were removed successfully or not. If the repository was already empty, false is returned (because nothing was actually <<removed>> ).

| Improve this Doc View Source

RemoveRange(IEnumerable<T1>)

Removes the range of entities from the repository.

Declaration
public Task<bool> RemoveRange(IEnumerable<T1> entities)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T1> entities

The entities to remove.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether all entities were removed successfully or not.

| Improve this Doc View Source

RemoveRange(IEnumerable<T2>)

Removes the range of entities from the repository.

Declaration
public Task<bool> RemoveRange(IEnumerable<T2> ids)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T2> ids

The unique ids of the entities to remove.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether all entities were removed successfully or not.

| Improve this Doc View Source

RemoveRange(Expression<Func<T1, Boolean>>)

Removes all entities that match the specified conditions (via the predicate System.Linq.Expressions.Expression parameter).

WARNING: Can be slow. If you know the entities' id, please use the other RemoveRange overloads!

Declaration
public Task<bool> RemoveRange(Expression<Func<T1, bool>> predicate)
Parameters
Type Name Description
System.Linq.Expressions.Expression<System.Func<T1, System.Boolean>> predicate

The predicate System.Linq.Expressions.Expression that defines which entities should be removed.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entities were removed successfully or not.

| Improve this Doc View Source

SingleOrDefault(Expression<Func<T1, Boolean>>)

Gets a single entity from the repo according to the specified predicate condition.

If 0 or >1 entities are found, null is returned.

WARNING: Can be very slow! For specialized queries, just create a new repository! Derive from this class and create custom SQL queries that return the mapped types that you need.

Declaration
public Task<T1> SingleOrDefault(Expression<Func<T1, bool>> predicate)
Parameters
Type Name Description
System.Linq.Expressions.Expression<System.Func<T1, System.Boolean>> predicate

The search predicate.

Returns
Type Description
System.Threading.Tasks.Task<T1>

Single found entity; default(T1) (usually this is null) if 0 or >1 entities were found.

| Improve this Doc View Source

Update(T1)

Updates the specified entity.

Declaration
public abstract Task<bool> Update(T1 entity)
Parameters
Type Name Description
T1 entity

The entity to update.

Returns
Type Description
System.Threading.Tasks.Task<System.Boolean>

Whether the entity could be updated successfully or not.

Implements

GlitchedPolygons.RepositoryPattern.IRepository<T1, T2>

See Also

GlitchedPolygons.RepositoryPattern.IRepository<T1, T2>
  • Improve this Doc
  • View Source
Back to top Generated by DocFX