Beruflich Dokumente
Kultur Dokumente
Overview
Introduction
SQL vs CouchDB
CouchDB Features
CouchDB Core API
Futon
Security
Application
Overview
Demo
Code
Advantages
DisAdvantages
Iris Couch
Conclusion
References
Introduction
Introduction...
NoSQL Database
NoSQL Databases
Schema-Free
Distributed
Open Source
Horizontally Scalable
Easy Replication Support
NoSQL Timeline
Document-Oriented DBMS
SQL vs CouchDB
SQL
CouchDB
Relational
Non-Relational
Tables
Document Fields
CouchDB Features
JSON
JSON.....
Example: {
"firstName": "John",
"lastName": "Smith",
"age": 25,
"phoneNumber": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}]
Server API
Database API
Document API
Replication API
HTTP API
Description
PUT
GET
POST
DELETE
COPY
Description
200 (OK)
201 (Created)
304 (Not Modified)
400 (Bad Request)
404 (Not Found)
405 (Method Not Allowed)
409 (Conflict)
412 (Precondition Failed)
500 (Internal Server Error)
Futon
Design Documents
Views
View Functions...
View Functions
B-tree for the view is built only once and all the
subsequent queries will just read the B-tree instead of
executing the map function again
Map Functions
Document-1
Document-2
Document-3
Document-4
id : 1
id : 2
id : 3
id : 4
Bname : Oracle
Bname : Networks
Bname : Circuits
Bname : AI
Category : CS
Category : CS
Category : Electronics
Category : CS
Author : abc
Author : xyz
Author : abcd
Author : pqrs
Edition : 2007
Edition : 2001
Edition : 2004
Edition : 2010
Map Functions
Output :
Key
Value
Oracle
Networks
Circuits
AI
Map Functions
Map Function :
map:function(doc) {
emit(doc.Bname, doc.id);
}
Output :
AI
Circuits
Networks
Oracle
Reduce Function
Security
Database Admins
Validation Functions
Validation Function
Application
GSUBooks.com
Code - add.js
add.js:
$(document).ready(
function() {
//Event handler crud stuff
$('input#addId').click(function(e)
{
if ($('#bookId').val().length == 0)
{
return;
}
var bookdoc = { booknm: $('#bookId').val(), authornm: $('#authorId').val(), category:
$('#categoryId').val(), edition: $('#editionId').val(),quantity: $('#quantityId').val() }
Code - add.js...
db.saveDoc(bookdoc, { success: function(resp)
{
checkList(); //refreshes the database with new book
}
});
Code-delete.js
delete.js
$(document).ready
(
function()
{
$('input#borrowId').click(function(e)
{
if ($('#idId').val().length == 0)
{
return;
}
var bookdoc = { _id: $('#idId').val(), _rev: $('#revId').val() }
db.removeDoc(bookdoc, { success: function(resp)
{
Code-delete.js
checkList(); //refreshes the database with the remaining books
alert("Book has been borrowed Successfully!!");
}});
clearDocument();
});
});
function clearDocument()
{
$('#idId').val('');
$('#revId').val('');
$('#bookId').val('');
$('#authorId').val('');
$('#categoryId').val('');
$('#editionId').val('');
$('#quantityId').val('');
};
Code - Update.js
update.js
$(document).ready(function()
{
$('input#updateId').click(function(e)
{
if ($('#idId').val().length == 0)
{
return;
}
var bookdoc = {
_id: $('#idId').val(),
_rev: $('#revId').val(),
booknm: $('#bookId').val(),
update.js...
authornm:$('#authorId').val(),
category:$('#categoryId').val(),
edition:$('#editionId').val(),
quantity:$('#quantityId').val()
}
db.saveDoc(bookdoc, { success: function(resp)
{
checkList();
}
});
});
Code - Display.js
display.js
$(document).ready(function()
{
checkList();
});
function checkList()
{
$("table#itemData").empty();
db.view("myfirstDesign/myfirstView", { success: function(data)
{
$('table#itemData').append('<tr><th><font color="black">Book
Name</font></th><th><font color="black">Author Name</font></th><th><font
color="black">Category</font></th><th><font color="black">Edition</font></th>
Code - Display.js
<th><font color="black">Quantity</font></th></tr>');
data.rows.map(function(row)
{
$('table#itemData').append('<tr><td id="'+row.value._id+'"align="center"><font
+row.value.booknm
+'</font></td><td align="center"><font color="navy">'
+row.value.authornm
+'</font></td><td align="center"><font color="navy">'
+row.value.category
+'</font></td><td align="center"><font color="navy">'
+row.value.edition
+'</font></td><td align="center"><font color="navy">'
+row.value.quantity
+'</font></td></tr>');
$('#'+row.value._id).click(function()
{
$('#idId').val(row.value._id);
Code - Display.js
$('#revId').val(row.value._rev);
$('#bookId').val(row.value.booknm);
$('#authorId').val(row.value.authornm);
$('#categoryId').val(row.value.category);
$('#editionId').val(row.value.edition);
$('#quantityId').val(row.value.quantity);
return false;
});
});
}
});
}
Advantages / DisAdvantages
Features
Not easy to learn especially if the user is
familiar with SQL
Security is weak
Temporary views on large datasets are very
slow.
Replication of large databases may fail
Documents are quite large as the data is
represented using JSON format
References
Thank You...