@@ -30,38 +30,41 @@ class ListItem
30
30
end
31
31
32
32
def check
33
- self.class.plugin_db .exec('UPDATE list_items SET checked = true WHERE id = $1', @id)
33
+ db .exec('UPDATE list_items SET checked = true WHERE id = $1', @id)
34
34
@checked = true
35
35
end
36
36
37
37
def uncheck
38
- self.class.plugin_db .exec('UPDATE list_items SET checked = false WHERE id = $1', @id)
38
+ db .exec('UPDATE list_items SET checked = false WHERE id = $1', @id)
39
39
@checked = false
40
40
end
41
41
42
42
def update_title(title)
43
- self.class.plugin_db .exec('UPDATE list_items SET title = $1 WHERE id = $2', title, @id)
43
+ db .exec('UPDATE list_items SET title = $1 WHERE id = $2', title, @id)
44
44
end
45
45
46
46
def destroy
47
- self.class.plugin_db .exec('DELETE FROM list_items WHERE id = $1', @id)
47
+ db .exec('DELETE FROM list_items WHERE id = $1', @id)
48
48
end
49
49
50
50
def valid?
51
51
@error.nil?
52
52
end
53
53
54
+ def db
55
+ self.class.db
56
+ end
54
57
55
- def self.plugin_db
58
+ def self.db
56
59
PG
57
60
end
58
61
59
62
def self.all
60
- plugin_db .query("SELECT * FROM list_items ORDER BY id DESC")
63
+ db .query("SELECT * FROM list_items ORDER BY id DESC")
61
64
end
62
65
63
66
def self.find(id)
64
- result = plugin_db .query("SELECT * FROM list_items WHERE id = $1", id).first
67
+ result = db .query("SELECT * FROM list_items WHERE id = $1", id).first
65
68
if result
66
69
new({ id: result[:id], title: result[:title], checked: result[:checked] })
67
70
end
@@ -72,7 +75,7 @@ class ListItem
72
75
if result[:error].nil?
73
76
title = params[:title]
74
77
checked = params[:checked].to_i == 1
75
- resultID = self.plugin_db .exec("INSERT INTO list_items (title, checked) VALUES ($1, $2)", title, checked)
78
+ resultID = db .exec("INSERT INTO list_items (title, checked) VALUES ($1, $2)", title, checked)
76
79
new({ id: resultID, title: title, checked: checked })
77
80
else
78
81
new({ error: result[:error] })
0 commit comments