This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edbc-sqlite.el
63 lines (49 loc) · 2.13 KB
/
edbc-sqlite.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
;;; edbc-sqlite.el --- Emacs Database Connectivity for sqlite
;; Copyright: (C) 2012 Zhang, Zepeng
;; Author: Zhang, Zepeng (Joe) <redraiment@gmail.com>
;; Version: 0.1
;; Time-stamp: <2012-09-04 CST>
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program ; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Code:
(require 'edbc)
(defadvice edbc-command-options
(after edbc-sqlite-command-options (options) activate)
(setf ad-return-value `("sqlite3" "-batch" "-line"
,(second (assoc 'url options)))))
(setf edbc-cmd-quit ".quit\n")
(defun sqlite-sql-format (sql)
(concat sql ";\n"))
(add-hook 'edbc-alive-sql-hook #'sqlite-sql-format)
(defmacro if-let (binding then &optional else)
"(if-let binding then else?)
binding => binding-form test
If test is true, evaluates then with binding-form bound to the value of
test, if not, yields else"
`(let (,binding)
(if ,(car binding)
,then
,else)))
(defun sqlite-output-format (output)
(mapcar (lambda (paragraph)
(mapcar (lambda (line)
(if-let (idx (string-match "=" line))
(cons (string-trim (substring line 0 idx))
(string-trim (substring line (1+ idx))))
(list (string-trim line))))
(delq "" (split-string paragraph "\r?\n"))))
(split-string output "\r?\n\r?\n")))
(add-hook 'edbc-output-format-hook #'sqlite-output-format)
(provide 'edbc-sqlite)