-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
rhea.go
51 lines (43 loc) · 1.09 KB
/
rhea.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package insert
import (
"context"
"github.com/TimothyStiles/allbase/pkg/config"
"github.com/TimothyStiles/allbase/pkg/rhea"
"github.com/jmoiron/sqlx"
"github.com/volatiletech/sqlboiler/v4/boil"
)
// Rhea parses and inserts Rhea data into the database.
func Rhea(ctx context.Context, db *sqlx.DB, config config.Config) error {
// parse Rhea file
rheaBytes, err := rhea.ReadGzippedXML(config.RheaRDF)
columns := boil.Infer()
if err != nil {
return err
}
parsedRhea, err := rhea.Parse(rheaBytes)
if err != nil {
return err
}
// insert Rhea reactions into database
for _, reaction := range parsedRhea.Reactions {
err = reaction.Insert(ctx, db, columns)
if err != nil {
// return err
}
}
// insert Rhea compounds into database
for _, compound := range parsedRhea.Compounds {
err = compound.Insert(ctx, db, columns)
if err != nil {
return err
}
}
// insert Rhea reactionParticipants into database
for _, reactionParticipant := range parsedRhea.ReactionParticipants {
err = reactionParticipant.Insert(ctx, db, columns)
if err != nil {
return err
}
}
return nil
}