-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata.go
50 lines (39 loc) · 1.03 KB
/
data.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
package main
import (
"context"
"database/sql"
"fmt"
_ "embed"
)
//go:embed sql/schema.sql
var ddl string
func createTables(ctx context.Context, db *sql.DB) error {
_, err := db.ExecContext(ctx, ddl)
return err
}
func populateTables(ctx context.Context, db *sql.DB, pkgDir string) error {
testResults, err := populateTestResults(ctx, db, pkgDir)
if err != nil {
return fmt.Errorf("failed to populate test results: %w", err)
}
err = populateCoverageResults(ctx, db, pkgDir)
if err != nil {
return fmt.Errorf("failed to populate coverage results: %w", err)
}
err = populateTestCoverageResults(ctx, db, pkgDir, testResults)
if err != nil {
return fmt.Errorf("failed to populate coverage results: %w", err)
}
err = populateCode(ctx, db, pkgDir)
if err != nil {
return fmt.Errorf("failed to populate code: %w", err)
}
return nil
}
func persistDatabase(db *sql.DB, dbFile string) error {
_, err := db.Exec("VACUUM INTO ?", dbFile)
if err != nil {
return fmt.Errorf("failed to save database file: %w", err)
}
return nil
}