Ruby: Read CouchDB data (Read)

couch_read.rb


#! /usr/bin/ruby
# -*- encoding: utf-8 -*-
#
#	couch_read.rb
#
#					Jul/31/2020
#
# ---------------------------------------------------------------------
require 'faraday'
require 'json'
#
# ---------------------------------------------------------------------
STDERR.puts	"***start***"
#
URL="http://localhost:5984/nagano/_all_docs?include_docs=true"
#
res = Faraday.get URL

# puts	res.status

json_str = res.body

dict_data=JSON.parse(json_str)
#
dict_data['rows'].each {|value|
		doc = value["doc"]
		str_out = doc["_id"] + "\t" + doc['name'] + "\t" \
			+ doc["population"].to_s + "\t" + doc['date_mod']
		print(str_out,"\n")
	}
#
STDERR.puts	"***End***"
# ---------------------------------------------------------------------

Run

./couch_read.rb

Recommended Posts

Ruby: Read CouchDB data (Read)
Ruby: Create CouchDB data (Create)
Ruby: Update CouchDB data (Update)
Ruby: Delete CouchDB data
Read design patterns in Ruby
[Ruby on Rails] Read try (: [],: key)
[Ruby on Rails] Introduction of initial data
How to get date data in Ruby
Read Metaprogramming Ruby (Part I, until Wednesday)