postgresql-web 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +37 -0
  8. data/Rakefile +2 -0
  9. data/lib/postgresql-web.rb +10 -0
  10. data/lib/postgresql_web/app.rb +46 -0
  11. data/lib/postgresql_web/app_helpers.rb +15 -0
  12. data/lib/postgresql_web/column.rb +14 -0
  13. data/lib/postgresql_web/configuration.rb +5 -0
  14. data/lib/postgresql_web/connection.rb +61 -0
  15. data/lib/postgresql_web/paginator.rb +36 -0
  16. data/myapp/.gitignore +16 -0
  17. data/myapp/Gemfile +44 -0
  18. data/myapp/README.rdoc +28 -0
  19. data/myapp/Rakefile +6 -0
  20. data/myapp/app/assets/javascripts/application.js +16 -0
  21. data/myapp/app/assets/stylesheets/application.css +15 -0
  22. data/myapp/app/controllers/application_controller.rb +5 -0
  23. data/myapp/app/helpers/application_helper.rb +2 -0
  24. data/myapp/app/views/layouts/application.html.erb +14 -0
  25. data/myapp/bin/bundle +3 -0
  26. data/myapp/bin/rails +4 -0
  27. data/myapp/bin/rake +4 -0
  28. data/myapp/config.ru +4 -0
  29. data/myapp/config/application.rb +22 -0
  30. data/myapp/config/boot.rb +4 -0
  31. data/myapp/config/database.yml +25 -0
  32. data/myapp/config/environment.rb +5 -0
  33. data/myapp/config/environments/development.rb +37 -0
  34. data/myapp/config/environments/production.rb +78 -0
  35. data/myapp/config/environments/test.rb +39 -0
  36. data/myapp/config/initializers/assets.rb +8 -0
  37. data/myapp/config/initializers/backtrace_silencers.rb +7 -0
  38. data/myapp/config/initializers/cookies_serializer.rb +3 -0
  39. data/myapp/config/initializers/filter_parameter_logging.rb +4 -0
  40. data/myapp/config/initializers/inflections.rb +16 -0
  41. data/myapp/config/initializers/mime_types.rb +4 -0
  42. data/myapp/config/initializers/session_store.rb +3 -0
  43. data/myapp/config/initializers/wrap_parameters.rb +14 -0
  44. data/myapp/config/locales/en.yml +23 -0
  45. data/myapp/config/routes.rb +3 -0
  46. data/myapp/config/secrets.yml +22 -0
  47. data/myapp/db/seeds.rb +7 -0
  48. data/myapp/public/404.html +67 -0
  49. data/myapp/public/422.html +67 -0
  50. data/myapp/public/500.html +66 -0
  51. data/myapp/public/favicon.ico +0 -0
  52. data/myapp/public/robots.txt +5 -0
  53. data/myapp/test/test_helper.rb +10 -0
  54. data/postgresql-web.gemspec +31 -0
  55. data/web/assets/css/application.css +50 -0
  56. data/web/assets/css/bootflat.css +62 -0
  57. data/web/assets/css/bootflat.css.map +7 -0
  58. data/web/assets/css/bootflat.min.css +18 -0
  59. data/web/assets/css/bootstrap.min.css +5 -0
  60. data/web/assets/img/check_flat/default.png +0 -0
  61. data/web/assets/img/check_flat/default.psd +0 -0
  62. data/web/assets/js/ace/src-min-noconflict/ace.js +11 -0
  63. data/web/assets/js/ace/src-min-noconflict/mode-sql.js +1 -0
  64. data/web/assets/js/ace/src-min-noconflict/theme-clouds.js +1 -0
  65. data/web/assets/js/application.js +62 -0
  66. data/web/assets/js/bootstrap.min.js +6 -0
  67. data/web/assets/js/icheck.min.js +11 -0
  68. data/web/assets/js/jquery-1.11.1.min.js +4 -0
  69. data/web/assets/js/jquery.fs.selecter.min.js +9 -0
  70. data/web/assets/js/jquery.fs.stepper.min.js +9 -0
  71. data/web/assets/scss/.csscomb.json +297 -0
  72. data/web/assets/scss/.csslintrc +15 -0
  73. data/web/assets/scss/bootflat.scss +40 -0
  74. data/web/views/_paging.slim +20 -0
  75. data/web/views/dashboard.slim +28 -0
  76. data/web/views/data.slim +15 -0
  77. data/web/views/layout.slim +22 -0
  78. data/web/views/query.slim +13 -0
  79. data/web/views/schema.slim +16 -0
  80. metadata +234 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 42b295b7ac6482c9746db1985c5003a228db633b
4
+ data.tar.gz: 0740588ad025847ef21f826b154acb2941408d81
5
+ SHA512:
6
+ metadata.gz: a8984a053dcb0721649649b5f929b418d2240218af9efdda0c2ef9999c7ea09d510015d5e6ec0a4a8d97e549f7630420a4d9cf1c1cfe91f345b3f92b0fb9966a
7
+ data.tar.gz: d8dfef011790423c32acf73d3e72e9d1f056b051ddb966e1708477fe5461701c06148e4561ccebd36836388dbcbad1b40249171aa7a45a04315fe7f8de11d077
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .DS_Store
24
+ .keep
25
+ .sass-cache
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ postgresql-web
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in postgresql-web.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Allen Wei
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,37 @@
1
+ # Postgresql::Web
2
+
3
+ This application is not finished yet, please do not use it in production
4
+
5
+ A web interface of postgresql which you can mount onto your rails application
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'postgresql-web'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install postgresql-web
20
+
21
+ ## Usage
22
+
23
+ Mount Postgresql Web application by put following code into `routes.rb`
24
+
25
+ mount PostgresqlWeb::App => "/postgresql-web"
26
+
27
+
28
+ Then vist the appliction at `http://localhost:3000/postgresql-web`
29
+
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( https://github.com/allenwei/postgresql-web/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,10 @@
1
+ module PostgresqlWeb
2
+ VERSION = "0.0.1"
3
+ autoload :Column, 'postgresql_web/column'
4
+ autoload :Paginator, 'postgresql_web/paginator'
5
+ end
6
+
7
+ require 'postgresql_web/configuration'
8
+ require 'postgresql_web/connection'
9
+ require 'postgresql_web/app_helpers'
10
+ require 'postgresql_web/app'
@@ -0,0 +1,46 @@
1
+ require 'sinatra'
2
+ require 'slim'
3
+
4
+ module PostgresqlWeb
5
+
6
+ class App < Sinatra::Base
7
+
8
+ set :root, File.expand_path(File.dirname(__FILE__) + "/../../web")
9
+ set :public_folder, Proc.new { "#{root}/assets" }
10
+ set :views, Proc.new { "#{root}/views" }
11
+
12
+ helpers AppHelpers
13
+
14
+ get "/" do
15
+ @tables = Connection.tables
16
+ slim :dashboard
17
+ end
18
+
19
+ get "/columns" do
20
+ @columns = Connection.columns(params[:table_name])
21
+ slim :schema, layout: false
22
+ end
23
+
24
+ get "/data" do
25
+ @columns = Connection.columns(params[:table_name])
26
+
27
+ page = params[:page].nil? ? 1 : params[:page].to_i
28
+ per_page = 1000
29
+
30
+ data, total_records = Connection.data(params[:table_name], per_page, page)
31
+
32
+ @paginator = Paginator.new(data, page, per_page, total_records)
33
+ slim :data, layout: false
34
+ end
35
+
36
+ post "/query" do
37
+ begin
38
+ @result = Connection.connection.exec(params[:query])
39
+ slim :query, layout: false
40
+ rescue PG::Error => e
41
+ halt 500, e.message
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,15 @@
1
+ module PostgresqlWeb
2
+ module AppHelpers
3
+ def root_path
4
+ "#{env['SCRIPT_NAME']}/"
5
+ end
6
+
7
+ def url_with_params(uri, params={})
8
+ result = URI.parse(uri)
9
+ new_query_ar = result.query ? URI.decode_www_form(result.query) : []
10
+ new_query_ar += params.to_a
11
+ result.query = URI.encode_www_form(new_query_ar)
12
+ result.to_s
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'hashie'
2
+ module PostgresqlWeb
3
+ class Column < Hashie::Dash
4
+ include Hashie::Extensions::IgnoreUndeclared
5
+ include Hashie::Extensions::IndifferentAccess
6
+
7
+ property :table_name
8
+ property :column_name
9
+ property :ordinal_position
10
+ property :is_nullable
11
+ property :data_type
12
+ property :column_default
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module PostgresqlWeb
2
+ class Configuration
3
+
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ require 'pg'
2
+ require 'connection_pool'
3
+
4
+ module PostgresqlWeb
5
+ module Connection
6
+ extend self
7
+ attr_accessor :dbname, :pool_size, :timeout
8
+
9
+ def connection
10
+ if @connection.nil?
11
+ initial_default_params
12
+ @connection = ConnectionPool::Wrapper.new(size: pool_size, timeout: pool_size) do
13
+ PG::Connection.new(dbname: dbname)
14
+ end
15
+ end
16
+ @connection
17
+ end
18
+
19
+ def initial_default_params
20
+ self.pool_size = 5;
21
+ self.timeout = 5
22
+ if is_pg_activerecord?
23
+ self.dbname = ActiveRecord::Base.connection.current_database
24
+ end
25
+ end
26
+
27
+ def is_pg_activerecord?
28
+ defined?(Rails) and defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
29
+ end
30
+
31
+
32
+ def tables
33
+ result = connection.exec("select tablename from pg_tables where schemaname = 'public'")
34
+ result.column_values(0).sort
35
+ end
36
+
37
+ def columns(table_name)
38
+ connection.exec("select * from INFORMATION_SCHEMA.COLUMNS where table_name = $1", [table_name]).map do |col|
39
+ Column.new(col)
40
+ end
41
+ end
42
+
43
+ def data(table_name, per_page, page)
44
+ if page <= 1
45
+ page = 1
46
+ end
47
+
48
+ total_records = connection.exec("select count(1) from #{table_name}").column_values(0).first
49
+ sql = "select * from #{table_name}"
50
+ if page > 1
51
+ sql += " offset #{per_page * (page - 1)}"
52
+ end
53
+ sql += " limit #{per_page}"
54
+ puts sql
55
+ data = connection.exec(sql).to_a
56
+ puts
57
+ [data, total_records]
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,36 @@
1
+ module PostgresqlWeb
2
+ class Paginator
3
+ attr_reader :data, :page, :per_page, :total_records
4
+
5
+ def initialize(data, page, per_page, total_records)
6
+ @data = data
7
+ @page = page.to_i
8
+ @per_page = per_page.to_i
9
+ @total_records = total_records.to_i
10
+ end
11
+
12
+ def offset
13
+ if page > 0
14
+ self.per_page * ( page - 1)
15
+ else
16
+ 0
17
+ end
18
+ end
19
+
20
+ def total_pages
21
+ if self.total_records > 0
22
+ (self.total_records.to_f / self.per_page).ceil
23
+ else
24
+ 1
25
+ end
26
+ end
27
+
28
+ def first_page?
29
+ page.to_i <= 1
30
+ end
31
+ def last_page?
32
+ page == total_pages
33
+ end
34
+
35
+ end
36
+ end
data/myapp/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile '~/.gitignore_global'
6
+
7
+ # Ignore bundler config.
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+ /db/*.sqlite3-journal
13
+
14
+ # Ignore all logfiles and tempfiles.
15
+ /log/*.log
16
+ /tmp
data/myapp/Gemfile ADDED
@@ -0,0 +1,44 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
+ gem 'rails', '4.1.6'
6
+ # Use sqlite3 as the database for Active Record
7
+ # gem 'sqlite3'
8
+ # Use SCSS for stylesheets
9
+ gem 'sass-rails', '~> 4.0.3'
10
+ # Use Uglifier as compressor for JavaScript assets
11
+ gem 'uglifier', '>= 1.3.0'
12
+ # Use CoffeeScript for .js.coffee assets and views
13
+ gem 'coffee-rails', '~> 4.0.0'
14
+ # See https://github.com/sstephenson/execjs#readme for more supported runtimes
15
+ # gem 'therubyracer', platforms: :ruby
16
+
17
+ # Use jquery as the JavaScript library
18
+ gem 'jquery-rails'
19
+ # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
20
+ gem 'turbolinks'
21
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
22
+ gem 'jbuilder', '~> 2.0'
23
+ # bundle exec rake doc:rails generates the API under doc/api.
24
+ gem 'sdoc', '~> 0.4.0', group: :doc
25
+
26
+ gem 'pg'
27
+ gem 'sinatra'
28
+ gem 'postgresql-web', path: ".."
29
+
30
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
31
+ gem 'spring', group: :development
32
+
33
+ # Use ActiveModel has_secure_password
34
+ # gem 'bcrypt', '~> 3.1.7'
35
+
36
+ # Use unicorn as the app server
37
+ # gem 'unicorn'
38
+
39
+ # Use Capistrano for deployment
40
+ # gem 'capistrano-rails', group: :development
41
+
42
+ # Use debugger
43
+ # gem 'debugger', group: [:development, :test]
44
+
data/myapp/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
data/myapp/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require turbolinks
16
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */