···
351
+
func GetProfiles(e Execer, filters ...filter) ([]Profile, error) {
352
+
var conditions []string
354
+
for _, filter := range filters {
355
+
conditions = append(conditions, filter.Condition())
356
+
args = append(args, filter.Arg()...)
360
+
if conditions != nil {
361
+
whereClause = " where " + strings.Join(conditions, " and ")
364
+
profilesQuery := fmt.Sprintf(
376
+
rows, err := e.Query(profilesQuery, args...)
381
+
profileMap := make(map[string]*Profile)
383
+
var profile Profile
384
+
var includeBluesky int
386
+
err = rows.Scan(&profile.ID, &profile.Did, &profile.Description, &includeBluesky, &profile.Location)
391
+
if includeBluesky != 0 {
392
+
profile.IncludeBluesky = true
395
+
profileMap[profile.Did] = &profile
397
+
if err = rows.Err(); err != nil {
401
+
// populate profile links
402
+
inClause := strings.TrimSuffix(strings.Repeat("?, ", len(profileMap)), ", ")
403
+
args = make([]any, len(profileMap))
405
+
for did := range profileMap {
410
+
linksQuery := fmt.Sprintf("select link, did from profile_links where did in (%s)", inClause)
411
+
rows, err = e.Query(linksQuery, args...)
415
+
idxs := make(map[string]int)
416
+
for did := range profileMap {
420
+
var link, did string
421
+
if err = rows.Scan(&link, &did); err != nil {
426
+
log.Println("idx", "idx", idx, "link", link)
427
+
profileMap[did].Links[idx] = link
428
+
idxs[did] = idx + 1
431
+
pinsQuery := fmt.Sprintf("select at_uri, did from profile_pinned_repositories where did in (%s)", inClause)
432
+
rows, err = e.Query(pinsQuery, args...)
436
+
idxs = make(map[string]int)
437
+
for did := range profileMap {
441
+
var link syntax.ATURI
443
+
if err = rows.Scan(&link, &did); err != nil {
448
+
profileMap[did].PinnedRepos[idx] = link
449
+
idxs[did] = idx + 1
452
+
var profiles []Profile
453
+
for _, p := range profileMap {
454
+
profiles = append(profiles, *p)
457
+
return profiles, nil
func GetProfile(e Execer, did string) (*Profile, error) {