-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
32 lines (22 loc) · 823 Bytes
/
app.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
require_relative 'lib/database_connection'
require 'tty-table' #to format as a table
require_relative 'lib/recipe_repo'
DatabaseConnection.connect('recipes_directory')
sql = 'SELECT * FROM recipes;'
result = DatabaseConnection.exec_params(sql, [])
# Create a table with headers
headers = ['ID', 'Name', 'Cooking Time', 'Rating']
# Create an array of rows using the result set
rows = result.map do |record|
[record['id'], record['names'], record['cooking_time'], record['rating']]
end
# Create the table with headers and rows
table = TTY::Table.new(headers, rows)
# Render the table and print it
puts table.render(:ascii)
puts "Indivdual value for first recipe: "
repo = RecipeRepo.new
entry = repo.find(1)
puts "recipe: #{entry.names}"
puts "cooking time: #{entry.cooking_time}"
puts "rating: #{entry.rating}"