Represents an object in PostgreSql (e.g. table, view, procedure)
Ejemplo n.º 1
0
 /// <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));
 }
Ejemplo n.º 2
0
 /// <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&lt;NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption&gt;.</returns>
 public TableDbCommandBuilder <NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption> From(PostgreSqlObjectName tableOrViewName, string whereClause, object argumentValue)
 {
     return(new PostgreSqlTableOrView(this, tableOrViewName, whereClause, argumentValue));
 }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
 /// <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));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Equalses the specified other.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns></returns>
 public bool Equals(PostgreSqlObjectName other) => this == other;
Ejemplo n.º 6
0
 /// <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));
 }
Ejemplo n.º 7
0
        /// <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));
        }
Ejemplo n.º 8
0
 /// <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));
 }
Ejemplo n.º 9
0
        /// <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&lt;NpgsqlCommand, NpgsqlParameter, TArgument&gt;.</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));
        }
Ejemplo n.º 10
0
 /// <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&lt;NpgsqlCommand, NpgsqlParameter, TArgument&gt;.</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));
 }
Ejemplo n.º 11
0
 /// <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&lt;NpgsqlCommand, NpgsqlParameter&gt;.</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));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Gets a record by its key.
 /// </summary>
 /// <param name="tableName">Name of the table.</param>
 /// <param name="key">The key.</param>
 /// <returns>MultipleRowDbCommandBuilder&lt;NpgsqlCommand, NpgsqlParameter&gt;.</returns>
 public SingleRowDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> GetByKey(PostgreSqlObjectName tableName, string key)
 {
     return(GetByKeyList(tableName, new List <string> {
         key
     }));
 }
Ejemplo n.º 13
0
 /// <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&lt;NpgsqlCommand, NpgsqlParameter&gt;.</returns>
 public SingleRowDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> GetByKey <TKey>(PostgreSqlObjectName tableName, TKey key)
     where TKey : struct
 {
     return(GetByKeyList(tableName, new List <TKey> {
         key
     }));
 }
Ejemplo n.º 14
0
 /// <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));
 }
Ejemplo n.º 15
0
 /// <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));
 }
Ejemplo n.º 16
0
        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));
        }
Ejemplo n.º 17
0
 /// <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));
 }
Ejemplo n.º 18
0
 /// <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&lt;NpgsqlCommand, NpgsqlParameter&gt;.</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));
 }
Ejemplo n.º 19
0
        /// <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));
        }
Ejemplo n.º 20
0
 /// <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&lt;NpgsqlCommand, NpgsqlParameter&gt;.</returns>
 public SingleRowDbCommandBuilder <NpgsqlCommand, NpgsqlParameter> DeleteByKey(PostgreSqlObjectName tableName, string key, DeleteOptions options = DeleteOptions.None)
 {
     return(DeleteByKeyList(tableName, new List <string> {
         key
     }, options));
 }
Ejemplo n.º 21
0
 /// <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));
 }
Ejemplo n.º 22
0
 /// <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));
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Froms the specified table or view name.
 /// </summary>
 /// <param name="tableOrViewName">Name of the table or view.</param>
 /// <returns>TableDbCommandBuilder&lt;NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption&gt;.</returns>
 public TableDbCommandBuilder <NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption> From(PostgreSqlObjectName tableOrViewName)
 {
     return(new PostgreSqlTableOrView(this, tableOrViewName));
 }
Ejemplo n.º 24
0
 /// <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));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Equalses the specified other.
 /// </summary>
 /// <param name="other">The other.</param>
 /// <returns></returns>
 public bool Equals(PostgreSqlObjectName other)
 {
     return this == other;
 }
Ejemplo n.º 26
0
 /// <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&lt;NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption&gt;.</returns>
 public TableDbCommandBuilder <NpgsqlCommand, NpgsqlParameter, PostgreSqlLimitOption> From(PostgreSqlObjectName tableOrViewName, object filterValue, FilterOptions filterOptions = FilterOptions.None)
 {
     return(new PostgreSqlTableOrView(this, tableOrViewName, filterValue, filterOptions));
 }