![]() |
![]() |
![]() |
Reference Manual for CouchDB GLib Bindings | ![]() |
---|---|---|---|---|
Top | Description |
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
);
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.
|
A CouchdbSession object |
Returns : |
A newly-created CouchdbDocument object, with no data on it. |
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.
|
A CouchdbSession object |
|
Name of the database to retrieve the document from |
|
Unique ID of the document to be retrieved |
|
Placeholder for error information |
Returns : |
A CouchdbDocument object if successful, NULL otherwise, in which case, the error argument will contain information about the error. |
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).
|
A CouchdbDocument object |
|
Name of the database where the document will be stored |
|
Placeholder for error information |
Returns : |
TRUE if successful, FALSE otherwise, in which case the error argument will contain information about the error. |
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.
|
A CouchdbDocument object |
|
Placeholder for error information |
Returns : |
TRUE if successful, FALSE otherwise, in which case the error argument will contain information about the error. |
const char * couchdb_document_get_id (CouchdbDocument *document
);
Retrieve the unique ID of the given document.
|
A CouchdbDocument object |
Returns : |
The unique ID of the given document. |
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.
|
A CouchdbDocument object |
|
New unique ID for the given document. |
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.
|
A CouchdbDocument object |
Returns : |
Revision of the given document. |
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.
|
A CouchdbDocument object |
|
String specifying the revision to set the document to |
gboolean couchdb_document_has_field (CouchdbDocument *document
,const char *field
);
Check whether the given document has a field with a specific name.
|
A CouchdbDocument object |
|
Name of the field to check existence for in the document |
Returns : |
TRUE if the field exists in the document, FALSE if not. |
void couchdb_document_remove_field (CouchdbDocument *document
,const char *field
);
Remove a field from the given document.
|
A CouchdbDocument object |
|
Name of the field to remove from the document |
gboolean couchdb_document_get_boolean_field (CouchdbDocument *document
,const char *field
);
Retrieve the value of a boolean field from the given document.
|
A CouchdbDocument object |
|
Name of the field to retrieve |
Returns : |
The value of the given 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.
|
A CouchdbDocument object |
|
Name of the field to set |
|
Value to set the field to |
gint couchdb_document_get_int_field (CouchdbDocument *document
,const char *field
);
Retrieve the value of an integer field from the given document.
|
A CouchdbDocument object |
|
Name of the field to retrieve |
Returns : |
The value of the given integer 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.
|
A CouchdbDocument object |
|
Name of the field to set |
|
Value to set the field to |
gdouble couchdb_document_get_double_field (CouchdbDocument *document
,const char *field
);
Retrieve the value of a decimal number field from the given document.
|
A CouchdbDocument object |
|
Name of the field to retrieve |
Returns : |
The value of the given decimal number 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.
|
A CouchdbDocument object |
|
Name of the field to set |
|
Value to set the field to |
const char * couchdb_document_get_string_field (CouchdbDocument *document
,const char *field
);
Retrieve the value of a string field from the given document.
|
A CouchdbDocument object |
|
Name of the field to retrieve |
Returns : |
The value of the given 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.
|
A CouchdbDocument object |
|
Name of the field to set |
|
Value to set the field to |
CouchdbStructField * couchdb_document_get_struct_field (CouchdbDocument *document
,const char *field
);
Retrieve the value of a struct field from the given document.
|
A CouchdbDocument object |
|
Name of the field to retrieve |
Returns : |
The value of the given 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.
|
A CouchdbDocument object |
|
Name of the field to set |
|
Value to set the field to |
char * couchdb_document_to_string (CouchdbDocument *document
);
Convert the given CouchdbDocument to a JSON string.
|
A CouchdbDocument object |
Returns : |
A string containing the given document in JSON format. |