Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
49 lines (40 sloc) 1.46 KB
require '../lib/chill.rb'
require 'pp'
# make a database or connect to one
ChillDB.goes :KittensApp
# delete everything and start fresh
# add a template (just in ruby instance)
cat: {
color: 'invisible',
softness: 5,
likes: %w{water food flying spaceships sunlight tictacs hugs exploding},
dislikes: %w{mysql}
# add a view
soft_cats: 'function(doc) {
if (doc.kind == "cat" && doc.softness > 1) emit(doc._id, null);
# add kittens
KittensApp.template(:cat).merge(_id: 'fredrick', softness: 16, dislikes: ['silly business']).commit!
KittensApp.template(:cat).merge(_id: 'bobby', softness: 2, dislikes: ['mice']).commit!
KittensApp.template(:cat).merge(_id: 'cheezly', softness: 1, dislikes: ['soy cheese products']).commit!
# use the view to get a list of non-hard cats
puts "Kitten Database lookup - soft cats:"
soft_ones =, include_docs: true) do |cat|
puts "#{cat['_id']} is #{cat['softness']} soft"
# just load fredrick
fredrick = KittensApp['fredrick']
puts "Fredrick's stats:"
fredrick.each do |item, value|
puts "#{item.rjust(10)}- #{value}"
# get the nonsoft cats the slow way - in ruby instead of with a view
nonsofties = ( - { |i| i['kind'] == 'cat' }
puts "Nonsoft cats: #{ { |cat| cat['_id'] }.join(', ')}"