Selaa lähdekoodia

Added MongoDB and Elasticsearch to docs

Andrew Kane 8 vuotta sitten
vanhempi
commit
fc43b9868c
3 muutettua tiedostoa jossa 46 lisäystä ja 5 poistoa
  1. 2 2
      CHANGELOG.md
  2. 35 2
      README.md
  3. 9 1
      lib/blazer/data_source.rb

+ 2 - 2
CHANGELOG.md

@@ -1,7 +1,7 @@
 ## 1.6.0 [unreleased]
 
-- Added support for MongoDB
-- Added support for Elasticsearch
+- Added support for MongoDB [beta]
+- Added support for Elasticsearch [beta]
 - Fixed deprecation warning in Rails 5
 
 ## 1.5.1

+ 35 - 2
README.md

@@ -355,15 +355,48 @@ data_sources:
 - Oracle
 - IBM DB2 and Informix
 - SQLite
+- MongoDB [beta]
+- Elasticsearch [beta]
 
 You can also create an adapter for any other data store.
 
+**Note:** In the examples below, we recommend using environment variables for urls.
+
+```yml
+data_sources:
+  my_source:
+    url: <%= ENV["BLAZER_MY_SOURCE_URL"] %>
+```
+
 ### Redshift
 
 Add [activerecord4-redshift-adapter](https://github.com/aamine/activerecord4-redshift-adapter) to your Gemfile and set:
 
-```ruby
-ENV["BLAZER_DATABASE_URL"] = "redshift://user:password@hostname:5439/database"
+```yml
+data_sources:
+  my_source:
+    url: redshift://user:password@hostname:5439/database
+```
+
+### MongoDB
+
+Add [mongo](https://github.com/mongodb/mongo-ruby-driver) to your Gemfile and set:
+
+```yml
+data_sources:
+  my_source:
+    url: mongodb://user:password@hostname:27017/database
+```
+
+### Elasticsearch
+
+Add [elasticsearch](https://github.com/elastic/elasticsearch-ruby) to your Gemfile and set:
+
+```yml
+data_sources:
+  my_source:
+    adapter: elasticsearch
+    url: http://user:password@hostname:9200/
 ```
 
 ## Learn SQL

+ 9 - 1
lib/blazer/data_source.rb

@@ -30,7 +30,7 @@ module Blazer
     end
 
     def adapter
-      settings["adapter"] || "sql"
+      settings["adapter"] || detect_adapter
     end
 
     def name
@@ -176,5 +176,13 @@ module Blazer
 
       Blazer::Result.new(self, columns, rows, error, nil, cache && !cache_data.nil?)
     end
+
+    def detect_adapter
+      if settings["url"].to_s.start_with?("mongodb://")
+        "mongodb"
+      else
+        "sql"
+      end
+    end
   end
 end