Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Canonical Sinatra app: create/drop table, function, procedure, sequence

(Also fix the way data_table is created.)

Change-Id: Iee8e0955b2c7d40251870773414160778ef8e52e
  • Loading branch information...
commit 11068f5bef71f7eddf4fe12f45b7b3fb8fa704f3 1 parent 2b809af
figo authored

Showing 1 changed file with 60 additions and 1 deletion. Show diff stats Hide diff stats

  1. +60 1 sinatra/app_sinatra_service/main.rb
61 sinatra/app_sinatra_service/main.rb
@@ -71,6 +71,34 @@
71 71 value
72 72 end
73 73
  74 +put '/service/mysql/table/:table' do
  75 + client = load_mysql
  76 + client.query("create table #{params[:table]} (x int);")
  77 + client.close
  78 + params[:table]
  79 +end
  80 +
  81 +delete '/service/mysql/:object/:name' do
  82 + client = load_mysql
  83 + client.query("drop #{params[:object]} #{params[:name]};")
  84 + client.close
  85 + params[:name]
  86 +end
  87 +
  88 +put '/service/mysql/function/:function' do
  89 + client = load_mysql
  90 + client.query("create function #{params[:function]}() returns int return 1234;");
  91 + client.close
  92 + params[:function]
  93 +end
  94 +
  95 +put '/service/mysql/procedure/:procedure' do
  96 + client = load_mysql
  97 + client.query("create procedure #{params[:procedure]}() begin end;");
  98 + client.close
  99 + params[:procedure]
  100 +end
  101 +
74 102 post '/service/postgresql/:key' do
75 103 client = load_postgresql
76 104 value = request.env["rack.input"].read
@@ -86,6 +114,37 @@
86 114 value
87 115 end
88 116
  117 +put '/service/postgresql/table/:table' do
  118 + client = load_postgresql
  119 + client.query("create table #{params[:table]} (x int);")
  120 + client.close
  121 + params[:table]
  122 +end
  123 +
  124 +delete '/service/postgresql/:object/:name' do
  125 + client = load_postgresql
  126 + object = params[:object]
  127 + name = params[:name]
  128 + name += "()" if object=="function" # PG 'drop function' docs: "The argument types to the function must be specified"
  129 + client.query("drop #{object} #{name};")
  130 + client.close
  131 + name
  132 +end
  133 +
  134 +put '/service/postgresql/function/:function' do
  135 + client = load_postgresql
  136 + client.query("create function #{params[:function]}() returns integer as 'select 1234;' language sql;")
  137 + client.close
  138 + params[:function]
  139 +end
  140 +
  141 +put '/service/postgresql/sequence/:sequence' do
  142 + client = load_postgresql
  143 + client.query("create sequence #{params[:sequence]};")
  144 + client.close
  145 + params[:sequence]
  146 +end
  147 +
89 148 post '/service/rabbit/:key' do
90 149 value = request.env["rack.input"].read
91 150 client = rabbit_service
@@ -133,7 +192,7 @@ def load_mongo
133 192 def load_postgresql
134 193 postgresql_service = load_service('postgresql')
135 194 client = PGconn.open(postgresql_service['host'], postgresql_service['port'], :dbname => postgresql_service['name'], :user => postgresql_service['username'], :password => postgresql_service['password'])
136   - client.query("create table data_values (id varchar(20), data_value varchar(20));") if client.query("select * from information_schema.tables where table_name = 'data_values';").first.nil?
  195 + client.query("create table data_values (id varchar(20), data_value varchar(20));") if client.query("select * from pg_catalog.pg_class where relname = 'data_values';").num_tuples() < 1
137 196 client
138 197 end
139 198

Git Notes

review

Code-Review+2: Nicholas Kushmerick <nicholask@vmware.com>
Verified+1: Figo Feng <ffeng@vmware.com>
Verified+1: cftestbuild <cftestbuild@gmail.com>
Submitted-by: Figo Feng <ffeng@vmware.com>
Submitted-at: Tue, 07 Feb 2012 01:23:22 +0000
Reviewed-on: http://cloudfoundry-codereview.qa.mozycloud.com/gerrit/3223
Project: vcap-test-assets
Branch: refs/heads/services-r8

0 comments on commit 11068f5

Please sign in to comment.
Something went wrong with that request. Please try again.