'\" t
.\"     Title: lcb_create
.\"    Author: Trond Norbye <trond.norbye@couchbase.com>
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\"      Date: 09/19/2013
.\"    Manual: \ \&
.\"    Source: \ \&
.\"  Language: English
.\"
.TH "LCB_CREATE" "3" "09/19/2013" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
lcb_create \- Create instance
.SH "SYNOPSIS"
.sp
cc [ flag \&... ] file\&... \-lcouchbase [ library \&... ]
.sp
.nf
#include <libcouchbase/couchbase\&.h>
.fi
.sp
.nf
lcb_error_t lcb_create(lcb_t *instance,
                       const struct lcb_create_st *options);
.fi
.SH "DESCRIPTION"
.sp
lcb_create() creates and stores the newly created instance in the instance parameter\&. If the options parameter is set to NULL it tries to connect to the default bucket on "127\&.0\&.0\&.1"\&. lcb_create_st is a structure defined in <libcouchbase/arguments\&.h>:
.sp
.if n \{\
.RS 4
.\}
.nf
struct lcb_create_st {
    int version; /* Specifies which filed in v to use */
    union {
        struct {
            const char *host;   /* host (list) to use */
            const char *user;   /* username for authentication */
            const char *passwd; /* password for authentication */
            const char *bucket; /* bucket to connect to */
            struct lcb_io_opt_st *io; /* IO instance to use */
        } v0;
        struct {
            const char *host;   /* host (list) to use */
            const char *user;   /* username for authentication */
            const char *passwd; /* password for authentication */
            const char *bucket; /* bucket to connect to */
            struct lcb_io_opt_st *io; /* IO instance to use */
            lcb_type_t type;    /* type of handle */
        } v1;
    } v;
.fi
.if n \{\
.RE
.\}
.sp
A lcb_create_st structure should be initialized by using memset to 0, causing the default values to be used for all options not specified\&.
.sp
The "version" member specifies how the "v" union should be interpreted\&. The only difference between version 0 and version 1 is that version 1 allows you to create an instance to use for http requests (without binding to a bucket)\&.
.sp
Hosts may be specified as a list of hosts separated by \fI;\fR\&. If the Couchbase cluster is using a non\-standard port, it may be specified by appending ":port" per host\&. ex: "host1;host2:9000;host3"\&. The hostname parameter may alternatively be specified as an URI like: http://hostname:8091/pools\&. libcouchbase does not support any other schema than http, and the only supported path is "/pools"\&. If no value is specified for host, "localhost:8091" is used\&.
.sp
If specified user and password specifies the credentials used for authorization\&. If you are trying to connect to a bucket (to perform data operations) you must use bucket\-level credentials instead of the administrator account\&. See examples 3 and 4\&.
.sp
If specified, bucket specifies the bucket in the cluster to connect to\&. If not specified the "default" bucket is selected\&.
.sp
If specified io specifies the io instance used for communications\&. See lcb_create_io_ops(3) for more information\&. If not specified a default io instance will be created\&.
.SH "RETURN VALUES"
.sp
lcb_create() returns the LCB_SUCCESS on success, or a specific error code upon failure\&. See lcb_strerror(3) for more information\&.
.SH "EXAMPLES"
.sp
Example 1: Create an instance using the default values:
.sp
.if n \{\
.RS 4
.\}
.nf
lcb_t instance;
lcb_error_t err = lcb_create(&instance, NULL);
if (err != LCB_SUCCESS) {
    fprintf(stderr, "Failed to create instance: %s\en",
            lcb_strerror(NULL, err));
    exit(EXIT_FAILURE);
}
.fi
.if n \{\
.RE
.\}
.sp
Example 2: Provide a special serverlist
.sp
.if n \{\
.RS 4
.\}
.nf
lcb_t instance;
lcb_error_t err;
struct lcb_create_st options;
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
memset(&options, 0, sizeof(options));
options\&.v\&.v0\&.host = "host1;host2;host3";
err = lcb_create(&instance, &options);
if (err != LCB_SUCCESS) {
    fprintf(stderr, "Failed to create instance: %s\en",
            lcb_strerror(NULL, err));
    exit(EXIT_FAILURE);
}
.fi
.if n \{\
.RE
.\}
.sp
Example 3: Create an handle to use for management requests
.sp
.if n \{\
.RS 4
.\}
.nf
lcb_t instance;
lcb_error_t err;
struct lcb_create_st options;
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
memset(&options, 0, sizeof(options));
options\&.version = 1;
options\&.v\&.v1\&.host = "host1";
options\&.v\&.v1\&.user = "Administrator";
options\&.v\&.v1\&.passwd = "secret";
options\&.v\&.v1\&.type = LCB_TYPE_CLUSTER;
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
err = lcb_create(&instance, &options);
if (err != LCB_SUCCESS) {
    fprintf(stderr, "Failed to create instance: %s\en",
            lcb_strerror(NULL, err));
    exit(EXIT_FAILURE);
}
.fi
.if n \{\
.RE
.\}
.sp
Example 4: Create an handle for data requests to protected bucket
.sp
.if n \{\
.RS 4
.\}
.nf
lcb_t instance;
lcb_error_t err;
struct lcb_create_st options;
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
memset(&options, 0, sizeof(options));
options\&.version = 1;
options\&.v\&.v1\&.host = "example\&.com:8091;example\&.org";
options\&.v\&.v1\&.bucket = "protected";
options\&.v\&.v1\&.user = "protected";
options\&.v\&.v1\&.passwd = "secret";
options\&.v\&.v1\&.type = LCB_TYPE_BUCKET;
.fi
.if n \{\
.RE
.\}
.sp
.if n \{\
.RS 4
.\}
.nf
err = lcb_create(&instance, &options);
if (err != LCB_SUCCESS) {
    fprintf(stderr, "Failed to create instance: %s\en",
            lcb_strerror(NULL, err));
    exit(EXIT_FAILURE);
}
.fi
.if n \{\
.RE
.\}
.SH "ATTRIBUTES"
.sp
See lcb_attributes(5) for descriptions of the following attributes:
.TS
allbox tab(:);
ltB ltB.
T{
ATTRIBUTE TYPE
T}:T{
ATTRIBUTE VALUE
T}
.T&
lt lt
lt lt.
T{
.sp
Interface Stability
T}:T{
.sp
Committed
T}
T{
.sp
MT\-Level
T}:T{
.sp
MT\-Safe
T}
.TE
.sp 1
.SH "COPYRIGHT"
.sp
Copyright 2010\-2013 Couchbase, Inc\&.
.SH "SEE ALSO"
.sp
Learn more at http://www\&.couchbase\&.com/communities/c\&.
.sp
libcouchbase(3), lcb_connect(3), lcb_destroy(3), lcb_attributes(5)
.SH "AUTHOR"
.PP
\fBTrond Norbye\fR <\&trond\&.norbye@couchbase\&.com\&>
.RS 4
Author.
.RE
