func (m *Module) SetAdminManager(a *admin.Manager) {
	m.admin = a
}
SetAdminManager sets the admin manager
package crud
import (
	"context"
	"encoding/base64"
	"strings"
	"github.com/graph-gophers/dataloader"
	"github.com/spaceuptech/helpers"
	"github.com/spaceuptech/space-cloud/gateway/config"
	"github.com/spaceuptech/space-cloud/gateway/managers/admin"
	"github.com/spaceuptech/space-cloud/gateway/model"
	"github.com/spaceuptech/space-cloud/gateway/utils"
)
func (m *Module) SetConfig(project string, crud config.DatabaseConfigs) error {
	m.Lock()
	defer m.Unlock()
	if err := m.admin.IsDBConfigValid(crud); err != nil {
		return err
	}
	m.project = project
	for dbAlias, v := range m.blocks {
		doesExist := false
		for _, databaseConfig := range crud {
			blockKey := strings.TrimPrefix(databaseConfig.DbAlias, "sql-")
			if dbAlias == blockKey {
				doesExist = true
			}
		}
		if !doesExist {
			_ = v.Close()
			delete(m.blocks, dbAlias)
		}
	}
	m.dataLoader = loader{loaderMap: map[string]*dataloader.Loader{}}
	for _, v := range crud {
		blockKey := strings.TrimPrefix(v.DbAlias, "sql-")
		if v.Type == "" {
			v.Type = v.DbAlias
		}
		if v.DBName == "" {
			v.DBName = project
		}
		if v.Limit == 0 {
			v.Limit = model.DefaultFetchLimit
		}
		secretName, isSecretExists := splitConnectionString(v.Conn)
		connectionString := v.Conn
		if isSecretExists {
			var err error
			connectionString, err = m.getSecrets(project, secretName, "CONN")
			if err != nil {
				return helpers.Logger.LogError(helpers.GetRequestID(context.TODO()), "Unable to fetch connection string secret from runner", err, map[string]interface{}{"project": project})
			}
		}
		if block, p := m.blocks[blockKey]; p {
			block.SetQueryFetchLimit(v.Limit)
			m.databaseConfigs[blockKey].BatchTime = v.BatchTime
			m.databaseConfigs[blockKey].BatchRecords = v.BatchRecords
			if block.IsSame(connectionString, v.DBName, v.DriverConf) {
				continue
			}
			if err := block.Close(); err != nil {
				_ = helpers.Logger.LogError(helpers.GetRequestID(context.TODO()), "Unable to close database connections", err, map[string]interface{}{"project": project})
			}
		}
		var c Crud
		var err error
		v.Type = strings.TrimPrefix(v.Type, "sql-")
		c, err = m.initBlock(model.DBType(v.Type), v.Enabled, connectionString, v.DBName, v.DriverConf)
		if v.Enabled {
			if err != nil {
				return helpers.Logger.LogError(helpers.GetRequestID(context.TODO()), "Cannot connect to database", err, map[string]interface{}{"project": project, "dbAlias": v.DbAlias, "dbType": v.Type, "conn": v.Conn, "logicalDbName": v.DBName})
			}
			helpers.Logger.LogInfo(helpers.GetRequestID(context.TODO()), "Successfully connected to database", map[string]interface{}{"project": project, "dbAlias": v.DbAlias, "dbType": v.Type})
		}
		m.databaseConfigs[blockKey] = v
		m.blocks[blockKey] = c
		c.SetQueryFetchLimit(v.Limit)
	}
	return nil
}
func (m *Module) SetPreparedQueryConfig(ctx context.Context, prepQueries config.DatabasePreparedQueries) error {
	m.Lock()
	defer m.Unlock()
	if m.blocks == nil {
		helpers.Logger.LogDebug(helpers.GetRequestID(ctx), "Unable to get database connection, crud module not initialized", nil)
		return nil
	}
	temp := make(config.DatabasePreparedQueries)
	for _, preparedQuery := range prepQueries {
		temp[getPreparedQueryKey(strings.TrimPrefix(preparedQuery.DbAlias, "sql-"), preparedQuery.ID)] = preparedQuery
	}
	m.queries = temp
	return nil
}
func (m *Module) SetSchemaConfig(ctx context.Context, schemaDoc model.Type, schemas config.DatabaseSchemas) error {
	m.Lock()
	defer m.Unlock()
	if m.blocks == nil {
		helpers.Logger.LogDebug(helpers.GetRequestID(ctx), "Unable to get database connection, crud module not initialized", nil)
		return nil
	}
	m.schemaDoc = schemaDoc
	m.closeBatchOperation()
	if err := m.initBatchOperation(m.project, schemas); err != nil {
		return helpers.Logger.LogError(helpers.GetRequestID(ctx), "Unable to initialize database batch operation", err, nil)
	}
	return nil
}
func (m *Module) SetGetSecrets(function utils.GetSecrets) {
	m.Lock()
	defer m.Unlock()
	m.getSecrets = function
}
func (m *Module) SetHooks(metricHook model.MetricCrudHook) {
	m.metricHook = metricHook
}
func (m *Module) SetProjectAESKey(aesKey string) error {
	m.RLock()
	defer m.RUnlock()
	decodedAESKey, err := base64.StdEncoding.DecodeString(aesKey)
	if err != nil {
		return err
	}
	for _, block := range m.blocks {
		block.SetProjectAESKey(decodedAESKey)
	}
	return nil
}