Exemple #1
0
        public async Task <IRestDbConnection> GetConnectionAsync(string connectionName)
        {
            await LoadConnectionDefinitions();

            var connectionDefinition = _connectionDefinitions.GetValueOrDefault(connectionName);

            if (connectionDefinition == null)
            {
                return(null);
            }

            var added      = false;
            var connection = _connections.GetOrAdd(connectionName, _ =>
            {
                added = true;

                IRestDbDriver driver = connectionDefinition.Vendor switch
                {
                    "sqlite" => new SqliteRestDbDriver(connectionDefinition.ConnectionString),
                    "postgresql" => new PostgreSqlRestDbDriver(connectionDefinition.ConnectionString),
                    "mysql" => new MySqlRestDbDriver(connectionDefinition.ConnectionString),
                    "mongodb" => new MongoDbRestDbDriver(connectionDefinition.ConnectionString),
                    _ => throw new NotImplementedException($"Vendor name {connectionDefinition.Vendor}")
                };
                return(new RestDbConnection(connectionDefinition, driver));
            });
Exemple #2
0
 public RestDbConnection(ConnectionDefinition connectionDefinition, IRestDbDriver restDbDriver)
 {
     ConnectionDefinition = connectionDefinition;
     _restDbDriver        = restDbDriver;
 }