Added basic search.

This commit is contained in:
Magnus Åhall 2023-07-19 10:00:36 +02:00
parent 57180e986e
commit c58a1b988b
6 changed files with 211 additions and 21 deletions

33
node.go
View file

@ -373,5 +373,38 @@ func (session Session) DeleteNode(nodeID int) (err error) {// {{{
)
return
}// }}}
func (session Session) SearchNodes(search string) (nodes []Node, err error) {// {{{
nodes = []Node{}
var rows *sqlx.Rows
rows, err = db.Queryx(`
SELECT
id,
user_id,
COALESCE(parent_id, 0) AS parent_id,
name,
updated
FROM node
WHERE
crypto_key_id IS NULL AND
content ~* $1
ORDER BY
updated DESC
`, search)
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
node := Node{}
node.Complete = false
if err = rows.StructScan(&node); err != nil {
return
}
nodes = append(nodes, node)
}
return
}// }}}
// vim: foldmethod=marker