Table of Contents

Class OrpheusDatabase

Namespace
OrpheusCore
Assembly
OrpheusCore.dll

Orpheus database.

public class OrpheusDatabase : IOrpheusDatabase, IDisposable
Inheritance
OrpheusDatabase
Implements
Inherited Members

Constructors

OrpheusDatabase(IOrpheusConnectionFactory, IOrpheusDDLHelper, ILogger<IOrpheusDatabase>, IServiceProvider, ILoggerFactory)

Initializes a new instance of the OrpheusDatabase class, using a connection factory. Connect() leases a pooled connection from the factory instead of opening a directly-injected connection; Dispose()/Disconnect() return it to the ADO.NET pool. The connection has the same one-per-OrpheusDatabase-instance lifetime as the IDbConnection constructor overload — this does not lease a new connection per operation.

public OrpheusDatabase(IOrpheusConnectionFactory connectionFactory, IOrpheusDDLHelper ddlHelper, ILogger<IOrpheusDatabase> logger, IServiceProvider serviceProvider = null, ILoggerFactory loggerFactory = null)

Parameters

connectionFactory IOrpheusConnectionFactory

The connection factory.

ddlHelper IOrpheusDDLHelper

The DDL helper.

logger ILogger<IOrpheusDatabase>

The logger

serviceProvider IServiceProvider

Optional service provider for resolving dependencies.

loggerFactory ILoggerFactory

Optional logger factory for creating typed loggers.

OrpheusDatabase(IDbConnection, IOrpheusDDLHelper, ILogger<IOrpheusDatabase>, IServiceProvider, ILoggerFactory)

Initializes a new instance of the OrpheusDatabase class.

public OrpheusDatabase(IDbConnection connection, IOrpheusDDLHelper ddlHelper, ILogger<IOrpheusDatabase> logger, IServiceProvider serviceProvider = null, ILoggerFactory loggerFactory = null)

Parameters

connection IDbConnection

The connection.

ddlHelper IOrpheusDDLHelper

The DDL helper.

logger ILogger<IOrpheusDatabase>

The logger

serviceProvider IServiceProvider

Optional service provider for resolving dependencies.

loggerFactory ILoggerFactory

Optional logger factory for creating typed loggers.

Properties

Connected

public bool Connected { get; }

Property Value

bool

State of the database. Connected or not.

ConnectionFactory

The connection factory this database was constructed with, if any. Null when constructed from a raw IDbConnection instead of a connection factory.

public IOrpheusConnectionFactory ConnectionFactory { get; }

Property Value

IOrpheusConnectionFactory

ConnectionString

public string ConnectionString { get; }

Property Value

string

Gets the underlying IDbConnection connection string.

DDLHelper

public IOrpheusDDLHelper DDLHelper { get; set; }

Property Value

IOrpheusDDLHelper

Helps execute DDL specific commands for the underlying db engine.

DatabaseConnectionConfiguration

public IDatabaseConnectionConfiguration DatabaseConnectionConfiguration { get; set; }

Property Value

IDatabaseConnectionConfiguration

Database connection configuration.

Exceptions

ArgumentNullException

The database connection configuration cannot be null.

DbConnection

public IDbConnection DbConnection { get; }

Property Value

IDbConnection

Exposing the underlying IDbConnection instance.

LastActiveTransaction

public IDbTransaction LastActiveTransaction { get; }

Property Value

IDbTransaction

Last active transaction.

Logger

public ILogger Logger { get; }

Property Value

ILogger

Logger instance.

Modules

public List<IOrpheusModule> Modules { get; }

Property Value

List<IOrpheusModule>

List of registered Orpheus modules.

TypeMap

public Dictionary<Type, DbType> TypeMap { get; }

Property Value

Dictionary<Type, DbType>

Mapping dictionary of types to data types.

Methods

BeginTransaction()

Creates a transaction object.

public IDbTransaction BeginTransaction()

Returns

IDbTransaction

Returns a transaction instance

BeginTransactionAsync(CancellationToken)

Asynchronously creates a transaction object.

public Task<IDbTransaction> BeginTransactionAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<IDbTransaction>

CommitTransaction(IDbTransaction)

Commits a transaction.

public void CommitTransaction(IDbTransaction transaction)

Parameters

transaction IDbTransaction

Transaction to be committed.

CommitTransactionAsync(IDbTransaction, CancellationToken)

Asynchronously commits a transaction.

public Task CommitTransactionAsync(IDbTransaction transaction, CancellationToken cancellationToken = default)

Parameters

transaction IDbTransaction
cancellationToken CancellationToken

Returns

Task

Connect(IDatabaseConnectionConfiguration)

Connects to the database engine defined in the configuration object.

public void Connect(IDatabaseConnectionConfiguration databaseConnectionConfiguration)

Parameters

databaseConnectionConfiguration IDatabaseConnectionConfiguration

Connect(string)

Connects to the database engine defined in the connection string.

public void Connect(string connectionString = null)

Parameters

connectionString string

ConnectAsync(string, CancellationToken)

Asynchronously connects to the database engine.

public Task ConnectAsync(string connectionString = null, CancellationToken cancellationToken = default)

Parameters

connectionString string
cancellationToken CancellationToken

Returns

Task

CreateCommand()

Create a DbCommand.

public IDbCommand CreateCommand()

Returns

IDbCommand

A DbCommand instance.

CreateModule(IOrpheusModuleDefinition)

Creates an OrpheusModule.

public IOrpheusModule CreateModule(IOrpheusModuleDefinition definition = null)

Parameters

definition IOrpheusModuleDefinition

Module definition

Returns

IOrpheusModule

An IOrpheusModule instance

CreateModuleDefinition()

Creates an OrpheusModuleDefinition.

public IOrpheusModuleDefinition CreateModuleDefinition()

Returns

IOrpheusModuleDefinition

An IOrpheusModuleDefinition instance.

CreatePreparedQuery(string)

Returns a prepared query with parameters created.

public IDbCommand CreatePreparedQuery(string SQL)

Parameters

SQL string

SQL for the prepared query

Returns

IDbCommand

A DbCommand instance.

CreatePreparedQuery(string, List<string>, List<object>)

Returns a prepared query with parameters created.

public IDbCommand CreatePreparedQuery(string SQL, List<string> parameters, List<object> parameterValues = null)

Parameters

SQL string

SQL for the prepared query

parameters List<string>

SQL parameters

parameterValues List<object>

SQL parameter values

Returns

IDbCommand

A DbCommand instance.

CreateSchema(Guid, string, double, string)

Creates a schema object and sets it's database.

public ISchema CreateSchema(Guid id, string description, double version, string name = null)

Parameters

id Guid

Schema id

description string

Schema description

version double

Schema version

name string

Schema name.From the supported db engines, only SQL server has support for named schemas.

Returns

ISchema

An ISchema instance.

CreateTableKeyField()

Creates an OrpheusTableKeyField.

public IOrpheusTableKeyField CreateTableKeyField()

Returns

IOrpheusTableKeyField

An IOrpheusTableKeyField instance.

CreateTableOptions()

Creates an OrpheusTableOptions.

public IOrpheusTableOptions CreateTableOptions()

Returns

IOrpheusTableOptions

An IOrpheusTableOptions instance.

CreateTable<T>()

Creates a table and sets its database,using the type name as the table name.

public IOrpheusTable<T> CreateTable<T>()

Returns

IOrpheusTable<T>

An Orpheus table instance.

Type Parameters

T

CreateTable<T>(IOrpheusTableOptions)

Creates a table and sets its database.

public IOrpheusTable<T> CreateTable<T>(IOrpheusTableOptions options)

Parameters

options IOrpheusTableOptions

Table options

Returns

IOrpheusTable<T>

An Orpheus table instance.

Type Parameters

T

Model type for table

CreateTable<T>(string, List<IOrpheusTableKeyField>)

Creates a table and sets its database.

public IOrpheusTable<T> CreateTable<T>(string tableName, List<IOrpheusTableKeyField> keyFields = null)

Parameters

tableName string

Table name

keyFields List<IOrpheusTableKeyField>

Table key fields

Returns

IOrpheusTable<T>

An Orpheus table instance.

Type Parameters

T

Model type for the table

DDLHelperAs<T>()

Casts the DDL helper to the specified type.

public T DDLHelperAs<T>()

Returns

T

An instance of T.

Type Parameters

T

Type in which to cast the DDLHelper. Must be a descendant of IOrpheusDDLHelper.

Disconnect()

Disconnects from the database engine.

public void Disconnect()

DisconnectAsync()

Asynchronously disconnects from the database engine.

public Task DisconnectAsync()

Returns

Task

Dispose()

Disposes the database connection and associated resources.

public void Dispose()

Dispose(bool)

Disposes managed resources.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

ExecuteDDL(string)

Executes a DDL command.

public bool ExecuteDDL(string DDLCommand)

Parameters

DDLCommand string

DbCommand to run.

Returns

bool

True if command was successfully executed.

ExecuteDDLAsync(string, CancellationToken)

Asynchronously executes a DDL command.

public Task<bool> ExecuteDDLAsync(string DDLCommand, CancellationToken cancellationToken = default)

Parameters

DDLCommand string
cancellationToken CancellationToken

Returns

Task<bool>

GetTableCount(string)

Returns the row count of a table.

public long GetTableCount(string tableName)

Parameters

tableName string

The table name.

Returns

long

GetTableCount<T>()

Returns the row count of a table.

public long GetTableCount<T>()

Returns

long

Type Parameters

T

The table type.

IsNullableType(Type)

Returns true if the type is a nullable type.

public bool IsNullableType(Type type)

Parameters

type Type

Type

Returns

bool

True if type is nullable

RegisterModule(IOrpheusModule)

Register an Orpheus module to the database.

public void RegisterModule(IOrpheusModule module)

Parameters

module IOrpheusModule

Module to be registered

RollbackTransaction(IDbTransaction)

Rolls back a transaction.

public void RollbackTransaction(IDbTransaction transaction)

Parameters

transaction IDbTransaction

Transaction to be rolled-back.

RollbackTransactionAsync(IDbTransaction, CancellationToken)

Asynchronously rolls back a transaction.

public Task RollbackTransactionAsync(IDbTransaction transaction, CancellationToken cancellationToken = default)

Parameters

transaction IDbTransaction
cancellationToken CancellationToken

Returns

Task

SQLAsync<T>(IDbCommand, string, CancellationToken)

Asynchronously executes a prepared DbCommand and returns typed models.

public Task<List<T>> SQLAsync<T>(IDbCommand dbCommand, string tableName = null, CancellationToken cancellationToken = default)

Parameters

dbCommand IDbCommand
tableName string
cancellationToken CancellationToken

Returns

Task<List<T>>

Type Parameters

T

SQLAsync<T>(string, string, CancellationToken)

Asynchronously executes a SQL statement and returns typed models.

public Task<List<T>> SQLAsync<T>(string SQL, string tableName = null, CancellationToken cancellationToken = default)

Parameters

SQL string
tableName string
cancellationToken CancellationToken

Returns

Task<List<T>>

Type Parameters

T

SQL<T>(IDbCommand, string)

Executes a db command and returns it as specific model.

public List<T> SQL<T>(IDbCommand dbCommand, string tableName = null)

Parameters

dbCommand IDbCommand

DbCommand to run.

tableName string

Optionally set the table name, for which the query will run.

Returns

List<T>

A list of 'T'

Type Parameters

T

SQL<T>(string, string)

Executes a SQL statement and returns it as specific model.

public List<T> SQL<T>(string SQL, string tableName = null)

Parameters

SQL string

SQL command to execute.

tableName string

Table name.

Returns

List<T>

A list of 'T'

Type Parameters

T