SQLiteTableOrView <TObject> OnGetByKey <TObject, TKey>(SQLiteObjectName tableName, ColumnMetadata <DbType> columnMetadata, TKey key) where TObject : class { string where = columnMetadata.SqlName + " = @Param0"; var parameters = new List <SQLiteParameter>(); var param = new SQLiteParameter("@Param0", key); if (columnMetadata.DbType.HasValue) { param.DbType = columnMetadata.DbType.Value; } parameters.Add(param); return(new SQLiteTableOrView <TObject>(this, tableName, where, parameters)); }
ObjectDbCommandBuilder <SQLiteCommand, SQLiteParameter, TArgument> OnUpdateObject <TArgument>(SQLiteObjectName tableName, TArgument argumentValue, UpdateOptions options) where TArgument : class { return(new SQLiteUpdateObject <TArgument>(this, tableName, argumentValue, options)); }
IUpdateManyCommandBuilder <SQLiteCommand, SQLiteParameter> OnUpdateMany(SQLiteObjectName tableName, string updateExpression, object updateArgumentValue, UpdateOptions options) { return(new SQLiteUpdateMany(this, tableName, updateExpression, updateArgumentValue, options)); }
TableDbCommandBuilder <SQLiteCommand, SQLiteParameter, SQLiteLimitOption> OnFromTableOrView(SQLiteObjectName tableOrViewName, object filterValue, FilterOptions filterOptions) { return(new SQLiteTableOrView(this, tableOrViewName, filterValue, filterOptions)); }
MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> OnDeleteMany(SQLiteObjectName tableName, string whereClause, object argumentValue) { return(new SQLiteDeleteMany(this, tableName, whereClause, argumentValue)); }
public MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> UpdateByKeyList <TArgument, TKey>(SQLiteObjectName tableName, TArgument newValues, IEnumerable <TKey> keys, UpdateOptions options = UpdateOptions.None) { var primaryKeys = DatabaseMetadata.GetTableOrView(tableName).Columns.Where(c => c.IsPrimaryKey).ToList(); if (primaryKeys.Count != 1) { throw new MappingException($"{nameof(UpdateByKeyList)} operation isn't allowed on {tableName} because it doesn't have a single primary key."); } var keyList = keys.AsList(); var columnMetadata = primaryKeys.Single(); string where; if (keys.Count() > 1) { where = columnMetadata.SqlName + " IN (" + string.Join(", ", keyList.Select((s, i) => "@Param" + i)) + ")"; } else { where = columnMetadata.SqlName + " = @Param0"; } var parameters = new List <SQLiteParameter>(); for (var i = 0; i < keyList.Count; i++) { var param = new SQLiteParameter("@Param" + i, keyList[i]); if (columnMetadata.DbType.HasValue) { param.DbType = columnMetadata.DbType.Value; } parameters.Add(param); } return(new SQLiteUpdateMany(this, tableName, newValues, where, parameters, parameters.Count, options)); }
/// <summary> /// Creates a <see cref="SQLiteDeleteObject{TArgument}" /> used to perform a delete operation. /// </summary> /// <param name="tableName"></param> /// <param name="argumentValue"></param> /// <param name="options"></param> /// <returns></returns> public ObjectDbCommandBuilder <SQLiteCommand, SQLiteParameter, TArgument> Delete <TArgument>(SQLiteObjectName tableName, TArgument argumentValue, DeleteOptions options = DeleteOptions.None) where TArgument : class { var table = DatabaseMetadata.GetTableOrView(tableName); if (!AuditRules.UseSoftDelete(table)) { return(new SQLiteDeleteObject <TArgument>(this, tableName, argumentValue, options)); } UpdateOptions effectiveOptions = UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected; if (options.HasFlag(DeleteOptions.UseKeyAttribute)) { effectiveOptions = effectiveOptions | UpdateOptions.UseKeyAttribute; } return(new SQLiteUpdateObject <TArgument>(this, tableName, argumentValue, effectiveOptions)); }
/// <summary> /// Deletes multiple records using a filter object. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="filterValue">The filter value.</param> /// <param name="filterOptions">The options.</param> public MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> DeleteWithFilter(SQLiteObjectName tableName, object filterValue, FilterOptions filterOptions = FilterOptions.None) { var table = DatabaseMetadata.GetTableOrView(tableName); if (!AuditRules.UseSoftDelete(table)) { return(new SQLiteDeleteMany(this, tableName, filterValue, filterOptions)); } return(new SQLiteUpdateMany(this, tableName, null, UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected).WithFilter(filterValue, filterOptions)); }
/// <summary> /// Creates a <see cref="SQLiteInsertOrUpdateObject{TArgument}"/> used to perform an "upsert" operation. /// </summary> /// <param name="tableName"></param> /// <param name="argumentValue"></param> /// <param name="options"></param> /// <returns></returns> public ObjectDbCommandBuilder <SQLiteCommand, SQLiteParameter, TArgument> Upsert <TArgument>(SQLiteObjectName tableName, TArgument argumentValue, UpsertOptions options = UpsertOptions.None) where TArgument : class { return(new SQLiteInsertOrUpdateObject <TArgument>(this, tableName, argumentValue, options)); }
/// <summary> /// Gets a set of records by their primary key. /// </summary> /// <typeparam name="TKey"></typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="keys">The keys.</param> /// <returns></returns> /// <remarks>This only works on tables that have a scalar primary key.</remarks> public MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> GetByKey <TKey>(SQLiteObjectName tableName, params TKey[] keys) where TKey : struct { return(GetByKeyList(tableName, keys)); }
/// <summary> /// Gets a record by its primary key. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="key">The key.</param> /// <returns>MultipleRowDbCommandBuilder<SQLiteCommand, SQLiteParameter>.</returns> public SingleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> GetByKey(SQLiteObjectName tableName, string key) { return(GetByKeyList(tableName, new List <string> { key })); }
/// <summary> /// Gets a record by its primary key. /// </summary> /// <typeparam name="TKey"></typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="key">The key.</param> /// <returns>MultipleRowDbCommandBuilder<SQLiteCommand, SQLiteParameter>.</returns> public SingleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> GetByKey <TKey>(SQLiteObjectName tableName, TKey key) where TKey : struct { return(GetByKeyList(tableName, new List <TKey> { key })); }
/// <summary> /// Creates a <see cref="SQLiteTableOrView" /> used to directly query a table or view /// </summary> /// <param name="tableOrViewName"></param> /// <param name="whereClause"></param> /// <returns></returns> public TableDbCommandBuilder <SQLiteCommand, SQLiteParameter, SQLiteLimitOption> From(SQLiteObjectName tableOrViewName, string whereClause) { return(new SQLiteTableOrView(this, tableOrViewName, whereClause, null)); }
/// <summary> /// Returns true if the two objects are equal. /// </summary> /// <param name="other"></param> /// <returns></returns> /// <remarks>This is a case-insensitive comparison.</remarks> public bool Equals(SQLiteObjectName other) { return this == other; }
DbCommandBuilder <SQLiteCommand, SQLiteParameter> OnInsertBatch <TObject>(SQLiteObjectName tableName, IEnumerable <TObject> objects, InsertOptions options) where TObject : class { return(new SQLiteInsertBatch <TObject>(this, tableName, objects, options)); }
/// <summary> /// Deletes multiple records using a where expression. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="whereClause">The where clause.</param> /// <param name="argumentValue">The argument value for the where clause.</param> public MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> DeleteWithFilter(SQLiteObjectName tableName, string whereClause, object argumentValue) { var table = DatabaseMetadata.GetTableOrView(tableName); if (!AuditRules.UseSoftDelete(table)) { return(new SQLiteDeleteMany(this, tableName, whereClause, argumentValue)); } return(new SQLiteUpdateMany(this, tableName, null, UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected).WithFilter(whereClause, argumentValue)); }
/// <summary> /// Delete a record by its primary key. /// </summary> /// <typeparam name="TArgument">The type of the t argument.</typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="newValues">The new values to use.</param> /// <param name="key">The key.</param> /// <param name="options">The options.</param> /// <returns>MultipleRowDbCommandBuilder<SQLiteCommand, SQLiteParameter>.</returns> public SingleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> UpdateByKey <TArgument, TKey>(SQLiteObjectName tableName, TArgument newValues, TKey key, UpdateOptions options = UpdateOptions.None) where TKey : struct { return(UpdateByKeyList(tableName, newValues, new List <TKey> { key }, options)); }
/// <summary> /// Updates multiple records using an update expression. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="updateExpression">The update expression.</param> /// <param name="options">The update options.</param> public IUpdateManyCommandBuilder <SQLiteCommand, SQLiteParameter> UpdateSet(SQLiteObjectName tableName, string updateExpression, UpdateOptions options = UpdateOptions.None) { return(new SQLiteUpdateMany(this, tableName, updateExpression, null, options)); }
/// <summary> /// Delete a record by its primary key. /// </summary> /// <typeparam name="TArgument">The type of the t argument.</typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="newValues">The new values to use.</param> /// <param name="key">The key.</param> /// <param name="options">The options.</param> /// <returns>MultipleRowDbCommandBuilder<SQLiteCommand, SQLiteParameter>.</returns> public SingleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> UpdateByKey <TArgument>(SQLiteObjectName tableName, TArgument newValues, string key, UpdateOptions options = UpdateOptions.None) { return(UpdateByKeyList(tableName, newValues, new List <string> { key }, options)); }
/// <summary> /// Updates multiple records using an update value. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="newValues">The new values to use.</param> /// <param name="options">The options.</param> public IUpdateManyCommandBuilder <SQLiteCommand, SQLiteParameter> UpdateSet(SQLiteObjectName tableName, object newValues, UpdateOptions options = UpdateOptions.None) { return(new SQLiteUpdateMany(this, tableName, newValues, options)); }
/// <summary> /// Delete multiple rows by key. /// </summary> /// <typeparam name="TArgument">The type of the t argument.</typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="newValues">The new values to use.</param> /// <param name="keys">The keys.</param> /// <returns></returns> /// <remarks>This only works on tables that have a scalar primary key.</remarks> public MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> UpdateByKey <TArgument, TKey>(SQLiteObjectName tableName, TArgument newValues, params TKey[] keys) where TKey : struct { return(UpdateByKeyList(tableName, newValues, keys)); }
MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> GetByKeyList <T>(SQLiteObjectName tableName, ColumnMetadata <DbType> columnMetadata, IEnumerable <T> keys) { var keyList = keys.AsList(); string where; if (keys.Count() > 1) { where = columnMetadata.SqlName + " IN (" + string.Join(", ", keyList.Select((s, i) => "@Param" + i)) + ")"; } else { where = columnMetadata.SqlName + " = @Param0"; } var parameters = new List <SQLiteParameter>(); for (var i = 0; i < keyList.Count; i++) { var param = new SQLiteParameter("@Param" + i, keyList[i]); if (columnMetadata.DbType.HasValue) { param.DbType = columnMetadata.DbType.Value; } parameters.Add(param); } return(new SQLiteTableOrView(this, tableName, where, parameters)); }
/// <summary> /// Delete multiple rows by key. /// </summary> /// <typeparam name="TArgument">The type of the t argument.</typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="newValues">The new values to use.</param> /// <param name="keys">The keys.</param> /// <returns></returns> /// <remarks>This only works on tables that have a scalar primary key.</remarks> public MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> UpdateByKey <TArgument>(SQLiteObjectName tableName, TArgument newValues, params string[] keys) { return(UpdateByKeyList(tableName, newValues, keys)); }
MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> OnDeleteMany(SQLiteObjectName tableName, object filterValue, FilterOptions filterOptions) { return(new SQLiteDeleteMany(this, tableName, filterValue, filterOptions)); }
/// <summary> /// Delete a record by its primary key. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="key">The key.</param> /// <param name="options">The options.</param> /// <returns>MultipleRowDbCommandBuilder<SQLiteCommand, SQLiteParameter>.</returns> public SingleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> DeleteByKey <T>(SQLiteObjectName tableName, T key, DeleteOptions options = DeleteOptions.None) where T : struct { return(DeleteByKeyList(tableName, new List <T> { key }, options)); }
TableDbCommandBuilder <SQLiteCommand, SQLiteParameter, SQLiteLimitOption> OnFromTableOrView(SQLiteObjectName tableOrViewName, string whereClause, object argumentValue) { return(new SQLiteTableOrView(this, tableOrViewName, whereClause, argumentValue)); }
/// <summary> /// Delete a record by its primary key. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="key">The key.</param> /// <param name="options">The options.</param> /// <returns>MultipleRowDbCommandBuilder<SQLiteCommand, SQLiteParameter>.</returns> public SingleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> DeleteByKey(SQLiteObjectName tableName, string key, DeleteOptions options = DeleteOptions.None) { return(DeleteByKeyList(tableName, new List <string> { key }, options)); }
IUpdateManyCommandBuilder <SQLiteCommand, SQLiteParameter> OnUpdateMany(SQLiteObjectName tableName, object newValues, UpdateOptions options) { return(new SQLiteUpdateMany(this, tableName, newValues, options)); }
/// <summary> /// Delete multiple rows by key. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="keys">The keys.</param> /// <returns></returns> /// <remarks>This only works on tables that have a scalar primary key.</remarks> public MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> DeleteByKey <T>(SQLiteObjectName tableName, params T[] keys) where T : struct { return(DeleteByKeyList(tableName, keys)); }
public MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> DeleteByKeyList <TKey>(SQLiteObjectName tableName, IEnumerable <TKey> keys, DeleteOptions options = DeleteOptions.None) { var primaryKeys = DatabaseMetadata.GetTableOrView(tableName).Columns.Where(c => c.IsPrimaryKey).ToList(); if (primaryKeys.Count != 1) { throw new MappingException($"{nameof(DeleteByKeyList)} operation isn't allowed on {tableName} because it doesn't have a single primary key."); } var keyList = keys.AsList(); var columnMetadata = primaryKeys.Single(); string where; if (keys.Count() > 1) { where = columnMetadata.SqlName + " IN (" + string.Join(", ", keyList.Select((s, i) => "@Param" + i)) + ")"; } else { where = columnMetadata.SqlName + " = @Param0"; } var parameters = new List <SQLiteParameter>(); for (var i = 0; i < keyList.Count; i++) { var param = new SQLiteParameter("@Param" + i, keyList[i]); if (columnMetadata.DbType.HasValue) { param.DbType = columnMetadata.DbType.Value; } parameters.Add(param); } var table = DatabaseMetadata.GetTableOrView(tableName); if (!AuditRules.UseSoftDelete(table)) { return(new SQLiteDeleteMany(this, tableName, where, parameters, options)); } UpdateOptions effectiveOptions = UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected; if (options.HasFlag(DeleteOptions.UseKeyAttribute)) { effectiveOptions = effectiveOptions | UpdateOptions.UseKeyAttribute; } return(new SQLiteUpdateMany(this, tableName, null, where, parameters, parameters.Count, effectiveOptions)); }
/// <summary> /// Delete multiple rows by key. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="keys">The keys.</param> /// <returns></returns> /// <remarks>This only works on tables that have a scalar primary key.</remarks> public MultipleRowDbCommandBuilder <SQLiteCommand, SQLiteParameter> DeleteByKey(SQLiteObjectName tableName, params string[] keys) { return(DeleteByKeyList(tableName, keys)); }