Where developers come to connect, share, build and be inspired.

18

Noir - Proper Models & CouchDB

1639 views

endorse import couch wrapper/handler

 user=> (require '[com.ashafa.clutch :as couch])
 nil

get/create database

user=> (couch/create-database "coderwall")
#cemerick.url.URL{:protocol "http",
 :username nil,
 :password nil,
 :host "localhost",
 :port 5984,
 :path "/coderwall",
 :query nil, 
:anchor nil}

create database model

user=> (defstruct user
#_=> :username
#_=> :password
#_=> :email
#_=> :banned?)
#'user/user

create object for db

  user=> (def new-user (struct user "admin" "changeme" "admin@host.com" false))
#'user/new-user

save object

user=> (couch/put-document "coderwall" new-user)
{:username "admin",
 :password "changeme",
 :email "admin@host.com",
 :banned? false,
 :_rev "1-56bdbdce1d8dfb44e2e108f5319d4248",
 :_id "98e9e777406b81074d4f876d3c000d00"}
user=> 

Comments

Add a comment