public void Init(string connectionString, DatabaseProvider databaseType)
        {
            DatabaseProvider = databaseType;
            conn             = DatabaseProvider.GetAndConfigureConnection(connectionString, (connection, dbType) =>
            {
                switch (dbType)
                {
                case DatabaseProvider.MySqlData:
                    MySqlBootstrap.Initialize();
                    break;

                case DatabaseProvider.Npgsql:
                    PostgreSqlBootstrap.Initialize();
                    break;

                case DatabaseProvider.SystemData:
                    {
                        var dbSetting = new SqlServerDbSetting();
                        DbSettingMapper.Add(typeof(System.Data.SqlClient.SqlConnection), dbSetting, true);

                        // Map the DbHelper
                        var dbHelper = new SqlServerDbHelper();
                        DbHelperMapper.Add(typeof(System.Data.SqlClient.SqlConnection), dbHelper, true);

                        // Map the Statement Builder
                        var statementBuilder = new SqlServerStatementBuilder(dbSetting);
                        StatementBuilderMapper.Add(typeof(System.Data.SqlClient.SqlConnection), statementBuilder, true);
                        break;
                    }

                case DatabaseProvider.MicrosoftData:
                    {
                        var dbSetting = new SqlServerDbSetting();
                        DbSettingMapper.Add(typeof(Microsoft.Data.SqlClient.SqlConnection), dbSetting, true);

                        // Map the DbHelper
                        var dbHelper = new SqlServerDbHelper();
                        DbHelperMapper.Add(typeof(Microsoft.Data.SqlClient.SqlConnection), dbHelper, true);

                        // Map the Statement Builder
                        var statementBuilder = new SqlServerStatementBuilder(dbSetting);
                        StatementBuilderMapper.Add(typeof(Microsoft.Data.SqlClient.SqlConnection), statementBuilder, true);
                        break;
                    }

                case DatabaseProvider.MySqlConnector:
                    MySqlConnectorBootstrap.Initialize();
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                connection.Open();
                return(connection);
            });
        }
Esempio n. 2
0
        public static void Initialize()
        {
            // Get the connection string
            var connectionStringForSys = Environment.GetEnvironmentVariable("REPODB_CONSTR_SYS", EnvironmentVariableTarget.Process);
            var connectionString       = Environment.GetEnvironmentVariable("REPODB_CONSTR", EnvironmentVariableTarget.Process);

            // Set the connection string
            ConnectionStringForSys = (connectionStringForSys ?? @"Server=localhost;Database=sys;Uid=user;Pwd=Password123;");
            ConnectionString       = (connectionString ?? @"Server=localhost;Database=RepoDb;Uid=user;Pwd=Password123;");

            // Initialize MySql
            MySqlConnectorBootstrap.Initialize();

            // Create databases
            CreateDatabase();

            // Create tables
            CreateTables();
        }
Esempio n. 3
0
 public void Initialize()
 {
     MySqlConnectorBootstrap.Initialize();
 }
Esempio n. 4
0
    public static IServiceCollection AddRepoDb(this IServiceCollection services)
    {
        MySqlConnectorBootstrap.Initialize();

        return(services);
    }