feat: implement memo property

This commit is contained in:
Steven
2024-05-13 22:04:37 +08:00
parent 555b4fbe32
commit c561362d62
13 changed files with 883 additions and 593 deletions

View File

@@ -87,8 +87,13 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
}
where = append(where, fmt.Sprintf("`memo`.`visibility` IN (%s)", strings.Join(placeholder, ",")))
}
if v := find.Tag; v != nil {
where, args = append(where, "JSON_EXTRACT(`memo`.`tags`, '$') LIKE ?"), append(args, fmt.Sprintf(`%%"%s"%%`, *v))
if v := find.PayloadFind; v != nil {
if v.Raw != nil {
where, args = append(where, "`memo`.`payload` = ?"), append(args, *v.Raw)
}
if v.Tag != nil {
where, args = append(where, "JSON_EXTRACT(`memo`.`payload`, '$.property.tags') LIKE ?"), append(args, fmt.Sprintf(`%%"%s"%%`, *v.Tag))
}
}
if find.ExcludeComments {
where = append(where, "`parent_id` IS NULL")
@@ -204,13 +209,6 @@ func (d *DB) UpdateMemo(ctx context.Context, update *store.UpdateMemo) error {
if v := update.Visibility; v != nil {
set, args = append(set, "`visibility` = ?"), append(args, *v)
}
if v := update.Tags; v != nil {
tagsBytes, err := json.Marshal(v)
if err != nil {
return err
}
set, args = append(set, "`tags` = ?"), append(args, string(tagsBytes))
}
if v := update.Payload; v != nil {
payloadBytes, err := protojson.Marshal(v)
if err != nil {