-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.rb
More file actions
30 lines (24 loc) · 735 Bytes
/
app.rb
File metadata and controls
30 lines (24 loc) · 735 Bytes
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
require 'sinatra/base'
require 'mysql2'
require 'time'
class Services
def self.client
return @client if @client
@client = Mysql2::Client.new(host: "mysql_host", username: "root", password: "labgoal", database: "app_development")
sql = "CREATE TABLE IF NOT EXISTS visits(id INT PRIMARY KEY AUTO_INCREMENT,created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)"
@client.query(sql)
@client
end
def self.total_visits
client.query("SELECT * from visits").count
end
def self.add_visit
client.query("INSERT INTO visits (id) VALUES (NULL)")
end
end
class App < Sinatra::Base
get '/' do
Services.add_visit
"Contador de visitas, #{Services.total_visits} visitas e contando..."
end
end