Sphyrnidae Common Library  2.0.1
Shared Utilities/Library
Sphyrnidae.Common.Dal.BaseRepo Class Reference

A base repository instance More...

Inheritance diagram for Sphyrnidae.Common.Dal.BaseRepo:
Sphyrnidae.Common.Dal.MySqlRepo Sphyrnidae.Common.Dal.SqlServerRepo Sphyrnidae.Common.DynamicSql.DynamicMySqlRepo Sphyrnidae.Common.DynamicSql.DynamicSqlServerRepo

Public Member Functions

virtual ApiResponseStandard HandleException ()
 If an exception was trapped, this will provide access to the trapped exception for proper responses More...
 

Protected Member Functions

virtual Task PreCall (IDbConnection cnn, IDbTransaction trans)
 If you need to execute something before the main call More...
 
virtual Task PostCall (IDbConnection cnn, IDbTransaction trans)
 If you need to execute something after the main call More...
 
 BaseRepo (ILogger logger)
 
Task< int > WriteSQLAsync (string sql, object parameters, IDbTransaction trans=null)
 Executes something against a database More...
 
Task< int > WriteSPAsync (string sp, object parameters, IDbTransaction trans=null)
 Executes something against a database More...
 
async Task< bool > WriteSQLAsBoolAsync (string sql, object parameters, IDbTransaction trans=null)
 Executes something against a database More...
 
async Task< bool > WriteSPAsBoolAsync (string sp, object parameters, IDbTransaction trans=null)
 Executes something against a database More...
 
Task< int?> WriteSQLTrappingExceptionsAsync (string sql, object parameters, IDbTransaction trans=null)
 Executes something against a database More...
 
Task< int?> WriteSPTrappingExceptionsAsync (string sp, object parameters, IDbTransaction trans=null)
 Executes something against a database More...
 
async Task< bool?> WriteSQLAsBoolTrappingExceptionsAsync (string sql, object parameters, IDbTransaction trans=null)
 Executes something against a database More...
 
async Task< bool?> WriteSPAsBoolTrappingExceptionsAsync (string sp, object parameters, IDbTransaction trans=null)
 Executes something against a database More...
 
Task< T > ScalarSQLAsync< T > (string sql, object parameters, IDbTransaction trans=null)
 Executes something against a database that returns a single result More...
 
Task< T > ScalarSPAsync< T > (string sp, object parameters, IDbTransaction trans=null)
 Executes something against a database that returns a single result More...
 
Task< T > ScalarSQLTrappingExceptionsAsync< T > (string sql, object parameters, IDbTransaction trans=null)
 Executes something against a database that returns a single result More...
 
Task< T > ScalarSPTrappingExceptionsAsync< T > (string sp, object parameters, IDbTransaction trans=null)
 Executes something against a database that returns a single result More...
 
Task< int?> InsertAsync (string sql, object parameters, IDbTransaction trans=null)
 Inserts a record into the database More...
 
Task< int?> InsertTrappingExceptionsAsync (string sql, object parameters, IDbTransaction trans=null)
 Inserts a record into the database More...
 
Task< int?> InsertAsync (string sql, DatabaseIdentity identity, object parameters, IDbTransaction trans=null, bool trapExceptions=false)
 Inserts a record into the database More...
 
Task< T > GetSQLAsync< T > (string sql, object parameters, IDbTransaction trans=null)
 Retrieves a single record from the database More...
 
Task< T > GetSPAsync< T > (string sp, object parameters, IDbTransaction trans=null)
 Retrieves a single record from the database More...
 
Task< IEnumerable< T > > GetListSQLAsync< T > (string sql, object parameters, IDbTransaction trans=null)
 Retrieves multiple records (0, 1, or more) from the database More...
 
Task< IEnumerable< T > > GetListSPAsync< T > (string sp, object parameters, IDbTransaction trans=null)
 Retrieves multiple records (0, 1, or more) from the database More...
 
Task< bool > ExistsAsync (string conditions, object parameters, IDbTransaction trans=null)
 Does an existence check against the database More...
 

Static Protected Member Functions

static string ExistsCondition (string fromTableAndWhere)
 Use this to add a "condition" to be used in "Exists" check More...
 

Protected Attributes

Exception Ex
 The trapped exception More...
 

Properties

abstract string CnnStr [get]
 The actual connection string More...
 
abstract string CnnName [get]
 Nice name of the database connection (eg. web.config key) used for logging More...
 
abstract IDbConnection GetConnection [get]
 The actual connection to the database More...
 
virtual bool DoLog [get]
 For use with database logger: Set to false so that it won't recursively log the log call More...
 
ILogger Logger [get]
 Implementation of the ILogger interface More...
 

Detailed Description

A base repository instance

Constructor & Destructor Documentation

◆ BaseRepo()

Sphyrnidae.Common.Dal.BaseRepo.BaseRepo ( ILogger  logger)
protected

Member Function Documentation

◆ ExistsAsync()

Task<bool> Sphyrnidae.Common.Dal.BaseRepo.ExistsAsync ( string  conditions,
object  parameters,
IDbTransaction  trans = null 
)
protected

Does an existence check against the database

Parameters
conditionsThe concatenated list of "ExistsCondition" method calls
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
True if found, otherwise false

◆ ExistsCondition()

static string Sphyrnidae.Common.Dal.BaseRepo.ExistsCondition ( string  fromTableAndWhere)
staticprotected

Use this to add a "condition" to be used in "Exists" check

Parameters
fromTableAndWhereEg. [tableName] where [something]=variable
Returns
A string to be inserted into "Exists" method (multiple calls can be concatenated together)

◆ GetListSPAsync< T >()

Task<IEnumerable<T> > Sphyrnidae.Common.Dal.BaseRepo.GetListSPAsync< T > ( string  sp,
object  parameters,
IDbTransaction  trans = null 
)
protected

Retrieves multiple records (0, 1, or more) from the database

Parameters
spThe Stored Procedure to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
The records (Could be 0, 1, or more)

◆ GetListSQLAsync< T >()

Task<IEnumerable<T> > Sphyrnidae.Common.Dal.BaseRepo.GetListSQLAsync< T > ( string  sql,
object  parameters,
IDbTransaction  trans = null 
)
protected

Retrieves multiple records (0, 1, or more) from the database

Parameters
sqlThe SQL to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
The records (Could be 0, 1, or more)

◆ GetSPAsync< T >()

Task<T> Sphyrnidae.Common.Dal.BaseRepo.GetSPAsync< T > ( string  sp,
object  parameters,
IDbTransaction  trans = null 
)
protected

Retrieves a single record from the database

Parameters
spThe Stored Procedure to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
The record (or default/null if no records)

◆ GetSQLAsync< T >()

Task<T> Sphyrnidae.Common.Dal.BaseRepo.GetSQLAsync< T > ( string  sql,
object  parameters,
IDbTransaction  trans = null 
)
protected

Retrieves a single record from the database

Parameters
sqlThe SQL to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
The record (or default/null if no records)

◆ HandleException()

virtual ApiResponseStandard Sphyrnidae.Common.Dal.BaseRepo.HandleException ( )
virtual

If an exception was trapped, this will provide access to the trapped exception for proper responses

Returns
The response object based on the exception

◆ InsertAsync() [1/2]

Task<int?> Sphyrnidae.Common.Dal.BaseRepo.InsertAsync ( string  sql,
DatabaseIdentity  identity,
object  parameters,
IDbTransaction  trans = null,
bool  trapExceptions = false 
)
protected

Inserts a record into the database

Parameters
sqlThe SQL to execute
identityDefault = @Identity (Identity). The type of identity to retrieve
parametersAny parameters needed for the execution
transOptional: The transaction to be used
trapExceptionsOptional: Default = false. If true, this will not throw out exceptions (will be caught in variable Ex)
Returns
The ID of the object

◆ InsertAsync() [2/2]

Task<int?> Sphyrnidae.Common.Dal.BaseRepo.InsertAsync ( string  sql,
object  parameters,
IDbTransaction  trans = null 
)
protected

Inserts a record into the database

Parameters
sqlThe SQL to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
Response Object

◆ InsertTrappingExceptionsAsync()

Task<int?> Sphyrnidae.Common.Dal.BaseRepo.InsertTrappingExceptionsAsync ( string  sql,
object  parameters,
IDbTransaction  trans = null 
)
protected

Inserts a record into the database

Parameters
sqlThe SQL to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
The ID of the object

◆ PostCall()

virtual Task Sphyrnidae.Common.Dal.BaseRepo.PostCall ( IDbConnection  cnn,
IDbTransaction  trans 
)
protectedvirtual

If you need to execute something after the main call

◆ PreCall()

virtual Task Sphyrnidae.Common.Dal.BaseRepo.PreCall ( IDbConnection  cnn,
IDbTransaction  trans 
)
protectedvirtual

If you need to execute something before the main call

Reimplemented in Sphyrnidae.Common.Dal.SqlServerRepo, and Sphyrnidae.Common.Dal.MySqlRepo.

◆ ScalarSPAsync< T >()

Task<T> Sphyrnidae.Common.Dal.BaseRepo.ScalarSPAsync< T > ( string  sp,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database that returns a single result

Parameters
spThe Stored Procedure to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
The result (or default if no records)

◆ ScalarSPTrappingExceptionsAsync< T >()

Task<T> Sphyrnidae.Common.Dal.BaseRepo.ScalarSPTrappingExceptionsAsync< T > ( string  sp,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database that returns a single result

Parameters
spThe Stored Procedure to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
The result (or default if no records)

◆ ScalarSQLAsync< T >()

Task<T> Sphyrnidae.Common.Dal.BaseRepo.ScalarSQLAsync< T > ( string  sql,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database that returns a single result

Parameters
sqlThe SQL to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
The result (or default if no records)

◆ ScalarSQLTrappingExceptionsAsync< T >()

Task<T> Sphyrnidae.Common.Dal.BaseRepo.ScalarSQLTrappingExceptionsAsync< T > ( string  sql,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database that returns a single result

Parameters
sqlThe SQL to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
The result (or default if no records)

◆ WriteSPAsBoolAsync()

async Task<bool> Sphyrnidae.Common.Dal.BaseRepo.WriteSPAsBoolAsync ( string  sp,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database

Parameters
spThe Stored Procedure to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
False if nothing was changed, otherwise true

◆ WriteSPAsBoolTrappingExceptionsAsync()

async Task<bool?> Sphyrnidae.Common.Dal.BaseRepo.WriteSPAsBoolTrappingExceptionsAsync ( string  sp,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database

Parameters
spThe Stored Procedure to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
Null if exception occurred, false if nothing was changed, otherwise true

◆ WriteSPAsync()

Task<int> Sphyrnidae.Common.Dal.BaseRepo.WriteSPAsync ( string  sp,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database

Parameters
spThe Stored Procedure to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
Number of records affected

◆ WriteSPTrappingExceptionsAsync()

Task<int?> Sphyrnidae.Common.Dal.BaseRepo.WriteSPTrappingExceptionsAsync ( string  sp,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database

Parameters
spThe Stored Procedure to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
Number of records affected, or null if exception occurred

◆ WriteSQLAsBoolAsync()

async Task<bool> Sphyrnidae.Common.Dal.BaseRepo.WriteSQLAsBoolAsync ( string  sql,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database

Parameters
sqlThe SQL to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
False if nothing was changed, otherwise true

◆ WriteSQLAsBoolTrappingExceptionsAsync()

async Task<bool?> Sphyrnidae.Common.Dal.BaseRepo.WriteSQLAsBoolTrappingExceptionsAsync ( string  sql,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database

Parameters
sqlThe SQL to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
Null if exception occurred, false if nothing was changed, otherwise true

◆ WriteSQLAsync()

Task<int> Sphyrnidae.Common.Dal.BaseRepo.WriteSQLAsync ( string  sql,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database

Parameters
sqlThe SQL to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
Number of records affected

◆ WriteSQLTrappingExceptionsAsync()

Task<int?> Sphyrnidae.Common.Dal.BaseRepo.WriteSQLTrappingExceptionsAsync ( string  sql,
object  parameters,
IDbTransaction  trans = null 
)
protected

Executes something against a database

Parameters
sqlThe SQL to execute
parametersAny parameters needed for the execution
transOptional: The transaction to be used
Returns
Number of records affected, or null if exception occurred

Member Data Documentation

◆ Ex

Exception Sphyrnidae.Common.Dal.BaseRepo.Ex
protected

The trapped exception

Property Documentation

◆ CnnName

abstract string Sphyrnidae.Common.Dal.BaseRepo.CnnName
getprotected

Nice name of the database connection (eg. web.config key) used for logging

◆ CnnStr

abstract string Sphyrnidae.Common.Dal.BaseRepo.CnnStr
get

The actual connection string

◆ DoLog

virtual bool Sphyrnidae.Common.Dal.BaseRepo.DoLog
getprotected

For use with database logger: Set to false so that it won't recursively log the log call

◆ GetConnection

abstract IDbConnection Sphyrnidae.Common.Dal.BaseRepo.GetConnection
getprotected

The actual connection to the database

◆ Logger

ILogger Sphyrnidae.Common.Dal.BaseRepo.Logger
getprotected

Implementation of the ILogger interface


The documentation for this class was generated from the following file: