<commit_before>﻿// <copyright file="DbConnectionTempTableExtensions.cs" company="Berkeleybross">
// Copyright (c) Berkeleybross. All rights reserved.
// </copyright>
namespace Dapper.MicroCRUD
{
    using System.Collections.Generic;
    using System.Data;
    using Dapper.MicroCRUD.Dialects;
    using Dapper.MicroCRUD.SqlCommands;
    using Dapper.MicroCRUD.Utils;

    /// <summary>
    /// Bulk extensions to the <see cref="IDbConnection"/>.
    /// </summary>
    public static class DbConnectionTempTableExtensions
    {
        /// <summary>
        /// <para>Creates a temporary table and inserts the <paramref name="entities"/>.</para>
        /// <para>For performance, it's recommended to always perform this action inside of a transaction.</para>
        /// </summary>
        /// <example>
        /// <code>
        /// <![CDATA[
        /// [Table("TempUsers")]
        /// public class TempUserEntity
        /// {
        ///     [Key]
        ///     public int Id { get; set; }
        ///
        ///     public string Name { get; set; }
        ///
        ///     public int Age { get; set; }
        /// }
        /// ...
        /// var entities = new []
        ///     {
        ///         new TempUser { Name = "Little bobby tables" },
        ///         new TempUser { Name = "Jimmy" };
        ///     };
        ///
        /// using (var transaction = this.connection.BeginTransaction())
        /// {
        ///     this.connection.CreateTempTable(entities, transaction);
        ///
        ///     transaction.Commit();
        /// }
        /// ]]>
        /// </code>
        /// </example>
        public static void CreateTempTable<TEntity>(
            this IDbConnection connection,
            IEnumerable<TEntity> entities,
            IDbTransaction transaction = null,
            IDialect dialect = null,
            int? commandTimeout = null)
        {
            Ensure.NotNull(connection, nameof(connection));
            var command = CommandFactory.MakeCreateTempTableCommand<TEntity>(transaction, dialect, commandTimeout);
            connection.Execute(command);

            var insertCommnad = CommandFactory.MakeInsertRangeCommand(entities, transaction, dialect, commandTimeout);
            connection.Execute(insertCommnad);
        }

        /// <summary>
        /// <para>Drops the temporary table with the given <paramref name="tableName"/>.</para>
        /// <para>USE WITH CAUTION! In some dialects, this can drop a non-temporary table! Make sure you specify the right entity and tablename.</para>
        /// </summary>
        /// <example>
        /// <code>
        /// <![CDATA[
        /// [Table("TempUsers")]
        /// public class TempUserEntity
        /// {
        ///     [Key]
        ///     public int Id { get; set; }
        ///
        ///     public string Name { get; set; }
        ///
        ///     public int Age { get; set; }
        /// }
        /// ...
        /// this.connection.DropTempTable<TempUser>("[TempUsers]");
        /// ]]>
        /// </code>
        /// </example>
        public static void DropTempTable<TEntity>(
            this IDbConnection connection,
            string tableName,
            IDbTransaction transaction = null,
            IDialect dialect = null,
            int? commandTimeout = null)
        {
            Ensure.NotNull(connection, nameof(connection));
            var command = CommandFactory.MakeDropTempTableCommand<TEntity>(tableName, transaction, dialect, commandTimeout);
            connection.Execute(command);
        }
    }
}<commit_msg>Added heplers for temp table creation and dropping on IDapperConnection<commit_after>﻿// <copyright file="DbConnectionTempTableExtensions.cs" company="Berkeleybross">
// Copyright (c) Berkeleybross. All rights reserved.
// </copyright>
namespace Dapper.MicroCRUD
{
    using System.Collections.Generic;
    using System.Data;
    using Dapper.MicroCRUD.Dialects;
    using Dapper.MicroCRUD.SqlCommands;
    using Dapper.MicroCRUD.Utils;

    /// <summary>
    /// Bulk extensions to the <see cref="IDbConnection"/>.
    /// </summary>
    public static class DbConnectionTempTableExtensions
    {
        /// <summary>
        /// <para>Creates a temporary table and inserts the <paramref name="entities"/>.</para>
        /// <para>For performance, it's recommended to always perform this action inside of a transaction.</para>
        /// </summary>
        /// <example>
        /// <code>
        /// <![CDATA[
        /// [Table("TempUsers")]
        /// public class TempUserEntity
        /// {
        ///     [Key]
        ///     public int Id { get; set; }
        ///
        ///     public string Name { get; set; }
        ///
        ///     public int Age { get; set; }
        /// }
        /// ...
        /// var entities = new []
        ///     {
        ///         new TempUser { Name = "Little bobby tables" },
        ///         new TempUser { Name = "Jimmy" };
        ///     };
        ///
        /// using (var transaction = this.connection.BeginTransaction())
        /// {
        ///     this.connection.CreateTempTable(entities, transaction);
        ///
        ///     transaction.Commit();
        /// }
        /// ]]>
        /// </code>
        /// </example>
        public static void CreateTempTable<TEntity>(
            this IDbConnection connection,
            IEnumerable<TEntity> entities,
            IDbTransaction transaction = null,
            IDialect dialect = null,
            int? commandTimeout = null)
        {
            Ensure.NotNull(connection, nameof(connection));
            var command = CommandFactory.MakeCreateTempTableCommand<TEntity>(transaction, dialect, commandTimeout);
            connection.Execute(command);

            var insertCommnad = CommandFactory.MakeInsertRangeCommand(entities, transaction, dialect, commandTimeout);
            connection.Execute(insertCommnad);
        }

        public static void CreateTempTable<TEntity>(
            this IDapperConnection connection,
            IEnumerable<TEntity> entities,
            int? commandTimeout = null)
        {
            connection.DbConnection.CreateTempTable(entities, connection.Transaction, connection.Dialect, commandTimeout);
        }

        /// <summary>
        /// <para>Drops the temporary table with the given <paramref name="tableName"/>.</para>
        /// <para>USE WITH CAUTION! In some dialects, this can drop a non-temporary table! Make sure you specify the right entity and tablename.</para>
        /// </summary>
        /// <example>
        /// <code>
        /// <![CDATA[
        /// [Table("TempUsers")]
        /// public class TempUserEntity
        /// {
        ///     [Key]
        ///     public int Id { get; set; }
        ///
        ///     public string Name { get; set; }
        ///
        ///     public int Age { get; set; }
        /// }
        /// ...
        /// this.connection.DropTempTable<TempUser>("[TempUsers]");
        /// ]]>
        /// </code>
        /// </example>
        public static void DropTempTable<TEntity>(
            this IDbConnection connection,
            string tableName,
            IDbTransaction transaction = null,
            IDialect dialect = null,
            int? commandTimeout = null)
        {
            Ensure.NotNull(connection, nameof(connection));
            var command = CommandFactory.MakeDropTempTableCommand<TEntity>(tableName, transaction, dialect, commandTimeout);
            connection.Execute(command);
        }

        public static void DropTempTable<TEntity>(
            this IDapperConnection connection,
            string tableName,
            int? commandTimeout = null)
        {
            connection.DbConnection.DropTempTable<TEntity>(tableName, connection.Transaction, connection.Dialect, commandTimeout);
        }
    }
}
{'fraction_non_alphanumeric': 0.13169558060022793, 'fraction_numerical': 0.0, 'mean_word_length': 1.664642375168691, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2397026', 'n_tokens_mistral': 2029, 'n_tokens_neox': 1999, 'n_words': 485}