deebee 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +1 -0
- data/deebee.gemspec +24 -0
- data/lib/deebee/version.rb +3 -0
- data/lib/deebee/views/index.erb +8 -0
- data/lib/deebee/views/layout.erb +90 -0
- data/lib/deebee/views/table.erb +32 -0
- data/lib/deebee.rb +79 -0
- metadata +122 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Rafaël Blais Masson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Deebee
|
2
|
+
======
|
3
|
+
|
4
|
+
> Web client for your DB
|
5
|
+
|
6
|
+
## Setup
|
7
|
+
|
8
|
+
Clone this repo, then set the `DATABASE_URL` environment variable in your [`.rbenv-vars`](https://github.com/sstephenson/rbenv-vars) or wherever you see fit.
|
9
|
+
|
10
|
+
bundle install
|
11
|
+
shotgun start
|
12
|
+
|
13
|
+
If you don’t use Postgres, change `gem 'pg'` to something else in the `Gemfile`.
|
14
|
+
|
15
|
+
You mostly want this protected, so just set the `HTTP_USERNAME` and `HTTP_PASSWORD` environment variables too.
|
16
|
+
|
17
|
+
## TODO
|
18
|
+
|
19
|
+
- `UPDATE` + `INSERT` functionality
|
20
|
+
- Sorting
|
21
|
+
- Filtering
|
22
|
+
|
23
|
+
---
|
24
|
+
|
25
|
+
© 2013 [Rafaël Blais Masson](http://rafbm.com)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/deebee.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'deebee/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'deebee'
|
8
|
+
spec.version = Deebee::VERSION
|
9
|
+
spec.authors = ['Rafaël Blais Masson']
|
10
|
+
spec.email = ['rafbmasson@gmail.com']
|
11
|
+
spec.description = 'Deebee is a convenient and fast web interface for your DB. As a Sinatra app, it can be used standalone or mounted within your Rails app.'
|
12
|
+
spec.summary = 'Web client for your DB'
|
13
|
+
spec.homepage = 'http://github.com/rafBM/deebee'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files | grep -Ev '^(examples)'`.split("\n")
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_dependency 'sinatra', '>= 1.2'
|
20
|
+
spec.add_dependency 'sequel', '>= 3.0'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<head>
|
3
|
+
<meta charset="utf-8">
|
4
|
+
<title>Deebee</title>
|
5
|
+
<style>
|
6
|
+
* { margin: 0; padding: 0; box-sizing: border-box }
|
7
|
+
|
8
|
+
body, input, textarea, button {
|
9
|
+
font: 16px Lucida Grande;
|
10
|
+
}
|
11
|
+
|
12
|
+
body {
|
13
|
+
padding: 3.5em 1em 1em;
|
14
|
+
}
|
15
|
+
|
16
|
+
ul { list-style: none }
|
17
|
+
li { margin: 1em 0 }
|
18
|
+
|
19
|
+
nav {
|
20
|
+
padding: 1em;
|
21
|
+
background: #fff;
|
22
|
+
position: fixed;
|
23
|
+
top: 0; right: 0; left: 0;
|
24
|
+
}
|
25
|
+
nav select {
|
26
|
+
margin-right: 1em;
|
27
|
+
}
|
28
|
+
|
29
|
+
table {
|
30
|
+
border-collapse: collapse;
|
31
|
+
}
|
32
|
+
table, table input, table textarea, table button {
|
33
|
+
font-size: 11px;
|
34
|
+
}
|
35
|
+
|
36
|
+
td, th {
|
37
|
+
border: 1px solid lightgrey;
|
38
|
+
padding: 0;
|
39
|
+
}
|
40
|
+
th {
|
41
|
+
padding: .2em .4em;
|
42
|
+
}
|
43
|
+
|
44
|
+
td input,
|
45
|
+
td textarea {
|
46
|
+
padding: .4em .5em;
|
47
|
+
margin: 0;
|
48
|
+
border: 0;
|
49
|
+
resize: none;
|
50
|
+
height: 2em;
|
51
|
+
}
|
52
|
+
td textarea {
|
53
|
+
overflow: hidden;
|
54
|
+
}
|
55
|
+
td textarea:focus {
|
56
|
+
overflow: scroll;
|
57
|
+
position: absolute;
|
58
|
+
z-index: 10;
|
59
|
+
width: 800px !important;
|
60
|
+
height: 600px !important;
|
61
|
+
max-width: none !important;
|
62
|
+
}
|
63
|
+
</style>
|
64
|
+
</head>
|
65
|
+
<body>
|
66
|
+
<nav>
|
67
|
+
<select onchange="location.href = '<%= url '/tables/' %>' + this.value">
|
68
|
+
<option value="">Choose a table…</option>
|
69
|
+
<% @tables.each do |table| %>
|
70
|
+
<option <%= 'selected' if params[:table] == table.to_s %>><%= table %></option>
|
71
|
+
<% end %>
|
72
|
+
</select>
|
73
|
+
|
74
|
+
<% if params[:table] %>
|
75
|
+
<% if params[:page] && params[:page].to_i > 1 %>
|
76
|
+
<a href="<%= url "/tables/#{params[:table]}/page/#{params[:page].to_i - 1}" %>">« Prev</a>
|
77
|
+
<% else %>
|
78
|
+
<a>« Prev</a>
|
79
|
+
<% end %>
|
80
|
+
|
81
|
+
<% if @records.size >= 500 %>
|
82
|
+
<a href="<%= url "/tables/#{params[:table]}/page/#{(params[:page] || 1).to_i + 1}" %>">Next »</a>
|
83
|
+
<% else %>
|
84
|
+
<a>Next »</a>
|
85
|
+
<% end %>
|
86
|
+
<% end %>
|
87
|
+
</nav>
|
88
|
+
<%= yield %>
|
89
|
+
</body>
|
90
|
+
</html>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<table>
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<% @table.columns.each do |column| %>
|
5
|
+
<th><%= column %></th>
|
6
|
+
<% end %>
|
7
|
+
</tr>
|
8
|
+
</thead>
|
9
|
+
<tbody>
|
10
|
+
<% @records.each do |record| %>
|
11
|
+
<tr>
|
12
|
+
<% record.each do |key, value| %>
|
13
|
+
<% type = @schema[key][:db_type] %>
|
14
|
+
|
15
|
+
<% if type.match /text|hstore/ %>
|
16
|
+
<td>
|
17
|
+
<textarea style="max-width: 200px"><%= CGI.escapeHTML(value.to_s) %></textarea>
|
18
|
+
</td>
|
19
|
+
<% elsif type.match /integer|numeric/ %>
|
20
|
+
<td>
|
21
|
+
<input value="<%= CGI.escapeHTML(value.to_s) %>" style="max-width: 300px; text-align: right">
|
22
|
+
</td>
|
23
|
+
<% else %>
|
24
|
+
<td>
|
25
|
+
<input value="<%= CGI.escapeHTML(value.to_s) %>" style="max-width: 300px">
|
26
|
+
</td>
|
27
|
+
<% end %>
|
28
|
+
<% end %>
|
29
|
+
</tr>
|
30
|
+
<% end %>
|
31
|
+
</tbody>
|
32
|
+
</table>
|
data/lib/deebee.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'deebee/version'
|
2
|
+
|
3
|
+
require 'sinatra/base'
|
4
|
+
require 'sequel'
|
5
|
+
|
6
|
+
require 'cgi'
|
7
|
+
|
8
|
+
module Deebee
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class ConnectionError < Error
|
12
|
+
def initialize(url)
|
13
|
+
@url = url
|
14
|
+
end
|
15
|
+
|
16
|
+
def message
|
17
|
+
"Invalid DATABASE_URL value: #{ENV['DATABASE_URL'].inspect}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class App < Sinatra::Base
|
22
|
+
set :root, File.expand_path('../deebee', __FILE__)
|
23
|
+
|
24
|
+
configure do
|
25
|
+
begin
|
26
|
+
set :db, Sequel.connect(ENV['DATABASE_URL'])
|
27
|
+
set :tables, settings.db.tables.sort
|
28
|
+
rescue Sequel::Error
|
29
|
+
raise ConnectionError.new(ENV['DATABASE_URL'])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
before do
|
34
|
+
@db = settings.db
|
35
|
+
@tables = settings.tables
|
36
|
+
redirect request.path_info.sub(/\/$/, '') if request.path_info =~ /.+\/$/
|
37
|
+
end
|
38
|
+
|
39
|
+
get '/' do
|
40
|
+
redirect to('/tables')
|
41
|
+
end
|
42
|
+
|
43
|
+
get '/tables' do
|
44
|
+
erb :index
|
45
|
+
end
|
46
|
+
|
47
|
+
get '/tables/:table' do
|
48
|
+
table = params[:table].to_sym
|
49
|
+
|
50
|
+
@table = @db[table]
|
51
|
+
@schema = Hash[@db.schema(table)]
|
52
|
+
|
53
|
+
if @schema.has_key? :id
|
54
|
+
@records = @table.limit(500).order(:id).all
|
55
|
+
else
|
56
|
+
@records = @table.limit(500).all
|
57
|
+
end
|
58
|
+
|
59
|
+
erb :table
|
60
|
+
end
|
61
|
+
|
62
|
+
get '/tables/:table/page/:page' do
|
63
|
+
table = params[:table].to_sym
|
64
|
+
|
65
|
+
@table = @db[table]
|
66
|
+
@schema = Hash[@db.schema(table)]
|
67
|
+
|
68
|
+
offset = 500 * (params[:page].to_i) - 500
|
69
|
+
|
70
|
+
if @schema.has_key? :id
|
71
|
+
@records = @table.limit(500, offset).order(:id).all
|
72
|
+
else
|
73
|
+
@records = @table.limit(500, offset).all
|
74
|
+
end
|
75
|
+
|
76
|
+
erb :table
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deebee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rafaël Blais Masson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.2'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sequel
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Deebee is a convenient and fast web interface for your DB. As a Sinatra
|
79
|
+
app, it can be used standalone or mounted within your Rails app.
|
80
|
+
email:
|
81
|
+
- rafbmasson@gmail.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- deebee.gemspec
|
92
|
+
- lib/deebee.rb
|
93
|
+
- lib/deebee/version.rb
|
94
|
+
- lib/deebee/views/index.erb
|
95
|
+
- lib/deebee/views/layout.erb
|
96
|
+
- lib/deebee/views/table.erb
|
97
|
+
homepage: http://github.com/rafBM/deebee
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.23
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Web client for your DB
|
122
|
+
test_files: []
|