Click here to Skip to main content
15,879,096 members
Articles / Database Development / NoSQL

RavenDB - An Introduction

,
Rate me:
Please Sign up or sign in to vote.
4.87/5 (38 votes)
28 Apr 2010CPOL7 min read 261K   2.7K   112  
An introduction to RavenDB - a new open source .NET document database using .NET 4.0 and VS 2010
$(document).ready(function () {
    $.ravenDB.init();
    
    var windowSize = $(window).height();
    var minBodySize = Math.floor(windowSize*.75);
    $('#body').css('min-height', minBodySize + 'px');
    
    $(window).resize(function() {
        var windowSize = $(window).height();
        var minBodySize = Math.floor(windowSize*.75);
        $('#body').css('min-height', minBodySize + 'px');
    });
    
    $('#nav a:not(.nav_active)').hover(function () {
        $(this).stop(true, true).animate({ backgroundColor: '#444751', color: '#fff' }, 500);
    }, function () {
        $(this).stop(true, true).animate({ backgroundColor: '#E8E9ED', color: '#000' }, 500);
    }).click(function() {
        $(this).stop(true, true).css('background-color', '#E8E9ED').css('color', '#000');
    });
});

function RavenUI() { }

//home page

RavenUI.UpdateQuickStats = function (targetSelector) {
    if (!$(targetSelector).hasTemplate()) {
        $(targetSelector).setTemplateURL('JSONTemplates/quickStats.html');
    }

    $.ravenDB.getStatistics(function (stats) {
        $(targetSelector).processTemplate(stats);
    });
}

//global statistics

RavenUI.GetGlobalStatistics = function (targetSelector) {
    if (!$(targetSelector).hasTemplate()) {
        $(targetSelector).setTemplateURL('JSONTemplates/globalStats.html');
    }

    $.ravenDB.getStatistics(function (stats) {
        $(targetSelector).processTemplate(stats);
    });
}

//Documents
RavenUI.GetDocumentCount = function (successCallback) {
    $.ravenDB.getDocumentCount(successCallback);
}

RavenUI.GetDocumentPage = function (pageNum, pageSize, successCallback) {
    $.ravenDB.getDocumentPage(pageNum, pageSize, function (docs) {
        successCallback(docs);
    });
}

RavenUI.GetDocument = function (id, operation, successCallback) {
	$.ravenDB.getDocument(id, operation, successCallback);
}

RavenUI.SaveDocument = function (id, etag, template, json, successCallback, errorCallback) {
    $.ravenDB.saveDocument(id, etag, template, json, successCallback,errorCallback);
}

RavenUI.DeleteDocument = function (id, etag, successCallback) {
    $.ravenDB.deleteDocument(id, etag, successCallback);
}

//indexes
RavenUI.GetIndexCount = function (successCallback) {
    $.ravenDB.getIndexCount(successCallback);
}

RavenUI.GetIndexPage = function (pageNum, pageSize, targetSelector, successCallback) {
    if (!$(targetSelector).hasTemplate()) {
        $(targetSelector).setTemplateURL('JSONTemplates/indexPage.html');
    }

    $.ravenDB.getIndexPage(pageNum, pageSize, function (indexes) {
        $(targetSelector).processTemplate(indexes);
        successCallback();
    });
}

RavenUI.GetIndex = function (name, successCallback) {
    $.ravenDB.getIndex(name, successCallback);
}

RavenUI.SaveIndex = function (name, def, successCallback, errorCallback) {
    $.ravenDB.saveIndex(name, def, successCallback, errorCallback);
}

RavenUI.DeleteIndex = function (name, successCallback) {
    $.ravenDB.deleteIndex(name, successCallback);
}

RavenUI.SearchIndexes = function (name, successCallback) {
    $.ravenDB.searchIndexes(name, successCallback);
}

RavenUI.QueryIndex = function (name, queryValues, pageNumber, pageSize, successCallback) {
    $.ravenDB.queryIndex(name, queryValues, pageNumber, pageSize, successCallback);
}

// View
RavenUI.ShowTemplatedDocument = function (docId, operation, elementName) {
	if ($.query.get('docId').length == 0) {
		$(elementName).html('No document id specified.');
		return;
	}
	RavenUI.GetDocument(docId, operation, function (data, etag, template) {
		if (data == null) {
			$(elementName).html('The document "' + docId +'" could not be found');
			return;
		}
		if (template == null) {
			$(elementName).html('No ' + operation.toLowerCase() + ' template was specified for this document.');
			return;
		}
		$(elementName).setTemplateURL(template, null, { filter_data: false });
		$(elementName).processTemplate(data);
	})
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
I've been a software developer since 1996 and have enjoyed C# since 2003. I have a Bachelor's degree in Computer Science and for some reason, a Master's degree in Business Administration. I currently do software development contracting/consulting.

Written By
Israel Israel
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions