NAME
Couch::DB::Design - handle design documents
INHERITANCE
Couch::DB::Design
is a Couch::DB::Document
SYNOPSIS
my $ddoc = Couch::DB::Design->new(id => 'myname', db => $db);
my $ddoc = $db->design('myname'); # same
my $ddoc = $db->design('_design/myname'); # same
my $ddoc = $db->design; # id generated
my $results = $db->design('d')->search('i', ...) or die;
my $results = $db->search(d => 'i', ...); # same
my $results = $db->search($ddoc => 'i', ...); # same
DESCRIPTION
In CouchDB, design documents provide the main interface for building a CouchDB application. The design document defines the views used to extract information from CouchDB through one or more views.
Design documents behave just like your own documents, but occupy the _design/ namespace in your database. A bunch of the methods are therefore exactly the same as the methods in base-class Couch::DB::Document.
Extends "DESCRIPTION" in Couch::DB::Document.
METHODS
Extends "METHODS" in Couch::DB::Document.
Constructors
Extends "Constructors" in Couch::DB::Document.
- $class->fromResult($result, $data, %options)
-
Inherited, see "Constructors" in Couch::DB::Document
- $class->new(%options)
-
If no id is passed, then one gets generated: a UUID is requested from the server. You may also use a local generator via UUID::URandom or Data::UUID, which is (of course) more efficient.
-Option --Defined in --Default batch Couch::DB::Document from database content Couch::DB::Document undef db Couch::DB::Document undef id Couch::DB::Document generated local Couch::DB::Document false row Couch::DB::Document undef- batch => BOOLEAN
- content => DATA
- db => Couch::DB::Database-object
- id => ID
- local => BOOLEAN
- row => Couch::DB::Row-object
Accessors
Extends "Accessors" in Couch::DB::Document.
- $obj->batch()
-
Inherited, see "Accessors" in Couch::DB::Document
- $obj->couch()
-
Inherited, see "Accessors" in Couch::DB::Document
- $obj->db()
-
Inherited, see "Accessors" in Couch::DB::Document
- $obj->id()
-
Inherited, see "Accessors" in Couch::DB::Document
- $obj->idBase()
-
Various calls need the
idwithout the_design. Whether the full document id for the design document or only the unique part is required/given is confusing. This method returns the unique part. - $obj->row( [$row] )
-
Inherited, see "Accessors" in Couch::DB::Document
- $class->setIdGenerator(CODE)
-
When a design document is created without explicit
id, that will get generated. By default, this is done by requesting a fresh UUID from the server. You may change this into some local random collission free id generator for better performance.The
CODEis called with the daabase object as only parameter.
Content
Extends "Content" in Couch::DB::Document.
- $obj->isDeleted()
-
Inherited, see "Content" in Couch::DB::Document
- $obj->isLocal()
-
Inherited, see "Content" in Couch::DB::Document
- $obj->latest()
-
Inherited, see "Content" in Couch::DB::Document
- $obj->rev()
-
Inherited, see "Content" in Couch::DB::Document
- $obj->revision($rev)
-
Inherited, see "Content" in Couch::DB::Document
- $obj->revisions()
-
Inherited, see "Content" in Couch::DB::Document
Document details
Extends "Document details" in Couch::DB::Document.
- $obj->conflicts()
-
Inherited, see "Document details" in Couch::DB::Document
- $obj->deletedConflicts()
-
Inherited, see "Document details" in Couch::DB::Document
- $obj->revisionInfo($revision)
-
Inherited, see "Document details" in Couch::DB::Document
- $obj->revisionsInfo()
-
Inherited, see "Document details" in Couch::DB::Document
- $obj->updateSequence()
-
Inherited, see "Document details" in Couch::DB::Document
Document in the database
All methods below are inherited from standard documents. Their call URI differs, but their implementation is the same. On the other hand: they add interpretation on fields which do not start with '_'.
Extends "Document in the database" in Couch::DB::Document.
- $obj->appendTo($doc, %options)
-
[CouchDB API "COPY /{db}/_design/{ddoc}"] Improves base, see L<Couch::DB::Document/"Document in the database"> - $obj->cloneInto($doc, %options)
-
[CouchDB API "COPY /{db}/_design/{ddoc}"] Improves base, see L<Couch::DB::Document/"Document in the database"> - $obj->create(\%data, %options)
-
[CouchDB API "POST /{db}/_index", UNTESTED] Create a new design document.In Couch::DB, the client-side, not the server, generates ids. Therefore, this method is equivalent to update(). Improves base, see "Document in the database" in Couch::DB::Document
-Option--Defined in --Default batch Couch::DB::Document new(batch) - $obj->delete(%options)
-
[CouchDB API "DELETE /{db}/_design/{ddoc}"] Improves base, see L<Couch::DB::Document/"Document in the database"> - $obj->details(%options)
-
[CouchDB API "GET /{db}/_design/{ddoc}/_info", UNTESTED]Obtains information about the specified design document, including the index, index size and current status of the design document and associated index information.
- $obj->exists(%option)
-
[CouchDB API "HEAD /{db}/_design/{ddoc}"]Returns the HTTP Headers containing a minimal amount of information about the specified design document. Improves base, see "Document in the database" in Couch::DB::Document
- $obj->get(%options)
-
[CouchDB API "GET /{db}/_design/{ddoc}"] Improves base, see L<Couch::DB::Document/"Document in the database"> - $obj->update(\%data, %options)
-
[CouchDB API "PUT /{db}/_design/{ddoc}"]Options
filters,lists,shows, andupdatesare HASHes which map names to fragments of code written in programming languagelanguage(usually erlang or javascript).Options
lists,show, andrewrites(query redirection) are deprecated since 3.0, and are removed from 4.0. Improves base, see "Document in the database" in Couch::DB::Document-Option--Defined in --Default batch Couch::DB::Document new(batch)
Attachments
Extends "Attachments" in Couch::DB::Document.
- $obj->attDelete($name, %options)
-
[CouchDB API "DELETE /{db}/_design/{ddoc}/{attname}" ] Improves base, see L<Couch::DB::Document/"Attachments"> - $obj->attExists($name, %options)
-
[CouchDB API "HEAD /{db}/_design/{ddoc}/{attname}"] Improves base, see L<Couch::DB::Document/"Attachments"> - $obj->attInfo($name)
-
Inherited, see "Attachments" in Couch::DB::Document
- $obj->attLoad($name, %options)
-
[CouchDB API "GET /{db}/_design/{ddoc}/{attname}" ] Improves base, see L<Couch::DB::Document/"Attachments"> - $obj->attSave($name, $data, %options)
-
[CouchDB API "PUT /{db}/_design/{ddoc}/{attname}" ] Improves base, see L<Couch::DB::Document/"Attachments"> -Option--Defined in --Default type Couch::DB::Document application/octet-stream - $obj->attachment($name)
-
Inherited, see "Attachments" in Couch::DB::Document
- $obj->attachments()
-
Inherited, see "Attachments" in Couch::DB::Document
Indexes (indices)
- $obj->createIndex(\%config, %options)
-
[CouchDB API "POST /{db}/_index", UNTESTED]Create an index on the database. If the name already exists and the configuration is different, then the index be get regenerated.
- $obj->deleteIndex($index, %options)
-
[CouchDB API "DELETE /{db}/_index/{design_doc}/json/{name}", UNTESTED]Remove an index from this design document.
- $obj->indexDetails($index, %options)
-
[CouchDB API "GET /{db}/_design/{ddoc}/_search_info/{index}", UNTESTED]Returns metadata for the specified search index.
- $obj->search( $index, [\%search, %options] )
-
[CouchDB API "GET /{db}/_design/{ddoc}/_search/{index}", UNTESTED]Executes a (text) search request against the named
$index. The default%searchcontains the whole index. When the search containsinclude_docs, then full docs are made available.(Of course) this command supports paging.
» example: return full index all as rows
my $d = $db->design('d'); my $rows = $d->search('i', {}, all => 1)->page; my $search = +{ include_docs => 1 }; my @docs = $d->search('i', \%search, all => 1)->pageDocs;
Views
- $obj->compactViews(%options)
-
[CouchDB API "POST /{db}/_compact/{ddoc}", UNTESTED]Start the compacting (optimization) of all views in this design document. See Couch::DB::Database::compactViews() to start them for all design documents at once.
- $obj->viewDocs( $view, [\%search|\@%search], %options] )
-
[CouchDB API "GET /{db}/_design/{ddoc}/_view/{view}", UNTESTED] [CouchDB API "POST /{db}/_design/{ddoc}/_view/{view}", UNTESTED] [CouchDB API "POST /{db}/_design/{ddoc}/_view/{view}/queries", UNTESTED] [CouchDB API "GET /{db}/_partition/{partition_id}/_design/{ddoc}/_view/{view}", UNTESTED]Executes the specified view function.
This work is handled in Couch::DB::Database::allDocs(). See that method for
%optionsand results.» example:
my %search; my $c = $db->design('people')->viewDocs(customers => \%search, all => 1); my $hits = $c->page; my %search = (design => 'people', view => 'customers'); my $c = $db->allDocs(\%search, all => 1);
Functions
- $obj->applyUpdate( $function, [$doc|$docid|undef, %options] )
-
[CouchDB API "POST /{db}/_design/{ddoc}/_update/{func}", UNTESTED] [CouchDB API "POST /{db}/_design/{ddoc}/_update/{func}/{docid}", UNTESTED]See what the update function would change. The update
$functionis run on a document, specified by id or object. By default or explicitundef, anull(missing) document will be used. - $obj->list($function, $view, %options)
-
[CouchDB API "GET /{db}/_design/{ddoc}/_list/{func}/{view}", deprecated 3.0, removed 4.0, UNTESTED] [CouchDB API "POST /{db}/_design/{ddoc}/_list/{func}/{view}", deprecated 3.0, removed 4.0, UNTESTED] [CouchDB API "GET /{db}/_design/{ddoc}/_list/{func}/{other-ddoc}/{view}", deprecated 3.0, removed 4.0, UNTESTED] [CouchDB API "POST /{db}/_design/{ddoc}/_list/{func}/{other-ddoc}/{view}", deprecated 3.0, removed 4.0, UNTESTED]Executes a list function against the
$view.-Option --Default view_ddoc undef - $obj->show( $function, [$doc|$docid|undef, %options] )
-
[CouchDB API "GET /{db}/_design/{ddoc}/_show/{func}", deprecated 3.0, removed 4.0, UNTESTED] [CouchDB API "POST /{db}/_design/{ddoc}/_show/{func}", deprecated 3.0, removed 4.0, UNTESTED] [CouchDB API "GET /{db}/_design/{ddoc}/_show/{func}/{docid}", deprecated 3.0, removed 4.0, UNTESTED] [CouchDB API "POST /{db}/_design/{ddoc}/_show/{func}/{docid}", deprecated 3.0, removed 4.0, UNTESTED]Apply show
$functionon the document, as specified by$docidor document object. By default or explicitundef, a "null" document will be used.
DIAGNOSTICS
- Warning: -hex
-
Cast by
revisions() - Error: you have requested the open_revs detail for the document yet.
-
Cast by
revisionsInfo()
SEE ALSO
This module is part of Couch-DB version 0.201, built on January 30, 2026. Website: http://perl.overmeer.net/CPAN/
LICENSE
For contributors see file ChangeLog.
This software is copyright (c) 2024-2026 by Mark Overmeer.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.