Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sync esqlite api instead of stream api to support MacOS #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions versuri.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
(defconst versuri--db-file-name "/versuri.db"
"Name of the db containing all the lyrics.")

(defconst versuri--db-process nil
"The process containing the opened db stream.")
(defconst versuri--db-file nil
"The path to the db.")

(defun versuri--db-stream ()
"Return the db stream or create and open it if doesn't exist."
(unless versuri--db-process
(defun versuri--db-file ()
"Return the db file or create it if doesn't exist."
(unless versuri--db-file
(let ((db-path (concat (xdg-config-home)
versuri--db-file-name)))
(esqlite-execute db-path
Expand All @@ -68,13 +68,12 @@
"song TEXT NOT NULL "
" COLLATE NOCASE, "
"lyrics TEXT COLLATE NOCASE);"))
(setf versuri--db-process
(esqlite-stream-open db-path))))
versuri--db-process)
(setf versuri--db-file db-path)))
versuri--db-file)

(defun versuri--db-read (query)
"Call the QUERY on the database and return the result."
(esqlite-stream-read (versuri--db-stream) query))
(esqlite-read (versuri--db-file) query))

(defun versuri--db-get-lyrics (artist song)
"Retrieve the stored lyrics for ARTIST and SONG."
Expand All @@ -101,7 +100,7 @@

(defun versuri--db-save-lyrics (artist song lyrics)
"Save the LYRICS for ARTIST and SONG in the database."
(esqlite-stream-execute (versuri--db-stream)
(esqlite-execute (versuri--db-file)
(format "INSERT INTO lyrics(artist,song,lyrics) VALUES(\"%s\", \"%s\", \"%s\")"
(esqlite-escape-string artist ?\")
(esqlite-escape-string song ?\")
Expand All @@ -110,8 +109,8 @@
(defun versuri-delete-lyrics (artist song)
"Remove entry for ARTIST and SONG form the database."
(print (format "%s - %s" artist song))
(esqlite-stream-execute
(versuri--db-stream)
(esqlite-execute
(versuri--db-file)
(format "DELETE FROM lyrics WHERE artist=\"%s\" and song=\"%s\""
artist song)))

Expand Down