dbbrowser 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Manifest.txt +0 -1
- data/README.md +1 -1
- data/Rakefile +7 -4
- data/lib/dbbrowser.rb +4 -5
- data/lib/dbbrowser/server.rb +5 -4
- data/lib/dbbrowser/version.rb +10 -1
- metadata +78 -28
- data/lib/dbbrowser/connection.rb +0 -275
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: c03dfe89bdee6580f1ed6421d66fd4558895428f
|
|
4
|
+
data.tar.gz: 85da6c87bcc2876d87c76b589d5366038f2f717e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: df5bdb91c09985a18a113b0e6c84f6797633b19b973a3bbe524dd773d55599265277ec69785dc398b9af568aa3f3f82a4868f78648931e2c6b5209cbcf8e9d83
|
|
7
|
+
data.tar.gz: 30d2eda5dc410f0347366228296be179afbace07ff96fceff8adcfc8b61d2d4a6dc2f24d88e6752fdadc18ad490a8f93ae2a730978f0e329a62eda5117c69e00
|
data/Manifest.txt
CHANGED
data/README.md
CHANGED
|
@@ -14,7 +14,7 @@ database browser (connections, schema, tables, records, etc.) as mountable web a
|
|
|
14
14
|
In your rack configuration (`config.ru`) mount the databrowser app; add the line:
|
|
15
15
|
|
|
16
16
|
~~~
|
|
17
|
-
map
|
|
17
|
+
map('/browse') { run DbBrowser::Server }
|
|
18
18
|
~~~
|
|
19
19
|
|
|
20
20
|
|
data/Rakefile
CHANGED
|
@@ -18,14 +18,17 @@ Hoe.spec 'dbbrowser' do
|
|
|
18
18
|
self.history_file = 'History.md'
|
|
19
19
|
|
|
20
20
|
self.extra_deps = [
|
|
21
|
-
['logutils', '>= 0.5']
|
|
21
|
+
## ['logutils', '>= 0.5'], # already part of textutils - remove ???
|
|
22
|
+
['textutils'],
|
|
23
|
+
['activerecord'],
|
|
24
|
+
['activerecord-utils', '>= 0.4.0'],
|
|
25
|
+
['sinatra']
|
|
22
26
|
]
|
|
23
27
|
|
|
24
28
|
self.licenses = ['Public Domain']
|
|
25
29
|
|
|
26
30
|
self.spec_extras = {
|
|
27
|
-
:
|
|
31
|
+
required_ruby_version: '>= 1.9.2'
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
end
|
|
34
|
+
end
|
data/lib/dbbrowser.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
1
3
|
|
|
2
4
|
require 'pp'
|
|
3
5
|
|
|
@@ -7,18 +9,15 @@ require 'pp'
|
|
|
7
9
|
require 'textutils'
|
|
8
10
|
|
|
9
11
|
require 'active_record'
|
|
12
|
+
require 'activerecord/utils' ## pull in browser support
|
|
10
13
|
|
|
11
14
|
|
|
12
15
|
# our own code
|
|
13
16
|
|
|
14
17
|
require 'dbbrowser/version' # let it always go first
|
|
15
|
-
require 'dbbrowser/connection'
|
|
16
18
|
|
|
17
|
-
module DbBrowser
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
"#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
|
|
21
|
-
end
|
|
20
|
+
module DbBrowser
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
### helper for DATABASE_URL for ActiveRecord
|
data/lib/dbbrowser/server.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
1
2
|
|
|
2
3
|
|
|
3
4
|
# 3rd party libs/gems
|
|
@@ -25,7 +26,7 @@ class Server < Sinatra::Base
|
|
|
25
26
|
set :static, true # set up static file routing
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
set :
|
|
29
|
+
set :browser, ActiveRecordUtils::Browser.new
|
|
29
30
|
|
|
30
31
|
#################
|
|
31
32
|
# Helpers
|
|
@@ -73,7 +74,7 @@ class Server < Sinatra::Base
|
|
|
73
74
|
end
|
|
74
75
|
|
|
75
76
|
def render_tables_for( key, opts={} )
|
|
76
|
-
con = settings.
|
|
77
|
+
con = settings.browser.connection_for( key )
|
|
77
78
|
erb( 'shared/_tables'.to_sym,
|
|
78
79
|
layout: false,
|
|
79
80
|
locals: { tables: con.tables } )
|
|
@@ -103,7 +104,7 @@ class Server < Sinatra::Base
|
|
|
103
104
|
end
|
|
104
105
|
|
|
105
106
|
get '/db/:key/:table_name' do |key,table_name|
|
|
106
|
-
con = settings.
|
|
107
|
+
con = settings.browser.connection_for( key )
|
|
107
108
|
table = con.table( table_name )
|
|
108
109
|
|
|
109
110
|
query_opts = {}
|
|
@@ -118,7 +119,7 @@ class Server < Sinatra::Base
|
|
|
118
119
|
end
|
|
119
120
|
|
|
120
121
|
get '/db/:key' do |key|
|
|
121
|
-
con = settings.
|
|
122
|
+
con = settings.browser.connection_for( key )
|
|
122
123
|
erb :db, locals: { key: key, tables: con.tables, con: con }
|
|
123
124
|
end
|
|
124
125
|
|
data/lib/dbbrowser/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,63 +1,114 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dbbrowser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
5
|
-
prerelease:
|
|
4
|
+
version: 0.2.0
|
|
6
5
|
platform: ruby
|
|
7
6
|
authors:
|
|
8
7
|
- Gerald Bauer
|
|
9
8
|
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 2015-02-04 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
|
-
name:
|
|
16
|
-
requirement:
|
|
17
|
-
none: false
|
|
14
|
+
name: textutils
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
18
16
|
requirements:
|
|
19
|
-
- -
|
|
17
|
+
- - ">="
|
|
20
18
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '0
|
|
19
|
+
version: '0'
|
|
22
20
|
type: :runtime
|
|
23
21
|
prerelease: false
|
|
24
|
-
version_requirements:
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activerecord
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: activerecord-utils
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.4.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.4.0
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: sinatra
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
25
69
|
- !ruby/object:Gem::Dependency
|
|
26
70
|
name: rdoc
|
|
27
|
-
requirement:
|
|
28
|
-
none: false
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
72
|
requirements:
|
|
30
|
-
- - ~>
|
|
73
|
+
- - "~>"
|
|
31
74
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '
|
|
75
|
+
version: '4.0'
|
|
33
76
|
type: :development
|
|
34
77
|
prerelease: false
|
|
35
|
-
version_requirements:
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '4.0'
|
|
36
83
|
- !ruby/object:Gem::Dependency
|
|
37
84
|
name: hoe
|
|
38
|
-
requirement:
|
|
39
|
-
none: false
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
40
86
|
requirements:
|
|
41
|
-
- - ~>
|
|
87
|
+
- - "~>"
|
|
42
88
|
- !ruby/object:Gem::Version
|
|
43
|
-
version: '3.
|
|
89
|
+
version: '3.13'
|
|
44
90
|
type: :development
|
|
45
91
|
prerelease: false
|
|
46
|
-
version_requirements:
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '3.13'
|
|
47
97
|
description: dbbrowser - database browser (connections, schema, tables, records, etc.)
|
|
48
98
|
as mountable web app
|
|
49
99
|
email: webslideshow@googlegroups.com
|
|
50
100
|
executables: []
|
|
51
101
|
extensions: []
|
|
52
102
|
extra_rdoc_files:
|
|
103
|
+
- History.md
|
|
53
104
|
- Manifest.txt
|
|
105
|
+
- README.md
|
|
54
106
|
files:
|
|
55
107
|
- History.md
|
|
56
108
|
- Manifest.txt
|
|
57
109
|
- README.md
|
|
58
110
|
- Rakefile
|
|
59
111
|
- lib/dbbrowser.rb
|
|
60
|
-
- lib/dbbrowser/connection.rb
|
|
61
112
|
- lib/dbbrowser/public/jquery-2.0.3.min.js
|
|
62
113
|
- lib/dbbrowser/public/jquery.tabs.js
|
|
63
114
|
- lib/dbbrowser/public/style.css
|
|
@@ -76,29 +127,28 @@ files:
|
|
|
76
127
|
homepage: https://github.com/rubylibs/dbbrowser
|
|
77
128
|
licenses:
|
|
78
129
|
- Public Domain
|
|
130
|
+
metadata: {}
|
|
79
131
|
post_install_message:
|
|
80
132
|
rdoc_options:
|
|
81
|
-
- --main
|
|
133
|
+
- "--main"
|
|
82
134
|
- README.md
|
|
83
135
|
require_paths:
|
|
84
136
|
- lib
|
|
85
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
|
-
none: false
|
|
87
138
|
requirements:
|
|
88
|
-
- -
|
|
139
|
+
- - ">="
|
|
89
140
|
- !ruby/object:Gem::Version
|
|
90
141
|
version: 1.9.2
|
|
91
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
|
-
none: false
|
|
93
143
|
requirements:
|
|
94
|
-
- -
|
|
144
|
+
- - ">="
|
|
95
145
|
- !ruby/object:Gem::Version
|
|
96
146
|
version: '0'
|
|
97
147
|
requirements: []
|
|
98
|
-
rubyforge_project:
|
|
99
|
-
rubygems_version:
|
|
148
|
+
rubyforge_project:
|
|
149
|
+
rubygems_version: 2.4.2
|
|
100
150
|
signing_key:
|
|
101
|
-
specification_version:
|
|
151
|
+
specification_version: 4
|
|
102
152
|
summary: dbbrowser - database browser (connections, schema, tables, records, etc.)
|
|
103
153
|
as mountable web app
|
|
104
154
|
test_files: []
|
data/lib/dbbrowser/connection.rb
DELETED
|
@@ -1,275 +0,0 @@
|
|
|
1
|
-
module DbBrowser
|
|
2
|
-
|
|
3
|
-
class ConnectionMan # connection manager
|
|
4
|
-
|
|
5
|
-
# get connection names
|
|
6
|
-
# def connection_names
|
|
7
|
-
# ActiveRecord::Base.configurations.keys
|
|
8
|
-
# end
|
|
9
|
-
|
|
10
|
-
CONNECTS = {} # cache connections
|
|
11
|
-
|
|
12
|
-
def connection_for( key )
|
|
13
|
-
# cache connections - needed? why? why not??
|
|
14
|
-
|
|
15
|
-
# hack: for now only use cached connection if still active
|
|
16
|
-
# if not; get a new one to avoid connection closed errors in rails
|
|
17
|
-
con = CONNECTS[ key ]
|
|
18
|
-
if con
|
|
19
|
-
puts "[ConnectionMan] cached connection found; con.active? #{con.active?}"
|
|
20
|
-
unless con.active?
|
|
21
|
-
puts "[ConnectionMan] *** reset cached connection (reason: connection stale/closed/not active)"
|
|
22
|
-
con = CONNECTS[ key ] = nil
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
if con.nil?
|
|
27
|
-
con = CONNECTS[ key ] = AbstractModel.connection_for( key )
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# note: make sure connection is active?
|
|
31
|
-
# use verify! - will try active? followed by reconnect!
|
|
32
|
-
# - todo: check ourselves if active? - why? why not??
|
|
33
|
-
# -- not working w/ rails - after verify! still getting error w/ closed connection
|
|
34
|
-
# -- con.verify!
|
|
35
|
-
|
|
36
|
-
# wrap ActiveRecord connection in our own connection class
|
|
37
|
-
Connection.new( con, key )
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
class AbstractModel < ActiveRecord::Base
|
|
42
|
-
self.abstract_class = true # no table; class just used for getting db connection
|
|
43
|
-
|
|
44
|
-
def self.connection_for( key )
|
|
45
|
-
establish_connection( key )
|
|
46
|
-
connection
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
end # class AbstractModel
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
class Connection
|
|
53
|
-
|
|
54
|
-
def initialize( connection, key )
|
|
55
|
-
@connection = connection
|
|
56
|
-
@key = key
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
attr_reader :connection
|
|
60
|
-
attr_reader :key
|
|
61
|
-
|
|
62
|
-
delegate :select_value, :select_all, :adapter_name,
|
|
63
|
-
:to => :connection
|
|
64
|
-
|
|
65
|
-
def class_name
|
|
66
|
-
@connection.class.name
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# delegate :quote_table_name, :quote_column_name, :quote,
|
|
70
|
-
# :update, :insert, :delete,
|
|
71
|
-
# :add_limit_offset!,
|
|
72
|
-
# :to => :connection
|
|
73
|
-
|
|
74
|
-
def tables
|
|
75
|
-
@tables ||= fetch_table_defs
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def table( name )
|
|
79
|
-
tables.find { |t| t.name.downcase == name.downcase }
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# getting list of column definitions
|
|
83
|
-
# and order them to be more human readable
|
|
84
|
-
def table_columns( name )
|
|
85
|
-
cols = fetch_table_column_defs( name )
|
|
86
|
-
### fix/to be done
|
|
87
|
-
# cols.sort_by{|col|
|
|
88
|
-
# [
|
|
89
|
-
# fields_to_head.index(col.name) || 1e6,
|
|
90
|
-
# -(fields_to_tail.index(col.name) || 1e6),
|
|
91
|
-
# col.name
|
|
92
|
-
# ]
|
|
93
|
-
# }
|
|
94
|
-
cols
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def fetch_table_defs
|
|
98
|
-
@connection.tables.sort.map do |name|
|
|
99
|
-
Table.new( self, name )
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def fetch_table_column_defs( name )
|
|
104
|
-
### fix/todo: add reference to table_def
|
|
105
|
-
@connection.columns( name ).map do |col|
|
|
106
|
-
Column.new( col.name, col.sql_type, col.default, col.null )
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def fetch_table_select_all( name, opts={} )
|
|
112
|
-
limit = (opts[:limit] || 33).to_i # 33 records limit/per page (for now default)
|
|
113
|
-
limit = 33 if limit == 0 # use default page size if limit 0 (from not a number para)
|
|
114
|
-
|
|
115
|
-
offset = (opts[:offset] || 0).to_i
|
|
116
|
-
|
|
117
|
-
sql = "select * from #{name} limit #{limit}"
|
|
118
|
-
|
|
119
|
-
sql << " offset #{offset}" if offset > 0 # add offset if present (e.g greater zero)
|
|
120
|
-
|
|
121
|
-
# page = (opts[:page] || 1 ).try(:to_i)
|
|
122
|
-
# fields = opts[:fields] || nil
|
|
123
|
-
|
|
124
|
-
# rez = { :fields => fields }
|
|
125
|
-
# if sql =~ /\s*select/i && per_page > 0
|
|
126
|
-
# rez[:count] = select_value("select count(*) from (#{sql}) as t").to_i
|
|
127
|
-
# rez[:pages] = (rez[:count].to_f / per_page).ceil
|
|
128
|
-
# sql = "select * from (#{sql}) as t"
|
|
129
|
-
# add_limit_offset!( sql,
|
|
130
|
-
# :limit => per_page,
|
|
131
|
-
# :offset => per_page * (page - 1))
|
|
132
|
-
# end
|
|
133
|
-
|
|
134
|
-
result = {}
|
|
135
|
-
result[ :sql ] = sql # note: lets also always add sql query to result too
|
|
136
|
-
result[ :rows ] = select_all( sql )
|
|
137
|
-
|
|
138
|
-
# unless rez[:rows].blank?
|
|
139
|
-
# rez[:fields] ||= []
|
|
140
|
-
# rez[:fields].concat( self.sort_fields(rez[:rows].first.keys) - rez[:fields] )
|
|
141
|
-
# end
|
|
142
|
-
|
|
143
|
-
Result.new( result )
|
|
144
|
-
rescue StandardError => ex
|
|
145
|
-
Result.new( error: ex )
|
|
146
|
-
end # fetch_table
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
=begin
|
|
150
|
-
def column_names(table)
|
|
151
|
-
columns(table).map{|c| c.name}
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
# fields to see first
|
|
155
|
-
def fields_to_head
|
|
156
|
-
@fields_to_head ||= %w{id name login value}
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
# fields to see last
|
|
160
|
-
def fields_to_tail
|
|
161
|
-
@fields_to_tail ||= %w{created_at created_on updated_at updated_on}
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
attr_writer :fields_to_head, :fields_to_tail
|
|
165
|
-
|
|
166
|
-
# sort field names in a rezult
|
|
167
|
-
def sort_fields(fields)
|
|
168
|
-
fields = (fields_to_head & fields) | (fields - fields_to_head)
|
|
169
|
-
fields = (fields - fields_to_tail) | (fields_to_tail & fields)
|
|
170
|
-
fields
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
# performs query with appropriate method
|
|
174
|
-
def query(sql, opts={})
|
|
175
|
-
per_page = (opts[:perpage] || nil).to_i
|
|
176
|
-
page = (opts[:page] || 1 ).try(:to_i)
|
|
177
|
-
fields = opts[:fields] || nil
|
|
178
|
-
case sql
|
|
179
|
-
when /\s*select/i , /\s*(update|insert|delete).+returning/im
|
|
180
|
-
rez = {:fields => fields}
|
|
181
|
-
if sql =~ /\s*select/i && per_page > 0
|
|
182
|
-
rez[:count] = select_value("select count(*) from (#{sql}) as t").to_i
|
|
183
|
-
rez[:pages] = (rez[:count].to_f / per_page).ceil
|
|
184
|
-
sql = "select * from (#{sql}) as t"
|
|
185
|
-
add_limit_offset!( sql,
|
|
186
|
-
:limit => per_page,
|
|
187
|
-
:offset => per_page * (page - 1))
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
rez[:rows] = select_all( sql )
|
|
191
|
-
|
|
192
|
-
unless rez[:rows].blank?
|
|
193
|
-
rez[:fields] ||= []
|
|
194
|
-
rez[:fields].concat( self.sort_fields(rez[:rows].first.keys) - rez[:fields] )
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
Result.new(rez)
|
|
198
|
-
when /\s*update/i
|
|
199
|
-
Result.new :value => update( sql )
|
|
200
|
-
when /\s*insert/i
|
|
201
|
-
Result.new :value => insert( sql )
|
|
202
|
-
when /\s*delete/i
|
|
203
|
-
Result.new :value => delete( sql )
|
|
204
|
-
end
|
|
205
|
-
rescue StandardError => e
|
|
206
|
-
Result.new :error => e
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
=end
|
|
210
|
-
|
|
211
|
-
end # class Connection
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
class Table
|
|
215
|
-
|
|
216
|
-
def initialize(connection, name)
|
|
217
|
-
@connection = connection
|
|
218
|
-
@name = name
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
attr_reader :connection
|
|
222
|
-
attr_reader :name
|
|
223
|
-
|
|
224
|
-
def count
|
|
225
|
-
@connection.select_value( "select count(*) from #{name}").to_i
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
def columns
|
|
229
|
-
# load columns on demand for now (cache on first lookup)
|
|
230
|
-
@columns ||= @connection.table_columns( @name )
|
|
231
|
-
end
|
|
232
|
-
|
|
233
|
-
def query( opts={})
|
|
234
|
-
@connection.fetch_table_select_all( @name, opts )
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
end # class Table
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
class Column
|
|
241
|
-
def initialize(name, type, default, null)
|
|
242
|
-
@name = name
|
|
243
|
-
@type = type # note: is sql_type
|
|
244
|
-
@default = default
|
|
245
|
-
@null = null # note: true|false depending if NOT NULL or not
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
attr_reader :name, :type, :default, :null
|
|
249
|
-
end # class Column
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
class Result
|
|
253
|
-
def initialize( opts={} )
|
|
254
|
-
@sql = opts[:sql] # sql statement as a string
|
|
255
|
-
|
|
256
|
-
if opts[:error]
|
|
257
|
-
@error = opts[:error]
|
|
258
|
-
else
|
|
259
|
-
@rows = opts[:rows]
|
|
260
|
-
# @count = opts[:count] || @rows.size
|
|
261
|
-
# @pages = opts[:pages] || 1
|
|
262
|
-
# @fields = opts[:fields]
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
attr_reader :sql, :rows, :error ### to be done :count, :pages, :fields,
|
|
267
|
-
|
|
268
|
-
def error?() @error.present?; end
|
|
269
|
-
def rows?() @rows != nil; end
|
|
270
|
-
end # class Result
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
end # class ConnectionMan
|
|
274
|
-
|
|
275
|
-
end # module DbBrowser
|