Class: Dbtools::Dump
- Inherits:
-
Thor
- Object
- Thor
- Dbtools::Dump
- Defined in:
- lib/tasks/dump.rb
Instance Method Summary collapse
- #blazegraph(url, file) ⇒ Object
- #rdf(sparql_endpoint, filename) ⇒ Object
- #schema(url, path) ⇒ Object
Instance Method Details
#blazegraph(url, file) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/tasks/dump.rb', line 67 def blazegraph(url, file) uri = URI(url) params = { :compress => [:compress], :file => file } uri.query = URI.encode_www_form(params) res = Net::HTTP.get_response(uri) end |
#rdf(sparql_endpoint, filename) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tasks/dump.rb', line 21 def rdf(sparql_endpoint, filename) repo = SPARQL::Client::Repository.new(uri: sparql_endpoint) # Use temp name when compressing if [:compress] target = filename + '_tmp.nt' STDERR.puts %q[Warning: compress option is selected, but filename doesn't end with .gz. You should change the name to end in .gz if you want to open it.] if File.extname(filename) != '.gz' else target = filename end RDF::Writer.open(target, format: :ntriples) do |w| repo.each {|stmt| w << stmt} end # Zlib::GzipWriter can't wrap around RDF::Writer, because RDF::Writer is not a IO-like object... if [:compress] # Compress the file using gz Zlib::GzipWriter.open(filename) do |gz| # Write in chunks. File.open(target) do |fp| while chunk = fp.read(16 * 1024) do gz.write chunk end end gz.close end # Delete the original file after generating the compressed version. File.delete(target) if File.exists?(target) end end |
#schema(url, path) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/tasks/dump.rb', line 78 def schema(url, path) adapter, user, password, host, database = url.match("^([a-zA-Z0-9]+):\/\/(.+):(.+)@(.+)\/(.+)").captures case adapter when "mysql2" dump_mysql_schema(user, password, database, host, path) when "postgres" dump_postgresql_schema(user, password, database, host, path) else puts "Not supported database" end end |