Remove db as a global variable
There's no need for it to be a global variable.
This commit is contained in:
parent
f71c70ca7b
commit
57f06ec8c9
1 changed files with 13 additions and 14 deletions
15
linkwave.scm
15
linkwave.scm
|
@ -15,11 +15,11 @@
|
||||||
(format #t "~a~% ~a~% ~a~% ~a~%~%" (string-no-null name) (string-no-null description)
|
(format #t "~a~% ~a~% ~a~% ~a~%~%" (string-no-null name) (string-no-null description)
|
||||||
(string-no-null url) (seconds->string seconds)))
|
(string-no-null url) (seconds->string seconds)))
|
||||||
|
|
||||||
(define (add-tag name)
|
(define (add-tag db name)
|
||||||
(execute db "INSERT INTO tag VALUES (?)" name)
|
(execute db "INSERT INTO tag VALUES (?)" name)
|
||||||
(last-insert-rowid db))
|
(last-insert-rowid db))
|
||||||
|
|
||||||
(define (add-bookmark url name description tags)
|
(define (add-bookmark db url name description tags)
|
||||||
(execute db "INSERT INTO bookmark VALUES (?, STRFTIME('%s'), ?, ?)"
|
(execute db "INSERT INTO bookmark VALUES (?, STRFTIME('%s'), ?, ?)"
|
||||||
url name description)
|
url name description)
|
||||||
(let ((bookmark-id (last-insert-rowid db)))
|
(let ((bookmark-id (last-insert-rowid db)))
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
(set! tag-id (first-result db "SELECT rowid FROM tag WHERE name = ?" tag))
|
(set! tag-id (first-result db "SELECT rowid FROM tag WHERE name = ?" tag))
|
||||||
(exn (exn sqlite3)
|
(exn (exn sqlite3)
|
||||||
(if (eq? (get-condition-property exn 'sqlite3 'status) 'done)
|
(if (eq? (get-condition-property exn 'sqlite3 'status) 'done)
|
||||||
(set! tag-id (add-tag tag))
|
(set! tag-id (add-tag db tag))
|
||||||
(signal exn))))
|
(signal exn))))
|
||||||
(execute db "INSERT INTO bookmark_tag VALUES (?, ?)"
|
(execute db "INSERT INTO bookmark_tag VALUES (?, ?)"
|
||||||
bookmark-id tag-id)))
|
bookmark-id tag-id)))
|
||||||
|
@ -41,17 +41,16 @@
|
||||||
(string= (substring str 0 8) "https://"))))
|
(string= (substring str 0 8) "https://"))))
|
||||||
|
|
||||||
(define (main args)
|
(define (main args)
|
||||||
|
(let ((db (open-database (data-file "linkwave.db"))))
|
||||||
(if (null? args)
|
(if (null? args)
|
||||||
(for-each-row print-row db "select * from bookmark")
|
(for-each-row print-row db "select * from bookmark")
|
||||||
(cond
|
(cond
|
||||||
((url-string? (car args))
|
((url-string? (car args))
|
||||||
(with-transaction
|
(with-transaction
|
||||||
db (lambda () (add-bookmark (car args) (cadr args) (caddr args) (cdddr args)) #t)))
|
db (lambda () (add-bookmark db (car args) (cadr args) (caddr args) (cdddr args)) #t)))
|
||||||
(else
|
(else
|
||||||
(format #t "Unrecognized option: ~a~%" (car args))))))
|
(format #t "Unrecognized option: ~a~%" (car args)))))
|
||||||
|
|
||||||
(define db (open-database (data-file "linkwave.db")))
|
(finalize! db #t)))
|
||||||
|
|
||||||
(main (command-line-arguments))
|
(main (command-line-arguments))
|
||||||
|
|
||||||
(finalize! db #t)
|
|
||||||
|
|
Loading…
Reference in a new issue