added org sqlite db init

This commit is contained in:
ndwarshuis 2018-12-20 21:28:14 -05:00
parent 3969e6dfe7
commit 41bc0cf8cf
1 changed files with 13 additions and 1 deletions

View File

@ -2641,13 +2641,25 @@ Org mode is great and all, but in many cases, text files just won't cut it. Hard
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(require 'sql) (require 'sql)
(defconst nd/sqlite3-cmd
"sqlite3"
"The shell command to summon sqlite3.")
(defconst nd/org-sqlite-db-path (defconst nd/org-sqlite-db-path
(expand-file-name "archive.db" org-directory) (expand-file-name "archive.db" org-directory)
"Path for the sqlite database that holds archive data.") "Path for the sqlite database that holds archive data.")
(defun nd/org-init-db () (defun nd/org-init-db ()
"Make a sqlite database for org archive files if it does not exits already." "Make a sqlite database for org archive files if it does not exits already."
(process-file-shell-command (concat "touch " nd/org-sqlite-db-path))) (unless (file-exists-p nd/org-sqlite-db-path)
(process-file-shell-command (concat "touch " nd/org-sqlite-db-path))
(nd/sql-cmd nd/org-sqlite-db-path "create table test(one smallint);")))
(defun nd/sql-cmd (db sql)
"Execute string SQL on database DB using sqlite3 shell command.
Returns the output of CMD. SQL should not contain any quotes as if it
were entered on the shell."
(shell-command-to-string (concat nd/sqlite3-cmd " " db " \"" sql "\"")))
#+END_SRC #+END_SRC
* tools * tools
** printing ** printing