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(); } }
public static void Drop(IMySqlConnectionFactory conn) { var sqlDrop = $"drop database if exists `mysqlcoretest`"; using (var c = conn.GetAsync().Result) { c.ExecuteAsync(sqlDrop).Wait(); } }
public DatabaseFixture() { ConnectionFactory = new MySqlConnectionFactory(TestConfig.ConnectionOptions); using (var conn = ConnectionFactory.GetConnection()) { conn.Execute($"create schema if not exits {TestConfig.Schema}"); } }
/// <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); }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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); }); }
public RoomRepository(IMySqlConnectionFactory factory) : base(factory) { }
public MigrationRepository(IMySqlConnectionFactory connectionFactory) : base(connectionFactory) { }
public MySqlIdGenerator(IMySqlConnectionFactory factory) : base(factory) { }
public IllMakeRepository(IMySqlConnectionFactory factory) : base(factory) { }
public MySqlServerVerificationStartupAction(IMySqlConnectionFactory connectionFactory, ILogger <MySqlServerVerificationStartupAction> logger) { _connectionFactory = connectionFactory; _logger = logger; }
protected BaseMySqlRepository(IMySqlConnectionFactory connectionFactory) : this(connectionFactory, new MySqlRepositoryOptions()) { }
public MySqlDistributedHash(IMySqlConnectionFactory factory) : base(factory) { }
public TestRepo(IMySqlConnectionFactory connectionFactory, MySqlRepositoryOptions options) : base(connectionFactory, options) { }
protected BaseRepository(IMySqlConnectionFactory factory) { _factory = factory; }
public OptionsRepository(IMySqlConnectionFactory factory) : base(factory) { }
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; }