Ruby: Delete CouchDB data

couch_delete.rb


#! /usr/bin/ruby
# -*- encoding: utf-8 -*-
#
#	couch_delete.rb
#
#					Jul/31/2020
#
# ---------------------------------------------------------------------
require 'faraday'
require 'json'
#
# ---------------------------------------------------------------------
STDERR.puts	"***start***"
#
key_in = ARGV[0]
puts key_in

URL="http://localhost:5984/nagano/" + key_in
#
res = Faraday.get URL

puts	res.status

if res.status == 200 then
	json_str = res.body

	data_aa=JSON.parse(json_str)
#
	puts data_aa
	puts data_aa["_rev"]
#
	url_del = URL + "?rev=" + data_aa["_rev"]

	res = Faraday.delete url_del

	puts res.status
end

STDERR.puts	"***End***"
# ---------------------------------------------------------------------

Run

./couch_delete.rb t2026

Recommended Posts

Ruby: Delete CouchDB data
Ruby: Create CouchDB data (Create)
Ruby: Update CouchDB data (Update)
Ruby: Read CouchDB data (Read)
Rasils data save, update, delete
[Rails] Various ways to delete data
Manipulating data in GCS during Ruby
[Ruby on Rails] Introduction of initial data
How to get date data in Ruby
Ruby on Rails controller create / delete command
How to delete data with foreign key