refactor to improve database operability
This commit is contained in:
@@ -1,5 +1,23 @@
|
||||
package jwt
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
// DBTransaction represents a database transaction that can execute queries.
|
||||
// This interface is compatible with *sql.Tx and can be implemented by ORM transactions
|
||||
// from libraries like GORM (gormDB.Begin()), Bun (bunDB.Begin()), etc.
|
||||
type DBTransaction interface {
|
||||
Exec(query string, args ...any) (sql.Result, error)
|
||||
Query(query string, args ...any) (*sql.Rows, error)
|
||||
Commit() error
|
||||
Rollback() error
|
||||
}
|
||||
|
||||
// BeginTX represents a wrapper function that is used to start a transaction with any dependencies injected
|
||||
type BeginTX func(ctx context.Context) (DBTransaction, error)
|
||||
|
||||
// DatabaseType specifies the database system and version being used.
|
||||
type DatabaseType struct {
|
||||
Type string // Database type: "postgres", "mysql", "sqlite", "mariadb"
|
||||
|
||||
Reference in New Issue
Block a user