feat: introduce database type (#982)

See https://github.com/ooni/probe/issues/2352

Co-authored-by: decfox <decfox@github.com>
This commit is contained in:
DecFox 2022-11-16 20:21:41 +05:30 committed by GitHub
commit 28aabe0947
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 144 additions and 94 deletions

View file

@ -8,7 +8,6 @@ import (
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/ooni"
"github.com/ooni/probe-cli/v3/internal/database"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/pkg/errors"
)
@ -72,7 +71,8 @@ func RunGroup(config RunGroupConfig) error {
log.WithError(err).Error("Failed to lookup the location of the probe")
return err
}
network, err := database.CreateNetwork(config.Probe.DB(), sess)
db := config.Probe.DB()
network, err := db.CreateNetwork(sess)
if err != nil {
log.WithError(err).Error("Failed to create the network row")
return err
@ -89,8 +89,8 @@ func RunGroup(config RunGroupConfig) error {
}
log.Debugf("Running test group %s", group.Label)
result, err := database.CreateResult(
config.Probe.DB(), config.Probe.Home(), config.GroupName, network.ID)
result, err := db.CreateResult(
config.Probe.Home(), config.GroupName, network.ID)
if err != nil {
log.Errorf("DB result error: %s", err)
return err
@ -131,8 +131,8 @@ func RunGroup(config RunGroupConfig) error {
if err != nil {
os.Remove(result.MeasurementDir)
}
if err = result.Finished(config.Probe.DB()); err != nil {
dbSess := db.Session()
if err = result.Finished(dbSess); err != nil {
return err
}
return nil