mirror of
https://github.com/dnote/dnote
synced 2026-03-15 06:55:49 +01:00
* Simplify the view command * Simplify the edit command * Migrate number-only book names * Run migration * Simplify remove * Print note info when adding, editing, or removing * Disallow users from editing or removing already removed notes
38 lines
978 B
Go
38 lines
978 B
Go
package core
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/dnote/dnote/cli/infra"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// NoteInfo is a basic information about a note
|
|
type NoteInfo struct {
|
|
RowID int
|
|
BookLabel string
|
|
UUID string
|
|
Content string
|
|
AddedOn int64
|
|
EditedOn int64
|
|
}
|
|
|
|
// GetNoteInfo returns a NoteInfo for the note with the given noteRowID
|
|
func GetNoteInfo(ctx infra.DnoteCtx, noteRowID string) (NoteInfo, error) {
|
|
var ret NoteInfo
|
|
|
|
db := ctx.DB
|
|
err := db.QueryRow(`SELECT books.label, notes.uuid, notes.body, notes.added_on, notes.edited_on, notes.rowid
|
|
FROM notes
|
|
INNER JOIN books ON books.uuid = notes.book_uuid
|
|
WHERE notes.rowid = ? AND notes.deleted = false`, noteRowID).
|
|
Scan(&ret.BookLabel, &ret.UUID, &ret.Content, &ret.AddedOn, &ret.EditedOn, &ret.RowID)
|
|
if err == sql.ErrNoRows {
|
|
return ret, errors.Errorf("note %s not found", noteRowID)
|
|
} else if err != nil {
|
|
return ret, errors.Wrap(err, "querying the note")
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|