/// <summary> /// This is used to query a scalar function. /// </summary> /// <param name="scalarFunctionName">Name of the scalar function.</param> /// <param name="functionArgumentValue">The function argument.</param> /// <returns></returns> public ScalarDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> ScalarFunction(PostgreSqlObjectName scalarFunctionName, object functionArgumentValue) { return(new PostgreSqlScalarFunction(this, scalarFunctionName, functionArgumentValue)); }
/// <summary> /// Froms the specified table or view name. /// </summary> /// <param name="tableOrViewName">Name of the table or view.</param> /// <param name="whereClause">The where clause.</param> /// <param name="argumentValue">The argument value.</param> /// <returns>TableDbCommandBuilder<NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption>.</returns> public TableDbCommandBuilder <NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption> From(PostgreSqlObjectName tableOrViewName, string whereClause, object argumentValue) { return(new PostgreSqlTableOrView(this, tableOrViewName, whereClause, argumentValue)); }
public MultipleRowDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> DeleteByKeyList <TKey>(PostgreSqlObjectName 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($"DeleteByKey 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 <NpgsqlParameter>(); for (var i = 0; i < keyList.Count; i++) { var param = new NpgsqlParameter("@Param" + i, keyList[i]); if (columnMetadata.DbType.HasValue) { param.NpgsqlDbType = columnMetadata.DbType.Value; } parameters.Add(param); } var table = DatabaseMetadata.GetTableOrView(tableName); if (!AuditRules.UseSoftDelete(table)) { return(new PostgreSqlDeleteMany(this, tableName, where, parameters, options)); } UpdateOptions effectiveOptions = UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected; if (options.HasFlag(DeleteOptions.UseKeyAttribute)) { effectiveOptions = effectiveOptions | UpdateOptions.UseKeyAttribute; } return(new PostgreSqlUpdateMany(this, tableName, null, where, parameters, parameters.Count, effectiveOptions)); }
/// <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 <NpgsqlCommand, NpgsqlParameter> UpdateSet(PostgreSqlObjectName tableName, object newValues, UpdateOptions options = UpdateOptions.None) { return(new PostgreSqlUpdateMany(this, tableName, newValues, options)); }
/// <summary> /// Equalses the specified other. /// </summary> /// <param name="other">The other.</param> /// <returns></returns> public bool Equals(PostgreSqlObjectName other) => this == other;
/// <summary> /// This is used to query a table valued function. /// </summary> /// <param name="tableFunctionName">Name of the table function.</param> /// <param name="functionArgumentValue">The function argument.</param> /// <returns></returns> public TableDbCommandBuilder <NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption> TableFunction(PostgreSqlObjectName tableFunctionName, object functionArgumentValue) { return(new PostgreSqlTableFunction(this, tableFunctionName, functionArgumentValue)); }
/// <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 <NpgsqlCommand, NpgsqlParameter> DeleteWithFilter(PostgreSqlObjectName tableName, object filterValue, FilterOptions filterOptions = FilterOptions.None) { var table = DatabaseMetadata.GetTableOrView(tableName); if (!AuditRules.UseSoftDelete(table)) { return(new PostgreSqlDeleteMany(this, tableName, filterValue, filterOptions)); } return(new PostgreSqlUpdateMany(this, tableName, null, UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected).WithFilter(filterValue, filterOptions)); }
/// <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 <NpgsqlCommand, NpgsqlParameter> UpdateByKey <TArgument>(PostgreSqlObjectName tableName, TArgument newValues, params string[] keys) { return(UpdateByKeyList(tableName, newValues, keys)); }
/// <summary> /// Deletes the specified table name. /// </summary> /// <typeparam name="TArgument">The type of the t argument.</typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="argumentValue">The argument value.</param> /// <param name="options">The options.</param> /// <returns>ObjectDbCommandBuilder<NpgsqlCommand, NpgsqlParameter, TArgument>.</returns> public ObjectDbCommandBuilder <NpgsqlCommand, NpgsqlParameter, TArgument> Delete <TArgument>(PostgreSqlObjectName tableName, TArgument argumentValue, DeleteOptions options = DeleteOptions.None) where TArgument : class { var table = DatabaseMetadata.GetTableOrView(tableName); if (!AuditRules.UseSoftDelete(table)) { return(new PostgreSqlDeleteObject <TArgument>(this, tableName, argumentValue, options)); } UpdateOptions effectiveOptions = UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected; if (options.HasFlag(DeleteOptions.UseKeyAttribute)) { effectiveOptions = effectiveOptions | UpdateOptions.UseKeyAttribute; } return(new PostgreSqlUpdateObject <TArgument>(this, tableName, argumentValue, effectiveOptions)); }
/// <summary> /// Upserts the specified table name. /// </summary> /// <typeparam name="TArgument">The type of the t argument.</typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="argumentValue">The argument value.</param> /// <param name="options">The options.</param> /// <returns>ObjectDbCommandBuilder<NpgsqlCommand, NpgsqlParameter, TArgument>.</returns> public ObjectDbCommandBuilder <NpgsqlCommand, NpgsqlParameter, TArgument> Upsert <TArgument>(PostgreSqlObjectName tableName, TArgument argumentValue, UpsertOptions options = UpsertOptions.None) where TArgument : class { return(new PostgreSqlInsertOrUpdateObject <TArgument>(this, tableName, argumentValue, 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<NpgsqlCommand, NpgsqlParameter>.</returns> public SingleRowDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> UpdateByKey <TArgument>(PostgreSqlObjectName tableName, TArgument newValues, string key, UpdateOptions options = UpdateOptions.None) { return(UpdateByKeyList(tableName, newValues, new List <string> { key }, options)); }
/// <summary> /// Gets a record by its key. /// </summary> /// <param name="tableName">Name of the table.</param> /// <param name="key">The key.</param> /// <returns>MultipleRowDbCommandBuilder<NpgsqlCommand, NpgsqlParameter>.</returns> public SingleRowDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> GetByKey(PostgreSqlObjectName tableName, string key) { return(GetByKeyList(tableName, new List <string> { key })); }
/// <summary> /// Gets a record by its key. /// </summary> /// <typeparam name="TKey"></typeparam> /// <param name="tableName">Name of the table.</param> /// <param name="key">The key.</param> /// <returns>MultipleRowDbCommandBuilder<NpgsqlCommand, NpgsqlParameter>.</returns> public SingleRowDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> GetByKey <TKey>(PostgreSqlObjectName tableName, TKey key) where TKey : struct { return(GetByKeyList(tableName, new List <TKey> { key })); }
/// <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 <NpgsqlCommand, NpgsqlParameter> GetByKey <TKey>(PostgreSqlObjectName tableName, params TKey[] keys) where TKey : struct { return(GetByKeyList(tableName, keys)); }
/// <summary> /// This is used to query a scalar function. /// </summary> /// <param name="scalarFunctionName">Name of the scalar function.</param> /// <returns></returns> public ScalarDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> ScalarFunction(PostgreSqlObjectName scalarFunctionName) { return(new PostgreSqlScalarFunction(this, scalarFunctionName, null)); }
public MultipleRowDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> UpdateByKeyList <TArgument, TKey>(PostgreSqlObjectName 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($"UpdateByKey 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 <NpgsqlParameter>(); for (var i = 0; i < keyList.Count; i++) { var param = new NpgsqlParameter("@Param" + i, keyList[i]); if (columnMetadata.DbType.HasValue) { param.NpgsqlDbType = columnMetadata.DbType.Value; } parameters.Add(param); } return(new PostgreSqlUpdateMany(this, tableName, newValues, where, parameters, parameters.Count, options)); }
/// <summary> /// This is used to query a table valued function. /// </summary> /// <param name="tableFunctionName">Name of the table function.</param> /// <returns></returns> public TableDbCommandBuilder <NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption> TableFunction(PostgreSqlObjectName tableFunctionName) { return(new PostgreSqlTableFunction(this, tableFunctionName, null)); }
/// <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<NpgsqlCommand, NpgsqlParameter>.</returns> public SingleRowDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> DeleteByKey <T>(PostgreSqlObjectName tableName, T key, DeleteOptions options = DeleteOptions.None) where T : struct { return(DeleteByKeyList(tableName, new List <T> { key }, 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 <NpgsqlCommand, NpgsqlParameter> DeleteWithFilter(PostgreSqlObjectName tableName, string whereClause, object argumentValue) { var table = DatabaseMetadata.GetTableOrView(tableName); if (!AuditRules.UseSoftDelete(table)) { return(new PostgreSqlDeleteMany(this, tableName, whereClause, argumentValue)); } return(new PostgreSqlUpdateMany(this, tableName, null, UpdateOptions.SoftDelete | UpdateOptions.IgnoreRowsAffected).WithFilter(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<NpgsqlCommand, NpgsqlParameter>.</returns> public SingleRowDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> DeleteByKey(PostgreSqlObjectName tableName, string key, DeleteOptions options = DeleteOptions.None) { return(DeleteByKeyList(tableName, new List <string> { 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="updateArgumentValue">The argument value.</param> /// <param name="options">The update options.</param> public IUpdateManyCommandBuilder <NpgsqlCommand, NpgsqlParameter> UpdateSet(PostgreSqlObjectName tableName, string updateExpression, object updateArgumentValue, UpdateOptions options = UpdateOptions.None) { return(new PostgreSqlUpdateMany(this, tableName, updateExpression, updateArgumentValue, 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 <NpgsqlCommand, NpgsqlParameter> DeleteByKey <T>(PostgreSqlObjectName tableName, params T[] keys) where T : struct { return(DeleteByKeyList(tableName, keys)); }
/// <summary> /// Froms the specified table or view name. /// </summary> /// <param name="tableOrViewName">Name of the table or view.</param> /// <returns>TableDbCommandBuilder<NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption>.</returns> public TableDbCommandBuilder <NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption> From(PostgreSqlObjectName tableOrViewName) { return(new PostgreSqlTableOrView(this, tableOrViewName)); }
/// <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 <NpgsqlCommand, NpgsqlParameter> DeleteByKey(PostgreSqlObjectName tableName, params string[] keys) { return(DeleteByKeyList(tableName, keys)); }
/// <summary> /// Equalses the specified other. /// </summary> /// <param name="other">The other.</param> /// <returns></returns> public bool Equals(PostgreSqlObjectName other) { return this == other; }
/// <summary> /// Froms the specified table or view name. /// </summary> /// <param name="tableOrViewName">Name of the table or view.</param> /// <param name="filterValue">The filter value.</param> /// <param name="filterOptions">The filter options.</param> /// <returns>TableDbCommandBuilder<NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption>.</returns> public TableDbCommandBuilder <NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption> From(PostgreSqlObjectName tableOrViewName, object filterValue, FilterOptions filterOptions = FilterOptions.None) { return(new PostgreSqlTableOrView(this, tableOrViewName, filterValue, filterOptions)); }