-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_setup.rb
45 lines (40 loc) · 883 Bytes
/
db_setup.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
require 'mysql2'
def connect
db = Mysql2::Client.new(
:host => "mel-exam-db",
:username => "root",
:password => "test456",
:database => "mel_exam_development"
)
db
end
def create_database
host = Mysql2::Client.new(
:host => "mel-exam-db",
:username => "root",
:password => "test456"
)
host.query("CREATE DATABASE mel_exam_development;")
end
def create_table(con)
con.query('create table items(
id int,
name varchar(255),
title varchar(255),
description varchar(255),
price int,
pv int,
status int,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB DEFAULT CHARSET=utf8')
end
def insert(con)
5.times do |i|
con.query("insert into items(id,name,title,description,price,pv,status) values(#{i},'name#{i}','title#{i}','status#{i}','price#{i}','pv#{i}','status#{i}');")
end
end
create_database
con = connect
create_table(con)
insert(con)