summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2014-07-20 11:31:53 +0300
committerytti <saku@ytti.fi>2014-07-20 11:31:53 +0300
commit2245a452788337338e67319fad6da1931c6c5be1 (patch)
treebad7bba600e301d60d59115f2380403a65228bb0
parentcee5eaf2d57f9e9c591a2d506a35d0e338264e56 (diff)
parentc3b006a449bcf3f6d9afb4de31499c865748748a (diff)
Merge pull request #25 from lysiszegerman/master
Generic SQL support for source
-rw-r--r--lib/oxidized/source/sql.rb28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/oxidized/source/sql.rb b/lib/oxidized/source/sql.rb
index c744e31..c65d335 100644
--- a/lib/oxidized/source/sql.rb
+++ b/lib/oxidized/source/sql.rb
@@ -23,18 +23,28 @@ class SQL < Source
end
end
+ def connect
+ #begin
+ #require @cfg.adapter
+ #rescue LoadError
+ #raise OxidizedError, "@{cfg.adapter} not found: install gem"
+ #end
+ Sequel.connect(:adapter => @cfg.adapter,
+ :host => @cfg.host,
+ :user => @cfg.user,
+ :password => @cfg.password,
+ :database => @cfg.database)
+ end
+
def load
nodes = []
- db = case @cfg.adapter
- when 'sqlite'
- begin
- require 'sqlite3'
- rescue LoadError
- raise OxidizedError, 'sqlite3 not found: sudo apt install libsqlite3-dev; sudo gem install sqlite3'
- end
- Sequel.sqlite @cfg.file
+ db = connect
+ if @cfg.query?
+ query = db[@cfg.table.to_sym].with_sql(@cfg.query)
+ else
+ query = db[@cfg.table.to_sym]
end
- db[@cfg.table.to_sym].each do |node|
+ query.each do |node|
# map node parameters
keys = {}
@cfg.map.each { |key, sql_column| keys[key.to_sym] = node[sql_column.to_sym] }