bookie/bookmark.go
2023-01-02 18:13:08 -08:00

41 lines
844 B
Go

package main
import (
"database/sql"
"fmt"
)
func bookmarkExists(url string, db *sql.DB) bool {
var count int
err := db.QueryRow("SELECT count() FROM bookmarks where URL=?", url).Scan(&count)
if err != nil {
fmt.Println("Could not check database for url")
panic(err)
}
if count > 0 {
return true
}
return false
}
func addBookmark(db *sql.DB, b Bookmark) (Bookmark, error) {
fmt.Println("Got request to add:", b.Title)
var ret Bookmark
_, err := db.Exec(`
INSERT INTO bookmarks(
url, title, author, date, pubDate, comments, mercuryContent, pdfpath,
tags
) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?);`, b.URL, b.Domain, b.Author,
b.Title, b.SaveDate, b.PubDate, b.Comments, b.MercuryContent, b.PDFpath,
b.Tags)
if err != nil {
fmt.Println("Could not insert bookmark.")
return ret, err
}
return ret, nil
}