GraphQL API and utilities for the rpdata project
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package postgres
import ( "context" "database/sql" "fmt" "git.aiterp.net/rpdata/api/database/postgres/psqlcore" "git.aiterp.net/rpdata/api/models" )
type tagRepository struct { db *sql.DB }
func (r *tagRepository) Find(ctx context.Context, kind models.TagKind, name string) (*models.Tag, error) { tag, err := psqlcore.New(r.db).SelectTagsByTag(ctx, fmt.Sprintf("%s:%s", kind, name)) if err != nil { return nil, err }
tag2 := &models.Tag{} err = tag2.Decode(tag[0].Tag) if err != nil { return nil, err }
return tag2, nil }
func (r *tagRepository) List(ctx context.Context, filter models.TagFilter) ([]*models.Tag, error) { var tags []string var err error if filter.Kind != nil { tags, err = psqlcore.New(r.db).SelectDistinctTagsLike(ctx, string(*filter.Kind)+"%") } else { tags, err = psqlcore.New(r.db).SelectDistinctTags(ctx) } if err != nil { return nil, err }
return models.DecodeTagArray(tags) }
|