diff --git a/PetaPoco/Core/ColumnInfo.cs b/PetaPoco/Core/ColumnInfo.cs index 8168691b..afa7d6f0 100644 --- a/PetaPoco/Core/ColumnInfo.cs +++ b/PetaPoco/Core/ColumnInfo.cs @@ -92,6 +92,18 @@ public class ColumnInfo /// public string UpdateTemplate { get; set; } + /// + /// Creates and populates a ColumnInfo from the attributes of a POCO property. + /// + /// The POCO property to use for initializing the ColumnInfo. + /// A ColumnInfo instance. + public static ColumnInfo FromProperty(PropertyInfo propertyInfo) + { + var ci = new ColumnInfo(); + PopulateFromProperty(propertyInfo, ref ci, out _); + return ci; + } + internal static void PopulateFromProperty(PropertyInfo pi, ref ColumnInfo ci, out ColumnAttribute columnAttr) { // Check if declaring poco has [Explicit] attribute @@ -123,17 +135,5 @@ internal static void PopulateFromProperty(PropertyInfo pi, ref ColumnInfo ci, ou } } } - - /// - /// Creates and populates a ColumnInfo from the attributes of a POCO property. - /// - /// The POCO property to use for initializing the ColumnInfo. - /// A ColumnInfo instance. - public static ColumnInfo FromProperty(PropertyInfo propertyInfo) - { - var ci = new ColumnInfo(); - PopulateFromProperty(propertyInfo, ref ci, out _); - return ci; - } } } diff --git a/PetaPoco/Core/IGridReader.cs b/PetaPoco/Core/IGridReader.cs index a2406075..1681dec3 100644 --- a/PetaPoco/Core/IGridReader.cs +++ b/PetaPoco/Core/IGridReader.cs @@ -8,6 +8,8 @@ namespace PetaPoco /// public interface IGridReader : IDisposable { + #region ReadSinglePoco + /// /// Performs a read, returning the results as an collection. /// @@ -15,6 +17,10 @@ public interface IGridReader : IDisposable /// An enumerable collection of POCOs containing the result records. IEnumerable Read(); + #endregion + + #region ReadMultiPoco : auto-mapping + /// IEnumerable Read(); @@ -31,6 +37,10 @@ public interface IGridReader : IDisposable /// An enumerable collection of POCOs containing the result records. IEnumerable Read(); + #endregion + + #region ReadMultiPoco : custom-mapping + /// IEnumerable Read(Func func); @@ -48,5 +58,7 @@ public interface IGridReader : IDisposable /// A callback function to used to connect the POCO instances, or to let PetaPoco automatically deduce the relationships. /// An enumerable collection of POCOs containing the result records. IEnumerable Read(Func func); + + #endregion } } diff --git a/PetaPoco/Core/PocoData.cs b/PetaPoco/Core/PocoData.cs index 255f4ef0..a9e9ac31 100644 --- a/PetaPoco/Core/PocoData.cs +++ b/PetaPoco/Core/PocoData.cs @@ -74,6 +74,14 @@ public PocoData(Type type, IMapper defaultMapper) QueryColumns = (from c in Columns where !c.Value.ResultColumn || c.Value.AutoSelectedResultColumn select c.Key).ToArray(); } + public static PocoData ForType(Type type, IMapper defaultMapper) + { + if (type == typeof(System.Dynamic.ExpandoObject)) + throw new InvalidOperationException("Can't use dynamic types with this method"); + + return _pocoDatas.GetOrAdd(type, () => new PocoData(type, defaultMapper)); + } + public static PocoData ForObject(object obj, string primaryKeyName, IMapper defaultMapper) { var t = obj.GetType(); @@ -97,20 +105,6 @@ public static PocoData ForObject(object obj, string primaryKeyName, IMapper defa return ForType(t, defaultMapper); } - public static PocoData ForType(Type type, IMapper defaultMapper) - { - if (type == typeof(System.Dynamic.ExpandoObject)) - throw new InvalidOperationException("Can't use dynamic types with this method"); - - return _pocoDatas.GetOrAdd(type, () => new PocoData(type, defaultMapper)); - } - - private static bool IsIntegralType(Type type) - { - var tc = Type.GetTypeCode(type); - return tc >= TypeCode.SByte && tc <= TypeCode.UInt64; - } - // Create factory function that can convert a IDataReader record into a POCO public Delegate GetFactory(string sql, string connectionString, int firstColumn, int countColumns, IDataReader reader, IMapper defaultMapper) { @@ -393,6 +387,12 @@ private static Func GetConverter(IMapper mapper, PocoColumn pc, return null; } + private static bool IsIntegralType(Type type) + { + var tc = Type.GetTypeCode(type); + return tc >= TypeCode.SByte && tc <= TypeCode.UInt64; + } + private static T RecurseInheritedTypes(Type t, Func cb) { while (t != null) diff --git a/PetaPoco/DatabaseConfigurationExtensions.cs b/PetaPoco/DatabaseConfigurationExtensions.cs index 85d40bfe..5fa286ea 100644 --- a/PetaPoco/DatabaseConfigurationExtensions.cs +++ b/PetaPoco/DatabaseConfigurationExtensions.cs @@ -12,13 +12,13 @@ public static class DatabaseConfigurationExtensions internal const string CommandTimeout = "CommandTimeout"; internal const string EnableAutoSelect = "EnableAutoSelect"; internal const string EnableNamedParams = "EnableNamedParams"; - internal const string Provider = "Provider"; - internal const string ConnectionString = "ConnectionString"; - internal const string ProviderName = "ProviderName"; #if !NETSTANDARD internal const string ConnectionStringName = "ConnectionStringName"; #endif + internal const string ConnectionString = "ConnectionString"; + internal const string ProviderName = "ProviderName"; + internal const string Provider = "Provider"; internal const string DefaultMapper = "DefaultMapper"; internal const string IsolationLevel = "IsolationLevel"; @@ -37,6 +37,8 @@ private static void SetSetting(this IDatabaseBuildConfiguration source, string k ((IBuildConfigurationSettings) source).SetSetting(key, value); } + #region Timeout Settings + /// /// Adds a command timeout - see . /// @@ -52,208 +54,223 @@ public static IDatabaseBuildConfiguration UsingCommandTimeout(this IDatabaseBuil return source; } + #endregion + + #region AutoSelect Settings + /// - /// Enables named params - see . + /// Enables auto select . /// /// The configuration source. /// The original configuration, to form a fluent interface. - public static IDatabaseBuildConfiguration WithNamedParams(this IDatabaseBuildConfiguration source) + public static IDatabaseBuildConfiguration WithAutoSelect(this IDatabaseBuildConfiguration source) { - source.SetSetting(EnableNamedParams, true); + source.SetSetting(EnableAutoSelect, true); return source; } /// - /// Disables named params - see . + /// Disables auto select - see . /// /// The configuration source. /// The original configuration, to form a fluent interface. - public static IDatabaseBuildConfiguration WithoutNamedParams(this IDatabaseBuildConfiguration source) + public static IDatabaseBuildConfiguration WithoutAutoSelect(this IDatabaseBuildConfiguration source) { - source.SetSetting(EnableNamedParams, false); + source.SetSetting(EnableAutoSelect, false); return source; } + #endregion + + #region NamedParams Settings + /// - /// Specifies the provider to be used. - see . This takes precedence over . + /// Enables named params - see . /// /// The configuration source. - /// The provider to use. /// The original configuration, to form a fluent interface. - /// Thrown when is null. - public static IDatabaseBuildConfiguration UsingProvider(this IDatabaseBuildConfiguration source, T provider) where T : class, IProvider + public static IDatabaseBuildConfiguration WithNamedParams(this IDatabaseBuildConfiguration source) { - if (provider == null) - throw new ArgumentNullException(nameof(provider)); - source.SetSetting(Provider, provider); + source.SetSetting(EnableNamedParams, true); return source; } /// - /// Specifies the provider to be used. - see . This takes precedence over . + /// Disables named params - see . /// - /// The provider type. /// The configuration source. - /// The configure provider callback. - /// The provider to use. /// The original configuration, to form a fluent interface. - /// Thrown when is null. - /// Thrown when is null. - public static IDatabaseBuildConfiguration UsingProvider(this IDatabaseBuildConfiguration source, T provider, Action configure) where T : class, IProvider + public static IDatabaseBuildConfiguration WithoutNamedParams(this IDatabaseBuildConfiguration source) { - if (provider == null) - throw new ArgumentNullException(nameof(provider)); - if (configure == null) - throw new ArgumentNullException(nameof(configure)); - configure(provider); - source.SetSetting(Provider, provider); + source.SetSetting(EnableNamedParams, false); return source; } + #endregion + + #region Connection Settings + +#if !NETSTANDARD /// - /// Specifies the provider to be used. - see . This takes precedence over . + /// Adds a connection string name. /// - /// The provider type. /// The configuration source. + /// The connection string name. /// The original configuration, to form a fluent interface. - public static IDatabaseBuildConfiguration UsingProvider(this IDatabaseBuildConfiguration source) where T : class, IProvider, new() + /// Thrown when is null or empty. + public static IDatabaseBuildConfiguration UsingConnectionStringName(this IDatabaseBuildConfiguration source, string connectionStringName) { - source.SetSetting(Provider, new T()); + if (string.IsNullOrEmpty(connectionStringName)) + throw new ArgumentException("Argument is null or empty", nameof(connectionStringName)); + source.SetSetting(ConnectionStringName, connectionStringName); return source; } +#endif /// - /// Specifies the to use, with an accompanying configuration provider custom callback. + /// Adds a connection string - see . /// - /// The provider type, constrained to a class deriving from . /// The configuration source. - /// The configure provider callback. + /// The connection string. /// The original configuration, to form a fluent interface. - /// Thrown when is null. - public static IDatabaseBuildConfiguration UsingProvider(this IDatabaseBuildConfiguration source, Action configure) where T : class, IProvider, new() + /// Thrown when is null or empty. + public static IDatabaseBuildConfiguration UsingConnectionString(this IDatabaseBuildConfiguration source, string connectionString) { - if (configure == null) - throw new ArgumentNullException(nameof(configure)); - var provider = new T(); - configure(provider); - source.SetSetting(Provider, provider); + if (string.IsNullOrEmpty(connectionString)) + throw new ArgumentException("Argument is null or empty", nameof(connectionString)); + source.SetSetting(ConnectionString, connectionString); return source; } /// - /// Enables auto select . + /// Specifies an to use. /// /// The configuration source. + /// The connection to use. /// The original configuration, to form a fluent interface. - public static IDatabaseBuildConfiguration WithAutoSelect(this IDatabaseBuildConfiguration source) + public static IDatabaseBuildConfiguration UsingConnection(this IDatabaseBuildConfiguration source, IDbConnection connection) { - source.SetSetting(EnableAutoSelect, true); + if (connection == null) + throw new ArgumentNullException(nameof(connection)); + + source.SetSetting(Connection, connection); return source; } + #endregion + + #region Provider Settings + /// - /// Disables auto select - see . + /// Adds a provider name string - see . /// /// The configuration source. + /// The provider name. /// The original configuration, to form a fluent interface. - public static IDatabaseBuildConfiguration WithoutAutoSelect(this IDatabaseBuildConfiguration source) + /// Thrown when is null or empty. + public static IDatabaseBuildConfiguration UsingProviderName(this IDatabaseBuildConfiguration source, string providerName) { - source.SetSetting(EnableAutoSelect, false); + if (string.IsNullOrEmpty(providerName)) + throw new ArgumentException("Argument is null or empty", nameof(providerName)); + source.SetSetting(ProviderName, providerName); return source; } /// - /// Adds a connection string - see . + /// Specifies the provider to be used. - see . This takes precedence over . /// + /// The provider type. /// The configuration source. - /// The connection string. /// The original configuration, to form a fluent interface. - /// Thrown when is null or empty. - public static IDatabaseBuildConfiguration UsingConnectionString(this IDatabaseBuildConfiguration source, string connectionString) + public static IDatabaseBuildConfiguration UsingProvider(this IDatabaseBuildConfiguration source) where T : class, IProvider, new() { - if (string.IsNullOrEmpty(connectionString)) - throw new ArgumentException("Argument is null or empty", nameof(connectionString)); - source.SetSetting(ConnectionString, connectionString); + source.SetSetting(Provider, new T()); return source; } -#if !NETSTANDARD /// - /// Adds a connection string name. + /// Specifies the to use, with an accompanying configuration provider custom callback. /// + /// The provider type, constrained to a class deriving from . /// The configuration source. - /// The connection string name. + /// The configure provider callback. /// The original configuration, to form a fluent interface. - /// Thrown when is null or empty. - public static IDatabaseBuildConfiguration UsingConnectionStringName(this IDatabaseBuildConfiguration source, string connectionStringName) + /// Thrown when is null. + public static IDatabaseBuildConfiguration UsingProvider(this IDatabaseBuildConfiguration source, Action configure) where T : class, IProvider, new() { - if (string.IsNullOrEmpty(connectionStringName)) - throw new ArgumentException("Argument is null or empty", nameof(connectionStringName)); - source.SetSetting(ConnectionStringName, connectionStringName); + if (configure == null) + throw new ArgumentNullException(nameof(configure)); + var provider = new T(); + configure(provider); + source.SetSetting(Provider, provider); return source; } -#endif /// - /// Adds a provider name string - see . + /// Specifies the provider to be used. - see . This takes precedence over . /// /// The configuration source. - /// The provider name. + /// The provider to use. /// The original configuration, to form a fluent interface. - /// Thrown when is null or empty. - public static IDatabaseBuildConfiguration UsingProviderName(this IDatabaseBuildConfiguration source, string providerName) + /// Thrown when is null. + public static IDatabaseBuildConfiguration UsingProvider(this IDatabaseBuildConfiguration source, T provider) where T : class, IProvider { - if (string.IsNullOrEmpty(providerName)) - throw new ArgumentException("Argument is null or empty", nameof(providerName)); - source.SetSetting(ProviderName, providerName); + if (provider == null) + throw new ArgumentNullException(nameof(provider)); + source.SetSetting(Provider, provider); return source; } /// - /// Specifies an to use. + /// Specifies the provider to be used. - see . This takes precedence over . /// + /// The provider type. /// The configuration source. - /// The connection to use. + /// The configure provider callback. + /// The provider to use. /// The original configuration, to form a fluent interface. - public static IDatabaseBuildConfiguration UsingConnection(this IDatabaseBuildConfiguration source, IDbConnection connection) + /// Thrown when is null. + /// Thrown when is null. + public static IDatabaseBuildConfiguration UsingProvider(this IDatabaseBuildConfiguration source, T provider, Action configure) where T : class, IProvider { - if (connection == null) - throw new ArgumentNullException(nameof(connection)); - - source.SetSetting(Connection, connection); + if (provider == null) + throw new ArgumentNullException(nameof(provider)); + if (configure == null) + throw new ArgumentNullException(nameof(configure)); + configure(provider); + source.SetSetting(Provider, provider); return source; } + #endregion + + #region Mapper Settings + /// /// Specifies the default mapper to use when no specific mapper has been registered. /// + /// The mapper type. /// The configuration source. - /// The mapper to use as the default. /// The original configuration, to form a fluent interface. - /// Thrown when is null. - public static IDatabaseBuildConfiguration UsingDefaultMapper(this IDatabaseBuildConfiguration source, T mapper) where T : class, IMapper + public static IDatabaseBuildConfiguration UsingDefaultMapper(this IDatabaseBuildConfiguration source) where T : class, IMapper, new() { - if (mapper == null) - throw new ArgumentNullException(nameof(mapper)); - source.SetSetting(DefaultMapper, mapper); + source.SetSetting(DefaultMapper, new T()); return source; } /// /// Specifies the default mapper to use when no specific mapper has been registered. /// + /// The type of the mapper. This type must be a class that implements the interface. /// The configuration source. - /// The mapper to use as the default. - /// The configure mapper callback. + /// A callback function to configure the mapper. /// The original configuration, to form a fluent interface. - /// Thrown when is null. - /// Thrown when is null. - public static IDatabaseBuildConfiguration UsingDefaultMapper(this IDatabaseBuildConfiguration source, T mapper, Action configure) where T : class, IMapper + /// Thrown if the callback function is null. + public static IDatabaseBuildConfiguration UsingDefaultMapper(this IDatabaseBuildConfiguration source, Action configure) where T : class, IMapper, new() { - if (mapper == null) - throw new ArgumentNullException(nameof(mapper)); if (configure == null) throw new ArgumentNullException(nameof(configure)); + var mapper = new T(); configure(mapper); source.SetSetting(DefaultMapper, mapper); return source; @@ -262,33 +279,42 @@ public static IDatabaseBuildConfiguration UsingDefaultMapper(this IDatabaseBu /// /// Specifies the default mapper to use when no specific mapper has been registered. /// - /// The mapper type. /// The configuration source. + /// The mapper to use as the default. /// The original configuration, to form a fluent interface. - public static IDatabaseBuildConfiguration UsingDefaultMapper(this IDatabaseBuildConfiguration source) where T : class, IMapper, new() + /// Thrown when is null. + public static IDatabaseBuildConfiguration UsingDefaultMapper(this IDatabaseBuildConfiguration source, T mapper) where T : class, IMapper { - source.SetSetting(DefaultMapper, new T()); + if (mapper == null) + throw new ArgumentNullException(nameof(mapper)); + source.SetSetting(DefaultMapper, mapper); return source; } /// /// Specifies the default mapper to use when no specific mapper has been registered. /// - /// The type of the mapper. This type must be a class that implements the interface. /// The configuration source. - /// A callback function to configure the mapper. + /// The mapper to use as the default. + /// The configure mapper callback. /// The original configuration, to form a fluent interface. - /// Thrown if the callback function is null. - public static IDatabaseBuildConfiguration UsingDefaultMapper(this IDatabaseBuildConfiguration source, Action configure) where T : class, IMapper, new() + /// Thrown when is null. + /// Thrown when is null. + public static IDatabaseBuildConfiguration UsingDefaultMapper(this IDatabaseBuildConfiguration source, T mapper, Action configure) where T : class, IMapper { + if (mapper == null) + throw new ArgumentNullException(nameof(mapper)); if (configure == null) throw new ArgumentNullException(nameof(configure)); - var mapper = new T(); configure(mapper); source.SetSetting(DefaultMapper, mapper); return source; } + #endregion + + #region Transaction Settings + /// /// Specifies the transaction isolation level to use. /// @@ -301,6 +327,10 @@ public static IDatabaseBuildConfiguration UsingIsolationLevel(this IDatabaseBuil return source; } + #endregion + + #region Event Settings + /// /// Specifies an event handler to use when a new transaction has been started. /// @@ -397,6 +427,10 @@ public static IDatabaseBuildConfiguration UsingExceptionThrown(this IDatabaseBui return source; } + #endregion + + #region Finalize Fluent Configuration + /// /// Creates an instance of PetaPoco using the specified . /// @@ -406,5 +440,7 @@ public static IDatabase Create(this IDatabaseBuildConfiguration source) { return new Database(source); } + + #endregion } } diff --git a/PetaPoco/IAlterPoco.cs b/PetaPoco/IAlterPoco.cs index cbdaa0b4..30240182 100644 --- a/PetaPoco/IAlterPoco.cs +++ b/PetaPoco/IAlterPoco.cs @@ -6,6 +6,16 @@ public interface IAlterPoco { #region Insert + /// + /// Performs an SQL Insert. + /// + /// + /// The name of the table, its primary key and whether it's an auto-allocated primary key are retrieved from the POCO's attributes + /// + /// A POCO object containing the column values to be inserted. + /// The auto allocated primary key of the new record, or for non-auto-increment tables. + object Insert(object poco); + /// /// Performs an SQL Insert. /// @@ -36,16 +46,6 @@ public interface IAlterPoco /// The auto allocated primary key of the new record, or for non-auto-increment tables. object Insert(string tableName, string primaryKeyName, bool autoIncrement, object poco); - /// - /// Performs an SQL Insert. - /// - /// - /// The name of the table, its primary key and whether it's an auto-allocated primary key are retrieved from the POCO's attributes - /// - /// A POCO object containing the column values to be inserted. - /// The auto allocated primary key of the new record, or for non-auto-increment tables. - object Insert(object poco); - #endregion #region Update @@ -53,96 +53,103 @@ public interface IAlterPoco /// /// Performs an SQL update. /// - /// The name of the table to update. - /// The name of the primary key column of the table. /// A POCO object containing the column values to be updated. - /// The primary key of the record to be updated. - /// The number of affected records. - int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue); + /// The number of affected rows. + int Update(object poco); /// /// Performs an SQL update. /// - /// The name of the table to update. - /// The name of the primary key column of the table. /// A POCO object containing the column values to be updated. - /// The primary key of the record to be updated. /// The column names of the columns to be updated, or for all. /// The number of affected rows. - int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable columns); + int Update(object poco, IEnumerable columns); /// /// Performs an SQL update. /// - /// The name of the table to update. - /// The name of the primary key column of the table. /// A POCO object containing the column values to be updated. + /// The primary key of the record to be updated. /// The number of affected rows. - int Update(string tableName, string primaryKeyName, object poco); + int Update(object poco, object primaryKeyValue); /// /// Performs an SQL update. /// - /// The name of the table to update. - /// The name of the primary key column of the table. /// A POCO object containing the column values to be updated. + /// The primary key of the record to be updated. /// The column names of the columns to be updated, or for all. /// The number of affected rows. - int Update(string tableName, string primaryKeyName, object poco, IEnumerable columns); + int Update(object poco, object primaryKeyValue, IEnumerable columns); /// /// Performs an SQL update. /// + /// The name of the table to update. + /// The name of the primary key column of the table. /// A POCO object containing the column values to be updated. - /// The column names of the columns to be updated, or for all. /// The number of affected rows. - int Update(object poco, IEnumerable columns); + int Update(string tableName, string primaryKeyName, object poco); /// /// Performs an SQL update. /// + /// The name of the table to update. + /// The name of the primary key column of the table. /// A POCO object containing the column values to be updated. + /// The column names of the columns to be updated, or for all. /// The number of affected rows. - int Update(object poco); + int Update(string tableName, string primaryKeyName, object poco, IEnumerable columns); /// /// Performs an SQL update. /// + /// The name of the table to update. + /// The name of the primary key column of the table. /// A POCO object containing the column values to be updated. /// The primary key of the record to be updated. - /// The number of affected rows. - int Update(object poco, object primaryKeyValue); + /// The number of affected records. + int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue); /// /// Performs an SQL update. /// + /// The name of the table to update. + /// The name of the primary key column of the table. /// A POCO object containing the column values to be updated. /// The primary key of the record to be updated. /// The column names of the columns to be updated, or for all. /// The number of affected rows. - int Update(object poco, object primaryKeyValue, IEnumerable columns); + int Update(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable columns); /// /// Performs an SQL update. /// /// The POCO class whose attributes specify the name of the table to update. - /// The SQL update and condition clause (everything after UPDATE tablename). - /// Arguments to any embedded parameters in the SQL. + /// An SQL builder object representing the SQL update and condition clause (everything after UPDATE tablename). /// The number of affected rows. - int Update(string sql, params object[] args); + int Update(Sql sql); /// /// Performs an SQL update. /// /// The POCO class whose attributes specify the name of the table to update. - /// An SQL builder object representing the SQL update and condition clause (everything after UPDATE tablename). + /// The SQL update and condition clause (everything after UPDATE tablename). + /// Arguments to any embedded parameters in the SQL. /// The number of affected rows. - int Update(Sql sql); + int Update(string sql, params object[] args); #endregion #region Delete + /// + /// Performs an SQL Delete. + /// + /// A POCO object specifying the table name and primary key value of the row to be deleted. + /// The number of rows affected. + int Delete(object poco); + /// /// Performs an SQL Delete. /// @@ -162,13 +169,6 @@ public interface IAlterPoco /// The number of rows affected. int Delete(string tableName, string primaryKeyName, object poco, object primaryKeyValue); - /// - /// Performs an SQL Delete. - /// - /// A POCO object specifying the table name and primary key value of the row to be deleted. - /// The number of rows affected. - int Delete(object poco); - /// /// Performs an SQL Delete. /// @@ -181,18 +181,18 @@ public interface IAlterPoco /// Performs an SQL Delete. /// /// The POCO class whose attributes specify the name of the table to delete from. - /// The SQL condition clause identifying the row to delete (everything after DELETE FROM tablename). - /// Arguments to any embedded parameters in the SQL. + /// An SQL builder object representing the SQL condition clause identifying the row to delete (everything after DELETE FROM tablename). /// The number of affected rows. - int Delete(string sql, params object[] args); + int Delete(Sql sql); /// /// Performs an SQL Delete. /// /// The POCO class whose attributes specify the name of the table to delete from. - /// An SQL builder object representing the SQL condition clause identifying the row to delete (everything after DELETE FROM tablename). + /// The SQL condition clause identifying the row to delete (everything after DELETE FROM tablename). + /// Arguments to any embedded parameters in the SQL. /// The number of affected rows. - int Delete(Sql sql); + int Delete(string sql, params object[] args); #endregion @@ -204,10 +204,9 @@ public interface IAlterPoco /// /// This method simply tests if the POCO's primary key column property has a non-default value. /// - /// The name of the primary key column. /// The object instance whose "newness" is to be tested. /// if the POCO represents a record already in the database. - bool IsNew(string primaryKeyName, object poco); + bool IsNew(object poco); /// /// Checks if a poco represents a new row. @@ -215,9 +214,10 @@ public interface IAlterPoco /// /// This method simply tests if the POCO's primary key column property has a non-default value. /// + /// The name of the primary key column. /// The object instance whose "newness" is to be tested. /// if the POCO represents a record already in the database. - bool IsNew(object poco); + bool IsNew(string primaryKeyName, object poco); #endregion @@ -226,16 +226,16 @@ public interface IAlterPoco /// /// Saves a POCO by performing either an INSERT or UPDATE operation. /// - /// The name of the table to be updated. - /// The name of the primary key column. /// The POCO object to be saved. - void Save(string tableName, string primaryKeyName, object poco); + void Save(object poco); /// /// Saves a POCO by performing either an INSERT or UPDATE operation. /// + /// The name of the table to be updated. + /// The name of the primary key column. /// The POCO object to be saved. - void Save(object poco); + void Save(string tableName, string primaryKeyName, object poco); #endregion } diff --git a/PetaPoco/IAlterPocoAsync.cs b/PetaPoco/IAlterPocoAsync.cs index 392df356..6e1f98c0 100644 --- a/PetaPoco/IAlterPocoAsync.cs +++ b/PetaPoco/IAlterPocoAsync.cs @@ -6,17 +6,17 @@ namespace PetaPoco { public interface IAlterPocoAsync { - #region Insert + #region InsertAsync /// - /// Async version of . + /// Async version of . /// - Task InsertAsync(string tableName, object poco); + Task InsertAsync(object poco); /// /// Async version of . /// - Task InsertAsync(CancellationToken cancellationToken, string tableName, object poco); + Task InsertAsync(string tableName, object poco); /// /// Async version of . @@ -24,88 +24,83 @@ public interface IAlterPocoAsync Task InsertAsync(string tableName, string primaryKeyName, object poco); /// - /// Async version of . + /// Async version of . /// - Task InsertAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco); + Task InsertAsync(string tableName, string primaryKeyName, bool autoIncrement, object poco); /// - /// Async version of . + /// Async version of . /// - Task InsertAsync(string tableName, string primaryKeyName, bool autoIncrement, object poco); + Task InsertAsync(CancellationToken cancellationToken, object poco); /// - /// Async version of . + /// Async version of . /// - Task InsertAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, bool autoIncrement, object poco); + Task InsertAsync(CancellationToken cancellationToken, string tableName, object poco); /// - /// Async version of . + /// Async version of . /// - Task InsertAsync(object poco); + Task InsertAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco); /// - /// Async version of . + /// Async version of . /// - Task InsertAsync(CancellationToken cancellationToken, object poco); + Task InsertAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, bool autoIncrement, object poco); #endregion - #region Update + #region UpdateAsync /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(string tableName, string primaryKeyName, object poco, object primaryKeyValue); + Task UpdateAsync(object poco); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco, object primaryKeyValue); + Task UpdateAsync(object poco, IEnumerable columns); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable columns); + Task UpdateAsync(object poco, object primaryKeyValue); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable columns); + Task UpdateAsync(object poco, object primaryKeyValue, IEnumerable columns); /// /// Async version of . /// Task UpdateAsync(string tableName, string primaryKeyName, object poco); - /// - /// Async version of . - /// - Task UpdateAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco); - /// /// Async version of . /// Task UpdateAsync(string tableName, string primaryKeyName, object poco, IEnumerable columns); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco, IEnumerable columns); + Task UpdateAsync(string tableName, string primaryKeyName, object poco, object primaryKeyValue); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(object poco, IEnumerable columns); + Task UpdateAsync(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable columns); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(CancellationToken cancellationToken, object poco, IEnumerable columns); + Task UpdateAsync(Sql sql); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(object poco); + Task UpdateAsync(string sql, params object[] args); /// /// Async version of . @@ -113,9 +108,9 @@ public interface IAlterPocoAsync Task UpdateAsync(CancellationToken cancellationToken, object poco); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(object poco, object primaryKeyValue); + Task UpdateAsync(CancellationToken cancellationToken, object poco, IEnumerable columns); /// /// Async version of . @@ -125,46 +120,51 @@ public interface IAlterPocoAsync /// /// Async version of . /// - Task UpdateAsync(object poco, object primaryKeyValue, IEnumerable columns); + Task UpdateAsync(CancellationToken cancellationToken, object poco, object primaryKeyValue, IEnumerable columns); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(CancellationToken cancellationToken, object poco, object primaryKeyValue, IEnumerable columns); + Task UpdateAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(string sql, params object[] args); + Task UpdateAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco, IEnumerable columns); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(CancellationToken cancellationToken, string sql, params object[] args); + Task UpdateAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco, object primaryKeyValue); /// - /// Async version of . + /// Async version of . /// - Task UpdateAsync(Sql sql); + Task UpdateAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable columns); /// /// Async version of . /// Task UpdateAsync(CancellationToken cancellationToken, Sql sql); + /// + /// Async version of . + /// + Task UpdateAsync(CancellationToken cancellationToken, string sql, params object[] args); + #endregion - #region Delete + #region DeleteAsync /// - /// Async version of . + /// Async version of . /// - Task DeleteAsync(string tableName, string primaryKeyName, object poco); + Task DeleteAsync(object poco); /// /// Async version of . /// - Task DeleteAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco); + Task DeleteAsync(string tableName, string primaryKeyName, object poco); /// /// Async version of . @@ -172,73 +172,73 @@ public interface IAlterPocoAsync Task DeleteAsync(string tableName, string primaryKeyName, object poco, object primaryKeyValue); /// - /// Async version of . + /// Async version of . /// - Task DeleteAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco, object primaryKeyValue); + Task DeleteAsync(object pocoOrPrimaryKey); /// - /// Async version of . + /// Async version of . /// - Task DeleteAsync(object poco); + Task DeleteAsync(Sql sql); /// - /// Async version of . + /// Async version of . /// - Task DeleteAsync(CancellationToken cancellationToken, object poco); + Task DeleteAsync(string sql, params object[] args); /// - /// Async version of . + /// Async version of . /// - Task DeleteAsync(object pocoOrPrimaryKey); + Task DeleteAsync(CancellationToken cancellationToken, object poco); /// - /// Async version of . + /// Async version of . /// - Task DeleteAsync(CancellationToken cancellationToken, object pocoOrPrimaryKey); + Task DeleteAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco); /// - /// Async version of . + /// Async version of . /// - Task DeleteAsync(string sql, params object[] args); + Task DeleteAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco, object primaryKeyValue); /// - /// Async version of . + /// Async version of . /// - Task DeleteAsync(CancellationToken cancellationToken, string sql, params object[] args); + Task DeleteAsync(CancellationToken cancellationToken, object pocoOrPrimaryKey); /// /// Async version of . /// - Task DeleteAsync(Sql sql); + Task DeleteAsync(CancellationToken cancellationToken, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task DeleteAsync(CancellationToken cancellationToken, Sql sql); + Task DeleteAsync(CancellationToken cancellationToken, string sql, params object[] args); #endregion - #region Save + #region SaveAsync /// - /// Async version of . + /// Async version of . /// - Task SaveAsync(string tableName, string primaryKeyName, object poco); + Task SaveAsync(object poco); /// /// Async version of . /// - Task SaveAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco); + Task SaveAsync(string tableName, string primaryKeyName, object poco); /// /// Async version of . /// - Task SaveAsync(object poco); + Task SaveAsync(CancellationToken cancellationToken, object poco); /// - /// Async version of . + /// Async version of . /// - Task SaveAsync(CancellationToken cancellationToken, object poco); + Task SaveAsync(CancellationToken cancellationToken, string tableName, string primaryKeyName, object poco); #endregion } diff --git a/PetaPoco/IDatabase.cs b/PetaPoco/IDatabase.cs index 01f8cb96..5d04de0b 100644 --- a/PetaPoco/IDatabase.cs +++ b/PetaPoco/IDatabase.cs @@ -139,6 +139,18 @@ public interface IDatabase : IDisposable, IQuery, IAlterPoco, IExecute, ITransac /// void BeginTransaction(); +#if ASYNC + /// + /// Async version of . + /// + Task BeginTransactionAsync(); + + /// + /// Async version of . + /// + Task BeginTransactionAsync(CancellationToken cancellationToken); +#endif + /// /// Aborts the entire outermost transaction scope. /// @@ -177,31 +189,19 @@ public interface IDatabase : IDisposable, IQuery, IAlterPoco, IExecute, ITransac /// event EventHandler CommandExecuted; - /// - /// Occurs when a database connection is about to be closed. - /// - event EventHandler ConnectionClosing; - /// /// Occurs when a database connection has been opened. /// event EventHandler ConnectionOpened; /// - /// Occurs when a database exception has been thrown. - /// - event EventHandler ExceptionThrown; - -#if ASYNC - /// - /// Async version of . + /// Occurs when a database connection is about to be closed. /// - Task BeginTransactionAsync(); + event EventHandler ConnectionClosing; /// - /// Async version of . + /// Occurs when a database exception has been thrown. /// - Task BeginTransactionAsync(CancellationToken cancellationToken); -#endif + event EventHandler ExceptionThrown; } } diff --git a/PetaPoco/IExecute.cs b/PetaPoco/IExecute.cs index 17e3657b..9fe2154b 100644 --- a/PetaPoco/IExecute.cs +++ b/PetaPoco/IExecute.cs @@ -11,33 +11,33 @@ public interface IExecute /// /// Executes a non-query command. /// - /// The SQL statement to execute. - /// Arguments to any embedded parameters in the SQL statement. + /// An Sql builder object representing the SQL statement and its arguments. /// The number of rows affected. - int Execute(string sql, params object[] args); + int Execute(Sql sql); /// /// Executes a non-query command. /// - /// An Sql builder object representing the SQL statement and its arguments. + /// The SQL statement to execute. + /// Arguments to any embedded parameters in the SQL statement. /// The number of rows affected. - int Execute(Sql sql); + int Execute(string sql, params object[] args); /// /// Executes the query and returns the first column of the first row in the result set. /// /// The type that the result value should be cast to. - /// The SQL query to execute. - /// Arguments to any embedded parameters in the SQL statement. + /// An Sql builder object representing the SQL query and its arguments. /// The scalar value cast to . - T ExecuteScalar(string sql, params object[] args); + T ExecuteScalar(Sql sql); /// /// Executes the query and returns the first column of the first row in the result set. /// /// The type that the result value should be cast to. - /// An Sql builder object representing the SQL query and its arguments. + /// The SQL query to execute. + /// Arguments to any embedded parameters in the SQL statement. /// The scalar value cast to . - T ExecuteScalar(Sql sql); + T ExecuteScalar(string sql, params object[] args); } } diff --git a/PetaPoco/IExecuteAsync.cs b/PetaPoco/IExecuteAsync.cs index b82629e5..38e00178 100644 --- a/PetaPoco/IExecuteAsync.cs +++ b/PetaPoco/IExecuteAsync.cs @@ -12,53 +12,53 @@ namespace PetaPoco /// public interface IExecuteAsync { + /// + Task ExecuteAsync(Sql sql); + /// Task ExecuteAsync(string sql, params object[] args); + /// + Task ExecuteScalarAsync(Sql sql); + + /// + Task ExecuteScalarAsync(string sql, params object[] args); + /// /// Asynchronously executes a non-query command with a cancellation token. /// /// A cancellation token that can be used to cancel the operation. - /// The SQL statement to execute. - /// Arguments to any embedded parameters in the SQL statement. + /// An Sql builder object representing the SQL statement and its arguments. /// A task that represents the asynchronous operation. The task result is the number of rows affected. - Task ExecuteAsync(CancellationToken cancellationToken, string sql, params object[] args); - - /// - Task ExecuteAsync(Sql sql); + Task ExecuteAsync(CancellationToken cancellationToken, Sql sql); /// /// Asynchronously executes a non-query command with a cancellation token. /// /// A cancellation token that can be used to cancel the operation. - /// An Sql builder object representing the SQL statement and its arguments. + /// The SQL statement to execute. + /// Arguments to any embedded parameters in the SQL statement. /// A task that represents the asynchronous operation. The task result is the number of rows affected. - Task ExecuteAsync(CancellationToken cancellationToken, Sql sql); - - /// - Task ExecuteScalarAsync(string sql, params object[] args); + Task ExecuteAsync(CancellationToken cancellationToken, string sql, params object[] args); /// /// Asynchronously executes the query with a cancellation token and returns the first column of the first row in the result set. /// /// The type that the result value should be cast to. /// A cancellation token that can be used to cancel the operation. - /// The SQL query to execute. - /// Arguments to any embedded parameters in the SQL statement. + /// An Sql builder object representing the SQL query and its arguments. /// A task that represents the asynchronous operation. The task result is the scalar value cast to . - Task ExecuteScalarAsync(CancellationToken cancellationToken, string sql, params object[] args); - - /// - Task ExecuteScalarAsync(Sql sql); + Task ExecuteScalarAsync(CancellationToken cancellationToken, Sql sql); /// /// Asynchronously executes the query with a cancellation token and returns the first column of the first row in the result set. /// /// The type that the result value should be cast to. /// A cancellation token that can be used to cancel the operation. - /// An Sql builder object representing the SQL query and its arguments. + /// The SQL query to execute. + /// Arguments to any embedded parameters in the SQL statement. /// A task that represents the asynchronous operation. The task result is the scalar value cast to . - Task ExecuteScalarAsync(CancellationToken cancellationToken, Sql sql); + Task ExecuteScalarAsync(CancellationToken cancellationToken, string sql, params object[] args); } #endif } diff --git a/PetaPoco/IQuery.cs b/PetaPoco/IQuery.cs index 5829f74b..d2bd1a98 100644 --- a/PetaPoco/IQuery.cs +++ b/PetaPoco/IQuery.cs @@ -5,7 +5,7 @@ namespace PetaPoco { public interface IQuery { - #region Query + #region Query : Single-Poco /// /// Streams the result of a select all query (SELECT *). @@ -24,10 +24,9 @@ public interface IQuery /// For some DB providers, care should be taken to not start a new Query before finishing with and disposing of the previous one. In cases where this is an issue, consider using Fetch, which returns the results as a List rather than an IEnumerable. /// /// The Type representing a row in the result set. - /// The SQL query. - /// Arguments to any embedded parameters in the SQL statement. + /// An SQL builder object representing the base SQL query and its arguments. /// An IEnumerable collection of POCOs. - IEnumerable Query(string sql, params object[] args); + IEnumerable Query(Sql sql); /// /// Runs an SQL query, returning the results as an IEnumerable collection. @@ -36,21 +35,66 @@ public interface IQuery /// For some DB providers, care should be taken to not start a new Query before finishing with and disposing of the previous one. In cases where this is an issue, consider using Fetch, which returns the results as a List rather than an IEnumerable. /// /// The Type representing a row in the result set. - /// An SQL builder object representing the base SQL query and its arguments. + /// The SQL query. + /// Arguments to any embedded parameters in the SQL statement. /// An IEnumerable collection of POCOs. - IEnumerable Query(Sql sql); + IEnumerable Query(string sql, params object[] args); + + #endregion + + #region Query : Multi-Poco + + /// + /// Perform a multi-poco query. + /// + /// The first POCO type. + /// The second POCO type. + /// An SQL builder object representing the query and its arguments. + /// A collection of POCOs as an IEnumerable. + IEnumerable Query(Sql sql); + + /// + /// Perform a multi-poco query. + /// + /// The first POCO type. + /// The second POCO type. + /// The third POCO type. + /// An SQL builder object representing the query and its arguments. + /// A collection of POCOs as an IEnumerable. + IEnumerable Query(Sql sql); + + /// + /// Perform a multi-poco query. + /// + /// The first POCO type. + /// The second POCO type. + /// The third POCO type. + /// The fourth POCO type. + /// An SQL builder object representing the query and its arguments. + /// A collection of POCOs as an IEnumerable. + IEnumerable Query(Sql sql); + + /// + /// Perform a multi-poco query. + /// + /// The first POCO type. + /// The second POCO type. + /// The third POCO type. + /// The fourth POCO type. + /// The fifth POCO type. + /// An SQL builder object representing the query and its arguments. + /// A collection of POCOs as an IEnumerable. + IEnumerable Query(Sql sql); /// /// Perform a multi-poco query. /// /// The first POCO type. /// The second POCO type. - /// The type of objects in the returned IEnumerable. - /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as an IEnumerable. - IEnumerable Query(Func cb, string sql, params object[] args); + IEnumerable Query(string sql, params object[] args); /// /// Perform a multi-poco query. @@ -58,12 +102,10 @@ public interface IQuery /// The first POCO type. /// The second POCO type. /// The third POCO type. - /// The type of objects in the returned IEnumerable. - /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as an IEnumerable. - IEnumerable Query(Func cb, string sql, params object[] args); + IEnumerable Query(string sql, params object[] args); /// /// Perform a multi-poco query. @@ -72,12 +114,10 @@ public interface IQuery /// The second POCO type. /// The third POCO type. /// The fourth POCO type. - /// The type of objects in the returned IEnumerable. - /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as an IEnumerable. - IEnumerable Query(Func cb, string sql, params object[] args); + IEnumerable Query(string sql, params object[] args); /// /// Perform a multi-poco query. @@ -87,12 +127,10 @@ public interface IQuery /// The third POCO type. /// The fourth POCO type. /// The fifth POCO type. - /// The type of objects in the returned IEnumerable. - /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as an IEnumerable. - IEnumerable Query(Func cb, string sql, params object[] args); + IEnumerable Query(string sql, params object[] args); /// /// Perform a multi-poco query. @@ -149,10 +187,12 @@ public interface IQuery /// /// The first POCO type. /// The second POCO type. + /// The type of objects in the returned IEnumerable. + /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as an IEnumerable. - IEnumerable Query(string sql, params object[] args); + IEnumerable Query(Func cb, string sql, params object[] args); /// /// Perform a multi-poco query. @@ -160,10 +200,12 @@ public interface IQuery /// The first POCO type. /// The second POCO type. /// The third POCO type. + /// The type of objects in the returned IEnumerable. + /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as an IEnumerable. - IEnumerable Query(string sql, params object[] args); + IEnumerable Query(Func cb, string sql, params object[] args); /// /// Perform a multi-poco query. @@ -172,10 +214,12 @@ public interface IQuery /// The second POCO type. /// The third POCO type. /// The fourth POCO type. + /// The type of objects in the returned IEnumerable. + /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as an IEnumerable. - IEnumerable Query(string sql, params object[] args); + IEnumerable Query(Func cb, string sql, params object[] args); /// /// Perform a multi-poco query. @@ -185,67 +229,46 @@ public interface IQuery /// The third POCO type. /// The fourth POCO type. /// The fifth POCO type. + /// The type of objects in the returned IEnumerable. + /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as an IEnumerable. - IEnumerable Query(string sql, params object[] args); + IEnumerable Query(Func cb, string sql, params object[] args); /// - /// Perform a multi-poco query. + /// Performs a multi-poco query. /// - /// The first POCO type. - /// The second POCO type. - /// An SQL builder object representing the query and its arguments. + /// The type of objects in the returned IEnumerable. + /// An array of Types representing the POCO types of the returned result set. + /// A callback function to connect the POCO instances, or to automatically guess the relationships. + /// The SQL query to be executed. + /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as an IEnumerable. - IEnumerable Query(Sql sql); + IEnumerable Query(Type[] types, object cb, string sql, params object[] args); - /// - /// Perform a multi-poco query. - /// - /// The first POCO type. - /// The second POCO type. - /// The third POCO type. - /// An SQL builder object representing the query and its arguments. - /// A collection of POCOs as an IEnumerable. - IEnumerable Query(Sql sql); + #endregion - /// - /// Perform a multi-poco query. - /// - /// The first POCO type. - /// The second POCO type. - /// The third POCO type. - /// The fourth POCO type. - /// An SQL builder object representing the query and its arguments. - /// A collection of POCOs as an IEnumerable. - IEnumerable Query(Sql sql); + #region QueryMultiple : Multi-POCO Result Set IGridReader /// - /// Perform a multi-poco query. + /// Perform a multi-results set query. /// - /// The first POCO type. - /// The second POCO type. - /// The third POCO type. - /// The fourth POCO type. - /// The fifth POCO type. /// An SQL builder object representing the query and its arguments. - /// A collection of POCOs as an IEnumerable. - IEnumerable Query(Sql sql); + /// A GridReader to be queried. + IGridReader QueryMultiple(Sql sql); /// - /// Performs a multi-poco query. + /// Perform a multi-results set query. /// - /// The type of objects in the returned IEnumerable. - /// An array of Types representing the POCO types of the returned result set. - /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. - /// A collection of POCOs as an IEnumerable. - IEnumerable Query(Type[] types, object cb, string sql, params object[] args); + /// A GridReader to be queried. + IGridReader QueryMultiple(string sql, params object[] args); #endregion - #region Fetch + #region Fetch : Single-Poco /// /// Runs a SELECT * query and returns the result set as a typed list. @@ -254,6 +277,14 @@ public interface IQuery /// A List holding the results of the query. List Fetch(); + /// + /// Runs a query and returns the result set as a typed list. + /// + /// The Type representing a row in the result set. + /// An SQL builder object representing the query and its arguments. + /// A List holding the results of the query. + List Fetch(Sql sql); + /// /// Runs a query and returns the result set as a typed list. /// @@ -263,64 +294,61 @@ public interface IQuery /// A List holding the results of the query. List Fetch(string sql, params object[] args); + #endregion + + #region Fetch : Multi-Poco + /// - /// Runs a query and returns the result set as a typed list. + /// Perform a multi-poco fetch. /// - /// The Type representing a row in the result set. + /// The first POCO type. + /// The second POCO type. /// An SQL builder object representing the query and its arguments. - /// A List holding the results of the query. - List Fetch(Sql sql); + /// A collection of POCOs as a List. + List Fetch(Sql sql); /// - /// Retrieves a page of records (without the total count). + /// Perform a multi-poco fetch. /// - /// - /// PetaPoco will automatically modify a default SELECT * statement to only retrieve the records for the specified page. - /// - /// The Type representing a row in the result set. - /// The 1-based page number to retrieve. - /// The number of records per page. - /// A List of results. - List Fetch(long page, long itemsPerPage); + /// The first POCO type. + /// The second POCO type. + /// The third POCO type. + /// An SQL builder object representing the query and its arguments. + /// A collection of POCOs as a List. + List Fetch(Sql sql); /// - /// Retrieves a page of records (without the total count). + /// Perform a multi-poco fetch. /// - /// - /// PetaPoco will automatically modify the supplied SELECT statement to only retrieve the records for the specified page. - /// - /// The Type representing a row in the result set. - /// The 1-based page number to retrieve. - /// The number of records per page. - /// The base SQL query. - /// Arguments to any embedded parameters in the SQL statement. - /// A List of results. - List Fetch(long page, long itemsPerPage, string sql, params object[] args); + /// The first POCO type. + /// The second POCO type. + /// The third POCO type. + /// The fourth POCO type. + /// An SQL builder object representing the query and its arguments. + /// A collection of POCOs as a List. + List Fetch(Sql sql); /// - /// Retrieves a page of records (without the total count). + /// Perform a multi-poco fetch. /// - /// - /// PetaPoco will automatically modify the supplied SELECT statement to only retrieve the records for the specified page. - /// - /// The Type representing a row in the result set. - /// The 1-based page number to retrieve. - /// The number of records per page. - /// An SQL builder object representing the base SQL query and its arguments. - /// A List of results. - List Fetch(long page, long itemsPerPage, Sql sql); + /// The first POCO type. + /// The second POCO type. + /// The third POCO type. + /// The fourth POCO type. + /// The fourth POCO type. + /// An SQL builder object representing the query and its arguments. + /// A collection of POCOs as a List. + List Fetch(Sql sql); /// /// Perform a multi-poco fetch. /// /// The first POCO type. /// The second POCO type. - /// The returned list POCO type. - /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as a List. - List Fetch(Func cb, string sql, params object[] args); + List Fetch(string sql, params object[] args); /// /// Perform a multi-poco fetch. @@ -328,12 +356,10 @@ public interface IQuery /// The first POCO type. /// The second POCO type. /// The third POCO type. - /// The returned list POCO type. - /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as a List. - List Fetch(Func cb, string sql, params object[] args); + List Fetch(string sql, params object[] args); /// /// Perform a multi-poco fetch. @@ -342,12 +368,10 @@ public interface IQuery /// The second POCO type. /// The third POCO type. /// The fourth POCO type. - /// The returned list POCO type. - /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as a List. - List Fetch(Func cb, string sql, params object[] args); + List Fetch(string sql, params object[] args); /// /// Perform a multi-poco fetch. @@ -357,12 +381,10 @@ public interface IQuery /// The third POCO type. /// The fourth POCO type. /// The fifth POCO type. - /// The returned list POCO type. - /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as a List. - List Fetch(Func cb, string sql, params object[] args); + List Fetch(string sql, params object[] args); /// /// Perform a multi-poco fetch. @@ -419,10 +441,12 @@ public interface IQuery /// /// The first POCO type. /// The second POCO type. + /// The returned list POCO type. + /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as a List. - List Fetch(string sql, params object[] args); + List Fetch(Func cb, string sql, params object[] args); /// /// Perform a multi-poco fetch. @@ -430,10 +454,12 @@ public interface IQuery /// The first POCO type. /// The second POCO type. /// The third POCO type. + /// The returned list POCO type. + /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as a List. - List Fetch(string sql, params object[] args); + List Fetch(Func cb, string sql, params object[] args); /// /// Perform a multi-poco fetch. @@ -442,10 +468,12 @@ public interface IQuery /// The second POCO type. /// The third POCO type. /// The fourth POCO type. + /// The returned list POCO type. + /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as a List. - List Fetch(string sql, params object[] args); + List Fetch(Func cb, string sql, params object[] args); /// /// Perform a multi-poco fetch. @@ -455,52 +483,55 @@ public interface IQuery /// The third POCO type. /// The fourth POCO type. /// The fifth POCO type. + /// The returned list POCO type. + /// A callback function to connect the POCO instances, or to automatically guess the relationships. /// The SQL query to be executed. /// Arguments to any embedded parameters in the SQL. /// A collection of POCOs as a List. - List Fetch(string sql, params object[] args); + List Fetch(Func cb, string sql, params object[] args); - /// - /// Perform a multi-poco fetch. - /// - /// The first POCO type. - /// The second POCO type. - /// An SQL builder object representing the query and its arguments. - /// A collection of POCOs as a List. - List Fetch(Sql sql); + #endregion + + #region Fetch : Paged SkipTake /// - /// Perform a multi-poco fetch. + /// Retrieves a page of records (without the total count). /// - /// The first POCO type. - /// The second POCO type. - /// The third POCO type. - /// An SQL builder object representing the query and its arguments. - /// A collection of POCOs as a List. - List Fetch(Sql sql); + /// + /// PetaPoco will automatically modify a default SELECT * statement to only retrieve the records for the specified page. + /// + /// The Type representing a row in the result set. + /// The 1-based page number to retrieve. + /// The number of records per page. + /// A List of results. + List Fetch(long page, long itemsPerPage); /// - /// Perform a multi-poco fetch. + /// Retrieves a page of records (without the total count). /// - /// The first POCO type. - /// The second POCO type. - /// The third POCO type. - /// The fourth POCO type. - /// An SQL builder object representing the query and its arguments. - /// A collection of POCOs as a List. - List Fetch(Sql sql); + /// + /// PetaPoco will automatically modify the supplied SELECT statement to only retrieve the records for the specified page. + /// + /// The Type representing a row in the result set. + /// The 1-based page number to retrieve. + /// The number of records per page. + /// An SQL builder object representing the base SQL query and its arguments. + /// A List of results. + List Fetch(long page, long itemsPerPage, Sql sql); /// - /// Perform a multi-poco fetch. + /// Retrieves a page of records (without the total count). /// - /// The first POCO type. - /// The second POCO type. - /// The third POCO type. - /// The fourth POCO type. - /// The fourth POCO type. - /// An SQL builder object representing the query and its arguments. - /// A collection of POCOs as a List. - List Fetch(Sql sql); + /// + /// PetaPoco will automatically modify the supplied SELECT statement to only retrieve the records for the specified page. + /// + /// The Type representing a row in the result set. + /// The 1-based page number to retrieve. + /// The number of records per page. + /// The base SQL query. + /// Arguments to any embedded parameters in the SQL statement. + /// A List of results. + List Fetch(long page, long itemsPerPage, string sql, params object[] args); #endregion @@ -510,29 +541,26 @@ public interface IQuery /// Retrieves a page of records and the total number of available records. /// /// - /// This method allows separate SQL statements to be explicitly provided for the two parts of the page query. The page and itemsPerPage parameters are not used directly and are used simply to populate the returned Page object. + /// PetaPoco will automatically modify a default SELECT * statement to only retrieve the records for the specified page. It will also execute a second query to retrieve the total number of records in the result set. /// /// The Type representing a row in the result set. /// The 1-based page number to retrieve. /// The number of records per page. - /// The SQL to retrieve the total number of records. - /// Arguments to any embedded parameters in the sqlCount statement. - /// The SQL to retrieve a single page of results. - /// Arguments to any embedded parameters in the sqlPage statement. /// A Page of results. - Page Page(long page, long itemsPerPage, string sqlCount, object[] countArgs, string sqlPage, object[] pageArgs); + Page Page(long page, long itemsPerPage); /// /// Retrieves a page of records and the total number of available records. /// /// - /// PetaPoco will automatically modify a default SELECT * statement to only retrieve the records for the specified page. It will also execute a second query to retrieve the total number of records in the result set. + /// PetaPoco will automatically modify the supplied SELECT statement to only retrieve the records for the specified page. It will also execute a second query to retrieve the total number of records in the result set. /// /// The Type representing a row in the result set. /// The 1-based page number to retrieve. /// The number of records per page. + /// An SQL builder object representing the base SQL query and its arguments. /// A Page of results. - Page Page(long page, long itemsPerPage); + Page Page(long page, long itemsPerPage, Sql sql); /// /// Retrieves a page of records and the total number of available records. @@ -552,14 +580,15 @@ public interface IQuery /// Retrieves a page of records and the total number of available records. /// /// - /// PetaPoco will automatically modify the supplied SELECT statement to only retrieve the records for the specified page. It will also execute a second query to retrieve the total number of records in the result set. + /// This method allows separate SQL statements to be explicitly provided for the two parts of the page query. The page and itemsPerPage parameters are not used directly and are used simply to populate the returned Page object. /// /// The Type representing a row in the result set. /// The 1-based page number to retrieve. /// The number of records per page. - /// An SQL builder object representing the base SQL query and its arguments. + /// An SQL builder object representing the SQL to retrieve the total number of records. + /// An SQL builder object representing the SQL to retrieve a single page of results. /// A Page of results. - Page Page(long page, long itemsPerPage, Sql sql); + Page Page(long page, long itemsPerPage, Sql sqlCount, Sql sqlPage); /// /// Retrieves a page of records and the total number of available records. @@ -570,10 +599,12 @@ public interface IQuery /// The Type representing a row in the result set. /// The 1-based page number to retrieve. /// The number of records per page. - /// An SQL builder object representing the SQL to retrieve the total number of records. - /// An SQL builder object representing the SQL to retrieve a single page of results. + /// The SQL to retrieve the total number of records. + /// Arguments to any embedded parameters in the sqlCount statement. + /// The SQL to retrieve a single page of results. + /// Arguments to any embedded parameters in the sqlPage statement. /// A Page of results. - Page Page(long page, long itemsPerPage, Sql sqlCount, Sql sqlPage); + Page Page(long page, long itemsPerPage, string sqlCount, object[] countArgs, string sqlPage, object[] pageArgs); #endregion @@ -600,10 +631,9 @@ public interface IQuery /// The Type representing a row in the result set. /// The number of rows at the start of the result set to skip over. /// The number of rows to retrieve. - /// The base SQL query. - /// Arguments to any embedded parameters in the SQL statement. + /// An SQL builder object representing the base SQL query and its arguments. /// A List of results. - List SkipTake(long skip, long take, string sql, params object[] args); + List SkipTake(long skip, long take, Sql sql); /// /// Retrieves a range of records from result set. @@ -614,9 +644,10 @@ public interface IQuery /// The Type representing a row in the result set. /// The number of rows at the start of the result set to skip over. /// The number of rows to retrieve. - /// An SQL builder object representing the base SQL query and its arguments. + /// The base SQL query. + /// Arguments to any embedded parameters in the SQL statement. /// A List of results. - List SkipTake(long skip, long take, Sql sql); + List SkipTake(long skip, long take, string sql, params object[] args); #endregion @@ -658,37 +689,29 @@ public interface IQuery /// Runs a query that should always return a single row. /// /// - /// Throws an exception if there is not exactly one record + /// Throws an exception if there is not exactly one matching record /// /// The Type representing a row in the result set. - /// The SQL query. - /// Arguments to any embedded parameters in the SQL statement. + /// An SQL builder object representing the query and its arguments. /// The single record matching the specified SQL query. - T Single(string sql, params object[] args); + T Single(Sql sql); /// /// Runs a query that should always return a single row. /// /// - /// Throws an exception if there is not exactly one matching record + /// Throws an exception if there is not exactly one record /// /// The Type representing a row in the result set. - /// An SQL builder object representing the query and its arguments. + /// The SQL query. + /// Arguments to any embedded parameters in the SQL statement. /// The single record matching the specified SQL query. - T Single(Sql sql); + T Single(string sql, params object[] args); #endregion #region SingleOrDefault - /// - /// Runs a query that should always return either a single row, or no rows. - /// - /// The Type representing a row in the result set. - /// An SQL builder object representing the query and its arguments. - /// The single record matching the specified primary key value, or default(T) if no matching rows. - T SingleOrDefault(Sql sql); - /// /// Returns the record with the specified primary key value, or the default value if not found. /// @@ -700,6 +723,14 @@ public interface IQuery /// The single record matching the specified primary key value. T SingleOrDefault(object primaryKey); + /// + /// Runs a query that should always return either a single row, or no rows. + /// + /// The Type representing a row in the result set. + /// An SQL builder object representing the query and its arguments. + /// The single record matching the specified primary key value, or default(T) if no matching rows. + T SingleOrDefault(Sql sql); + /// /// Runs a query that should always return either a single row, or no rows. /// @@ -717,18 +748,18 @@ public interface IQuery /// Runs a query that should always return at least one record. /// /// The Type representing a row in the result set. - /// The SQL query. - /// Arguments to any embedded parameters in the SQL statement. + /// An SQL builder object representing the query and its arguments. /// The first record in the result set. - T First(string sql, params object[] args); + T First(Sql sql); /// /// Runs a query that should always return at least one record. /// /// The Type representing a row in the result set. - /// An SQL builder object representing the query and its arguments. + /// The SQL query. + /// Arguments to any embedded parameters in the SQL statement. /// The first record in the result set. - T First(Sql sql); + T First(string sql, params object[] args); #endregion @@ -738,37 +769,18 @@ public interface IQuery /// Runs a query and returns the first record, or the default value if no matching records. /// /// The Type representing a row in the result set. - /// The SQL query. - /// Arguments to any embedded parameters in the SQL statement. + /// An SQL builder object representing the query and its arguments. /// The first record in the result set, or default(T) if no matching rows. - T FirstOrDefault(string sql, params object[] args); + T FirstOrDefault(Sql sql); /// /// Runs a query and returns the first record, or the default value if no matching records. /// /// The Type representing a row in the result set. - /// An SQL builder object representing the query and its arguments. + /// The SQL query. + /// Arguments to any embedded parameters in the SQL statement. /// The first record in the result set, or default(T) if no matching rows. - T FirstOrDefault(Sql sql); - - #endregion - - #region QueryMultiple - - /// - /// Perform a multi-results set query. - /// - /// An SQL builder object representing the query and its arguments. - /// A GridReader to be queried. - IGridReader QueryMultiple(Sql sql); - - /// - /// Perform a multi-results set query. - /// - /// The SQL query to be executed. - /// Arguments to any embedded parameters in the SQL. - /// A GridReader to be queried. - IGridReader QueryMultiple(string sql, params object[] args); + T FirstOrDefault(string sql, params object[] args); #endregion } diff --git a/PetaPoco/IQueryAsync.cs b/PetaPoco/IQueryAsync.cs index 1d033b56..1dd74562 100644 --- a/PetaPoco/IQueryAsync.cs +++ b/PetaPoco/IQueryAsync.cs @@ -9,131 +9,151 @@ namespace PetaPoco #if ASYNC public interface IQueryAsync { - #region Query + #region QueryAsync : Single-Poco /// /// Async version of . /// - Task QueryAsync(Action receivePocoCallback); + Task> QueryAsync(); /// - /// Async version of . + /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, CommandType commandType); + Task> QueryAsync(Sql sql); /// - /// Async version of . + /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken); + Task> QueryAsync(string sql, params object[] args); /// /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken, CommandType commandType); + Task> QueryAsync(CancellationToken cancellationToken); /// - /// Async version of . + /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, string sql, params object[] args); + Task> QueryAsync(CancellationToken cancellationToken, Sql sql); /// /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, CommandType commandType, string sql, params object[] args); + Task> QueryAsync(CancellationToken cancellationToken, string sql, params object[] args); + + #endregion + + #region QueryAsync : Single-Poco as CommandType /// - /// Async version of . + /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken, string sql, params object[] args); + Task> QueryAsync(CommandType commandType); /// - /// Async version of . + /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken, CommandType commandType, string sql, params object[] args); + Task> QueryAsync(CommandType commandType, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, Sql sql); + Task> QueryAsync(CommandType commandType, string sql, params object[] args); /// - /// Async version of . + /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, CommandType commandType, Sql sql); + Task> QueryAsync(CancellationToken cancellationToken, CommandType commandType); /// /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken, Sql sql); + Task> QueryAsync(CancellationToken cancellationToken, CommandType commandType, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken, CommandType commandType, Sql sql); + Task> QueryAsync(CancellationToken cancellationToken, CommandType commandType, string sql, params object[] args); + + #endregion + + #region QueryAsync with Action : Single-Poco /// /// Async version of . /// - Task> QueryAsync(); + Task QueryAsync(Action receivePocoCallback); /// - /// Async version of . + /// Async version of . /// - Task> QueryAsync(CommandType commandType); + Task QueryAsync(Action receivePocoCallback, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task> QueryAsync(CancellationToken cancellationToken); + Task QueryAsync(Action receivePocoCallback, string sql, params object[] args); /// /// Async version of . /// - Task> QueryAsync(CancellationToken cancellationToken, CommandType commandType); + Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken); /// - /// Async version of . + /// Async version of . /// - Task> QueryAsync(string sql, params object[] args); + Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken, Sql sql); /// /// Async version of . /// - Task> QueryAsync(CommandType commandType, string sql, params object[] args); + Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken, string sql, params object[] args); + + #endregion + + #region QueryAsync with Action : Single-Poco as CommandType /// - /// Async version of . + /// Async version of . /// - Task> QueryAsync(CancellationToken cancellationToken, string sql, params object[] args); + Task QueryAsync(Action receivePocoCallback, CommandType commandType); /// - /// Async version of . + /// Async version of . /// - Task> QueryAsync(CancellationToken cancellationToken, CommandType commandType, string sql, params object[] args); + Task QueryAsync(Action receivePocoCallback, CommandType commandType, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task> QueryAsync(Sql sql); + Task QueryAsync(Action receivePocoCallback, CommandType commandType, string sql, params object[] args); /// - /// Async version of . + /// Async version of . /// - Task> QueryAsync(CommandType commandType, Sql sql); + Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken, CommandType commandType); /// /// Async version of . /// - Task> QueryAsync(CancellationToken cancellationToken, Sql sql); + Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken, CommandType commandType, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task> QueryAsync(CancellationToken cancellationToken, CommandType commandType, Sql sql); + Task QueryAsync(Action receivePocoCallback, CancellationToken cancellationToken, CommandType commandType, string sql, params object[] args); + + #endregion + + #region QueryAsync : Multi-Poco + + #endregion + + #region QueryMultipleAsync : Multi-POCO Result Set #endregion - #region Fetch + #region FetchAsync : Single-Poco /// /// Async version of . @@ -141,59 +161,71 @@ public interface IQueryAsync Task> FetchAsync(); /// - /// Async version of . + /// Async version of . /// - Task> FetchAsync(CommandType commandType); + Task> FetchAsync(Sql sql); /// - /// Async version of . + /// Async version of . /// - Task> FetchAsync(CancellationToken cancellationToken); + Task> FetchAsync(string sql, params object[] args); /// /// Async version of . /// - Task> FetchAsync(CancellationToken cancellationToken, CommandType commandType); + Task> FetchAsync(CancellationToken cancellationToken); /// - /// Async version of . + /// Async version of . /// - Task> FetchAsync(string sql, params object[] args); + Task> FetchAsync(CancellationToken cancellationToken, Sql sql); /// /// Async version of . /// - Task> FetchAsync(CommandType commandType, string sql, params object[] args); + Task> FetchAsync(CancellationToken cancellationToken, string sql, params object[] args); + + #endregion + + #region FetchAsync : Single-Poco as CommandType /// /// Async version of . /// - Task> FetchAsync(CancellationToken cancellationToken, string sql, params object[] args); + Task> FetchAsync(CommandType commandType); /// /// Async version of . /// - Task> FetchAsync(CancellationToken cancellationToken, CommandType commandType, string sql, params object[] args); + Task> FetchAsync(CommandType commandType, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task> FetchAsync(Sql sql); + Task> FetchAsync(CommandType commandType, string sql, params object[] args); /// /// Async version of . /// - Task> FetchAsync(CommandType commandType, Sql sql); + Task> FetchAsync(CancellationToken cancellationToken, CommandType commandType); /// /// Async version of . /// - Task> FetchAsync(CancellationToken cancellationToken, Sql sql); + Task> FetchAsync(CancellationToken cancellationToken, CommandType commandType, Sql sql); /// /// Async version of . /// - Task> FetchAsync(CancellationToken cancellationToken, CommandType commandType, Sql sql); + Task> FetchAsync(CancellationToken cancellationToken, CommandType commandType, string sql, params object[] args); + + #endregion + + #region FetchAsync : Multi-Poco + + #endregion + + #region FetchAsync : Paged SkipTake /// /// Async version of . @@ -201,9 +233,9 @@ public interface IQueryAsync Task> FetchAsync(long page, long itemsPerPage); /// - /// Async version of . + /// Async version of . /// - Task> FetchAsync(CancellationToken cancellationToken, long page, long itemsPerPage); + Task> FetchAsync(long page, long itemsPerPage, Sql sql); /// /// Async version of . @@ -211,33 +243,23 @@ public interface IQueryAsync Task> FetchAsync(long page, long itemsPerPage, string sql, params object[] args); /// - /// Async version of . + /// Async version of . /// - Task> FetchAsync(CancellationToken cancellationToken, long page, long itemsPerPage, string sql, params object[] args); + Task> FetchAsync(CancellationToken cancellationToken, long page, long itemsPerPage); /// /// Async version of . /// - Task> FetchAsync(long page, long itemsPerPage, Sql sql); + Task> FetchAsync(CancellationToken cancellationToken, long page, long itemsPerPage, Sql sql); /// /// Async version of . /// - Task> FetchAsync(CancellationToken cancellationToken, long page, long itemsPerPage, Sql sql); + Task> FetchAsync(CancellationToken cancellationToken, long page, long itemsPerPage, string sql, params object[] args); #endregion - #region Page - - /// - /// Async version of . - /// - Task> PageAsync(long page, long itemsPerPage, string sqlCount, object[] countArgs, string sqlPage, object[] pageArgs); - - /// - /// Async version of . - /// - Task> PageAsync(CancellationToken cancellationToken, long page, long itemsPerPage, string sqlCount, object[] countArgs, string sqlPage, object[] pageArgs); + #region PageAsync /// /// Async version of . @@ -245,9 +267,9 @@ public interface IQueryAsync Task> PageAsync(long page, long itemsPerPage); /// - /// Async version of . + /// Async version of . /// - Task> PageAsync(CancellationToken cancellationToken, long page, long itemsPerPage); + Task> PageAsync(long page, long itemsPerPage, Sql sql); /// /// Async version of . @@ -255,14 +277,19 @@ public interface IQueryAsync Task> PageAsync(long page, long itemsPerPage, string sql, params object[] args); /// - /// Async version of . + /// Async version of . /// - Task> PageAsync(CancellationToken cancellationToken, long page, long itemsPerPage, string sql, params object[] args); + Task> PageAsync(long page, long itemsPerPage, Sql sqlCount, Sql sqlPage); /// - /// Async version of . + /// Async version of . /// - Task> PageAsync(long page, long itemsPerPage, Sql sql); + Task> PageAsync(long page, long itemsPerPage, string sqlCount, object[] countArgs, string sqlPage, object[] pageArgs); + + /// + /// Async version of . + /// + Task> PageAsync(CancellationToken cancellationToken, long page, long itemsPerPage); /// /// Async version of . @@ -270,18 +297,23 @@ public interface IQueryAsync Task> PageAsync(CancellationToken cancellationToken, long page, long itemsPerPage, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task> PageAsync(long page, long itemsPerPage, Sql sqlCount, Sql sqlPage); + Task> PageAsync(CancellationToken cancellationToken, long page, long itemsPerPage, string sql, params object[] args); /// /// Async version of . /// Task> PageAsync(CancellationToken cancellationToken, long page, long itemsPerPage, Sql sqlCount, Sql sqlPage); + /// + /// Async version of . + /// + Task> PageAsync(CancellationToken cancellationToken, long page, long itemsPerPage, string sqlCount, object[] countArgs, string sqlPage, object[] pageArgs); + #endregion - #region SkipTake + #region SkipTakeAsync /// /// Async version of . @@ -289,9 +321,9 @@ public interface IQueryAsync Task> SkipTakeAsync(long skip, long take); /// - /// Async version of . + /// Async version of . /// - Task> SkipTakeAsync(CancellationToken cancellationToken, long skip, long take); + Task> SkipTakeAsync(long skip, long take, Sql sql); /// /// Async version of . @@ -299,23 +331,23 @@ public interface IQueryAsync Task> SkipTakeAsync(long skip, long take, string sql, params object[] args); /// - /// Async version of . + /// Async version of . /// - Task> SkipTakeAsync(CancellationToken cancellationToken, long skip, long take, string sql, params object[] args); + Task> SkipTakeAsync(CancellationToken cancellationToken, long skip, long take); /// /// Async version of . /// - Task> SkipTakeAsync(long skip, long take, Sql sql); + Task> SkipTakeAsync(CancellationToken cancellationToken, long skip, long take, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task> SkipTakeAsync(CancellationToken cancellationToken, long skip, long take, Sql sql); + Task> SkipTakeAsync(CancellationToken cancellationToken, long skip, long take, string sql, params object[] args); #endregion - #region Exists + #region ExistsAsync /// /// Async version of . @@ -323,14 +355,14 @@ public interface IQueryAsync Task ExistsAsync(object primaryKey); /// - /// Async version of . + /// Async version of . /// - Task ExistsAsync(CancellationToken cancellationToken, object primaryKey); + Task ExistsAsync(string sqlCondition, params object[] args); /// - /// Async version of . + /// Async version of . /// - Task ExistsAsync(string sqlCondition, params object[] args); + Task ExistsAsync(CancellationToken cancellationToken, object primaryKey); /// /// Async version of . @@ -339,7 +371,7 @@ public interface IQueryAsync #endregion - #region Single + #region SingleAsync /// /// Async version of . @@ -347,9 +379,9 @@ public interface IQueryAsync Task SingleAsync(object primaryKey); /// - /// Async version of . + /// Async version of . /// - Task SingleAsync(CancellationToken cancellationToken, object primaryKey); + Task SingleAsync(Sql sql); /// /// Async version of . @@ -357,38 +389,38 @@ public interface IQueryAsync Task SingleAsync(string sql, params object[] args); /// - /// Async version of . + /// Async version of . /// - Task SingleAsync(CancellationToken cancellationToken, string sql, params object[] args); + Task SingleAsync(CancellationToken cancellationToken, object primaryKey); /// /// Async version of . /// - Task SingleAsync(Sql sql); + Task SingleAsync(CancellationToken cancellationToken, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task SingleAsync(CancellationToken cancellationToken, Sql sql); + Task SingleAsync(CancellationToken cancellationToken, string sql, params object[] args); #endregion - #region SingleOrDefault + #region SingleOrDefaultAsync /// - /// Async version of . + /// Async version of . /// - Task SingleOrDefaultAsync(Sql sql); + Task SingleOrDefaultAsync(object primaryKey); /// /// Async version of . /// - Task SingleOrDefaultAsync(CancellationToken cancellationToken, Sql sql); + Task SingleOrDefaultAsync(Sql sql); /// - /// Async version of . + /// Async version of . /// - Task SingleOrDefaultAsync(object primaryKey); + Task SingleOrDefaultAsync(string sql, params object[] args); /// /// Async version of . @@ -396,9 +428,9 @@ public interface IQueryAsync Task SingleOrDefaultAsync(CancellationToken cancellationToken, object primaryKey); /// - /// Async version of . + /// Async version of . /// - Task SingleOrDefaultAsync(string sql, params object[] args); + Task SingleOrDefaultAsync(CancellationToken cancellationToken, Sql sql); /// /// Async version of . @@ -407,55 +439,51 @@ public interface IQueryAsync #endregion - #region First + #region FirstAsync /// - /// Async version of . + /// Async version of . /// - Task FirstAsync(string sql, params object[] args); + Task FirstAsync(Sql sql); /// /// Async version of . /// - Task FirstAsync(CancellationToken cancellationToken, string sql, params object[] args); + Task FirstAsync(string sql, params object[] args); /// /// Async version of . /// - Task FirstAsync(Sql sql); + Task FirstAsync(CancellationToken cancellationToken, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task FirstAsync(CancellationToken cancellationToken, Sql sql); + Task FirstAsync(CancellationToken cancellationToken, string sql, params object[] args); #endregion - #region FirstOrDefault + #region FirstOrDefaultAsync /// - /// Async version of . + /// Async version of . /// - Task FirstOrDefaultAsync(string sql, params object[] args); + Task FirstOrDefaultAsync(Sql sql); /// /// Async version of . /// - Task FirstOrDefaultAsync(CancellationToken cancellationToken, string sql, params object[] args); + Task FirstOrDefaultAsync(string sql, params object[] args); /// /// Async version of . /// - Task FirstOrDefaultAsync(Sql sql); + Task FirstOrDefaultAsync(CancellationToken cancellationToken, Sql sql); /// - /// Async version of . + /// Async version of . /// - Task FirstOrDefaultAsync(CancellationToken cancellationToken, Sql sql); - - #endregion - - #region QueryMultiple + Task FirstOrDefaultAsync(CancellationToken cancellationToken, string sql, params object[] args); #endregion } diff --git a/PetaPoco/IStoredProc.cs b/PetaPoco/IStoredProc.cs index 7dbc7ccf..54e0830d 100644 --- a/PetaPoco/IStoredProc.cs +++ b/PetaPoco/IStoredProc.cs @@ -8,50 +8,50 @@ namespace PetaPoco public interface IStoredProc { /// - /// Executes a stored procedure and returns the result as an IEnumerable of type T. + /// Executes a non-query stored procedure and returns the number of rows affected. /// /// /// For any arguments which are POCOs, each readable property will be turned into a named parameter for the stored procedure. Arguments which are IDbDataParameters will be passed through. Any other argument types will throw an exception. /// - /// The Type representing a row in the result set. /// The name of the stored procedure to execute. /// The arguments to pass to the stored procedure. - /// An IEnumerable of type T containing the result set of the stored procedure. - IEnumerable QueryProc(string storedProcedureName, params object[] args); + /// The number of rows affected by the stored procedure. + int ExecuteNonQueryProc(string storedProcedureName, params object[] args); /// - /// Executes a stored procedure and returns the result as a List of type T. + /// Executes a stored procedure and returns the first column of the first row in the result set as type T. /// /// /// For any arguments which are POCOs, each readable property will be turned into a named parameter for the stored procedure. Arguments which are IDbDataParameters will be passed through. Any other argument types will throw an exception. /// - /// The Type representing a row in the result set. + /// The type that the result value should be cast to. /// The name of the stored procedure to execute. /// The arguments to pass to the stored procedure. - /// A List of type T containing the result set of the stored procedure. - List FetchProc(string storedProcedureName, params object[] args); + /// The scalar result of the stored procedure of type T. + T ExecuteScalarProc(string storedProcedureName, params object[] args); /// - /// Executes a stored procedure and returns the first column of the first row in the result set as type T. + /// Executes a stored procedure and returns the result as an IEnumerable of type T. /// /// /// For any arguments which are POCOs, each readable property will be turned into a named parameter for the stored procedure. Arguments which are IDbDataParameters will be passed through. Any other argument types will throw an exception. /// - /// The type that the result value should be cast to. + /// The Type representing a row in the result set. /// The name of the stored procedure to execute. /// The arguments to pass to the stored procedure. - /// The scalar result of the stored procedure of type T. - T ExecuteScalarProc(string storedProcedureName, params object[] args); + /// An IEnumerable of type T containing the result set of the stored procedure. + IEnumerable QueryProc(string storedProcedureName, params object[] args); /// - /// Executes a non-query stored procedure and returns the number of rows affected. + /// Executes a stored procedure and returns the result as a List of type T. /// /// /// For any arguments which are POCOs, each readable property will be turned into a named parameter for the stored procedure. Arguments which are IDbDataParameters will be passed through. Any other argument types will throw an exception. /// + /// The Type representing a row in the result set. /// The name of the stored procedure to execute. /// The arguments to pass to the stored procedure. - /// The number of rows affected by the stored procedure. - int ExecuteNonQueryProc(string storedProcedureName, params object[] args); + /// A List of type T containing the result set of the stored procedure. + List FetchProc(string storedProcedureName, params object[] args); } } diff --git a/PetaPoco/IStoredProcAsync.cs b/PetaPoco/IStoredProcAsync.cs index 123cc167..d3e9386e 100644 --- a/PetaPoco/IStoredProcAsync.cs +++ b/PetaPoco/IStoredProcAsync.cs @@ -10,44 +10,48 @@ namespace PetaPoco /// public interface IStoredProcAsync { + /// + Task ExecuteNonQueryProcAsync(string storedProcedureName, params object[] args); + + /// + Task ExecuteScalarProcAsync(string storedProcedureName, params object[] args); + + /// + Task> QueryProcAsync(string storedProcedureName, params object[] args); + /// Task QueryProcAsync(Action receivePocoCallback, string storedProcedureName, params object[] args); + /// + Task> FetchProcAsync(string storedProcedureName, params object[] args); + /// - /// Asynchronously executes a stored procedure and returns the result as an IAsyncReader of type T. + /// Asynchronously executes a non-query stored procedure and returns the number of rows affected. /// /// /// For any arguments which are POCOs, each readable property will be turned into a named parameter for the stored procedure. Arguments which are IDbDataParameters will be passed through. Any other argument types will throw an exception. /// - /// The Type representing a row in the result set. - /// An action callback to execute on each POCO in the result set. /// A cancellation token that can be used to cancel the operation. /// The name of the stored procedure to execute. /// The arguments to pass to the stored procedure. - /// A task representing the asynchronous operation. The task result is an IAsyncReader of type T containing the result set of the stored procedure. - Task QueryProcAsync(Action receivePocoCallback, CancellationToken cancellationToken, string storedProcedureName, params object[] args); - - /// - Task> QueryProcAsync(string storedProcedureName, params object[] args); + /// A task representing the asynchronous operation. The task result is the number of rows affected by the stored procedure. + Task ExecuteNonQueryProcAsync(CancellationToken cancellationToken, string storedProcedureName, params object[] args); /// - /// Asynchronously executes a stored procedure and returns the result as an IAsyncReader of type T. + /// Asynchronously executes a stored procedure and returns the first column of the first row in the result set as type T. /// /// /// For any arguments which are POCOs, each readable property will be turned into a named parameter for the stored procedure. Arguments which are IDbDataParameters will be passed through. Any other argument types will throw an exception. /// - /// The Type representing a row in the result set. + /// The type that the result value should be cast to. /// A cancellation token that can be used to cancel the operation. /// The name of the stored procedure to execute. /// The arguments to pass to the stored procedure. - /// A task representing the asynchronous operation. The task result is an IAsyncReader of type T containing the result set of the stored procedure. - Task> QueryProcAsync(CancellationToken cancellationToken, string storedProcedureName, params object[] args); - - /// - Task> FetchProcAsync(string storedProcedureName, params object[] args); + /// A task representing the asynchronous operation. The task result is the scalar result of the stored procedure of type T. + Task ExecuteScalarProcAsync(CancellationToken cancellationToken, string storedProcedureName, params object[] args); /// - /// Asynchronously executes a stored procedure and returns the result as a List of type T. + /// Asynchronously executes a stored procedure and returns the result as an IAsyncReader of type T. /// /// /// For any arguments which are POCOs, each readable property will be turned into a named parameter for the stored procedure. Arguments which are IDbDataParameters will be passed through. Any other argument types will throw an exception. @@ -56,38 +60,34 @@ public interface IStoredProcAsync /// A cancellation token that can be used to cancel the operation. /// The name of the stored procedure to execute. /// The arguments to pass to the stored procedure. - /// A task representing the asynchronous operation. The task result is a List of type T containing the result set of the stored procedure. - Task> FetchProcAsync(CancellationToken cancellationToken, string storedProcedureName, params object[] args); - - /// - Task ExecuteScalarProcAsync(string storedProcedureName, params object[] args); + /// A task representing the asynchronous operation. The task result is an IAsyncReader of type T containing the result set of the stored procedure. + Task> QueryProcAsync(CancellationToken cancellationToken, string storedProcedureName, params object[] args); /// - /// Asynchronously executes a stored procedure and returns the first column of the first row in the result set as type T. + /// Asynchronously executes a stored procedure and returns the result as an IAsyncReader of type T. /// /// /// For any arguments which are POCOs, each readable property will be turned into a named parameter for the stored procedure. Arguments which are IDbDataParameters will be passed through. Any other argument types will throw an exception. /// - /// The type that the result value should be cast to. + /// The Type representing a row in the result set. + /// An action callback to execute on each POCO in the result set. /// A cancellation token that can be used to cancel the operation. /// The name of the stored procedure to execute. /// The arguments to pass to the stored procedure. - /// A task representing the asynchronous operation. The task result is the scalar result of the stored procedure of type T. - Task ExecuteScalarProcAsync(CancellationToken cancellationToken, string storedProcedureName, params object[] args); - - /// - Task ExecuteNonQueryProcAsync(string storedProcedureName, params object[] args); + /// A task representing the asynchronous operation. The task result is an IAsyncReader of type T containing the result set of the stored procedure. + Task QueryProcAsync(Action receivePocoCallback, CancellationToken cancellationToken, string storedProcedureName, params object[] args); /// - /// Asynchronously executes a non-query stored procedure and returns the number of rows affected. + /// Asynchronously executes a stored procedure and returns the result as a List of type T. /// /// /// For any arguments which are POCOs, each readable property will be turned into a named parameter for the stored procedure. Arguments which are IDbDataParameters will be passed through. Any other argument types will throw an exception. /// + /// The Type representing a row in the result set. /// A cancellation token that can be used to cancel the operation. /// The name of the stored procedure to execute. /// The arguments to pass to the stored procedure. - /// A task representing the asynchronous operation. The task result is the number of rows affected by the stored procedure. - Task ExecuteNonQueryProcAsync(CancellationToken cancellationToken, string storedProcedureName, params object[] args); + /// A task representing the asynchronous operation. The task result is a List of type T containing the result set of the stored procedure. + Task> FetchProcAsync(CancellationToken cancellationToken, string storedProcedureName, params object[] args); } } diff --git a/PetaPoco/Utilities/AsyncReader.cs b/PetaPoco/Utilities/AsyncReader.cs index b1bb0fe7..485794fd 100644 --- a/PetaPoco/Utilities/AsyncReader.cs +++ b/PetaPoco/Utilities/AsyncReader.cs @@ -14,8 +14,8 @@ public class AsyncReader : IAsyncReader { private readonly bool _isAsync; private readonly Func _pocoFactory; - private IDbCommand _cmd; private IDatabase _db; + private IDbCommand _cmd; private IDataReader _reader; private DbDataReader Reader => (DbDataReader)_reader; diff --git a/PetaPoco/Utilities/AutoSelectHelper.cs b/PetaPoco/Utilities/AutoSelectHelper.cs index 7a18f63d..1d85257d 100644 --- a/PetaPoco/Utilities/AutoSelectHelper.cs +++ b/PetaPoco/Utilities/AutoSelectHelper.cs @@ -9,7 +9,8 @@ internal static class AutoSelectHelper private static Regex rxSelect = new Regex(@"\A\s*(SELECT|EXECUTE|CALL|WITH|SET|DECLARE)\s", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline); - private static Regex rxFrom = new Regex(@"\A\s*FROM\s", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline); + private static Regex rxFrom = new Regex(@"\A\s*FROM\s", + RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Multiline); public static string AddSelectClause(IProvider provider, string sql, IMapper defaultMapper) { @@ -30,4 +31,4 @@ public static string AddSelectClause(IProvider provider, string sql, IMapper return sql; } } -} \ No newline at end of file +}