Browse code

Added basic DB interactions

Jaidyn Lev authored on 2018-06-14 05:16:05
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+(defsystem "doormat"
2
+  :version "0.0"
3
+  :author "Jaidyn Lev <jadedctrl@teknik.io>"
4
+  :license "CSL v1+"
5
+  :depends-on ("simple-sql") 
6
+  :components ((:module "src"
7
+                :components
8
+		((:file "package")
9
+		(:file "main"))))
10
+  :description
11
+	"Guest/visitor-counter for websites.")
0 12
new file mode 100644
... ...
@@ -0,0 +1,39 @@
1
+;; MAIN.LISP
2
+;; ========================
3
+
4
+(in-package :doormat)
5
+
6
+(defun increment-visitors (url)
7
+  "Increment the visitor count of a set URL by one"
8
+
9
+  (simple-sql:init "doormat")
10
+
11
+  (let ((visitor-count
12
+          (nth 1
13
+               (nth 0
14
+                    (simple-sql:fetch-where "entries"
15
+                                            "url" (stra url))))))
16
+    (if visitor-count
17
+      (simple-sql:update-where "entries" "visitors" nil
18
+                               (format nil "~A" (+ visitor-count 1))
19
+                               "url" (stra url)))))
20
+
21
+
22
+(defun create-entry (url)
23
+  "Create a new entry for a set URL (with one initial visit)!"
24
+
25
+  (simple-sql:init "doormat")
26
+  
27
+  (simple-sql:insert-row "entries" (stra url ) 1))
28
+
29
+
30
+(defun fetch-visitors (url)
31
+  "Fetches the visitor-count of a URL."
32
+
33
+  (nth 1 (nth 0 (simple-sql:fetch-where "entries" "url" (stra url)))))
34
+
35
+
36
+(defun stra (string)
37
+  "Encases a string in apostrophes."
38
+
39
+  (concatenate `string "'" string "'"))
0 40
new file mode 100644
... ...
@@ -0,0 +1,9 @@
1
+(defpackage :doormat
2
+  (:use :cl)
3
+  (:export
4
+    :increment-visitors
5
+    :fetch-visitors
6
+    :create-entry))
7
+
8
+
9
+(in-package :doormat)