-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbcon.rb
56 lines (44 loc) · 1.51 KB
/
dbcon.rb
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
require 'sqlite3'
module Dbcon
$db = SQLite3::Database.new('newtodos.db')
$db.execute('create table if not exists todos(
id integer primary key autoincrement,
title varchar(50) not null,
description varchar(200),
priority varchar(20),
deadline datetime
)')
def self.insert(title,description,priority,deadline)
title=title
description=description
priority=priority
deadline=deadline
$db.execute('insert into todos values(null,?,?,?,?)',[title,description,priority,deadline])
end
def self.edit(id,title,description,priority)
id = id
title = title
description = description
priority=priority
$db.execute("update todos set title = ?,description=?,priority=? where id = ?",[title,description,priority,id])
end
def self.delete(id)
id = id
$db.execute('delete from todos where id = ?',(id))
end
def self.list_by_priority
puts "ID: TITLE: Desc: priority: deadline:"
$db.execute('select * from todos order by priority').each do |row|
p "#{row[0]} #{row[1]} #{row[2]} #{row[3]} #{row[4]}"
end
end
def self.list_by_id
puts "ID: TITLE: Desc: priority: deadline:"
$db.execute('select * from todos').each do |row|
p "#{row[0]} #{row[1]} #{row[2]} #{row[3]} #{row[4]}"
end
end
def self.closeconn
$db.close
end
end