Add --linking-to filter option

pull/6/head
Mickaël Menu 3 years ago
parent a0ba426aa2
commit 7c6b5af4f9
No known key found for this signature in database
GPG Key ID: 53D73664CD359895

@ -384,6 +384,20 @@ func (d *NoteDAO) findRows(opts note.FinderOpts) (*sql.Rows, error) {
"("+strutil.JoinInt64(ids, ",")+")"),
)
case note.LinkingToFilter:
ids, err := d.findIdsByPathPrefixes(filter)
if err != nil {
return nil, err
}
if len(filter) == 0 {
break
}
whereExprs = append(whereExprs, fmt.Sprintf(
"n.id IN (SELECT source_id FROM links WHERE target_id IN %v)",
"("+strutil.JoinInt64(ids, ",")+")"),
)
case note.DateFilter:
value := "?"
field := "n." + dateField(filter)

@ -500,6 +500,15 @@ func TestNoteDAOFindLinkedBy(t *testing.T) {
)
}
func TestNoteDAOFindLinkingTo(t *testing.T) {
testNoteDAOFindPaths(t,
note.FinderOpts{
Filters: []note.Filter{note.LinkingToFilter([]string{"log/2021-01-04", "ref/test/a.md"})},
},
[]string{"f39c8.md", "log/2021-01-03.md"},
)
}
func TestNoteDAOFindCreatedOn(t *testing.T) {
testNoteDAOFindPaths(t,
note.FinderOpts{

@ -19,7 +19,8 @@ type Filtering struct {
Modified string `help:"Only the notes modified on the given date" placeholder:"<date>"`
ModifiedBefore string `help:"Only the notes modified before the given date" placeholder:"<date>"`
ModifiedAfter string `help:"Only the notes modified after the given date" placeholder:"<date>"`
LinkedBy []string `help:"Only the notes linked by the given notes" placeholder:"<path>"`
LinkedBy []string `help:"Only the notes linked by the given notes" placeholder:"<path>" short:"l"`
LinkingTo []string `help:"Only the notes linking to the given notes" placeholder:"<path>" short:"L"`
Exclude []string `help:"Excludes notes matching the given file path pattern from the list" short:"x" placeholder:"<glob>"`
Interactive bool `help:"Further filter the list of notes interactively" short:"i"`
}
@ -124,6 +125,11 @@ func NewFinderOpts(zk *zk.Zk, filtering Filtering, sorting Sorting) (*note.Finde
filters = append(filters, note.LinkedByFilter(linkedByPaths))
}
linkingToPaths, ok := relPaths(zk, filtering.LinkingTo)
if ok {
filters = append(filters, note.LinkingToFilter(linkingToPaths))
}
if filtering.Interactive {
filters = append(filters, note.InteractiveFilter(true))
}

@ -43,6 +43,9 @@ type ExcludePathFilter []string
// LinkedByFilter is a note filter used to select notes being linked by another one.
type LinkedByFilter []string
// LinkingToFilter is a note filter used to select notes being linked by another one.
type LinkingToFilter []string
// DateFilter can be used to filter notes created or modified before, after or on a given date.
type DateFilter struct {
Date time.Time
@ -57,6 +60,7 @@ func (f MatchFilter) sealed() {}
func (f PathFilter) sealed() {}
func (f ExcludePathFilter) sealed() {}
func (f LinkedByFilter) sealed() {}
func (f LinkingToFilter) sealed() {}
func (f DateFilter) sealed() {}
func (f InteractiveFilter) sealed() {}

Loading…
Cancel
Save