-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabase.lisp
More file actions
65 lines (54 loc) · 1.89 KB
/
Copy pathdatabase.lisp
File metadata and controls
65 lines (54 loc) · 1.89 KB
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
64
65
;;;; database.lisp
(in-package #:todolist)
(defparameter *db-file* (project-dir "./db"))
(defparameter *first-run* nil)
;;; Groups table
(mito:deftable groups ()
((name :col-type :text)))
;;; Statuses table
(mito:deftable statuses ()
((name :col-type :text)))
;;; Todos table
(mito:deftable todos ()
((group-id :col-type :integer)
(status-id :col-type :integer)
(text :col-type :text)))
(defun check-first-run ()
"Check first run application"
(when (not (probe-file *db-file*))
(setf *first-run* t)))
(defun create-default-groups ()
"Create default groups"
(mito:create-dao 'groups :id 1 :name "work")
(mito:create-dao 'groups :id 2 :name "study")
(mito:create-dao 'groups :id 3 :name "finance")
(mito:create-dao 'groups :id 4 :name "home")
(mito:create-dao 'groups :id 5 :name "others"))
(defun create-default-statuses ()
"Create default statuses"
(mito:create-dao 'statuses :id 1 :name "TODO")
(mito:create-dao 'statuses :id 2 :name "DOING")
(mito:create-dao 'statuses :id 3 :name "DONE"))
(defun create-default-database-values ()
"Create default database values, and create test note in todolist"
(create-default-groups)
(create-default-statuses)
(mito:create-dao 'todos
:group-id 2
:status-id 1
:text "<p>Hello Friend! This is a test note, on it you can try how this application works.</p>"))
(defun database-connect ()
"Connect to database"
(format t "DATABASE: Starting connection...~%")
(check-first-run)
(mito:connect-toplevel :sqlite3 :database-name *db-file*)
(when *first-run*
(mapcar #'mito:ensure-table-exists '(todos groups statuses))
(create-default-database-values)
(setf *first-run* nil))
(format t "DATABASE: Connection started...~%"))
(defun database-disconnect ()
"Disconnect from database"
(format t "DATABASE: Stopping connection...~%")
(mito:disconnect-toplevel)
(format t "DATABASE: Connection stopped...~%"))