Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print SQL statement and DB name for every SQL statement that fails #50

Open
jeyhun opened this issue Jul 18, 2023 · 0 comments
Open

Print SQL statement and DB name for every SQL statement that fails #50

jeyhun opened this issue Jul 18, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@jeyhun
Copy link
Contributor

jeyhun commented Jul 18, 2023

Is your feature request related to a problem? Please describe.

Sometimes, the ErrExecutingSqlStmt error generated by multi-tenant-persistence-for-saas does not contain the SQL statement that fails:

SQL statement could not be executed
	ERROR: duplicate key value violates unique constraint "service_configs_pkey" (SQLSTATE 23505)

Describe the solution you'd like

Every time ErrExecutingSqlStmt is returned, it needs to contain the SQL statement and DB name.
This can be implemented this way:

var stmt = func(tx *gorm.DB) *gorm.DB { return tx.Table(tableName).Where(record).First(record) }
tx = stmt(tx)
if err := tx.Error; err != nil {
    kvMap := map[ErrorContextKey]string {
        "sql_stmt": tx.ToSQL(stmt),
        "db_name": tx.Dialector.Name(),
    }
    err = ErrExecutingSqlStmt.WithMap(kvMap)
    return err
}

Describe alternatives you've considered

No response

Additional context

No response

@jeyhun jeyhun added the enhancement New feature or request label Jul 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant