func (m *Module) Delete(ctx context.Context, dbAlias, col string, req *model.DeleteRequest, params model.RequestParams) error {
	m.RLock()
	defer m.RUnlock()
	crud, err := m.getCrudBlock(dbAlias)
	if err != nil {
		return err
	}
	if err := crud.IsClientSafe(ctx); err != nil {
		return err
	}
	dbType, err := m.getDBType(dbAlias)
	if err != nil {
		return err
	}
	if err := schemaHelpers.AdjustWhereClause(ctx, dbAlias, model.DBType(dbType), col, m.schemaDoc, req.Find); err != nil {
		return err
	}
	params.Payload = req
	hookResponse := m.integrationMan.InvokeHook(ctx, params)
	if hookResponse.CheckResponse() {
		if err := hookResponse.Error(); err != nil {
			return err
		}
		return nil
	}
	n, err := crud.Delete(ctx, col, req)
	if err == nil {
		m.metricHook(m.project, dbAlias, col, n, model.Delete)
	}
	return err
}
Delete removes the documents(s) which match a query from the database based on dbType
package crud
import (
	"context"
	"fmt"
	"github.com/spaceuptech/helpers"
	"github.com/spaceuptech/space-cloud/gateway/model"
	schemaHelpers "github.com/spaceuptech/space-cloud/gateway/modules/schema/helpers"
	"github.com/spaceuptech/space-cloud/gateway/utils"
)
func (m *Module) Create(ctx context.Context, dbAlias, col string, req *model.CreateRequest, params model.RequestParams) error {
	m.RLock()
	defer m.RUnlock()
	dbType, err := m.getDBType(dbAlias)
	if err != nil {
		return err
	}
	if err := schemaHelpers.ValidateCreateOperation(ctx, dbAlias, dbType, col, m.schemaDoc, req); err != nil {
		return err
	}
	params.Payload = req
	hookResponse := m.integrationMan.InvokeHook(ctx, params)
	if hookResponse.CheckResponse() {
		if err := hookResponse.Error(); err != nil {
			return err
		}
		return nil
	}
	crud, err := m.getCrudBlock(dbAlias)
	if err != nil {
		return err
	}
	if err := crud.IsClientSafe(ctx); err != nil {
		return err
	}
	var n int64
	if req.IsBatch {
		n, err = m.createBatch(ctx, m.project, dbAlias, col, req.Document)
	} else {
		n, err = crud.Create(ctx, col, req)
	}
	if err == nil {
		m.metricHook(m.project, dbAlias, col, n, model.Create)
	}
	return err
}
func (m *Module) Read(ctx context.Context, dbAlias, col string, req *model.ReadRequest, params model.RequestParams) (interface{}, *model.SQLMetaData, error) {
	m.RLock()
	defer m.RUnlock()
	dbType, err := m.getDBType(dbAlias)
	if err != nil {
		return nil, nil, err
	}
	if err := schemaHelpers.AdjustWhereClause(ctx, dbAlias, model.DBType(dbType), col, m.schemaDoc, req.Find); err != nil {
		return nil, nil, err
	}
	crud, err := m.getCrudBlock(dbAlias)
	if err != nil {
		return nil, nil, err
	}
	if err := crud.IsClientSafe(ctx); err != nil {
		return nil, nil, err
	}
	params.Payload = req
	hookResponse := m.integrationMan.InvokeHook(ctx, params)
	if hookResponse.CheckResponse() {
		if err := hookResponse.Error(); err != nil {
			return nil, nil, err
		}
		return hookResponse.Result(), nil, nil
	}
	if req.IsBatch {
		dbType, err := m.getDBType(dbAlias)
		if err != nil {
			return nil, nil, err
		}
		key := model.ReadRequestKey{DBType: dbType, DBAlias: dbAlias, Col: col, HasOptions: req.Options.HasOptions, Req: *req, ReqParams: params}
		dataLoader, ok := m.getLoader(fmt.Sprintf("%s-%s-%s", m.project, dbAlias, col))
		if !ok {
			dataLoader = m.createLoader(fmt.Sprintf("%s-%s-%s", m.project, dbAlias, col))
		}
		data, err := dataLoader.Load(ctx, key)()
		if err != nil {
			return nil, nil, err
		}
		res := data.(queryResult)
		if res.metaData != nil {
			res.metaData.DbAlias = dbAlias
			res.metaData.Col = col
		}
		return res.doc, res.metaData, err
	}
	dbCacheOptions, err := m.caching.GetDatabaseKey(ctx, m.project, dbAlias, col, req)
	if err != nil {
		return nil, nil, err
	}
	var metaData *model.SQLMetaData
	var result interface{}
	if !dbCacheOptions.IsCacheHit() {
		var n int64
		var cacheJoinInfo map[string]map[string]string
		n, result, cacheJoinInfo, metaData, err = crud.Read(ctx, col, req)
		if err == nil {
			if err := m.caching.SetDatabaseKey(ctx, m.project, dbAlias, col, &model.CacheDatabaseResult{MetricCount: n, Result: result}, dbCacheOptions, req.Cache, cacheJoinInfo); err != nil {
				return nil, nil, err
			}
			m.metricHook(m.project, dbAlias, col, n, model.Read)
		}
	} else {
		metaData = &model.SQLMetaData{QueryTime: "0s", SQL: "fetched from cache"}
		cacheResult := dbCacheOptions.GetDatabaseResult()
		result = cacheResult.Result
		m.metricHook(m.project, dbAlias, col, cacheResult.MetricCount, model.Read)
	}
	if err := schemaHelpers.CrudPostProcess(ctx, dbAlias, dbType, col, m.schemaDoc, result); err != nil {
		return nil, nil, helpers.Logger.LogError(helpers.GetRequestID(ctx), fmt.Sprintf("error executing read request in crud module unable to perform schema post process for un marshalling json for project (%s) col (%s)", m.project, col), err, nil)
	}
	if metaData != nil {
		metaData.DbAlias = dbAlias
		metaData.Col = col
	}
	return result, metaData, err
}
func (m *Module) Update(ctx context.Context, dbAlias, col string, req *model.UpdateRequest, params model.RequestParams) error {
	m.RLock()
	defer m.RUnlock()
	dbType, err := m.getDBType(dbAlias)
	if err != nil {
		return err
	}
	if err := schemaHelpers.ValidateUpdateOperation(ctx, dbAlias, dbType, col, req.Operation, req.Update, req.Find, m.schemaDoc); err != nil {
		return err
	}
	params.Payload = req
	hookResponse := m.integrationMan.InvokeHook(ctx, params)
	if hookResponse.CheckResponse() {
		if err := hookResponse.Error(); err != nil {
			return err
		}
		return nil
	}
	crud, err := m.getCrudBlock(dbAlias)
	if err != nil {
		return err
	}
	if err := crud.IsClientSafe(ctx); err != nil {
		return err
	}
	if err := schemaHelpers.AdjustWhereClause(ctx, dbAlias, model.DBType(dbType), col, m.schemaDoc, req.Find); err != nil {
		return err
	}
	n, err := crud.Update(ctx, col, req)
	if err == nil {
		m.metricHook(m.project, dbAlias, col, n, model.Update)
	}
	return err
}