Skip to content

Commit

Permalink
WIP: Corrected function argument aliases from i or params to args and…
Browse files Browse the repository at this point in the history
… added expectation in sql package in database
  • Loading branch information
shashank-priyadarshi committed Mar 20, 2024
1 parent 19374e8 commit 002e172
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 73 deletions.
50 changes: 25 additions & 25 deletions database/internal/mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func Handle(log ports.Logger, client *mongo.Client) *Handler {
}
}

func (h *Handler) Create(ctx context.Context, params ...interface{}) (*models.Response, error) {
func (h *Handler) Create(ctx context.Context, args ...interface{}) (*models.Response, error) {

if len(params) < 3 {
if len(args) < 3 {
return nil, utilities.InsufficientParameters
}

Expand All @@ -37,15 +37,15 @@ func (h *Handler) Create(ctx context.Context, params ...interface{}) (*models.Re
ok bool
)

if database, ok = params[0].(string); !ok {
if database, ok = args[0].(string); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "database")
}

if collection, ok = params[1].(string); !ok {
if collection, ok = args[1].(string); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "collection")
}

if documents, ok = params[2].([]interface{}); !ok {
if documents, ok = args[2].([]interface{}); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "documents")
}

Expand All @@ -56,9 +56,9 @@ func (h *Handler) Create(ctx context.Context, params ...interface{}) (*models.Re
return nil, nil
}

func (h *Handler) Query(ctx context.Context, params ...interface{}) (*models.Response, error) {
func (h *Handler) Query(ctx context.Context, args ...interface{}) (*models.Response, error) {

if len(params) < 3 {
if len(args) < 3 {
return nil, utilities.InsufficientParameters
}

Expand All @@ -71,15 +71,15 @@ func (h *Handler) Query(ctx context.Context, params ...interface{}) (*models.Res
ok bool
)

if database, ok = params[0].(string); !ok {
if database, ok = args[0].(string); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "database")
}

if collection, ok = params[1].(string); !ok {
if collection, ok = args[1].(string); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "collection")
}

if query, ok = params[2].(bson.D); !ok {
if query, ok = args[2].(bson.D); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "query")
}

Expand All @@ -102,9 +102,9 @@ func (h *Handler) Query(ctx context.Context, params ...interface{}) (*models.Res
return response, nil
}

func (h *Handler) Update(ctx context.Context, params ...interface{}) (*models.Response, error) {
func (h *Handler) Update(ctx context.Context, args ...interface{}) (*models.Response, error) {

if len(params) < 4 {
if len(args) < 4 {
return nil, utilities.InsufficientParameters
}

Expand All @@ -118,19 +118,19 @@ func (h *Handler) Update(ctx context.Context, params ...interface{}) (*models.Re
ok bool
)

if database, ok = params[0].(string); !ok {
if database, ok = args[0].(string); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "database")
}

if collection, ok = params[1].(string); !ok {
if collection, ok = args[1].(string); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "collection")
}

if filterQuery, ok = params[2].(bson.D); !ok {
if filterQuery, ok = args[2].(bson.D); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "filter query")
}

if updateQuery, ok = params[2].(bson.D); !ok {
if updateQuery, ok = args[2].(bson.D); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "update query")
}

Expand All @@ -148,9 +148,9 @@ func (h *Handler) Update(ctx context.Context, params ...interface{}) (*models.Re
}}}, nil
}

func (h *Handler) Delete(ctx context.Context, params ...interface{}) (*models.Response, error) {
func (h *Handler) Delete(ctx context.Context, args ...interface{}) (*models.Response, error) {

if len(params) < 4 {
if len(args) < 4 {
return nil, utilities.InsufficientParameters
}

Expand All @@ -163,15 +163,15 @@ func (h *Handler) Delete(ctx context.Context, params ...interface{}) (*models.Re
deleteResult *mongo.DeleteResult
)

if database, ok = params[0].(string); !ok {
if database, ok = args[0].(string); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "database")
}

if collection, ok = params[1].(string); !ok {
if collection, ok = args[1].(string); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "collection")
}

if filterQuery, ok = params[2].(bson.D); !ok {
if filterQuery, ok = args[2].(bson.D); !ok {
return nil, utilities.NewError(utilities.InvalidParameter.Error(), "filter query")
}

Expand All @@ -182,19 +182,19 @@ func (h *Handler) Delete(ctx context.Context, params ...interface{}) (*models.Re
return &models.Response{Result: []interface{}{deleteResult.DeletedCount}}, nil
}

func (h *Handler) Begin(ctx context.Context, params ...interface{}) (*models.Response, error) {
func (h *Handler) Begin(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Execute(ctx context.Context, params ...interface{}) (*models.Response, error) {
func (h *Handler) Execute(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Rollback(ctx context.Context, params ...interface{}) (*models.Response, error) {
func (h *Handler) Rollback(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Configure(ctx context.Context, params ...interface{}) error {
func (h *Handler) Configure(ctx context.Context, args ...interface{}) error {
return nil
}

Expand Down
16 changes: 8 additions & 8 deletions database/internal/rdbms/orm/gorm/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,35 @@ func Handle(log ports.Logger, client *gorm.DB) (handle *Handler) {
return
}

func (h *Handler) Create(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Create(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Query(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Query(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Update(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Update(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Delete(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Delete(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Begin(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Begin(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Execute(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Execute(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Rollback(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Rollback(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Configure(ctx context.Context, i ...interface{}) error {
func (h *Handler) Configure(ctx context.Context, args ...interface{}) error {
return nil
}

Expand Down
22 changes: 12 additions & 10 deletions database/internal/rdbms/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,37 @@ func Handle(log ports.Logger, client *sql.DB) (handle *Handler) {
return
}

func (h *Handler) Create(ctx context.Context, i ...interface{}) (*models.Response, error) {
return nil, nil
func (h *Handler) Create(ctx context.Context, args ...interface{}) (*models.Response, error) {
return h.Update(ctx, args...)
}

func (h *Handler) Query(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Query(ctx context.Context, args ...interface{}) (*models.Response, error) {
h.client.QueryContext(ctx, "SELECT * FROM something", args...)
return nil, nil
}

func (h *Handler) Update(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Update(ctx context.Context, args ...interface{}) (*models.Response, error) {
h.client.ExecContext(ctx, "SELECT * FROM TABLE ( something )", args...)
return nil, nil
}

func (h *Handler) Delete(ctx context.Context, i ...interface{}) (*models.Response, error) {
return nil, nil
func (h *Handler) Delete(ctx context.Context, args ...interface{}) (*models.Response, error) {
return h.Update(ctx, args...)
}

func (h *Handler) Begin(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Begin(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Execute(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Execute(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Rollback(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Rollback(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Configure(ctx context.Context, i ...interface{}) error {
func (h *Handler) Configure(ctx context.Context, args ...interface{}) error {
return nil
}

Expand Down
34 changes: 17 additions & 17 deletions database/internal/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func Handle(log ports.Logger, client *redis.Client) (handle *Handler) {
}

// Create all arguments of Redis Set like nx, xx etc.
func (h *Handler) Create(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Create(ctx context.Context, args ...interface{}) (*models.Response, error) {

paramsLength := len(i)
paramsLength := len(args)
if paramsLength < 2 {
return nil, utilities.InsufficientParameters
}
Expand All @@ -43,15 +43,15 @@ func (h *Handler) Create(ctx context.Context, i ...interface{}) (*models.Respons
isKey, isExpiration bool
)

if key, isKey = i[0].(string); !isKey {
if key, isKey = args[0].(string); !isKey {
err = utilities.NewError(utilities.InvalidParameter.Error(), "key")
return nil, err
}

value = i[1]
value = args[1]

if paramsLength > 2 {
if expiration, isExpiration = i[2].(time.Duration); !isExpiration {
if expiration, isExpiration = args[2].(time.Duration); !isExpiration {
err = utilities.NewError(utilities.InvalidParameter.Error(), "expiration")
return nil, err
}
Expand All @@ -72,9 +72,9 @@ func (h *Handler) Create(ctx context.Context, i ...interface{}) (*models.Respons
}, nil
}

func (h *Handler) Query(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Query(ctx context.Context, args ...interface{}) (*models.Response, error) {

paramsLength := len(i)
paramsLength := len(args)
if paramsLength < 2 {
return nil, utilities.InsufficientParameters
}
Expand All @@ -86,7 +86,7 @@ func (h *Handler) Query(ctx context.Context, i ...interface{}) (*models.Response
isKey bool
)

if key, isKey = i[0].(string); !isKey {
if key, isKey = args[0].(string); !isKey {
err = utilities.NewError(utilities.InvalidParameter.Error(), "key")
return nil, err
}
Expand All @@ -106,13 +106,13 @@ func (h *Handler) Query(ctx context.Context, i ...interface{}) (*models.Response
}, nil
}

func (h *Handler) Update(ctx context.Context, i ...interface{}) (*models.Response, error) {
return h.Create(ctx, i...)
func (h *Handler) Update(ctx context.Context, args ...interface{}) (*models.Response, error) {
return h.Create(ctx, args...)
}

func (h *Handler) Delete(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Delete(ctx context.Context, args ...interface{}) (*models.Response, error) {

paramsLength := len(i)
paramsLength := len(args)
if paramsLength < 2 {
return nil, utilities.InsufficientParameters
}
Expand All @@ -124,7 +124,7 @@ func (h *Handler) Delete(ctx context.Context, i ...interface{}) (*models.Respons
isKey bool
)

if key, isKey = i[0].(string); !isKey {
if key, isKey = args[0].(string); !isKey {
err = utilities.NewError(utilities.InvalidParameter.Error(), "key")
return nil, err
}
Expand All @@ -144,19 +144,19 @@ func (h *Handler) Delete(ctx context.Context, i ...interface{}) (*models.Respons
}, nil
}

func (h *Handler) Begin(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Begin(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Execute(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Execute(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Rollback(ctx context.Context, i ...interface{}) (*models.Response, error) {
func (h *Handler) Rollback(ctx context.Context, args ...interface{}) (*models.Response, error) {
return nil, nil
}

func (h *Handler) Configure(ctx context.Context, i ...interface{}) error {
func (h *Handler) Configure(ctx context.Context, args ...interface{}) error {
return nil
}

Expand Down
10 changes: 5 additions & 5 deletions logger/internal/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ func NewLogrus() *Logrus { return &Logrus{} }

func (l *Logrus) init() {}

func (l *Logrus) Info(s string, i ...interface{}) {
func (l *Logrus) Info(s string, args ...interface{}) {
return
}

func (l *Logrus) Warn(s string, i ...interface{}) {
func (l *Logrus) Warn(s string, args ...interface{}) {
return
}

func (l *Logrus) Error(err error, i ...interface{}) {
func (l *Logrus) Error(err error, args ...interface{}) {
return
}

func (l *Logrus) Fatal(err error, i ...interface{}) {
func (l *Logrus) Fatal(err error, args ...interface{}) {
return
}

func (l *Logrus) Debug(s string, i ...interface{}) {
func (l *Logrus) Debug(s string, args ...interface{}) {
return
}

Expand Down
Loading

0 comments on commit 002e172

Please sign in to comment.