The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Mojo::CouchDB::DB

SYNOPSIS

    # Create a Mojo::CouchDB::DB instance via Mojo::CouchDB
    my $couch = Mojo::CouchDB->new('http://localhost:5984', 'username', 'password');

    my $books_db = $couch->db('books'); # Mojo::CouchDB::DB;

    # Do database stuff
    my $dune_books = $books_db->find({ selector => { name => "Dune" } })->{docs};
    # ...

all_docs

    $db->all_docs({ limit => 10, skip => 5});

Retrieves a list of all of the documents in the database. This is packaged as a hashref with offset: the offset of the query, rows: the documents in the page, and total_rows: the number of rows returned in the dataset.

Optionally, can take a hashref of query parameters that correspond with the CouchDB view query specification.

all_docs_p

    $db->all_docs_p({ limit => 10, skip => 5 });

See "all_docs", except returns the result in a Mojo::Promise.

create_db

    $db->create_db

Create the database, returns 1 if succeeds or if it already exsits, else returns undef.

find

    $db->find($search_criteria);

Searches for documents based on the search criteria specified. The search criteria hashref provided for searching must follow the CouchDB _find specification.

Returns a hashref with two fields: docs and execution_stats. docs contains an arrayref of found documents, while execution_stats contains a hashref of various statistics about the query you ran to find the documents.

find_p

    $db->find_p($search_criteria);

See "find", except returns the result asynchronously in a Mojo::Promise.

get

    $db->get($id);

Finds a document by a given id. Dies if it can't find the document. Returns the document in hashref form.

get_p

    $db->get_p($id);

See "get", except returns the result asynchronously in a Mojo::Promise.

index

    $db->index($idx);

Creates an index, where $idx is a hashref following the CouchDB mango specification. Returns the result of the index creation.

index_p

    $db->index_p($idx);

See "index", except returns the result asynchronously in a Mojo::Promise.

save

    $db->save($document);

Saves a document (hashref) to the database. If the _id field is provided, it will update if it already exists. If you provide both the _id and _rev field, that specific revision will be updated. Returns a hashref that corresponds to the CouchDB POST /{db} specification.

save_p

    $couch->save_p($document);

Does the same as "save" but instead returns the result asynchronously in a Mojo::Promise.

save_many

    $couch->save_many($documents);

Saves an arrayref of documents (hashrefs) to the database. Each document follows the same rules as \"save". Returns an arrayref of the documents you saved with the _id and _rev fields filled.

save_many_p

    $couch->save_many_p($documents);

See "save_many", except returns the result asynchronously in a Mojo::Promise.

API

AUTHOR

Rawley Fowler, rawleyfow@cpan.org.

CREDITS

LICENSE

Copyright (C) 2023, Rawley Fowler and contributors.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

SEE ALSO

https://mojolicious.org.