static void
doc_changed_cb (CouchdbSession *couchdb, const char *dbname, CouchdbDocument *document, gpointer user_data)
{
    char *doc_str;

    doc_str = couchdb_document_to_string (document);
    g_print ("Document %s has been %s: %s\n",
             couchdb_document_get_id (document),
             (const gchar *) user_data,
             doc_str);

    g_free (doc_str);
}
Esempio n. 2
0
static gchar *
format(Log4gLayout *base, Log4gLoggingEvent *event)
{
	struct Private *priv = GET_PRIVATE(base);
	g_free(priv->string);
	CouchdbDocument *document =
		log4g_couchdb_layout_format_document(base, event);
	if (!document) {
		return NULL;
	}
	priv->string = couchdb_document_to_string(document);
	g_object_unref(document);
	return priv->string;
}
static void
test_list_documents (void)
{
    GError *error = NULL;
    GSList *dblist;

    dblist = couchdb_session_list_databases (couchdb, &error);
    g_assert (error == NULL);

    while (dblist != NULL) {
        GSList *doclist;

        error = NULL;
        doclist = couchdb_session_list_documents (couchdb, (const char *) dblist->data, &error);
        g_assert (error == NULL);

        while (doclist) {
            CouchdbDocumentInfo *doc_info = doclist->data;
            CouchdbDocument *document;
            char *str;

            error = NULL;
            document = couchdb_document_get (couchdb, (const char *) dblist->data,
                                             couchdb_document_info_get_docid (doc_info),
                                             &error);
            g_assert (error == NULL);
            g_assert (document != NULL);
            g_assert (g_strcmp0 (couchdb_document_info_get_docid (doc_info), couchdb_document_get_id (document)) == 0);
            g_assert (g_strcmp0 (couchdb_document_info_get_revision (doc_info), couchdb_document_get_revision (document)) == 0);

            str = couchdb_document_to_string (document);
            g_assert (str != NULL);
            g_free (str);

            g_object_unref (G_OBJECT (document));

            doclist = g_slist_remove (doclist, doc_info);
            couchdb_document_info_unref (doc_info);
        }

        dblist = g_slist_remove (dblist, dblist->data);
    }
}