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
connectionFactoryIOrpheusConnectionFactoryThe connection factory.
ddlHelperIOrpheusDDLHelperThe DDL helper.
loggerILogger<IOrpheusDatabase>The logger
serviceProviderIServiceProviderOptional service provider for resolving dependencies.
loggerFactoryILoggerFactoryOptional 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
connectionIDbConnectionThe connection.
ddlHelperIOrpheusDDLHelperThe DDL helper.
loggerILogger<IOrpheusDatabase>The logger
serviceProviderIServiceProviderOptional service provider for resolving dependencies.
loggerFactoryILoggerFactoryOptional 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
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
cancellationTokenCancellationToken
Returns
CommitTransaction(IDbTransaction)
Commits a transaction.
public void CommitTransaction(IDbTransaction transaction)
Parameters
transactionIDbTransactionTransaction to be committed.
CommitTransactionAsync(IDbTransaction, CancellationToken)
Asynchronously commits a transaction.
public Task CommitTransactionAsync(IDbTransaction transaction, CancellationToken cancellationToken = default)
Parameters
transactionIDbTransactioncancellationTokenCancellationToken
Returns
Connect(IDatabaseConnectionConfiguration)
Connects to the database engine defined in the configuration object.
public void Connect(IDatabaseConnectionConfiguration databaseConnectionConfiguration)
Parameters
databaseConnectionConfigurationIDatabaseConnectionConfiguration
Connect(string)
Connects to the database engine defined in the connection string.
public void Connect(string connectionString = null)
Parameters
connectionStringstring
ConnectAsync(string, CancellationToken)
Asynchronously connects to the database engine.
public Task ConnectAsync(string connectionString = null, CancellationToken cancellationToken = default)
Parameters
connectionStringstringcancellationTokenCancellationToken
Returns
CreateCommand()
Create a DbCommand.
public IDbCommand CreateCommand()
Returns
- IDbCommand
A DbCommand instance.
CreateModule(IOrpheusModuleDefinition)
Creates an OrpheusModule.
public IOrpheusModule CreateModule(IOrpheusModuleDefinition definition = null)
Parameters
definitionIOrpheusModuleDefinitionModule 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
SQLstringSQL 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
SQLstringSQL for the prepared query
parametersList<string>SQL parameters
parameterValuesList<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
idGuidSchema id
descriptionstringSchema description
versiondoubleSchema version
namestringSchema 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
optionsIOrpheusTableOptionsTable options
Returns
- IOrpheusTable<T>
An Orpheus table instance.
Type Parameters
TModel 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
tableNamestringTable name
keyFieldsList<IOrpheusTableKeyField>Table key fields
Returns
- IOrpheusTable<T>
An Orpheus table instance.
Type Parameters
TModel 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
TType 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
Dispose()
Disposes the database connection and associated resources.
public void Dispose()
Dispose(bool)
Disposes managed resources.
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
ExecuteDDL(string)
Executes a DDL command.
public bool ExecuteDDL(string DDLCommand)
Parameters
DDLCommandstringDbCommand 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
DDLCommandstringcancellationTokenCancellationToken
Returns
GetTableCount(string)
Returns the row count of a table.
public long GetTableCount(string tableName)
Parameters
tableNamestringThe table name.
Returns
GetTableCount<T>()
Returns the row count of a table.
public long GetTableCount<T>()
Returns
Type Parameters
TThe table type.
IsNullableType(Type)
Returns true if the type is a nullable type.
public bool IsNullableType(Type type)
Parameters
typeTypeType
Returns
- bool
True if type is nullable
RegisterModule(IOrpheusModule)
Register an Orpheus module to the database.
public void RegisterModule(IOrpheusModule module)
Parameters
moduleIOrpheusModuleModule to be registered
RollbackTransaction(IDbTransaction)
Rolls back a transaction.
public void RollbackTransaction(IDbTransaction transaction)
Parameters
transactionIDbTransactionTransaction to be rolled-back.
RollbackTransactionAsync(IDbTransaction, CancellationToken)
Asynchronously rolls back a transaction.
public Task RollbackTransactionAsync(IDbTransaction transaction, CancellationToken cancellationToken = default)
Parameters
transactionIDbTransactioncancellationTokenCancellationToken
Returns
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
dbCommandIDbCommandtableNamestringcancellationTokenCancellationToken
Returns
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
SQLstringtableNamestringcancellationTokenCancellationToken
Returns
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
dbCommandIDbCommandDbCommand to run.
tableNamestringOptionally 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
Returns
- List<T>
A list of 'T'
Type Parameters
T