2020-05-26 16:46:16 +02:00
|
|
|
package view
|
|
|
|
|
|
|
|
import (
|
2023-04-28 16:28:13 +02:00
|
|
|
"context"
|
|
|
|
|
2020-05-26 16:46:16 +02:00
|
|
|
"github.com/jinzhu/gorm"
|
2023-04-28 16:28:13 +02:00
|
|
|
|
|
|
|
"github.com/zitadel/zitadel/internal/api/call"
|
2023-02-27 22:36:43 +01:00
|
|
|
"github.com/zitadel/zitadel/internal/database"
|
2020-05-26 16:46:16 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type View struct {
|
2023-04-28 16:28:13 +02:00
|
|
|
Db *gorm.DB
|
|
|
|
client *database.DB
|
2020-05-26 16:46:16 +02:00
|
|
|
}
|
|
|
|
|
2023-02-27 22:36:43 +01:00
|
|
|
func StartView(sqlClient *database.DB) (*View, error) {
|
2023-08-22 14:49:02 +02:00
|
|
|
gorm, err := gorm.Open("postgres", sqlClient.DB)
|
2020-05-26 16:46:16 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &View{
|
2023-04-28 16:28:13 +02:00
|
|
|
Db: gorm,
|
|
|
|
client: sqlClient,
|
2020-05-26 16:46:16 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *View) Health() (err error) {
|
|
|
|
return v.Db.DB().Ping()
|
|
|
|
}
|
2023-04-28 16:28:13 +02:00
|
|
|
|
|
|
|
func (v *View) TimeTravel(ctx context.Context, tableName string) string {
|
|
|
|
return tableName + v.client.Timetravel(call.Took(ctx))
|
|
|
|
}
|