Permalink
Browse files

MySQLから値を返す

  • Loading branch information...
massat committed Feb 28, 2017
1 parent 777e1f7 commit 666e1e0ac00a11b3cf53c2e879c99ebff3afe191
Showing with 11 additions and 1 deletion.
  1. +11 −1 app.rb
View
12 app.rb
@@ -1,9 +1,19 @@
+require 'json'
+require 'mysql2'
require 'sinatra'
class App < Sinatra::Base
get '/' do
- 'Hello world!'
+ mysql = Mysql2::Client.new(
+ host: 'mysql',
+ username: 'app',
+ password: 'app',
+ database: 'app'
+ )
+ entries = mysql.query('SELECT * FROM `book`').entries
+
+ JSON.generate(entries)
end
end

0 comments on commit 666e1e0

Please sign in to comment.