-
Notifications
You must be signed in to change notification settings - Fork 0
/
sinapp.rb
111 lines (74 loc) · 2.07 KB
/
sinapp.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
require "rubygems"
require "sinatra"
# if use active record
require "active_record"
require "mysql2"
#if use sequel
require "sequel"
require "mysql"
require "nokogiri"
require "json"
configure do
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => "127.0.0.1",
:username => "stbn",
:password => "software",
:database => "AQLT"
)
end
=begin
configure do
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => "192.168.1.133",
:username => "jmgalaminos",
:password => "System2406",
:database => "AQLT"
)
end
=end
#DB = Sequel.connect('mysql://AQLT:[email protected]/users')
#Sequel::Model.plugin(:schema) # I worked this out, but I can't find it documented
DB = Sequel.connect('mysql://stbn:software@localhost/AQLT',:logger => Logger.new('db.log'))
#sequel = Sequel.connect('mysql://root:root@localhost/ruote_test')
#sequel = Sequel.connect(
# :adapter => 'mysql2',
# :user => 'root',
# :password => 'root',
# :socket=> '/tmp/mysql.sock',
# :database => 'foo_development')
class User < ActiveRecord::Base
end
#Sequel::Model.plugin(:schema) # I worked this out, but I can't find it documented
#DB = Sequel.connect('sqlite://db/discover.sqlite',:logger => Logger.new('db.log'))
#class Stream
# def each
# 100.times { |i| yield "#{i}\n" }
# end
#end
#get('/stream') { Stream.new }
get "/" do
erb :index
end
#get "/usuarios" do
# content_type :json
# foo = DB[:serverinfo].select(:DB, :SERVERNM).where(:STATUS => 'A').first
# erb:
#end
get '/users' do
@result = String.new
@users = DB[:users]
@users.each do |u|
@result << "<hr>" << u[:id] << " " << u[:email].to_s << "<hr>"
end
erb :users
end
get "/user/:id" do
@result = String.new
@users = DB["select * from users where id = #{params[:id]}"]
@users.each do |u|
@result << "<hr>" << u[:email] << "<hr>"
end
erb :users
end