mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-20 23:07:33 +00:00
22af4dcd97
feat(storage): read only transactions for queries (#6415) * fix: tests * bastle wie en grosse * fix(database): scan as callback * fix tests * fix merge failures * remove as of system time * refactor: remove unused test * refacotr: remove unused lines
35 lines
626 B
Go
35 lines
626 B
Go
package view
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/call"
|
|
"github.com/zitadel/zitadel/internal/database"
|
|
)
|
|
|
|
type View struct {
|
|
Db *gorm.DB
|
|
client *database.DB
|
|
}
|
|
|
|
func StartView(sqlClient *database.DB) (*View, error) {
|
|
gorm, err := gorm.Open("postgres", sqlClient.DB)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &View{
|
|
Db: gorm,
|
|
client: sqlClient,
|
|
}, nil
|
|
}
|
|
|
|
func (v *View) Health() (err error) {
|
|
return v.Db.DB().Ping()
|
|
}
|
|
|
|
func (v *View) TimeTravel(ctx context.Context, tableName string) string {
|
|
return tableName + v.client.Timetravel(call.Took(ctx))
|
|
}
|