-
Notifications
You must be signed in to change notification settings - Fork 249
/
loadprocs.go
146 lines (118 loc) · 3.35 KB
/
loadprocs.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package sqlite
import (
"database/sql"
)
// TODO: Finish separating procedures from loader layer: make this a type to make
// unit tests more granular?
func addChannelEntry(tx *sql.Tx, channelName, packageName, csvName string, depth int) (int64, error) {
addChannelEntry, err := tx.Prepare("insert into channel_entry(channel_name, package_name, operatorbundle_name, depth) values(?, ?, ?, ?)")
if err != nil {
return 0, err
}
defer addChannelEntry.Close()
res, err := addChannelEntry.Exec(channelName, packageName, csvName, depth)
if err != nil {
return 0, err
}
currentID, err := res.LastInsertId()
if err != nil {
return 0, err
}
return currentID, err
}
func addReplaces(tx *sql.Tx, replacesID, entryID int64) error {
addReplaces, err := tx.Prepare("update channel_entry set replaces = ? where entry_id = ?")
if err != nil {
return err
}
defer addReplaces.Close()
_, err = addReplaces.Exec(replacesID, entryID)
if err != nil {
return err
}
return nil
}
func addPackage(tx *sql.Tx, packageName string) error {
addPackage, err := tx.Prepare("insert into package(name) values(?)")
if err != nil {
return err
}
defer addPackage.Close()
_, err = addPackage.Exec(packageName)
if err != nil {
return err
}
return nil
}
func addPackageIfNotExists(tx *sql.Tx, packageName string) error {
addPackage, err := tx.Prepare("insert or replace into package(name) values(?)")
if err != nil {
return err
}
defer addPackage.Close()
_, err = addPackage.Exec(packageName)
if err != nil {
return err
}
return nil
}
func addChannel(tx *sql.Tx, channelName, packageName, headCsvName string) error {
addChannel, err := tx.Prepare("insert into channel(name, package_name, head_operatorbundle_name) values(?, ?, ?)")
if err != nil {
return err
}
defer addChannel.Close()
_, err = addChannel.Exec(channelName, packageName, headCsvName)
if err != nil {
return err
}
return nil
}
func updateChannel(tx *sql.Tx, channelName, packageName, headCsvName string) error {
updateChannel, err := tx.Prepare("update channel set head_operatorbundle_name = ? where name = ? and package_name = ?")
if err != nil {
return err
}
defer updateChannel.Close()
_, err = updateChannel.Exec(channelName, packageName, headCsvName)
if err != nil {
return err
}
return nil
}
func addOrUpdateChannel(tx *sql.Tx, channelName, packageName, headCsvName string) error {
addChannel, err := tx.Prepare("insert or replace into channel(name, package_name, head_operatorbundle_name) values(?, ?, ?)")
if err != nil {
return err
}
defer addChannel.Close()
_, err = addChannel.Exec(channelName, packageName, headCsvName)
if err != nil {
return err
}
return nil
}
func updateDefaultChannel(tx *sql.Tx, channelName, packageName string) error {
updateDefaultChannel, err := tx.Prepare("update package set default_channel = ? where name = ?")
if err != nil {
return err
}
defer updateDefaultChannel.Close()
_, err = updateDefaultChannel.Exec(channelName, packageName)
if err != nil {
return err
}
return nil
}
func truncChannelGraph(tx *sql.Tx, channelName, packageName string) error {
truncChannelGraph, err := tx.Prepare("delete from channel_entry where channel_name = ? and package_name = ?")
if err != nil {
return err
}
defer truncChannelGraph.Close()
_, err = truncChannelGraph.Exec(channelName, packageName)
if err != nil {
return err
}
return nil
}