示例#1
0
        public static void InsertFooTable(IMySqlConnectionFactory conn, int numberOfRowsToInsert = 10)
        {
            StringBuilder sqlInsert = new StringBuilder();

            sqlInsert.Append("INSERT INTO `mysqlcoretest`.`foo` (id,Description) VALUES");

            bool first = true;

            for (int i = 1; i <= numberOfRowsToInsert; i++)
            {
                Guid guidInsert = Guid.NewGuid();
                if (first)
                {
                    sqlInsert.Append($"('{guidInsert.ToString()}','row {i.ToString()}')");

                    first = false;
                }
                else
                {
                    sqlInsert.Append($",('{guidInsert.ToString()}','row {i.ToString()}')");
                }
            }

            //Execute SQL Query
            using (var c = conn.GetAsync(GetDatabaseNameString()).Result)
            {
                c.ExecuteAsync(sqlInsert.ToString()).Wait();
            }
        }
示例#2
0
        public static void Drop(IMySqlConnectionFactory conn)
        {
            var sqlDrop = $"drop database if exists `mysqlcoretest`";

            using (var c = conn.GetAsync().Result)
            {
                c.ExecuteAsync(sqlDrop).Wait();
            }
        }
示例#3
0
        public DatabaseFixture()
        {
            ConnectionFactory = new MySqlConnectionFactory(TestConfig.ConnectionOptions);

            using (var conn = ConnectionFactory.GetConnection())
            {
                conn.Execute($"create schema if not exits {TestConfig.Schema}");
            }
        }
示例#4
0
        /// <summary>
        /// Constructor for Migration Worker to store the connection string and Database Name
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="databaseName"></param>
        public MigrationWorker(string connectionString, string databaseName)
        {
            _connectionString = connectionString;
            _databaseName     = databaseName;

            conn = new MySqlConnectionFactory(_connectionString, _databaseName);

            _repository = new MigrationRepository(conn);
        }
示例#5
0
        public static void Create(out IMySqlConnectionFactory conn)
        {
            conn = new MySqlConnectionFactory(GetConnectionString(), GetDatabaseNameString());

            var sqlCreate = $"create database if not exists `mysqlcoretest`";

            using (var c = conn.GetAsync("sys").Result)
            {
                c.ExecuteAsync(sqlCreate).Wait();
            }
        }
示例#6
0
        public static void CreateFooView(IMySqlConnectionFactory conn)
        {
            StringBuilder sqlCreateView = new StringBuilder();

            sqlCreateView.AppendLine("CREATE VIEW `mysqlcoretest`.FooView ");
            sqlCreateView.AppendLine("AS ");
            sqlCreateView.AppendLine("SELECT `id`,`Description`,CONCAT('Foo --> ',Description) as Concat FROM `mysqlcoretest`.`foo`");

            //Execute SQL Query
            using (var c = conn.GetAsync(GetDatabaseNameString()).Result)
            {
                c.ExecuteAsync(sqlCreateView.ToString()).Wait();
            }
        }
示例#7
0
        public static void CreateFooStoredProcedureWithNullParameter(IMySqlConnectionFactory conn)
        {
            StringBuilder sqlCreateStoredProcedure = new StringBuilder();

            sqlCreateStoredProcedure.AppendLine("CREATE PROCEDURE `mysqlcoretest`.FooStoredProcedureWithNullParameter (IN idValue CHAR(36), IN descriptionValue VARCHAR(200)) ");
            sqlCreateStoredProcedure.AppendLine("BEGIN ");
            sqlCreateStoredProcedure.AppendLine("INSERT INTO `mysqlcoretest`.`foo` (`id`,`Description`) VALUEs(idValue,descriptionValue); ");
            sqlCreateStoredProcedure.AppendLine("END ");

            //Execute SQL Query
            using (var c = conn.GetAsync(GetDatabaseNameString()).Result)
            {
                c.ExecuteAsync(sqlCreateStoredProcedure.ToString()).Wait();
            }
        }
示例#8
0
        public static void CreateFooStoredProcedureWithoutParameter(IMySqlConnectionFactory conn)
        {
            StringBuilder sqlCreateStoredProcedure = new StringBuilder();

            sqlCreateStoredProcedure.AppendLine("CREATE PROCEDURE `mysqlcoretest`.FooStoredProcedureWithoutParameter() ");
            sqlCreateStoredProcedure.AppendLine("BEGIN ");
            sqlCreateStoredProcedure.AppendLine("SELECT `id`,`Description` FROM `mysqlcoretest`.`foo`; ");
            sqlCreateStoredProcedure.AppendLine("END ");

            //Execute SQL Query
            using (var c = conn.GetAsync(GetDatabaseNameString()).Result)
            {
                c.ExecuteAsync(sqlCreateStoredProcedure.ToString()).Wait();
            }
        }
示例#9
0
        public static void CreateFooTable(IMySqlConnectionFactory conn)
        {
            StringBuilder sqlCreate = new StringBuilder();

            sqlCreate.Append("CREATE TABLE IF NOT EXISTS `mysqlcoretest`.`foo`");
            sqlCreate.Append("(");
            sqlCreate.Append("`id` CHAR(36) NOT NULL ,");
            sqlCreate.Append("`Description` VARCHAR(100) NULL,");
            sqlCreate.Append("`CreatedAt` DateTime NULL,");
            sqlCreate.Append(" PRIMARY KEY (`id`),");
            sqlCreate.Append("UNIQUE INDEX `ID_UNIQUE` (`id` ASC)");
            sqlCreate.Append(")");

            //Execute SQL Query
            using (var c = conn.GetAsync(GetDatabaseNameString()).Result)
            {
                c.ExecuteAsync(sqlCreate.ToString()).Wait();
            }
        }
示例#10
0
        protected BaseMySqlRepository(IMySqlConnectionFactory connectionFactory, MySqlRepositoryOptions options)
            : base(connectionFactory)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            // try to create a logger
            if (options.LoggerFactory != null)
            {
                _logger = options.LoggerFactory.CreateLogger <BaseMySqlRepository>();
            }

            _retryPolicy = Policy
                           .Handle <MySqlException>(MySqlUtils.IsFailoverException)
                           .WaitAndRetryAsync(options.FailOverRetryCount, options.FailOverRetryTimeout,
                                              (ex, time) =>
            {
                // only log if we have a logger
                if (_logger == null)
                {
                    return;
                }

                // exception should always be the correct type as we are only handling MySqlExceptions
                var mysqlEx = (MySqlException)ex;

                _logger.LogWarning(ex,
                                   "MySql query failed with error: {@Error}. Retrying in {RetrySeconds} seconds...",
                                   new
                {
                    Msg = mysqlEx.Message,
                    mysqlEx.Number,
                    HR = mysqlEx.HResult
                },
                                   time.TotalSeconds);
            });
        }
示例#11
0
 public RoomRepository(IMySqlConnectionFactory factory) : base(factory)
 {
 }
示例#12
0
 public MigrationRepository(IMySqlConnectionFactory connectionFactory) : base(connectionFactory)
 {
 }
示例#13
0
 public MySqlIdGenerator(IMySqlConnectionFactory factory) : base(factory)
 {
 }
示例#14
0
 public IllMakeRepository(IMySqlConnectionFactory factory) : base(factory)
 {
 }
示例#15
0
 public MySqlServerVerificationStartupAction(IMySqlConnectionFactory connectionFactory, ILogger <MySqlServerVerificationStartupAction> logger)
 {
     _connectionFactory = connectionFactory;
     _logger            = logger;
 }
示例#16
0
 protected BaseMySqlRepository(IMySqlConnectionFactory connectionFactory)
     : this(connectionFactory, new MySqlRepositoryOptions())
 {
 }
示例#17
0
 public MySqlDistributedHash(IMySqlConnectionFactory factory) : base(factory)
 {
 }
示例#18
0
 public TestRepo(IMySqlConnectionFactory connectionFactory, MySqlRepositoryOptions options) : base(connectionFactory, options)
 {
 }
示例#19
0
 protected BaseRepository(IMySqlConnectionFactory factory)
 {
     _factory = factory;
 }
示例#20
0
 public OptionsRepository(IMySqlConnectionFactory factory) : base(factory)
 {
 }
示例#21
0
 public TestRepo(IMySqlConnectionFactory connectionFactory) : base(connectionFactory)
 {
 }
 /// <summary>
 /// 建構子
 /// </summary>
 /// <param name="factory">連線工廠</param>
 public MySqlTestRepository(IMySqlConnectionFactory factory) : base(factory)
 {
 }
 /// <summary>
 /// The default constructor for BaseMySqlRepository.
 /// </summary>
 /// <param name="connectionFactory"></param>
 public BaseMySqlRepository(IMySqlConnectionFactory connectionFactory)
 {
     _connectionFactory = connectionFactory;
 }