Signed-off-by: oppiliappan me@oppi.li
+4
-4
appview/db/follow.go
+4
-4
appview/db/follow.go
···
56
}
57
58
type FollowStats struct {
59
-
Followers int
60
-
Following int
61
}
62
63
func GetFollowerFollowingCount(e Execer, did string) (FollowStats, error) {
64
-
followers, following := 0, 0
65
err := e.QueryRow(
66
`SELECT
67
COUNT(CASE WHEN subject_did = ? THEN 1 END) AS followers,
···
122
123
for rows.Next() {
124
var did string
125
-
var followers, following int
126
if err := rows.Scan(&did, &followers, &following); err != nil {
127
return nil, err
128
}
···
56
}
57
58
type FollowStats struct {
59
+
Followers int64
60
+
Following int64
61
}
62
63
func GetFollowerFollowingCount(e Execer, did string) (FollowStats, error) {
64
+
var followers, following int64
65
err := e.QueryRow(
66
`SELECT
67
COUNT(CASE WHEN subject_did = ? THEN 1 END) AS followers,
···
122
123
for rows.Next() {
124
var did string
125
+
var followers, following int64
126
if err := rows.Scan(&did, &followers, &following); err != nil {
127
return nil, err
128
}
+25
-64
appview/db/repos.go
+25
-64
appview/db/repos.go
···
2
3
import (
4
"database/sql"
5
"fmt"
6
"log"
7
"slices"
···
38
return p
39
}
40
41
-
func GetAllRepos(e Execer, limit int) ([]Repo, error) {
42
-
var repos []Repo
43
-
44
-
rows, err := e.Query(
45
-
`select did, name, knot, rkey, description, created, source
46
-
from repos
47
-
order by created desc
48
-
limit ?
49
-
`,
50
-
limit,
51
-
)
52
-
if err != nil {
53
-
return nil, err
54
-
}
55
-
defer rows.Close()
56
-
57
-
for rows.Next() {
58
-
var repo Repo
59
-
err := scanRepo(
60
-
rows, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &repo.Description, &repo.Created, &repo.Source,
61
-
)
62
-
if err != nil {
63
-
return nil, err
64
-
}
65
-
repos = append(repos, repo)
66
-
}
67
-
68
-
if err := rows.Err(); err != nil {
69
-
return nil, err
70
-
}
71
-
72
-
return repos, nil
73
-
}
74
-
75
func GetRepos(e Execer, limit int, filters ...filter) ([]Repo, error) {
76
repoMap := make(map[syntax.ATURI]*Repo)
77
···
318
return repos, nil
319
}
320
321
func GetAllReposByDid(e Execer, did string) ([]Repo, error) {
322
var repos []Repo
323
···
570
IssueCount IssueCount
571
PullCount PullCount
572
}
573
-
574
-
func scanRepo(rows *sql.Rows, did, name, knot, rkey, description *string, created *time.Time, source *string) error {
575
-
var createdAt string
576
-
var nullableDescription sql.NullString
577
-
var nullableSource sql.NullString
578
-
if err := rows.Scan(did, name, knot, rkey, &nullableDescription, &createdAt, &nullableSource); err != nil {
579
-
return err
580
-
}
581
-
582
-
if nullableDescription.Valid {
583
-
*description = nullableDescription.String
584
-
} else {
585
-
*description = ""
586
-
}
587
-
588
-
createdAtTime, err := time.Parse(time.RFC3339, createdAt)
589
-
if err != nil {
590
-
*created = time.Now()
591
-
} else {
592
-
*created = createdAtTime
593
-
}
594
-
595
-
if nullableSource.Valid {
596
-
*source = nullableSource.String
597
-
} else {
598
-
*source = ""
599
-
}
600
-
601
-
return nil
602
-
}
···
2
3
import (
4
"database/sql"
5
+
"errors"
6
"fmt"
7
"log"
8
"slices"
···
39
return p
40
}
41
42
func GetRepos(e Execer, limit int, filters ...filter) ([]Repo, error) {
43
repoMap := make(map[syntax.ATURI]*Repo)
44
···
285
return repos, nil
286
}
287
288
+
func CountRepos(e Execer, filters ...filter) (int64, error) {
289
+
var conditions []string
290
+
var args []any
291
+
for _, filter := range filters {
292
+
conditions = append(conditions, filter.Condition())
293
+
args = append(args, filter.Arg()...)
294
+
}
295
+
296
+
whereClause := ""
297
+
if conditions != nil {
298
+
whereClause = " where " + strings.Join(conditions, " and ")
299
+
}
300
+
301
+
repoQuery := fmt.Sprintf(`select count(1) from repos %s`, whereClause)
302
+
var count int64
303
+
err := e.QueryRow(repoQuery, args...).Scan(&count)
304
+
305
+
if !errors.Is(err, sql.ErrNoRows) && err != nil {
306
+
return 0, err
307
+
}
308
+
309
+
return count, nil
310
+
}
311
+
312
func GetAllReposByDid(e Execer, did string) ([]Repo, error) {
313
var repos []Repo
314
···
561
IssueCount IssueCount
562
PullCount PullCount
563
}
+26
appview/db/star.go
+26
appview/db/star.go
···
1
package db
2
3
import (
4
+
"database/sql"
5
+
"errors"
6
"fmt"
7
"log"
8
"strings"
···
185
return stars, nil
186
}
187
188
+
func CountStars(e Execer, filters ...filter) (int64, error) {
189
+
var conditions []string
190
+
var args []any
191
+
for _, filter := range filters {
192
+
conditions = append(conditions, filter.Condition())
193
+
args = append(args, filter.Arg()...)
194
+
}
195
+
196
+
whereClause := ""
197
+
if conditions != nil {
198
+
whereClause = " where " + strings.Join(conditions, " and ")
199
+
}
200
+
201
+
repoQuery := fmt.Sprintf(`select count(1) from stars %s`, whereClause)
202
+
var count int64
203
+
err := e.QueryRow(repoQuery, args...).Scan(&count)
204
+
205
+
if !errors.Is(err, sql.ErrNoRows) && err != nil {
206
+
return 0, err
207
+
}
208
+
209
+
return count, nil
210
+
}
211
+
212
func GetAllStars(e Execer, limit int) ([]Star, error) {
213
var stars []Star
214
+24
appview/db/strings.go
+24
appview/db/strings.go
···
206
return all, nil
207
}
208
209
+
func CountStrings(e Execer, filters ...filter) (int64, error) {
210
+
var conditions []string
211
+
var args []any
212
+
for _, filter := range filters {
213
+
conditions = append(conditions, filter.Condition())
214
+
args = append(args, filter.Arg()...)
215
+
}
216
+
217
+
whereClause := ""
218
+
if conditions != nil {
219
+
whereClause = " where " + strings.Join(conditions, " and ")
220
+
}
221
+
222
+
repoQuery := fmt.Sprintf(`select count(1) from strings %s`, whereClause)
223
+
var count int64
224
+
err := e.QueryRow(repoQuery, args...).Scan(&count)
225
+
226
+
if !errors.Is(err, sql.ErrNoRows) && err != nil {
227
+
return 0, err
228
+
}
229
+
230
+
return count, nil
231
+
}
232
+
233
func DeleteString(e Execer, filters ...filter) error {
234
var conditions []string
235
var args []any