func (s *SQL) IsClientSafe(ctx context.Context) error {
	if !s.enabled {
		return utils.ErrDatabaseDisabled
	}
	if s.getClient() == nil {
		if err := s.connect(); err != nil {
			helpers.Logger.LogInfo(helpers.GetRequestID(ctx), fmt.Sprintf("Error connecting to "+s.dbType+" : "+err.Error()), nil)
			return utils.ErrDatabaseConnection
		}
	}
	return nil
}
IsClientSafe checks whether database is enabled and connected
package sql
import (
	"context"
	"database/sql"
	"fmt"
	"strings"
	"sync"
	"time"
	"github.com/jmoiron/sqlx"
	"github.com/spaceuptech/helpers"
	_ "github.com/denisenkom/go-mssqldb"  
	_ "github.com/go-sql-driver/mysql"    
	_ "github.com/lib/pq"                 
	"github.com/spaceuptech/space-cloud/gateway/config"
	"github.com/spaceuptech/space-cloud/gateway/model"
	"github.com/spaceuptech/space-cloud/gateway/utils"
)
type SQL struct {
	lock                sync.RWMutex
	enabled             bool
	queryFetchLimit     *int64
	connection          string
	client              *sqlx.DB
	dbType              string
	name                string  
	driverConf          config.DriverConfig
	connRetryCloserChan chan struct{}
	aesKey []byte
}
func Init(dbType model.DBType, enabled bool, connection string, dbName string, driverConf config.DriverConfig) (s *SQL, err error) {
	s = &SQL{enabled: enabled, connection: connection, name: dbName, client: nil, driverConf: driverConf}
	switch dbType {
	case model.Postgres:
		s.dbType = "postgres"
	case model.MySQL:
		s.dbType = "mysql"
	case model.SQLServer:
		s.dbType = "sqlserver"
	default:
		err = utils.ErrUnsupportedDatabase
		return
	}
	if s.enabled {
		err = s.connect()
		if err != nil {
			return nil, err
		}
	}
	closer := make(chan struct{}, 1)
	s.connRetryCloserChan = closer
	go func() {
		ticker := time.NewTicker(10 * time.Second)
		for {
			select {
			case <-ticker.C:
				ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
				if !s.GetConnectionState(ctx) {
					if err := s.connect(); err != nil {
						_ = helpers.Logger.LogError(helpers.GetRequestID(ctx), fmt.Sprintf("Automatic connection retry failed for (%s) db with logical db name (%s)", dbType, dbName), err, nil)
					}
				}
				cancel()
			case <-closer:
				close(closer)
				ticker.Stop()
				return
			}
		}
	}()
	return
}
func (s *SQL) IsSame(conn, dbName string, driverConf config.DriverConfig) bool {
	return strings.HasPrefix(s.connection, conn) && dbName == s.name && driverConf.MaxConn == s.driverConf.MaxConn && driverConf.MaxIdleTimeout == s.driverConf.MaxIdleTimeout && driverConf.MaxIdleConn == s.driverConf.MaxIdleConn
}
func (s *SQL) Close() error {
	if s.getClient() != nil {
		s.connRetryCloserChan <- struct{}{}
		if err := s.getClient().Close(); err != nil {
			_ = helpers.Logger.LogError("close", fmt.Sprintf("Unable to close (%s) db (%s) connection", s.dbType, s.name), err, nil)
		}
		s.setClient(nil)
	}
	return nil
}
func (s *SQL) GetDBType() model.DBType {
	switch s.dbType {
	case "postgres":
		return model.Postgres
	case "mysql":
		return model.MySQL
	case "sqlserver":
		return model.SQLServer
	}
	return model.MySQL
}