NAME
DB::CouchDB::Schema - A Schema driven CouchDB module
VERSION
0.3.01
RATIONALE
After working with several of the CouchDB modules already in CPAN I found myself dissatisfied with them. DB::CouchDB::Schema is intended to approach the CouchDB Workflow from the standpoint of the schema. It provides tools for dumping and restoring the views that define your schema and for querying the views in your schema easily.
METHODS
new(%opts)
my $schema = DB::CouchDB::Schema->new(host => $hostname,
port => $db_port, # optional defaults to 5984
db => $databse_name);
Constructor for a CouchDB Schema.
load_schema_from_script($script)
loads a CouchDB Schema from a json script file. This is sort of like the DDL in a SQL DB only its essentially just a list of _design/* documents for the CouchDB
load_schema_from_db()
Loads a CouchDB Schema from the Database on the server. this can later be dumped to a file and pushed to a database using load_schema_from_script.
This method gets called for you during object construction so that you will have a current look at the CouchDB Schema stored in your object.
get_views()
Returns a List of all the views in the database;
dump_db
dumps the entire db to a file for backup
schema
Returns the database schema as an arrayref of _design/ docs serialized to perl objects. You can update you schema by modifying this object if you know what you are doing. Then push the modifications to your database.
dump($pretty)
Returns the database schema as a json string. if $pretty is true then the dump will be pretty printed
push()
Pushes the current schema stored in the object to the database. Used in combination with load_schema_from_script you can restore or create databse schemas from a json defintion file.
push_from_script
get($doc)
create_doc(%sargs)
create a doc on the server. accepts the following arguments
id => 'the name of the document' #optional if you want to let CouchDB name it for you
doc => $object #not optional $object is the document to store in CouchDB
create_new_db(db => 'database name')
create a new database in CouchDB and return a DB::CouchDB::Schema object for it.
It takes the following argument
db => 'database name' # not optional the name of the database to create.
wipe
Wipes the schema from the database. Only deletes the views not data and only deletes views it knows about from either of the load_schema_from_* methods.
ACCESSORS
When DB::CouchDB objects are new'ed up they create accessors for the views defined in the Database. Calling $schema->view_name(\%view_args) will return you the data for the views. See DB::CouchDB view method for more information on the args for a view. The view_name gets translated as follows:
#for view _design/docs/all
my $rs = $schema->docs_all({group => "true"});