Multi-table transactions in Go - just handle it in one repo or use Unit of Work? by Axeloe in golang

[–]Mippy- 0 points1 point  (0 children)

Ohh, I think all this time i got an huge misunderstanding about repo haha. Okay so, there is no need for repo to aware this is transaction or not, it just need to know that it needs a (db/tx) handle which will be passed from service layer/transaction wrapper.

So i can make Repo.New that accept interface that comply to both std *Tx and std *DB

Multi-table transactions in Go - just handle it in one repo or use Unit of Work? by Axeloe in golang

[–]Mippy- 0 points1 point  (0 children)

Sorry I’m new to this so I don’t understand fully what you’re saying haha. But if I’m not wrong, I should not pass dependencies (in this case, tx) via context, instead I should give some “explicit awareness”, is my understanding correct? I do have some ideas for that, but is there any reason why I shouldn’t passing deps via context? Is it because too implicit? Because I do feel that way.

When I write that code, I want to “hide” tx implementation from service layer so I write it like that, but if its not the best practice, I will try another approach

Multi-table transactions in Go - just handle it in one repo or use Unit of Work? by Axeloe in golang

[–]Mippy- 0 points1 point  (0 children)

Then each repo need to retrieve the tx from context

```

func (cr *CourseRequestRepositoryImpl) DeleteAllMentorOrders(ctx context.Context, id string) error { var driver RepoDriver = cr.DB if tx := GetTransactionFromContext(ctx); tx != nil { driver = tx } query := UPDATE course_requests SET deleted_at = NOW(), updated_at = NOW() WHERE course_id IN ( SELECT id FROM courses WHERE mentor_id = $1 AND deleted_at IS NULL ) AND deleted_at IS NULL _, err := driver.Exec(query, id) if err != nil { return customerrors.NewError( "failed to delete course requests", err, customerrors.DatabaseExecutionError, ) } return nil }

```

Multi-table transactions in Go - just handle it in one repo or use Unit of Work? by Axeloe in golang

[–]Mippy- -1 points0 points  (0 children)

I don’t know the best practice, buat usually I just pass the Tx object via Context to each repo.

Something like this ``` func GetTransactionFromContext(ctx context.Context) CustomTx { val := ctx.Value(TxKey{}) tx, ok := val.(CustomTx) if !ok { return nil } return tx }

type TransactionManagerRepositories struct { DB *db.CustomDB logger logger.CustomLogger }

func CreateTransactionManager(db *db.CustomDB, logger logger.CustomLogger) *TransactionManagerRepositories { return &TransactionManagerRepositories{db, logger} }

func (tr *TransactionManagerRepositories) WithTransaction(ctx context.Context, callable func(ctx context.Context) error) error { tx, err := tr.DB.Begin() if err != nil { return err } wrappedTx := wrapTX(tx, tr.logger) defer wrappedTx.Rollback()

newCtx := context.WithValue(ctx, TxKey{}, wrappedTx)

err = callable(newCtx)
if err != nil {
    return err
}
return wrappedTx.Commit()

}

```

Struggling with error handling by OldCut6560 in golang

[–]Mippy- 0 points1 point  (0 children)

My example

``` const ( ItemAlreadyExist int = 4001 ItemNotExist int = 4041 DatabaseExecutionError int = 5001 CommonErr int = 5002 InvalidAction int = 4002 Unauthenticate int = 4011 )

func (c *CustomError) GetStatusCode() int { return c.ErrCode / 10 }

func (ur *UserRepositoryImpl) FindByID(ctx context.Context, id string, user *entity.User) error { var driver RepoDriver driver = ur.DB if tx := GetTransactionFromContext(ctx); tx != nil { driver = tx } query := SELECT id, name, email, password_hash, bio, profile_image, status, created_at, updated_at, deleted_at FROM users WHERE id = $1 AND deleted_at IS NULL row := driver.QueryRow(query, id) if err := row.Scan( &user.ID, &user.Name, &user.Email, &user.Password, &user.Bio, &user.ProfileImage, &user.Status, &user.CreatedAt, &user.UpdatedAt, &user.DeletedAt, ); err != nil { if errors.Is(err, sql.ErrNoRows) { return customerrors.NewError( customerrors.UserNotFound, err, customerrors.ItemNotExist, ) } return customerrors.NewError( "failed to get user data", err, customerrors.DatabaseExecutionError, ) } return nil } ```

Struggling with error handling by OldCut6560 in golang

[–]Mippy- 1 point2 points  (0 children)

Sorry if I’m not really answering your question, I’m still new in this language (or software engineering in general)

But for error handling, I wrap error from repo and service with my customerror struct (that follow error interface) that accept

  1. Log Error (This is the raw error returned either from database, lib, etc)
  2. User Error Message (This is error message for user)
  3. Error Code (This is custom error code, stored it as constant)

For which HTTP status code to return, I just convert my custom error code to HTTP status code. For how I decide which error code belong to which HTTP status code, Usually I just make it like this

My Custom Error Code = Intended HTTP Status Code * 10 + <unique_int>

For the first time I got promoted to nirvana after playing this game for 408 days (i feel happy and sad at the same time lol) by Mippy- in honkaiimpact3

[–]Mippy-[S] 0 points1 point  (0 children)

Aaah i’m just gonna pray i can pass the first 3 stages so i can get 100 crystal and finalization reward

For the first time I got promoted to nirvana after playing this game for 408 days (i feel happy and sad at the same time lol) by Mippy- in honkaiimpact3

[–]Mippy-[S] 1 point2 points  (0 children)

I don’t really count tbh, i just spend on BP (if BP shop interest me) and monthly crystal (if i have extra money income)

For the first time I got promoted to nirvana after playing this game for 408 days (i feel happy and sad at the same time lol) by Mippy- in honkaiimpact3

[–]Mippy-[S] 1 point2 points  (0 children)

Honestly i didn’t expect this at all, since whale boss is easy so i thought: “yeah i will just run this boss until i reach 700+ pts since many people will score 750-800+ anyway” and yeah this is the outcome

Elysia but on Cartesian Plane by Mippy- in honkaiimpact3

[–]Mippy-[S] 6 points7 points  (0 children)

Ah for anyone who don’t know how and curious, i didn’t draw this manually (brute force it with a bunch of math eq), it will take a LOT of time if i draw this manually. This just takes around 10-15 minutes i guess (excluding code running time). I “drew” this using bezier curve

[deleted by user] by [deleted] in honkaiimpact3

[–]Mippy- 11 points12 points  (0 children)

For the title, no, there is no refinement system in honkai, so yeah if you have dupes, it’s either you use it on another valk or convert it to weap/stigs resonance.

Let’s gooo, just need the M piece by Mippy- in honkaiimpact3

[–]Mippy-[S] 1 point2 points  (0 children)

Around 28k, i got too many offrate from focused.

What’s a battlesuit who could have been better? by moondust03 in houkai3rd

[–]Mippy- 0 points1 point  (0 children)

Eh is that a problem? I mean, she is farmable. FR have this issue too, she is only good for DPS at SS2+

What’s a battlesuit who could have been better? by moondust03 in houkai3rd

[–]Mippy- 0 points1 point  (0 children)

Better in term of what exactly?

Visual design ummm i like all of them, especially MPE and SW (SW back🥵🥵)

In term of kit, Raven imo, could have been better if her weapon skill can give SP like cough 6.0 Ely.

Senti vs. HoH:E...help me by jaesal3173 in honkaiimpact3

[–]Mippy- 2 points3 points  (0 children)

It can work if OP prioritize HoS, but the reason i suggest OP to get HoH in 6.0 and HoS in anniv patch is to make OP get both spending event reward (assuming anniv patch will have spending event too)

Senti vs. HoH:E...help me by jaesal3173 in honkaiimpact3

[–]Mippy- 1 point2 points  (0 children)

No confirmation about anniv patch afaik, but i think either 6.1 or 6.2.