Created
January 7, 2010 22:14
-
-
Save masak2009/271634 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mac OS X | |
I když si na Mac OS X můžete též hezky zakompilovat, existuje tu snazší způsob, jak si na něm pohrát s CouchDB – pomocí CouchDBX. Sice se jedná o neoficiální aplikaci, ale instalace je velice pohodlná – stáhněte, dvojklikněte a máte běžící CouchDB. | |
Další možností je využít MacPorts: | |
$ sudo port selfupdate | |
$ sudo port install couchdb | |
$ sudo launchctl load -w /opt/local/Library/LaunchDaemons/org.apache.couchdb.plist | |
Poslední příkaz spustí CouchDB a přidá ji do seznamu démonů spouštěných po startu. | |
Vyzkoušení jestli CouchDB funguje: | |
http://localhost:5984/ | |
Jelikož budeme chtít odesílat i jiné požadavky, než jen GET, bude potřeba nějaký nástroj, ve kterém se to bude moci nastavit. | |
Nastroj pro Firefox: https://addons.mozilla.org/cs/firefox/addon/9780 | |
CouchDB také nabídne hezké Ajaxové administrační rozhraní zvané Futon. Dostanete se k němu ze svého oblíbeného prohlížeče napsáním http://localhost:5984/_utils/ do adresního řádku. | |
zdroj: | |
http://zdrojak.root.cz/clanky/couchdb-tak-trochu-jina-databaze-1-cast/ | |
Ruby on Rails dancing with CouchDB | |
$ gem install json | |
After that, create the Rails application | |
$ rails heroes | |
Than install the ActiveCouch plugin | |
$ cd heroes | |
$ ./script/plugin install git://github.com/arunthampi/activecouch.git | |
Configure the Rails Application | |
Create a file called activecouch.yml in your application's /config directory which looks something like this, depending on your installation and CouchDB server configuration: | |
development: | |
site: http://localhost:5984/ | |
test: | |
site: http://localhost:5984/ | |
production: | |
site: http://localhost:5984/ | |
Creating the Database using ActiveCouch | |
ActiveCouch supplies a list of rake tasks to manage CouchDB databases. | |
You can also create CouchDB databases and documents using the web interface on the server. | |
To view all of ActiveCouch's rake tasks enter: | |
$ rake --tasks | grep CouchDB | |
rake activecouch:create_db # Creates a database in CouchDB | |
rake activecouch:delete_db # Deletes a database from CouchDB | |
rake activecouch:delete_view # Deletes a view in CouchDB | |
rake activecouch:save_view # Saves a view in CouchDB | |
We will create a database named heros for our sample application: | |
POZOR NEUMI REGULERNI MNOZNE CISLO POUZE PRIDAVA "S" NA KONEC! | |
$ rake activecouch:create_db db=heros | |
Creating an ActiveCouch Model | |
The ActiveCouch plugin comes with its own model generator. To use it, simply enter in the command line of your Rails application's root path: | |
$ script/generate activecouch_model hero | |
which will generate a hero.rb file in your app/models directory just like a regular model. The ActiveCouch model will look something like this: | |
class Hero < ActiveCouch::Base | |
site YAML::load(File.open(File.join(Rails.root, | |
'config', 'activecouch.yml')))[Rails.env]['site'] | |
end | |
Now, we will add some fields to that model. Unlike the traditional Rails way of manipulating database structure, we will not use migrations. Instead, specify the fields on the model in a way similar to Ruby's attr_accessor method. | |
class Hero < ActiveCouch::Base | |
site YAML::load(File.open(File.join(Rails.root, | |
'config', 'activecouch.yml')))[Rails.env]['site'] | |
has :hero_name | |
has :real_name | |
has :hands | |
has :super_powers | |
end | |
zdroj: | |
http://zdrojak.root.cz/clanky/couchdb-tak-trochu-jina-databaze-1-cast/ | |
http://wiki.rubyonrails.org/database-support/couchdb | |
http://aimee.mychores.co.uk/2008/09/09/post/325 | |
http://wiki.apache.org/couchdb/Installing_on_FreeBSD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment