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

SYNOPSIS

    use Mojo::CouchDB;

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

    $db->create_db; # Create the database on the server

    # Make a document
    my $book = {
        title => 'Nineteen Eighty Four',
        author => 'George Orwell'
    };

    # Save your document to the database
    $book = $db->save($book);

    # If _id is assigned to a hashref, save will update rather than create
    say $book->{_id}; # Assigned when saving or getting
    $book->{title} = 'Dune';
    $book->{author} = 'Frank Herbert'

    # Re-save to update the document
    $book = $db->save($book);

    # Get the document as a hashref
    my $dune = $db->get($book->{_id});

    # You can also save many documents at a time
    my $books = $db->save_many([{title => 'book', author => 'John'}, { title => 'foo', author => 'bar' }])->{docs};

db

    my $db = $couch->db('books');

Create an instance of "Mojo::CouchDB::DB" that corresponds to the database name specified in the first parameter.

new

    my $url   = 'https://127.0.0.1:5984';
    my $couch = Mojo::CouchDB->new($url, $username, $password);

Creates an instance of "Mojo::CouchDB". The URL specified must include the protocol either http or https as well as the port your CouchDB instance is using.

API

AUTHOR

Rawley Fowler, rawleyfowler@proton.me.

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.