CouchdbDocument

CouchdbDocument

Stability Level

, unless otherwise indicated

Synopsis

                    CouchdbDocumentClass;
CouchdbDocument *   couchdb_document_new                (CouchdbSession *couchdb);
CouchdbDocument *   couchdb_document_get                (CouchdbSession *couchdb,
                                                         const char *dbname,
                                                         const char *docid,
                                                         GError **error);
gboolean            couchdb_document_put                (CouchdbDocument *document,
                                                         const char *dbname,
                                                         GError **error);
gboolean            couchdb_document_delete             (CouchdbDocument *document,
                                                         GError **error);
const char *        couchdb_document_get_id             (CouchdbDocument *document);
void                couchdb_document_set_id             (CouchdbDocument *document,
                                                         const char *id);
const char *        couchdb_document_get_revision       (CouchdbDocument *document);
void                couchdb_document_set_revision       (CouchdbDocument *document,
                                                         const char *revision);
gboolean            couchdb_document_has_field          (CouchdbDocument *document,
                                                         const char *field);
void                couchdb_document_remove_field       (CouchdbDocument *document,
                                                         const char *field);
gboolean            couchdb_document_get_boolean_field  (CouchdbDocument *document,
                                                         const char *field);
void                couchdb_document_set_boolean_field  (CouchdbDocument *document,
                                                         const char *field,
                                                         gboolean value);
gint                couchdb_document_get_int_field      (CouchdbDocument *document,
                                                         const char *field);
void                couchdb_document_set_int_field      (CouchdbDocument *document,
                                                         const char *field,
                                                         gint value);
gdouble             couchdb_document_get_double_field   (CouchdbDocument *document,
                                                         const char *field);
void                couchdb_document_set_double_field   (CouchdbDocument *document,
                                                         const char *field,
                                                         gdouble value);
const char *        couchdb_document_get_string_field   (CouchdbDocument *document,
                                                         const char *field);
void                couchdb_document_set_string_field   (CouchdbDocument *document,
                                                         const char *field,
                                                         const char *value);
CouchdbStructField * couchdb_document_get_struct_field  (CouchdbDocument *document,
                                                         const char *field);
void                couchdb_document_set_struct_field   (CouchdbDocument *document,
                                                         const char *field,
                                                         CouchdbStructField *value);
char *              couchdb_document_to_string          (CouchdbDocument *document);

Description

Details

CouchdbDocumentClass

typedef struct {
	GObjectClass parent_class;
} CouchdbDocumentClass;


couchdb_document_new ()

CouchdbDocument *   couchdb_document_new                (CouchdbSession *couchdb);

Create an empty CouchdbDocument object, which can then be populated with data and added to a database on the specified CouchDB instance.

couchdb :

A CouchdbSession object

Returns :

A newly-created CouchdbDocument object, with no data on it.

couchdb_document_get ()

CouchdbDocument *   couchdb_document_get                (CouchdbSession *couchdb,
                                                         const char *dbname,
                                                         const char *docid,
                                                         GError **error);

Retrieve the last revision of a document from the given database.

couchdb :

A CouchdbSession object

dbname :

Name of the database to retrieve the document from

docid :

Unique ID of the document to be retrieved

error :

Placeholder for error information

Returns :

A CouchdbDocument object if successful, NULL otherwise, in which case, the error argument will contain information about the error.

couchdb_document_put ()

gboolean            couchdb_document_put                (CouchdbDocument *document,
                                                         const char *dbname,
                                                         GError **error);

Store a document on a CouchDB database.

If it is a new document, and hence does not have a unique ID, a unique ID will be generated and stored on the CouchdbDocument object. Likewise, whether the document is new or just an update to an existing one, the CouchdbDocument object passed to this function will be updated to contain the latest revision of the document, as returned by CouchDB (revision that can be retrieved by calling couchdb_document_get_revision).

document :

A CouchdbDocument object

dbname :

Name of the database where the document will be stored

error :

Placeholder for error information

Returns :

TRUE if successful, FALSE otherwise, in which case the error argument will contain information about the error.

couchdb_document_delete ()

gboolean            couchdb_document_delete             (CouchdbDocument *document,
                                                         GError **error);

Delete an existing document from a CouchDB instance.

Please take note that this operation can fail if there was an update to the document and that last revision was not retrieved by the calling application. This is due to the fact that, to remove a document from CouchDB, the latest revision needs to be sent, so if the CouchdbDocument object passed to this function does not contain the last revision, the operation will fail. In that case, retrieving the latest revision from CouchDB (with couchdb_document_get) and trying the delete operation again should fix the issue.

document :

A CouchdbDocument object

error :

Placeholder for error information

Returns :

TRUE if successful, FALSE otherwise, in which case the error argument will contain information about the error.

couchdb_document_get_id ()

const char *        couchdb_document_get_id             (CouchdbDocument *document);

Retrieve the unique ID of the given document.

document :

A CouchdbDocument object

Returns :

The unique ID of the given document.

couchdb_document_set_id ()

void                couchdb_document_set_id             (CouchdbDocument *document,
                                                         const char *id);

Set the unique ID for a given document.

This usually is not needed by calling applications, unless they want to force IDs on the CouchDB documents created/updated for some reason, like compatibility with 3rd party applications. In most cases, the autogenerated IDs from CouchDB when new documents are created (see couchdb_document_put) should be ok for most applications.

document :

A CouchdbDocument object

id :

New unique ID for the given document.

couchdb_document_get_revision ()

const char *        couchdb_document_get_revision       (CouchdbDocument *document);

Retrieve the revision of a given document.

CouchDB does not overwrite updated documents in place, instead it creates a new document at the end of the database file, with the same ID but a new revision.

Document revisions are used for optimistic concurrency control and applications should not rely on document revisions for any other purpose than concurrency control.

document :

A CouchdbDocument object

Returns :

Revision of the given document.

couchdb_document_set_revision ()

void                couchdb_document_set_revision       (CouchdbDocument *document,
                                                         const char *revision);

Set the revision of the given document. This should never be used by applications, unless they really know what they are doing, since using a wrong revision string will confuse CouchDB when doing updates to the document.

document :

A CouchdbDocument object

revision :

String specifying the revision to set the document to

couchdb_document_has_field ()

gboolean            couchdb_document_has_field          (CouchdbDocument *document,
                                                         const char *field);

Check whether the given document has a field with a specific name.

document :

A CouchdbDocument object

field :

Name of the field to check existence for in the document

Returns :

TRUE if the field exists in the document, FALSE if not.

couchdb_document_remove_field ()

void                couchdb_document_remove_field       (CouchdbDocument *document,
                                                         const char *field);

Remove a field from the given document.

document :

A CouchdbDocument object

field :

Name of the field to remove from the document

couchdb_document_get_boolean_field ()

gboolean            couchdb_document_get_boolean_field  (CouchdbDocument *document,
                                                         const char *field);

Retrieve the value of a boolean field from the given document.

document :

A CouchdbDocument object

field :

Name of the field to retrieve

Returns :

The value of the given boolean field.

couchdb_document_set_boolean_field ()

void                couchdb_document_set_boolean_field  (CouchdbDocument *document,
                                                         const char *field,
                                                         gboolean value);

Set the value of a boolean field in the given document.

document :

A CouchdbDocument object

field :

Name of the field to set

value :

Value to set the field to

couchdb_document_get_int_field ()

gint                couchdb_document_get_int_field      (CouchdbDocument *document,
                                                         const char *field);

Retrieve the value of an integer field from the given document.

document :

A CouchdbDocument object

field :

Name of the field to retrieve

Returns :

The value of the given integer field.

couchdb_document_set_int_field ()

void                couchdb_document_set_int_field      (CouchdbDocument *document,
                                                         const char *field,
                                                         gint value);

Set the value of an integer field in the given document.

document :

A CouchdbDocument object

field :

Name of the field to set

value :

Value to set the field to

couchdb_document_get_double_field ()

gdouble             couchdb_document_get_double_field   (CouchdbDocument *document,
                                                         const char *field);

Retrieve the value of a decimal number field from the given document.

document :

A CouchdbDocument object

field :

Name of the field to retrieve

Returns :

The value of the given decimal number field.

couchdb_document_set_double_field ()

void                couchdb_document_set_double_field   (CouchdbDocument *document,
                                                         const char *field,
                                                         gdouble value);

Set the value of a decimal number field in the given document.

document :

A CouchdbDocument object

field :

Name of the field to set

value :

Value to set the field to

couchdb_document_get_string_field ()

const char *        couchdb_document_get_string_field   (CouchdbDocument *document,
                                                         const char *field);

Retrieve the value of a string field from the given document.

document :

A CouchdbDocument object

field :

Name of the field to retrieve

Returns :

The value of the given string field.

couchdb_document_set_string_field ()

void                couchdb_document_set_string_field   (CouchdbDocument *document,
                                                         const char *field,
                                                         const char *value);

Set the value of a string field in the given document.

document :

A CouchdbDocument object

field :

Name of the field to set

value :

Value to set the field to

couchdb_document_get_struct_field ()

CouchdbStructField * couchdb_document_get_struct_field  (CouchdbDocument *document,
                                                         const char *field);

Retrieve the value of a struct field from the given document.

document :

A CouchdbDocument object

field :

Name of the field to retrieve

Returns :

The value of the given struct field.

couchdb_document_set_struct_field ()

void                couchdb_document_set_struct_field   (CouchdbDocument *document,
                                                         const char *field,
                                                         CouchdbStructField *value);

Set the value of a struct field in the given document.

document :

A CouchdbDocument object

field :

Name of the field to set

value :

Value to set the field to

couchdb_document_to_string ()

char *              couchdb_document_to_string          (CouchdbDocument *document);

Convert the given CouchdbDocument to a JSON string.

document :

A CouchdbDocument object

Returns :

A string containing the given document in JSON format.