Permalink
Browse files

switch to using mongo instead of yaml and sqlite

  • Loading branch information...
Studener, Max
Studener, Max committed Feb 13, 2014
1 parent 4397d83 commit 6f46038cd7d7ba27341c084c35d6fb3fd1547158
Showing 396 changed files with 74,794 additions and 484 deletions.
View
@@ -27,3 +27,5 @@
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
+
+/lib/*.jar
View
@@ -7,9 +7,10 @@ gem 'jdbc-openedge', '10.2B'
gem 'jdbc-sqlite3'
gem 'activerecord-jdbcsqlite3-adapter'
+gem "mongoid", "~> 3.0.0"
+
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
-end
-
+end
View
@@ -55,7 +55,14 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25)
+ mongoid (3.0.23)
+ activemodel (~> 3.1)
+ moped (~> 1.2)
+ origin (~> 1.0)
+ tzinfo (~> 0.3.22)
+ moped (1.5.2)
multi_json (1.8.0)
+ origin (1.1.0)
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
@@ -112,6 +119,7 @@ DEPENDENCIES
coffee-rails (~> 3.2.1)
jdbc-openedge (= 10.2B)
jdbc-sqlite3
+ mongoid (~> 3.0.0)
rails (= 3.2.13)
sass-rails (~> 3.2.3)
sequel
View
@@ -1,5 +1,19 @@
# DataPet
+Requires jruby
+
+##To active databases
+###Progress 10.2B
+place openedge.jar and pool.jar into Rail.root lib
+
+###Sql Server
+place jtds.jar in Rails.root lib
+
+Create Secret token file
+```
+DataPet::Application.config.secret_token = "secret"
+```
+
Configurable database tool to allow quick naviagation between configured relations thru pop-up menus.
## todo
@@ -1,18 +1,6 @@
class ApplicationController < ActionController::Base
protect_from_forgery
- def main
-
- end
-
- def testing
-
- end
-
- def scrolling_tables
-
- end
-
def set_connection
@connection = Connection.get(params[:connection_name])
end
@@ -24,21 +12,4 @@ def set_table
@full_table_name = schema_name.present? ? "#{schema_name}.#{table_name}" : table_name
end
- def snake_params(thing_to_snake)
- return thing_to_snake unless thing_to_snake.is_a?(Hash)
-
- snake = {}
- thing_to_snake.each do |k, v|
- snake_key = k.underscore.to_sym
- if v.is_a?(Hash)
- snake[snake_key] = snake_params(v)
- elsif v.is_a?(Array)
- snake[snake_key] = v.map{ |value| snake_params(value) }
- else
- snake[snake_key] = v
- end
- end
- snake
- end
-
end
@@ -1,7 +1,26 @@
class ConnectionsController < ApplicationController
def index
- render json: Connection.all.map{ |connection_name| { name: connection_name } }
+ respond_to do |format|
+ format.html
+ format.json { render json: ConnectionAttributes.all }
+ end
+ end
+
+ def new
+ end
+
+ def show
+ @connection = ConnectionAttributes.where(id: params[:id]).first
+ respond_to do |format|
+ format.html
+ format.json { render json: @connection }
+ end
+ end
+
+ def create
+ con = ConnectionAttributes.create!(params["connection"])
+ render json: con
end
def tables
@@ -1,35 +1,27 @@
class RelationsController < ApplicationController
def index
- # basic filter from query string
- @relations = params.reject{|k,_| k=='action' || k=='controller' }.inject(Relation.all){|json, p| json.select{|j| j[p[0]].to_s.match(/#{p[1]}/i) } }
+ respond_to do |format|
+ format.html
+ format.json { render json: Relation.all }
+ end
end
def new
- @relation = Relation.new
+ end
+
+ def show
+ @relation = Relation.where(id: params[:id]).first
+ respond_to do |format|
+ format.html
+ format.json { render json: @relation }
+ end
end
def create
# convert camelCased params to snake_case
- relation = snake_params(params[:relation])
- # the entire through relation object is passed back, we only want the id
- through_relation = relation.delete(:through_relation)
- relation[:through_relation_id] = through_relation[:id] if through_relation.present?
- # get the where_clauses for this relation, ignoring the autogenerated stub
- where_clauses = relation.delete(:where_clauses)
- # get the join_clauses for this relation, ignoring the autogenerated stub
- join_clauses = relation.delete(:join_clauses)
- begin
- relation = Relation.create!(relation)
- relation.create_where_clauses(where_clauses)
- relation.create_join_clauses(join_clauses)
- message = 'Relation Saved!'
- message_class = 'success'
- rescue Exception => e
- message = e.message
- message_class = 'danger'
- end
- render json: { message: message, message_class: message_class }
+ relation = Relation.create!(params["relation"])
+ render json: relation
end
def destroy
@@ -18,7 +18,9 @@ def query
end
result_set = @connection.execute_query(@connection.create_query(@full_table_name, sql, limit))
- relations = Relation.where(connection_name: connection_name, table_name: Query.unquote_table(@full_table_name)).all
+
+ relations = Relation.where(from_connection_id: connection_name, from_table_name: Query.unquote_table(@full_table_name)).all
+
if result_set.present?
render json: { columns: result_set.first.keys, rows: result_set.map{ |row| row.values }, relations: relations }
@@ -28,7 +30,7 @@ def query
end
def relations
- render json: Relation.where(connection_name: params[:connection_name], table_name: @full_table_name).all
+ render json: Relation.where(from_connection_id: params[:connection_name], from_table_name: @full_table_name).all
end
end
View
No changes.
View
@@ -1,7 +1,5 @@
class Connection
- DB_DIRECTORY = Rails.root.join('config', 'DataPet')
- CONNECTIONS_DIRECTORY = Rails.root.join('config', 'DataPet', 'connections')
MODIFY_WORDS = %w[ delete update set alter create drop insert truncate index lock ]
def initialize(configuration)
@@ -43,26 +41,13 @@ def is_select_query?(sql)
class << self
- def check_directory_structure
- Dir.mkdir(DB_DIRECTORY) unless Dir.exists?(DB_DIRECTORY)
- Dir.mkdir(CONNECTIONS_DIRECTORY) unless Dir.exists?(CONNECTIONS_DIRECTORY)
+ def get(id)
+ get_connection(get_configuration(id))
end
- def all
- Connection.check_directory_structure
-
- Dir.glob("#{CONNECTIONS_DIRECTORY}/*.yml").inject([]) do |connections, file|
- file_name = file.split('.').first.split('/').last
- connections << file_name
- end
- end
-
- def get(connection_name)
- get_connection(get_configuration(connection_name))
- end
-
- def get_configuration(connection_name)
- YAML::load(ERB.new(IO.read("#{CONNECTIONS_DIRECTORY}/#{connection_name}.yml")).result)[connection_name].symbolize_keys!
+ def get_configuration(id)#todo
+ con = ConnectionAttributes.where(id: id).first
+ con.attributes.except("_id", "name").symbolize_keys!
end
def get_connection(configuration)
@@ -72,24 +57,8 @@ def get_connection(configuration)
when 'progress'
Connection::ProgressConnection.new(configuration)
else
- # use the default connection class
- Connection.new(configuration) # this class is incomplete and will not work !!!
- end
- end
-
- def details(connection_name)
- connection = Connection.get(connection_name)
- tables = connection.tables.map do |full_table_name|
- if full_table_name.match(/\./)
- schema_name, table_name = full_table_name.split('.')
- else
- schema_name = ''
- table_name = full_table_name
- end
-
- { connectionName: connection_name, schemaName: schema_name, tableName: table_name}
+ raise "Database Connection not yet supported!"
end
- { name: connection_name, tables: tables }
end
end
@@ -0,0 +1,6 @@
+class ConnectionAttributes
+ include Mongoid::Document
+
+ has_many :from_relations, class_name: 'Relation', inverse_of: :from_connection
+ has_many :to_relations, class_name: 'Relation', inverse_of: :to_connection
+end
@@ -1,5 +0,0 @@
-class JoinClause < ActiveRecord::Base
- attr_accessible :from_column, :join_column, :relation_id
-
- validates_presence_of :from_column, :join_column, :relation_id
-end
View
@@ -1,25 +1,22 @@
-class Relation < ActiveRecord::Base
- attr_accessible :connection_name, :table_name, :relation_name, :relation_type, :relation_connection_name, :relation_table_name, :through_relation_id
+class Relation
- has_many :join_clauses, dependent: :destroy
- has_many :where_clauses, dependent: :destroy
- has_one :through_relation, class_name: 'Relation', foreign_key: :id, primary_key: :through_relation_id
+ include Mongoid::Document
- validates_presence_of :connection_name, :table_name, :relation_name, :relation_type, :relation_connection_name, :relation_table_name
+ field :relation_name, type: String
+ field :relation_type, type: String
+ field :from_table_name, type: String
+ field :to_table_name, type: String
+ field :where_clauses, type: Hash
+ field :join_clauses, type: Hash #used for has_many_through
- def create_where_clauses(where_clauses)
- return unless where_clauses.present?
- where_clauses.select{ |where_clause| where_clause[:comparison_value].present? }.each do |where_clause|
- WhereClause.create!(where_clause.merge({relation_id: self.id}))
- end
- end
+ has_one :receiver, :class_name => 'Relation', :inverse_of => :through_relation
+ belongs_to :through_relation, :class_name => 'Relation', :inverse_of => :receiver
- def create_join_clauses(join_clauses)
- return unless join_clauses.present?
- join_clauses.select{ |join_clause| join_clause[:from_column].present? }.each do |join_clause|
- JoinClause.create!(join_clause.merge({relation_id: self.id}))
- end
- end
+ belongs_to :from_connection, class_name: 'ConnectionAttributes', inverse_of: :from_relations
+ belongs_to :to_connection, class_name: 'ConnectionAttributes', inverse_of: :to_relations
+
+ # TODO
+ # validates_presence_of :connection_name, :table_name, :relation_name, :relation_type, :relation_connection_name, :relation_table_name
end
@@ -5,9 +5,9 @@ def initialize(connection_name, table_name, relation_name, data_hash)
@data_hash = data_hash
# find the configuration for this relation
- relation = Relation.where(connection_name: connection_name, table_name: table_name, relation_name: relation_name).first
- @connection_name = relation.relation_connection_name
- @relation_table_name = relation.relation_table_name
+ relation = Relation.where(from_connection_id: connection_name, from_table_name: table_name, relation_name: relation_name).first
+ @connection_name = relation.to_connection_id
+ @relation_table_name = relation.to_table_name
@where_clauses = relation.where_clauses
@sql = "SELECT * FROM \"#{Query.quote_table(@relation_table_name)}\" WHERE "
@@ -45,8 +45,8 @@ def add_join_clauses
end
def create_join_clause(join)
- join_column = join.join_column
- from_column = join.from_column
+ join_column = join['join_column']
+ from_column = join['from_column']
join_data = @join_data.collect{ |row| row[from_column.downcase.to_sym] }.join("','")
raise 'Cannot join without values.' if join_data.blank?
@@ -55,14 +55,14 @@ def create_join_clause(join)
end
def create_where_clause(where)
- column = where.relation_table_column
- operator = where.comparison_operator
+ column = where['to_table_column']
+ operator = where['comparison_operator']
- case where.comparison_type
+ case where['comparison_type']
when 'Column'
- my_value = @data_hash[where.comparison_value.downcase]
+ my_value = @data_hash[where['comparison_value'].to_s.downcase]
when 'Value'
- my_value = where.comparison_value
+ my_value = where['comparison_value']
else
raise "This type of WHERE clause is not supported."
@@ -112,7 +112,7 @@ def rows
end
def relations
- Relation.where(connection_name: @connection_name, table_name: Query.unquote_table( @relation_table_name)).all
+ Relation.where(from_connection_id: @connection_name, from_table_name: Query.unquote_table( @relation_table_name)).all
end
end
@@ -1,5 +0,0 @@
-class WhereClause < ActiveRecord::Base
- attr_accessible :relation_table_column, :comparison_operator, :comparison_type, :comparison_value, :relation_id
-
- validates_presence_of :relation_table_column, :comparison_operator, :comparison_type, :comparison_value, :relation_id
-end
@@ -14,12 +14,12 @@
<br/>
<ul>
<li ng-repeat='connection in connections'>
- <a href='#' ng-click='toggleDisplay(connection.name)'>{{connection.name}}</a>
+ <a href='#' ng-click='toggleDisplay(connection)'>{{connection.name}}</a>
<div ng-show='connection.display'>
<ul>
<li ng-repeat='table in connection.tables | filter:tableFilter | orderBy:"fullTableName"'>
- <a href='#' ng-click='createConnectionWindow(connection.name, table.fullTableName)'>{{table.fullTableName}}</a>
+ <a href='#' ng-click='createConnectionWindow(connection, table.fullTableName)'>{{table.fullTableName}}</a>
</li>
</ul>
</div>
Oops, something went wrong.

0 comments on commit 6f46038

Please sign in to comment.