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