<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sagarn</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sagarn"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Sagarn"/>
	<updated>2026-05-17T22:12:30Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79946</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w44 s</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79946"/>
		<updated>2013-10-08T00:51:03Z</updated>

		<summary type="html">&lt;p&gt;Sagarn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Non-relational Databases in Rails Applications''' ==&lt;br /&gt;
&lt;br /&gt;
Active Record is basic to Rails and it is responsible for allowing programs to treat records in relational databases as objects. It employs Object-Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system (RDBMS). While Active Record is efficient in what it does, the complexities of ORM make way for a new approach for databases with rails, that is to move to different Database Models namely Object-Oriented Databases and No-SQL Databases.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Overview''' ==&lt;br /&gt;
Rails, as a web development framework, and Ruby, as a programming language, can be used with a choice of operating systems (Linux, Mac OS X, Windows), databases (SQLite, MySQL, PostgreSQL, and others), and web servers (Apache, Nginx, and others).&lt;br /&gt;
The Rails stack can also include a variety of software libraries (gems) that add features to a website or make development easier. Sometimes the choice of components in a stack is driven by the requirements of an application&lt;br /&gt;
&lt;br /&gt;
Rails uses the Active Record pattern which describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. &lt;br /&gt;
&lt;br /&gt;
Active Record is the layer of the system responsible for representing business data and logic. It facilitates the creation and use of business objects whose data requires persistent storage to a database. It employs ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. Using ORM, the properties and relationships of the objects in an application can be easily stored and retrieved from a database without writing SQL statements directly and with less overall database access code.&lt;br /&gt;
&lt;br /&gt;
Active Record gives us several mechanisms, the most important being the ability to:&lt;br /&gt;
:Represent models and their data.&lt;br /&gt;
:Represent associations between these models.&lt;br /&gt;
:Represent inheritance hierarchies through related models.&lt;br /&gt;
:Validate models before they get persisted to the database.&lt;br /&gt;
:Perform database operations in an object-oriented fashion.&lt;br /&gt;
&lt;br /&gt;
== '''Object-relational impedance mismatch''' ==&lt;br /&gt;
&lt;br /&gt;
The relational model on which Active Record relies on takes data and separates it into many interrelated tables that contain rows and columns. Tables reference each other through foreign keys that are stored in columns as well.  When looking up data, the desired information needs to be collected from many tables (often hundreds in today’s enterprise applications) and combined before it can be provided to the application. Similarly, when writing data, the write needs to be coordinated and performed on many tables.&lt;br /&gt;
&lt;br /&gt;
The Active Record pattern describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. The pattern has numerous limitations referred to as the Object-relational impedance mismatch. Some of these technical difficulties are structural. In Object Oriented programming, objects may be composed of other objects. The Active Record pattern maps these sub-objects to separate tables, thus introducing issues concerning the representation of relationships and encapsulated data. Active Record uses macros to create relationships between objects and single table inheritance to represent inheritance.&lt;br /&gt;
&lt;br /&gt;
Active Record is a solution for the Object-relational impedance mismatch, but this is assuming the datastore is relational. It’s also, fundamentally, a hack.&lt;br /&gt;
&lt;br /&gt;
== '''Non Relational Databases''' ==&lt;br /&gt;
=== '''Object Database''' ===&lt;br /&gt;
An object database also known as Object-Oriented Database Management System (OODBMS) is a Database Management System (DBMS) which allows information to be represented in the form of objects as used in object-oriented programming. OODBMSs provide an integrated application development environment by joining object-oriented programming with database technology. OODBMSs enforces object oriented programming concepts such as encapsulation, polymorphism and inheritance as well as database management concepts such as Atomicity, Consistency, Isolation and Durability. Since both the programming languages and OODBMS use the same object-oriented model, the programmers can maintain the consistency easily between the two environments.&lt;br /&gt;
&lt;br /&gt;
==== '''Comparing RDBMS with Object Database''' ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Criteria !! RDBMS !! OODBMS&lt;br /&gt;
|-&lt;br /&gt;
| Object-oriented programming support || Poor || Extensive&lt;br /&gt;
|-&lt;br /&gt;
| Ease of Use || Table schemas easy to understand for everyone || Good for Programmers only&lt;br /&gt;
|-&lt;br /&gt;
| Ease in development || Independent from application || Objects are a natural way to model, can incorporate types and relationships&lt;br /&gt;
|-&lt;br /&gt;
| Extensiblity || Low || High&lt;br /&gt;
|-&lt;br /&gt;
| Data relationships || Hard to model || Easy to handle&lt;br /&gt;
|-&lt;br /&gt;
| Maturity || Very Mature || Relatively Mature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== '''No-SQL Databases''' ===&lt;br /&gt;
A NoSQL database provides a mechanism for storage and retrieval of data that is less constrained in its consistency models than traditional Relational Databases.&lt;br /&gt;
&lt;br /&gt;
NoSQL encompasses a wide variety of different database technologies but generally all NoSQL databases have a few features in common.&lt;br /&gt;
*'''Dynamic Schemas'''&lt;br /&gt;
Relational databases require that schemas be defined before you can add data. This fits poorly with agile development approaches, because each time you complete new features, the schema of your database often needs to change. Furthermore, if the database is large, this is a very slow process that involves significant downtime.&lt;br /&gt;
In contrast NoSQL databases are built to allow the insertion of data without a predefined schema. That makes it easy to make significant application changes in real-time, without worrying about service interruptions – which means development is faster, code integration is more reliable, and less database administrator time is needed.&lt;br /&gt;
*'''Sharding, Replication and Caching'''&lt;br /&gt;
Because of the way they are structured, relational databases usually scale vertically. This gets expensive quickly, places limits on scale and is failure prone. &lt;br /&gt;
The solution is to scale horizontally, by adding servers instead of concentrating more capacity in a single server. NoSQL databases usually support auto-sharding, automatic replication, meaning that you get high availability and finally caching capabilities.&lt;br /&gt;
&lt;br /&gt;
NoSQL Database Types&lt;br /&gt;
:Document databases &lt;br /&gt;
:Graph stores&lt;br /&gt;
:Key-value stores&lt;br /&gt;
:Wide-column stores&lt;br /&gt;
&lt;br /&gt;
==== '''Comparing No-SQL DB with RDBMS'''&amp;lt;ref&amp;gt;http://www.couchbase.com/why-nosql/nosql-database&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
Relational and Object database models are very different. &lt;br /&gt;
For example, a document-oriented database takes the data you want to store and aggregates it into documents using the JSON format. Each JSON document can be thought of as an object to be used by your application. A JSON document might, for example, take all the data stored in a row that spans 20 tables of a relational database and aggregate it into a single document/object. Aggregating this information may lead to duplication of  information, but since storage is no longer cost prohibitive, the resulting data model flexibility, ease of efficiently distributing the resulting documents and read and write performance improvements make it an easy trade-off for web-based applications.&lt;br /&gt;
&lt;br /&gt;
[[File:nosqlvsrdbms.jpg|frame|none|alt=Document Object Model equivalent to Relational tables|Document Object Model equivalent to Relational tables&amp;lt;ref&amp;gt;http://www.couchbase.com/why-nosql/nosql-database&amp;lt;/ref&amp;gt;]]&lt;br /&gt;
&lt;br /&gt;
Another major difference is that relational databases have rigid schemas. Relational databases requires strict definition of a schema prior to storing any data into a database. Changing the schema once data is inserted is a big deal, extremely disruptive and frequently avoided.&lt;br /&gt;
In comparison, document databases are schemaless, allowing you to freely add fields to JSON documents without having to first define changes. The format of the data being inserted can be changed at any time, without application disruption.&lt;br /&gt;
&lt;br /&gt;
== '''Examples in Rails Apps''' ==&lt;br /&gt;
&lt;br /&gt;
In this section we will see how to incorporate two Document Object Databases MongoDB and CouchDB in a rails application. We will also explore Embedding and Nesting for models to better exhibit their use.&lt;br /&gt;
&lt;br /&gt;
=== '''MongoDB'''&amp;lt;ref&amp;gt;http://docs.mongodb.org/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
MongoDB is a document database that provides high performance, high availability, and easy scalability. Key features:&lt;br /&gt;
*'''Flexibility'''&lt;br /&gt;
MongoDB stores data in JSON documents (which we serialize to BSON). JSON provides a rich data model that seamlessly maps to native programming language types, and the dynamic schema makes it easier to evolve your data model than with a system with enforced schemas such as a RDBMS.&lt;br /&gt;
*'''Power'''&lt;br /&gt;
MongoDB provides a lot of the features of a traditional RDBMS such as secondary indexes, dynamic queries, sorting, rich updates, upserts (update if document exists, insert if it doesn’t), and easy aggregation. This gives you the breadth of functionality that you are used to from an RDBMS, with the flexibility and scaling capability that the non-relational model allows.&lt;br /&gt;
*'''Speed/Scaling'''&lt;br /&gt;
By keeping related data together in documents, queries can be much faster than in a relational database where related data is separated into multiple tables and then needs to be joined later. MongoDB also makes it easy to scale out your database. Autosharding allows you to scale your cluster linearly by adding more machines. It is possible to increase capacity without any downtime, which is very important on the web when load can increase suddenly and can bring down the website. Thus leading to extended maintenance which can cost large amounts of revenue.&lt;br /&gt;
*'''Ease of use'''&lt;br /&gt;
MongoDB works hard to be very easy to install, configure, maintain, and use. To this end, MongoDB provides few configuration options, and instead tries to automatically do the “right thing” whenever possible. This means that MongoDB works right out of the box, and you can dive right into developing your application, instead of spending a lot of time fine-tuning obscure database configurations.&lt;br /&gt;
&lt;br /&gt;
A MongoDB deployment hosts a number of databases. A database holds a set of collections. A collection holds a set of documents. A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.&lt;br /&gt;
&lt;br /&gt;
MongoDB stores all data in documents, which are JSON-style data structures composed of field-and-value pairs:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{ &amp;quot;item&amp;quot;: &amp;quot;pencil&amp;quot;, &amp;quot;qty&amp;quot;: 500, &amp;quot;type&amp;quot;: &amp;quot;no.2&amp;quot; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MongoDB stores documents on disk in the BSON serialization format. BSON is a binary representation of JSON documents, though contains more data types than does JSON&lt;br /&gt;
&lt;br /&gt;
MongoMapper and Mongoid are the two leading gems that make it possible to use MongoDB as a datastore with Rails. MongoMapper is a simple ORM for MongoDB. Mongoid’s goal is to provide a familiar API to Active Record, while still leveraging MongoDB’s advantages of schema flexibility, document design, atomic modifiers, and rich query interface.&lt;br /&gt;
&lt;br /&gt;
==== '''MongoDB in Rails'''&amp;lt;ref&amp;gt;http://docs.mongodb.org/ecosystem/tutorial/model-data-for-ruby-on-rails/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Firstly to create a new Rails app using MongoDB we need to ensure we create it without active record and install the necessary gems outlined before.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; rails new my_app --skip-active-record&lt;br /&gt;
&amp;gt; cd my_app&lt;br /&gt;
&amp;gt; gem install mongo&lt;br /&gt;
&amp;gt; gem install bson&lt;br /&gt;
&amp;gt; gem install bson_ext&lt;br /&gt;
&amp;gt; gem install mongomapper&lt;br /&gt;
&amp;gt; gem install mongoid&lt;br /&gt;
&amp;gt; rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rails model files are altered to not have the classes inherit from ActiveRecord::Base, instead must include a module MongoMapper::Document, and define the schema in the actual file. Database migrations are not necessary.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Story&lt;br /&gt;
 include MongoMapper::Document&lt;br /&gt;
&lt;br /&gt;
 key :title,     String&lt;br /&gt;
 key :url,       String&lt;br /&gt;
 key :voters,    Array&lt;br /&gt;
 key :votes,     Integer, :default =&amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
 # Cached values.&lt;br /&gt;
 key :comment_count, Integer, :default =&amp;gt; 0&lt;br /&gt;
 key :username,      String&lt;br /&gt;
&lt;br /&gt;
 # Note this: ids are of class ObjectId.&lt;br /&gt;
 key :user_id,   ObjectId&lt;br /&gt;
 timestamps!&lt;br /&gt;
&lt;br /&gt;
 # Relationships.&lt;br /&gt;
 belongs_to :user&lt;br /&gt;
&lt;br /&gt;
 # Validations.&lt;br /&gt;
 validates_presence_of :title, :url, :user_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, you have a number of configuration options available, such as allow_dynamic_fields that allows you to define attributes on an object that aren’t in the model file’s schema. You can then add some logic in your model file if you need to do something different depending on the existence or absence of this field.&lt;br /&gt;
&lt;br /&gt;
For fast lookups, we can create an index on this field. In the MongoDB shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
db.courses.ensureIndex('voters');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To find all the Courses by name:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Course.all(:conditions =&amp;gt; {:name =&amp;gt; @suject.name})&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''Embedding'''&amp;lt;ref&amp;gt;http://docs.mongodb.org/ecosystem/tutorial/model-data-for-ruby-on-rails/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
Now we will see how we can acheive embedding in a Rails App that uses MongoDB. We do this by example, incorporating comments into the Story example illustrated above.&lt;br /&gt;
In a relational database, comments are usually given their own table, related by foreign key to some parent table. This approach is occasionally necessary in MongoDB; however, it’s always best to try to embed first, as this will achieve greater query efficiency.&lt;br /&gt;
&lt;br /&gt;
*'''Linear Comments'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Story&lt;br /&gt;
  include MongoMapper::Document&lt;br /&gt;
  many :comments&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
 class Comment&lt;br /&gt;
  include MongoMapper::EmbeddedDocument&lt;br /&gt;
  key :body, String&lt;br /&gt;
&lt;br /&gt;
  belongs_to :story&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we were using the Ruby driver alone, we could save our structure like so:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@stories  = @db.collection('stories')&lt;br /&gt;
@document = {:title =&amp;gt; &amp;quot;MongoDB on Rails&amp;quot;,&lt;br /&gt;
             :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Revelatory! Loved it!&amp;quot;,&lt;br /&gt;
                            :username =&amp;gt; &amp;quot;Matz&amp;quot;&lt;br /&gt;
                           }&lt;br /&gt;
                          ]&lt;br /&gt;
            }&lt;br /&gt;
@stories.save(@document)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Nested Comments'''&lt;br /&gt;
To build threaded comments:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@stories  = @db.collection('stories')&lt;br /&gt;
@document = {:title =&amp;gt; &amp;quot;MongoDB on Rails&amp;quot;,&lt;br /&gt;
             :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Revelatory! Loved it!&amp;quot;,&lt;br /&gt;
                            :username =&amp;gt; &amp;quot;Matz&amp;quot;,&lt;br /&gt;
                            :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Agreed.&amp;quot;,&lt;br /&gt;
                                           :username =&amp;gt; &amp;quot;rubydev29&amp;quot;&lt;br /&gt;
                                          }&lt;br /&gt;
                                         ]&lt;br /&gt;
                           }&lt;br /&gt;
                          ]&lt;br /&gt;
            }&lt;br /&gt;
@stories.save(@document)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can also represent comments as their own collection. Relative to the other options, this incurs a small performance penalty while granting us the greatest flexibility. The tree structure can be represented by storing the unique path for each leaf.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Comment&lt;br /&gt;
  include MongoMapper::Document&lt;br /&gt;
&lt;br /&gt;
  key :body,       String&lt;br /&gt;
  key :depth,      Integer, :default =&amp;gt; 0&lt;br /&gt;
  key :path,       String,  :default =&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  # Note: we're intentionally storing parent_id as a string&lt;br /&gt;
  key :parent_id,  String&lt;br /&gt;
  key :story_id,   ObjectId&lt;br /&gt;
  timestamps!&lt;br /&gt;
&lt;br /&gt;
  # Relationships.&lt;br /&gt;
  belongs_to :story&lt;br /&gt;
&lt;br /&gt;
  # Callbacks.&lt;br /&gt;
  after_create :set_path&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Store the comment's path.&lt;br /&gt;
  def set_path&lt;br /&gt;
  ....&lt;br /&gt;
    end&lt;br /&gt;
    save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== '''CouchDB''' ===&lt;br /&gt;
CouchDB is often categorized as a “NoSQL” database. A CouchDB database lacks a schema, or rigid pre-defined data structures such as tables. &lt;br /&gt;
A CouchDB server hosts named databases stores documents. Data stored in CouchDB is a JSON document(s). The structure of the data, or document(s), can change dynamically to accommodate evolving needs. Each document is uniquely named in the database, and CouchDB provides a RESTful HTTP API for reading and updating (add, edit, delete) database documents.&lt;br /&gt;
Documents are the primary unit of data in CouchDB and consist of any number of fields and attachments. Documents also include metadata that’s maintained by the database system. Document fields are uniquely named and contain values of varying types (text, number, boolean, lists, etc), and there is no set limit to text size or element count.&lt;br /&gt;
User can just chuck arbitrary JSON objects up at this thing and it’ll store it. No setup, no schemas, no nothing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Key Charachteristics&lt;br /&gt;
&lt;br /&gt;
*'''Documents'''&lt;br /&gt;
A CouchDB document is a JSON object that consists of named fields. Field values may be strings, numbers, dates, or even ordered lists and associative maps. An example of a document would be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;Subject&amp;quot;: &amp;quot;Foo Bar&amp;quot;,&lt;br /&gt;
    &amp;quot;Author&amp;quot;: &amp;quot;John Doe&amp;quot;,&lt;br /&gt;
    &amp;quot;PostedDate&amp;quot;: &amp;quot;10/7/2013&amp;quot;,&lt;br /&gt;
    &amp;quot;Tags&amp;quot;: [&amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;],&lt;br /&gt;
    &amp;quot;Body&amp;quot;: &amp;quot;Lorem Ipsum...&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A CouchDB database is a flat collection of these documents. Each document is identified by a unique ID.&lt;br /&gt;
&lt;br /&gt;
*'''Views'''&lt;br /&gt;
To address this problem of adding structure back to semi-structured data, CouchDB integrates a view model using JavaScript for description. Views are the method of aggregating and reporting on the documents in a database, and are built on-demand to aggregate, join and report on database documents. Views are built dynamically and don’t affect the underlying document; you can have as many different view representations of the same data as you like. Incremental updates to documents do not require full re-indexing of views.&lt;br /&gt;
&lt;br /&gt;
*'''Schema Free'''&lt;br /&gt;
Unlike SQL databases, which are designed to store and report on highly structured, interrelated data, CouchDB is designed to store and report on large amounts of semi-structured, document oriented data. CouchDB greatly simplifies the development of document oriented applications, such as collaborative web applications.&lt;br /&gt;
&lt;br /&gt;
In an SQL database, the schema and storage of the existing data must be updated as needs evolve. With CouchDB, no schema is required, so new document types with new meaning can be safely added alongside the old. However, for applications requiring robust validation of new documents custom validation functions are possible. The view engine is designed to easily handle new document types and disparate but similar documents.&lt;br /&gt;
&lt;br /&gt;
*'''Distributed'''&lt;br /&gt;
CouchDB is a peer based distributed database system. Any number of CouchDB hosts (servers and offline-clients) can have independent &amp;quot;replica copies&amp;quot; of the same database, where applications have full database interactivity (query, add, edit, delete). When back online or on a schedule, database changes can be replicated bi-directionally.&lt;br /&gt;
&lt;br /&gt;
CouchDB has built-in conflict detection and management and the replication process is incremental and fast, copying only documents changed since the previous replication. Most applications require no special planning to take advantage of distributed updates and replication.&lt;br /&gt;
&lt;br /&gt;
==== '''CouchDB on Rails'''&amp;lt;ref&amp;gt;http://www.couchrest.info/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
Installing CouchDB.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install couchdb -y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or we can use the many pre compiled binaries on the CouchDB website.&lt;br /&gt;
&lt;br /&gt;
After installation, check if everything works fine by sending a curl request &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ curl http://localhost:5984&lt;br /&gt;
&lt;br /&gt;
{&amp;quot;couchdb&amp;quot;:&amp;quot;Welcome&amp;quot;,&amp;quot;version&amp;quot;:&amp;quot;1.1.1&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now install the Couchrest gem for ruby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install couchrest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To create a new model, we need to define a class that inherits from the CouchRest::Model::Base class in much the same way as an ActiveRecord model. Unlike a regular database mapper, CouchRest Model requires you to define the properties or attributes your model needs to use directly in the class. There are no migrations or automatic column detection in a Document Database. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person &amp;lt; CouchRest::Model::Base&lt;br /&gt;
  use_database 'people'&lt;br /&gt;
  property :first_name, String&lt;br /&gt;
  property :last_name, String&lt;br /&gt;
  timestamps!&lt;br /&gt;
  belongs_to :person&lt;br /&gt;
  collection_of :tags&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
CouchDB is accessed via HTTP requests, as such, there is no requirement to create a binary connection to a specific database. The use_database method tells the model which database it should use. This can be provided as a CouchRest::Database object or as simple string that will be concatenated to the connection prefix. A special property macro is available called timestamps! that will create the created_at and updated_at accessors.&lt;br /&gt;
&lt;br /&gt;
As you’d expect, CouchRest Model supports all the standard CRUD operations you’re used to in other object mappers. CouchRest Model supports a few basic queries for retrieving your data from the database.&lt;br /&gt;
&lt;br /&gt;
==== '''Embedding'''&amp;lt;ref&amp;gt;http://www.couchrest.info/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
The CouchRest Model Embeddable module allows you to take full advantage of CouchDB’s ability to store complex documents and retrieve them. Simply include the module in a Class and set any properties you’d like to use.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class CatToy&lt;br /&gt;
  include CouchRest::Model::Embeddable&lt;br /&gt;
&lt;br /&gt;
  property :name, String&lt;br /&gt;
  property :purchased, Date&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Cat &amp;lt; CouchRest::Model::Base&lt;br /&gt;
  property :name, String&lt;br /&gt;
  property :toys, CatToy, :array =&amp;gt; true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
@cat = Cat.new(:name =&amp;gt; 'Felix', :toys =&amp;gt; [{:name =&amp;gt; 'mouse', :purchased =&amp;gt; 1.month.ago}])&lt;br /&gt;
@cat.toys.first.class == CatToy&lt;br /&gt;
@cat.toys.first.name == 'mouse'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
While Active Record's ORM is most prevelant other forms of databases provide considerable advantage over RDBMS. Other alternatives help us address issues such as scalability, flexibility and are more in-tune with the Cloud model of deploying apps.&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://mongoid.org/en/mongoid/index.html&lt;br /&gt;
*http://mongomapper.com/&lt;br /&gt;
*http://en.wikipedia.org/wiki/Object_database&lt;br /&gt;
*http://www.mongodb.org/&lt;br /&gt;
*http://couchdb.apache.org/&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sagarn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79944</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w44 s</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79944"/>
		<updated>2013-10-08T00:48:59Z</updated>

		<summary type="html">&lt;p&gt;Sagarn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Non-relational Databases in Rails Applications''' ==&lt;br /&gt;
&lt;br /&gt;
Active Record is basic to Rails and it is responsible for allowing programs to treat records in relational databases as objects. It employs Object-Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system (RDBMS). While Active Record is efficient in what it does, the complexities of ORM make way for a new approach for databases with rails, that is to move to different Database Models namely Object-Oriented Databases and No-SQL Databases.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Overview''' ==&lt;br /&gt;
Rails, as a web development framework, and Ruby, as a programming language, can be used with a choice of operating systems (Linux, Mac OS X, Windows), databases (SQLite, MySQL, PostgreSQL, and others), and web servers (Apache, Nginx, and others).&lt;br /&gt;
The Rails stack can also include a variety of software libraries (gems) that add features to a website or make development easier. Sometimes the choice of components in a stack is driven by the requirements of an application&lt;br /&gt;
&lt;br /&gt;
Rails uses the Active Record pattern which describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. &lt;br /&gt;
&lt;br /&gt;
Active Record is the layer of the system responsible for representing business data and logic. It facilitates the creation and use of business objects whose data requires persistent storage to a database. It employs ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. Using ORM, the properties and relationships of the objects in an application can be easily stored and retrieved from a database without writing SQL statements directly and with less overall database access code.&lt;br /&gt;
&lt;br /&gt;
Active Record gives us several mechanisms, the most important being the ability to:&lt;br /&gt;
:Represent models and their data.&lt;br /&gt;
:Represent associations between these models.&lt;br /&gt;
:Represent inheritance hierarchies through related models.&lt;br /&gt;
:Validate models before they get persisted to the database.&lt;br /&gt;
:Perform database operations in an object-oriented fashion.&lt;br /&gt;
&lt;br /&gt;
== '''Object-relational impedance mismatch''' ==&lt;br /&gt;
&lt;br /&gt;
The relational model on which Active Record relies on takes data and separates it into many interrelated tables that contain rows and columns. Tables reference each other through foreign keys that are stored in columns as well.  When looking up data, the desired information needs to be collected from many tables (often hundreds in today’s enterprise applications) and combined before it can be provided to the application. Similarly, when writing data, the write needs to be coordinated and performed on many tables.&lt;br /&gt;
&lt;br /&gt;
The Active Record pattern describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. The pattern has numerous limitations referred to as the Object-relational impedance mismatch. Some of these technical difficulties are structural. In Object Oriented programming, objects may be composed of other objects. The Active Record pattern maps these sub-objects to separate tables, thus introducing issues concerning the representation of relationships and encapsulated data. Active Record uses macros to create relationships between objects and single table inheritance to represent inheritance.&lt;br /&gt;
&lt;br /&gt;
Active Record is a solution for the Object-relational impedance mismatch, but this is assuming the datastore is relational. It’s also, fundamentally, a hack.&lt;br /&gt;
&lt;br /&gt;
== '''Non Relational Databases''' ==&lt;br /&gt;
=== '''Object Database''' ===&lt;br /&gt;
An object database also known as Object-Oriented Database Management System (OODBMS) is a Database Management System (DBMS) which allows information to be represented in the form of objects as used in object-oriented programming. OODBMSs provide an integrated application development environment by joining object-oriented programming with database technology. OODBMSs enforces object oriented programming concepts such as encapsulation, polymorphism and inheritance as well as database management concepts such as Atomicity, Consistency, Isolation and Durability. Since both the programming languages and OODBMS use the same object-oriented model, the programmers can maintain the consistency easily between the two environments.&lt;br /&gt;
&lt;br /&gt;
==== '''Comparing RDBMS with Object Database''' ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Criteria !! RDBMS !! OODBMS&lt;br /&gt;
|-&lt;br /&gt;
| Object-oriented programming support || Poor || Extensive&lt;br /&gt;
|-&lt;br /&gt;
| Ease of Use || Table schemas easy to understand for everyone || Good for Programmers only&lt;br /&gt;
|-&lt;br /&gt;
| Ease in development || Independent from application || Objects are a natural way to model, can incorporate types and relationships&lt;br /&gt;
|-&lt;br /&gt;
| Extensiblity || Low || High&lt;br /&gt;
|-&lt;br /&gt;
| Data relationships || Hard to model || Easy to handle&lt;br /&gt;
|-&lt;br /&gt;
| Maturity || Very Mature || Relatively Mature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== '''No-SQL Databases''' ===&lt;br /&gt;
A NoSQL database provides a mechanism for storage and retrieval of data that is less constrained in its consistency models than traditional Relational Databases.&lt;br /&gt;
&lt;br /&gt;
NoSQL encompasses a wide variety of different database technologies but generally all NoSQL databases have a few features in common.&lt;br /&gt;
*'''Dynamic Schemas'''&lt;br /&gt;
Relational databases require that schemas be defined before you can add data. This fits poorly with agile development approaches, because each time you complete new features, the schema of your database often needs to change. Furthermore, if the database is large, this is a very slow process that involves significant downtime.&lt;br /&gt;
In contrast NoSQL databases are built to allow the insertion of data without a predefined schema. That makes it easy to make significant application changes in real-time, without worrying about service interruptions – which means development is faster, code integration is more reliable, and less database administrator time is needed.&lt;br /&gt;
*'''Sharding, Replication and Caching'''&lt;br /&gt;
Because of the way they are structured, relational databases usually scale vertically. This gets expensive quickly, places limits on scale and is failure prone. &lt;br /&gt;
The solution is to scale horizontally, by adding servers instead of concentrating more capacity in a single server. NoSQL databases usually support auto-sharding, automatic replication, meaning that you get high availability and finally caching capabilities.&lt;br /&gt;
&lt;br /&gt;
NoSQL Database Types&lt;br /&gt;
:Document databases &lt;br /&gt;
:Graph stores&lt;br /&gt;
:Key-value stores&lt;br /&gt;
:Wide-column stores&lt;br /&gt;
&lt;br /&gt;
==== '''Comparing No-SQL DB with RDBMS'''&amp;lt;ref&amp;gt;http://www.couchbase.com/why-nosql/nosql-database&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
Relational and Object database models are very different. &lt;br /&gt;
For example, a document-oriented database takes the data you want to store and aggregates it into documents using the JSON format. Each JSON document can be thought of as an object to be used by your application. A JSON document might, for example, take all the data stored in a row that spans 20 tables of a relational database and aggregate it into a single document/object. Aggregating this information may lead to duplication of  information, but since storage is no longer cost prohibitive, the resulting data model flexibility, ease of efficiently distributing the resulting documents and read and write performance improvements make it an easy trade-off for web-based applications.&lt;br /&gt;
&lt;br /&gt;
[[File:nosqlvsrdbms.jpg|frame|none|alt=Document Object Model equivalent to Relational tables|Document Object Model equivalent to Relational tables]]&lt;br /&gt;
&lt;br /&gt;
Another major difference is that relational databases have rigid schemas. Relational databases requires strict definition of a schema prior to storing any data into a database. Changing the schema once data is inserted is a big deal, extremely disruptive and frequently avoided.&lt;br /&gt;
In comparison, document databases are schemaless, allowing you to freely add fields to JSON documents without having to first define changes. The format of the data being inserted can be changed at any time, without application disruption.&lt;br /&gt;
&lt;br /&gt;
== '''Examples in Rails Apps''' ==&lt;br /&gt;
&lt;br /&gt;
In this section we will see how to incorporate two Document Object Databases MongoDB and CouchDB in a rails application. We will also explore Embedding and Nesting for models to better exhibit their use.&lt;br /&gt;
&lt;br /&gt;
=== '''MongoDB'''&amp;lt;ref&amp;gt;http://docs.mongodb.org/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
MongoDB is a document database that provides high performance, high availability, and easy scalability. Key features:&lt;br /&gt;
*'''Flexibility'''&lt;br /&gt;
MongoDB stores data in JSON documents (which we serialize to BSON). JSON provides a rich data model that seamlessly maps to native programming language types, and the dynamic schema makes it easier to evolve your data model than with a system with enforced schemas such as a RDBMS.&lt;br /&gt;
*'''Power'''&lt;br /&gt;
MongoDB provides a lot of the features of a traditional RDBMS such as secondary indexes, dynamic queries, sorting, rich updates, upserts (update if document exists, insert if it doesn’t), and easy aggregation. This gives you the breadth of functionality that you are used to from an RDBMS, with the flexibility and scaling capability that the non-relational model allows.&lt;br /&gt;
*'''Speed/Scaling'''&lt;br /&gt;
By keeping related data together in documents, queries can be much faster than in a relational database where related data is separated into multiple tables and then needs to be joined later. MongoDB also makes it easy to scale out your database. Autosharding allows you to scale your cluster linearly by adding more machines. It is possible to increase capacity without any downtime, which is very important on the web when load can increase suddenly and can bring down the website. Thus leading to extended maintenance which can cost large amounts of revenue.&lt;br /&gt;
*'''Ease of use'''&lt;br /&gt;
MongoDB works hard to be very easy to install, configure, maintain, and use. To this end, MongoDB provides few configuration options, and instead tries to automatically do the “right thing” whenever possible. This means that MongoDB works right out of the box, and you can dive right into developing your application, instead of spending a lot of time fine-tuning obscure database configurations.&lt;br /&gt;
&lt;br /&gt;
A MongoDB deployment hosts a number of databases. A database holds a set of collections. A collection holds a set of documents. A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.&lt;br /&gt;
&lt;br /&gt;
MongoDB stores all data in documents, which are JSON-style data structures composed of field-and-value pairs:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{ &amp;quot;item&amp;quot;: &amp;quot;pencil&amp;quot;, &amp;quot;qty&amp;quot;: 500, &amp;quot;type&amp;quot;: &amp;quot;no.2&amp;quot; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MongoDB stores documents on disk in the BSON serialization format. BSON is a binary representation of JSON documents, though contains more data types than does JSON&lt;br /&gt;
&lt;br /&gt;
MongoMapper and Mongoid are the two leading gems that make it possible to use MongoDB as a datastore with Rails. MongoMapper is a simple ORM for MongoDB. Mongoid’s goal is to provide a familiar API to Active Record, while still leveraging MongoDB’s advantages of schema flexibility, document design, atomic modifiers, and rich query interface.&lt;br /&gt;
&lt;br /&gt;
==== '''MongoDB in Rails'''&amp;lt;ref&amp;gt;http://docs.mongodb.org/ecosystem/tutorial/model-data-for-ruby-on-rails/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Firstly to create a new Rails app using MongoDB we need to ensure we create it without active record and install the necessary gems outlined before.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; rails new my_app --skip-active-record&lt;br /&gt;
&amp;gt; cd my_app&lt;br /&gt;
&amp;gt; gem install mongo&lt;br /&gt;
&amp;gt; gem install bson&lt;br /&gt;
&amp;gt; gem install bson_ext&lt;br /&gt;
&amp;gt; gem install mongomapper&lt;br /&gt;
&amp;gt; gem install mongoid&lt;br /&gt;
&amp;gt; rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rails model files are altered to not have the classes inherit from ActiveRecord::Base, instead must include a module MongoMapper::Document, and define the schema in the actual file. Database migrations are not necessary.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Story&lt;br /&gt;
 include MongoMapper::Document&lt;br /&gt;
&lt;br /&gt;
 key :title,     String&lt;br /&gt;
 key :url,       String&lt;br /&gt;
 key :voters,    Array&lt;br /&gt;
 key :votes,     Integer, :default =&amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
 # Cached values.&lt;br /&gt;
 key :comment_count, Integer, :default =&amp;gt; 0&lt;br /&gt;
 key :username,      String&lt;br /&gt;
&lt;br /&gt;
 # Note this: ids are of class ObjectId.&lt;br /&gt;
 key :user_id,   ObjectId&lt;br /&gt;
 timestamps!&lt;br /&gt;
&lt;br /&gt;
 # Relationships.&lt;br /&gt;
 belongs_to :user&lt;br /&gt;
&lt;br /&gt;
 # Validations.&lt;br /&gt;
 validates_presence_of :title, :url, :user_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, you have a number of configuration options available, such as allow_dynamic_fields that allows you to define attributes on an object that aren’t in the model file’s schema. You can then add some logic in your model file if you need to do something different depending on the existence or absence of this field.&lt;br /&gt;
&lt;br /&gt;
For fast lookups, we can create an index on this field. In the MongoDB shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
db.courses.ensureIndex('voters');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To find all the Courses by name:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Course.all(:conditions =&amp;gt; {:name =&amp;gt; @suject.name})&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''Embedding'''&amp;lt;ref&amp;gt;http://docs.mongodb.org/ecosystem/tutorial/model-data-for-ruby-on-rails/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
Now we will see how we can acheive embedding in a Rails App that uses MongoDB. We do this by example, incorporating comments into the Story example illustrated above.&lt;br /&gt;
In a relational database, comments are usually given their own table, related by foreign key to some parent table. This approach is occasionally necessary in MongoDB; however, it’s always best to try to embed first, as this will achieve greater query efficiency.&lt;br /&gt;
&lt;br /&gt;
*'''Linear Comments'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Story&lt;br /&gt;
  include MongoMapper::Document&lt;br /&gt;
  many :comments&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
 class Comment&lt;br /&gt;
  include MongoMapper::EmbeddedDocument&lt;br /&gt;
  key :body, String&lt;br /&gt;
&lt;br /&gt;
  belongs_to :story&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we were using the Ruby driver alone, we could save our structure like so:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@stories  = @db.collection('stories')&lt;br /&gt;
@document = {:title =&amp;gt; &amp;quot;MongoDB on Rails&amp;quot;,&lt;br /&gt;
             :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Revelatory! Loved it!&amp;quot;,&lt;br /&gt;
                            :username =&amp;gt; &amp;quot;Matz&amp;quot;&lt;br /&gt;
                           }&lt;br /&gt;
                          ]&lt;br /&gt;
            }&lt;br /&gt;
@stories.save(@document)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Nested Comments'''&lt;br /&gt;
To build threaded comments:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@stories  = @db.collection('stories')&lt;br /&gt;
@document = {:title =&amp;gt; &amp;quot;MongoDB on Rails&amp;quot;,&lt;br /&gt;
             :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Revelatory! Loved it!&amp;quot;,&lt;br /&gt;
                            :username =&amp;gt; &amp;quot;Matz&amp;quot;,&lt;br /&gt;
                            :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Agreed.&amp;quot;,&lt;br /&gt;
                                           :username =&amp;gt; &amp;quot;rubydev29&amp;quot;&lt;br /&gt;
                                          }&lt;br /&gt;
                                         ]&lt;br /&gt;
                           }&lt;br /&gt;
                          ]&lt;br /&gt;
            }&lt;br /&gt;
@stories.save(@document)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can also represent comments as their own collection. Relative to the other options, this incurs a small performance penalty while granting us the greatest flexibility. The tree structure can be represented by storing the unique path for each leaf.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Comment&lt;br /&gt;
  include MongoMapper::Document&lt;br /&gt;
&lt;br /&gt;
  key :body,       String&lt;br /&gt;
  key :depth,      Integer, :default =&amp;gt; 0&lt;br /&gt;
  key :path,       String,  :default =&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  # Note: we're intentionally storing parent_id as a string&lt;br /&gt;
  key :parent_id,  String&lt;br /&gt;
  key :story_id,   ObjectId&lt;br /&gt;
  timestamps!&lt;br /&gt;
&lt;br /&gt;
  # Relationships.&lt;br /&gt;
  belongs_to :story&lt;br /&gt;
&lt;br /&gt;
  # Callbacks.&lt;br /&gt;
  after_create :set_path&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Store the comment's path.&lt;br /&gt;
  def set_path&lt;br /&gt;
  ....&lt;br /&gt;
    end&lt;br /&gt;
    save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== '''CouchDB''' ===&lt;br /&gt;
CouchDB is often categorized as a “NoSQL” database. A CouchDB database lacks a schema, or rigid pre-defined data structures such as tables. &lt;br /&gt;
A CouchDB server hosts named databases stores documents. Data stored in CouchDB is a JSON document(s). The structure of the data, or document(s), can change dynamically to accommodate evolving needs. Each document is uniquely named in the database, and CouchDB provides a RESTful HTTP API for reading and updating (add, edit, delete) database documents.&lt;br /&gt;
Documents are the primary unit of data in CouchDB and consist of any number of fields and attachments. Documents also include metadata that’s maintained by the database system. Document fields are uniquely named and contain values of varying types (text, number, boolean, lists, etc), and there is no set limit to text size or element count.&lt;br /&gt;
User can just chuck arbitrary JSON objects up at this thing and it’ll store it. No setup, no schemas, no nothing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Key Charachteristics&lt;br /&gt;
&lt;br /&gt;
*'''Documents'''&lt;br /&gt;
A CouchDB document is a JSON object that consists of named fields. Field values may be strings, numbers, dates, or even ordered lists and associative maps. An example of a document would be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;Subject&amp;quot;: &amp;quot;Foo Bar&amp;quot;,&lt;br /&gt;
    &amp;quot;Author&amp;quot;: &amp;quot;John Doe&amp;quot;,&lt;br /&gt;
    &amp;quot;PostedDate&amp;quot;: &amp;quot;10/7/2013&amp;quot;,&lt;br /&gt;
    &amp;quot;Tags&amp;quot;: [&amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;],&lt;br /&gt;
    &amp;quot;Body&amp;quot;: &amp;quot;Lorem Ipsum...&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A CouchDB database is a flat collection of these documents. Each document is identified by a unique ID.&lt;br /&gt;
&lt;br /&gt;
*'''Views'''&lt;br /&gt;
To address this problem of adding structure back to semi-structured data, CouchDB integrates a view model using JavaScript for description. Views are the method of aggregating and reporting on the documents in a database, and are built on-demand to aggregate, join and report on database documents. Views are built dynamically and don’t affect the underlying document; you can have as many different view representations of the same data as you like. Incremental updates to documents do not require full re-indexing of views.&lt;br /&gt;
&lt;br /&gt;
*'''Schema Free'''&lt;br /&gt;
Unlike SQL databases, which are designed to store and report on highly structured, interrelated data, CouchDB is designed to store and report on large amounts of semi-structured, document oriented data. CouchDB greatly simplifies the development of document oriented applications, such as collaborative web applications.&lt;br /&gt;
&lt;br /&gt;
In an SQL database, the schema and storage of the existing data must be updated as needs evolve. With CouchDB, no schema is required, so new document types with new meaning can be safely added alongside the old. However, for applications requiring robust validation of new documents custom validation functions are possible. The view engine is designed to easily handle new document types and disparate but similar documents.&lt;br /&gt;
&lt;br /&gt;
*'''Distributed'''&lt;br /&gt;
CouchDB is a peer based distributed database system. Any number of CouchDB hosts (servers and offline-clients) can have independent &amp;quot;replica copies&amp;quot; of the same database, where applications have full database interactivity (query, add, edit, delete). When back online or on a schedule, database changes can be replicated bi-directionally.&lt;br /&gt;
&lt;br /&gt;
CouchDB has built-in conflict detection and management and the replication process is incremental and fast, copying only documents changed since the previous replication. Most applications require no special planning to take advantage of distributed updates and replication.&lt;br /&gt;
&lt;br /&gt;
==== '''CouchDB on Rails'''&amp;lt;ref&amp;gt;http://www.couchrest.info/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
Installing CouchDB.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install couchdb -y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or we can use the many pre compiled binaries on the CouchDB website.&lt;br /&gt;
&lt;br /&gt;
After installation, check if everything works fine by sending a curl request &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ curl http://localhost:5984&lt;br /&gt;
&lt;br /&gt;
{&amp;quot;couchdb&amp;quot;:&amp;quot;Welcome&amp;quot;,&amp;quot;version&amp;quot;:&amp;quot;1.1.1&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now install the Couchrest gem for ruby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install couchrest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To create a new model, we need to define a class that inherits from the CouchRest::Model::Base class in much the same way as an ActiveRecord model. Unlike a regular database mapper, CouchRest Model requires you to define the properties or attributes your model needs to use directly in the class. There are no migrations or automatic column detection in a Document Database. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person &amp;lt; CouchRest::Model::Base&lt;br /&gt;
  use_database 'people'&lt;br /&gt;
  property :first_name, String&lt;br /&gt;
  property :last_name, String&lt;br /&gt;
  timestamps!&lt;br /&gt;
  belongs_to :person&lt;br /&gt;
  collection_of :tags&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
CouchDB is accessed via HTTP requests, as such, there is no requirement to create a binary connection to a specific database. The use_database method tells the model which database it should use. This can be provided as a CouchRest::Database object or as simple string that will be concatenated to the connection prefix. A special property macro is available called timestamps! that will create the created_at and updated_at accessors.&lt;br /&gt;
&lt;br /&gt;
As you’d expect, CouchRest Model supports all the standard CRUD operations you’re used to in other object mappers. CouchRest Model supports a few basic queries for retrieving your data from the database.&lt;br /&gt;
&lt;br /&gt;
==== '''Embedding'''&amp;lt;ref&amp;gt;http://www.couchrest.info/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
The CouchRest Model Embeddable module allows you to take full advantage of CouchDB’s ability to store complex documents and retrieve them. Simply include the module in a Class and set any properties you’d like to use.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class CatToy&lt;br /&gt;
  include CouchRest::Model::Embeddable&lt;br /&gt;
&lt;br /&gt;
  property :name, String&lt;br /&gt;
  property :purchased, Date&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Cat &amp;lt; CouchRest::Model::Base&lt;br /&gt;
  property :name, String&lt;br /&gt;
  property :toys, CatToy, :array =&amp;gt; true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
@cat = Cat.new(:name =&amp;gt; 'Felix', :toys =&amp;gt; [{:name =&amp;gt; 'mouse', :purchased =&amp;gt; 1.month.ago}])&lt;br /&gt;
@cat.toys.first.class == CatToy&lt;br /&gt;
@cat.toys.first.name == 'mouse'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
While Active Record's ORM is most prevelant other forms of databases provide considerable advantage over RDBMS. Other alternatives help us address issues such as scalability, flexibility and are more in-tune with the Cloud model of deploying apps.&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://mongoid.org/en/mongoid/index.html&lt;br /&gt;
*http://mongomapper.com/&lt;br /&gt;
*http://en.wikipedia.org/wiki/Object_database&lt;br /&gt;
*http://www.mongodb.org/&lt;br /&gt;
*http://couchdb.apache.org/&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sagarn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79930</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w44 s</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79930"/>
		<updated>2013-10-08T00:28:08Z</updated>

		<summary type="html">&lt;p&gt;Sagarn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Non-relational Databases in Rails Applications''' ==&lt;br /&gt;
&lt;br /&gt;
Active Record is basic to Rails and it is responsible to for allowing programs to treat records in relational dbs as objects. It employs Object-Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. While Active Record is efficient in what it does, the complexities of ORM make way for a new approach for databases with rails, that is to move to different Database Models namely Object-Oriented Databases and No-SQL Databases.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Overview''' ==&lt;br /&gt;
Rails, as a web development framework, and Ruby, as a programming language, can be used with a choice of operating systems (Linux, Mac OS X, Windows), databases (SQLite, MySQL, PostgreSQL, and others), and web servers (Apache, Nginx, and others).&lt;br /&gt;
The Rails stack can also include a variety of software libraries (gems) that add features to a website or make development easier. Sometimes the choice of components in a stack is driven by the requirements of an application&lt;br /&gt;
&lt;br /&gt;
Rails uses the Active Record pattern which describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. &lt;br /&gt;
&lt;br /&gt;
Active Record is the layer of the system responsible for representing business data and logic. It facilitates the creation and use of business objects whose data requires persistent storage to a database. It employs Object-Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. Using ORM, the properties and relationships of the objects in an application can be easily stored and retrieved from a database without writing SQL statements directly and with less overall database access code.&lt;br /&gt;
&lt;br /&gt;
Active Record gives us several mechanisms, the most important being the ability to:&lt;br /&gt;
:Represent models and their data.&lt;br /&gt;
:Represent associations between these models.&lt;br /&gt;
:Represent inheritance hierarchies through related models.&lt;br /&gt;
:Validate models before they get persisted to the database.&lt;br /&gt;
:Perform database operations in an object-oriented fashion.&lt;br /&gt;
&lt;br /&gt;
== '''Object-relational impedance mismatch''' ==&lt;br /&gt;
&lt;br /&gt;
The relational model on which Active Record relies on takes data and separates it into many interrelated tables that contain rows and columns. Tables reference each other through foreign keys that are stored in columns as well.  When looking up data, the desired information needs to be collected from many tables (often hundreds in today’s enterprise applications) and combined before it can be provided to the application. Similarly, when writing data, the write needs to be coordinated and performed on many tables.&lt;br /&gt;
&lt;br /&gt;
The Active Record pattern describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. The pattern has numerous limitations referred to as the Object-relational impedance mismatch. Some of these technical difficulties are structural. In OO programming, objects may be composed of other objects. The Active Record pattern maps these sub-objects to separate tables, thus introducing issues concerning the representation of relationships and encapsulated data. Active Record uses macros to create relationships between objects and single table inheritance to represent inheritance.&lt;br /&gt;
&lt;br /&gt;
Active Record is a solution for the Object-relational impedance mismatch, but this is assuming the datastore is relational. It’s also, fundamentally, a hack.&lt;br /&gt;
&lt;br /&gt;
== '''Non Relational Databases''' ==&lt;br /&gt;
=== '''Object Database''' ===&lt;br /&gt;
An object database (also object-oriented database management system). Object-Oriented Database Management System (OODBMS) is a Database Management System (DBMS) which allows information to be represented in the form of objects as used in object-oriented programming. OODBMSs provide an integrated application development environment by joining object-oriented programming with database technology. OODBMSs enforce object oriented programming concepts such as encapsulation, polymorphism and inheritance as well as database management concepts such as Atomicity, Consistency, Isolation and Durability. Since both the programming language and OODBMS use the same object-oriented model, the programmers can maintain the consistency easily between the two environments.&lt;br /&gt;
&lt;br /&gt;
==== '''Comparing RDBMS with Object Database''' ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Criteria !! RDBMS !! OODBMS&lt;br /&gt;
|-&lt;br /&gt;
| Object-oriented programming support || Poor || Extensive&lt;br /&gt;
|-&lt;br /&gt;
| Ease of Use || Table schemas easy to understand for everyone || Good for Programmers only&lt;br /&gt;
|-&lt;br /&gt;
| Ease in development || Independent from application || Objects are a natural way to model, can incorporate types and relationships&lt;br /&gt;
|-&lt;br /&gt;
| Extensiblity || Low || High&lt;br /&gt;
|-&lt;br /&gt;
| Data relationships || Hard to model || Easy to handle&lt;br /&gt;
|-&lt;br /&gt;
| Maturity || Very Mature || Relatively Mature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== '''No-SQL Databases''' ===&lt;br /&gt;
A NoSQL database provides a mechanism for storage and retrieval of data that is less constrained in its consistency models than traditional Relational Databases.&lt;br /&gt;
&lt;br /&gt;
NoSQL encompasses a wide variety of different database technologies but generally all NoSQL databases have a few features in common.&lt;br /&gt;
*'''Dynamic Schemas'''&lt;br /&gt;
Relational databases require that schemas be defined before you can add data. This fits poorly with agile development approaches, because each time you complete new features, the schema of your database often needs to change. Furthermore, if the database is large, this is a very slow process that involves significant downtime.&lt;br /&gt;
In contrast NoSQL databases are built to allow the insertion of data without a predefined schema. That makes it easy to make significant application changes in real-time, without worrying about service interruptions – which means development is faster, code integration is more reliable, and less database administrator time is needed.&lt;br /&gt;
*'''Sharding, Replication and Caching'''&lt;br /&gt;
Because of the way they are structured, relational databases usually scale vertically. his gets expensive quickly, places limits on scale nad is failure prone. &lt;br /&gt;
The solution is to scale horizontally, by adding servers instead of concentrating more capacity in a single server. NoSQL databases usually support auto-sharding, automatic replication, meaning that you get high availability and finally caching capabilities.&lt;br /&gt;
&lt;br /&gt;
NoSQL Database Types&lt;br /&gt;
:Document databases &lt;br /&gt;
:Graph stores&lt;br /&gt;
:Key-value stores&lt;br /&gt;
:Wide-column stores&lt;br /&gt;
&lt;br /&gt;
==== '''Comparing No-SQL DB with RDBMS'''&amp;lt;ref&amp;gt;http://www.couchbase.com/why-nosql/nosql-database&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
Relational and Object database models are very different. &lt;br /&gt;
For example, a document-oriented database takes the data you want to store and aggregates it into documents using the JSON format. Each JSON document can be thought of as an object to be used by your application. A JSON document might, for example, take all the data stored in a row that spans 20 tables of a relational database and aggregate it into a single document/object. Aggregating this information may lead to duplication of  information, but since storage is no longer cost prohibitive, the resulting data model flexibility, ease of efficiently distributing the resulting documents and read and write performance improvements make it an easy trade-off for web-based applications.&lt;br /&gt;
&lt;br /&gt;
[[File:nosqlvsrdbms.jpg|frame|none|alt=Document Object Model equivalent to Relational tables|Document Object Model equivalent to Relational tables]]&lt;br /&gt;
&lt;br /&gt;
Another major difference is that relational technologies have rigid schemas. Relational technology requires strict definition of a schema prior to storing any data into a database. Changing the schema once data is inserted is a big deal, extremely disruptive and frequently avoided.&lt;br /&gt;
In comparison, document databases are schemaless, allowing you to freely add fields to JSON documents without having to first define changes. The format of the data being inserted can be changed at any time, without application disruption.&lt;br /&gt;
&lt;br /&gt;
== '''Examples in Rails Apps''' ==&lt;br /&gt;
&lt;br /&gt;
In this section we will see how to incorporate two Document Object Databases MongoDB and CouchDB it a rails app. We will also explore Embedding and Nesting for models to better exhibit their use.&lt;br /&gt;
&lt;br /&gt;
=== '''MongoDB'''&amp;lt;ref&amp;gt;http://docs.mongodb.org/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
MongoDB is a document database that provides high performance, high availability, and easy scalability. Key features:&lt;br /&gt;
*'''Flexibility'''&lt;br /&gt;
MongoDB stores data in JSON documents (which we serialize to BSON). JSON provides a rich data model that seamlessly maps to native programming language types, and the dynamic schema makes it easier to evolve your data model than with a system with enforced schemas such as a RDBMS.&lt;br /&gt;
*'''Power'''&lt;br /&gt;
MongoDB provides a lot of the features of a traditional RDBMS such as secondary indexes, dynamic queries, sorting, rich updates, upserts (update if document exists, insert if it doesn’t), and easy aggregation. This gives you the breadth of functionality that you are used to from an RDBMS, with the flexibility and scaling capability that the non-relational model allows.&lt;br /&gt;
*'''Speed/Scaling'''&lt;br /&gt;
By keeping related data together in documents, queries can be much faster than in a relational database where related data is separated into multiple tables and then needs to be joined later. MongoDB also makes it easy to scale out your database. Autosharding allows you to scale your cluster linearly by adding more machines. It is possible to increase capacity without any downtime, which is very important on the web when load can increase suddenly and bringing down the website for extended maintenance can cost your business large amounts of revenue.&lt;br /&gt;
*'''Ease of use'''&lt;br /&gt;
MongoDB works hard to be very easy to install, configure, maintain, and use. To this end, MongoDB provides few configuration options, and instead tries to automatically do the “right thing” whenever possible. This means that MongoDB works right out of the box, and you can dive right into developing your application, instead of spending a lot of time fine-tuning obscure database configurations.&lt;br /&gt;
&lt;br /&gt;
A MongoDB deployment hosts a number of databases. A database holds a set of collections. A collection holds a set of documents. A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.&lt;br /&gt;
&lt;br /&gt;
MongoDB stores all data in documents, which are JSON-style data structures composed of field-and-value pairs:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{ &amp;quot;item&amp;quot;: &amp;quot;pencil&amp;quot;, &amp;quot;qty&amp;quot;: 500, &amp;quot;type&amp;quot;: &amp;quot;no.2&amp;quot; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MongoDB stores documents on disk in the BSON serialization format. BSON is a binary representation of JSON documents, though contains more data types than does JSON&lt;br /&gt;
&lt;br /&gt;
MongoMapper and Mongoid are the two leading gems that make it possible use MongoDB as a datastore with Rails. MongoMapper is a simple ORM for MongoDB. Mongoid’s goal is to provide a familiar API to Active Record, while still leveraging MongoDB’s schema flexibility, document design, atomic modifiers, and rich query interface.&lt;br /&gt;
&lt;br /&gt;
==== '''MongoDB in Rails'''&amp;lt;ref&amp;gt;http://docs.mongodb.org/ecosystem/tutorial/model-data-for-ruby-on-rails/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Firstly to create a new Rails app using MongoDB we need to ensure we create it without active record and install the necessary gems outlines before.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; rails new my_app --skip-active-record&lt;br /&gt;
&amp;gt; cd my_app&lt;br /&gt;
&amp;gt; gem install mongo&lt;br /&gt;
&amp;gt; gem install bson&lt;br /&gt;
&amp;gt; gem install bson_ext&lt;br /&gt;
&amp;gt; gem install mongomapper&lt;br /&gt;
&amp;gt; gem install mongoid&lt;br /&gt;
&amp;gt; rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rails model files are altered to not have the classes inherit from ActiveRecord::Base, must include a module MongoMapper::Document, and define the schema in the actual file. Database migrations are not necessary.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Story&lt;br /&gt;
 include MongoMapper::Document&lt;br /&gt;
&lt;br /&gt;
 key :title,     String&lt;br /&gt;
 key :url,       String&lt;br /&gt;
 key :voters,    Array&lt;br /&gt;
 key :votes,     Integer, :default =&amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
 # Cached values.&lt;br /&gt;
 key :comment_count, Integer, :default =&amp;gt; 0&lt;br /&gt;
 key :username,      String&lt;br /&gt;
&lt;br /&gt;
 # Note this: ids are of class ObjectId.&lt;br /&gt;
 key :user_id,   ObjectId&lt;br /&gt;
 timestamps!&lt;br /&gt;
&lt;br /&gt;
 # Relationships.&lt;br /&gt;
 belongs_to :user&lt;br /&gt;
&lt;br /&gt;
 # Validations.&lt;br /&gt;
 validates_presence_of :title, :url, :user_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, you have a number of configuration options available, such as allow_dynamic_fields that allows you to define attributes on an object that aren’t in the model file’s schema. You can then add some logic in your model file if you need to do something different depending on the existence or absence of this field.&lt;br /&gt;
&lt;br /&gt;
For fast lookups, we can create an index on this field. In the MongoDB shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
db.courses.ensureIndex('voters');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To find all the Courses by name:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Course.all(:conditions =&amp;gt; {:name =&amp;gt; @suject.name})&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== '''Embedding'''&amp;lt;ref&amp;gt;http://docs.mongodb.org/ecosystem/tutorial/model-data-for-ruby-on-rails/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
Now we will see how we can acheive embedding in a Rails App that uses MongoDB. We do this by example, incorporating comments into the Story example illustrated above.&lt;br /&gt;
In a relational database, comments are usually given their own table, related by foreign key to some parent table. This approach is occasionally necessary in MongoDB; however, it’s always best to try to embed first, as this will achieve greater query efficiency.&lt;br /&gt;
&lt;br /&gt;
*'''Linear Comments'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Story&lt;br /&gt;
  include MongoMapper::Document&lt;br /&gt;
  many :comments&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
 class Comment&lt;br /&gt;
  include MongoMapper::EmbeddedDocument&lt;br /&gt;
  key :body, String&lt;br /&gt;
&lt;br /&gt;
  belongs_to :story&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we were using the Ruby driver alone, we could save our structure like so:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@stories  = @db.collection('stories')&lt;br /&gt;
@document = {:title =&amp;gt; &amp;quot;MongoDB on Rails&amp;quot;,&lt;br /&gt;
             :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Revelatory! Loved it!&amp;quot;,&lt;br /&gt;
                            :username =&amp;gt; &amp;quot;Matz&amp;quot;&lt;br /&gt;
                           }&lt;br /&gt;
                          ]&lt;br /&gt;
            }&lt;br /&gt;
@stories.save(@document)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Nested Comments'''&lt;br /&gt;
To build threaded comments:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@stories  = @db.collection('stories')&lt;br /&gt;
@document = {:title =&amp;gt; &amp;quot;MongoDB on Rails&amp;quot;,&lt;br /&gt;
             :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Revelatory! Loved it!&amp;quot;,&lt;br /&gt;
                            :username =&amp;gt; &amp;quot;Matz&amp;quot;,&lt;br /&gt;
                            :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Agreed.&amp;quot;,&lt;br /&gt;
                                           :username =&amp;gt; &amp;quot;rubydev29&amp;quot;&lt;br /&gt;
                                          }&lt;br /&gt;
                                         ]&lt;br /&gt;
                           }&lt;br /&gt;
                          ]&lt;br /&gt;
            }&lt;br /&gt;
@stories.save(@document)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can also represent comments as their own collection. Relative to the other options, this incurs a small performance penalty while granting us the greatest flexibility. The tree structure can be represented by storing the unique path for each leaf.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Comment&lt;br /&gt;
  include MongoMapper::Document&lt;br /&gt;
&lt;br /&gt;
  key :body,       String&lt;br /&gt;
  key :depth,      Integer, :default =&amp;gt; 0&lt;br /&gt;
  key :path,       String,  :default =&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  # Note: we're intentionally storing parent_id as a string&lt;br /&gt;
  key :parent_id,  String&lt;br /&gt;
  key :story_id,   ObjectId&lt;br /&gt;
  timestamps!&lt;br /&gt;
&lt;br /&gt;
  # Relationships.&lt;br /&gt;
  belongs_to :story&lt;br /&gt;
&lt;br /&gt;
  # Callbacks.&lt;br /&gt;
  after_create :set_path&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Store the comment's path.&lt;br /&gt;
  def set_path&lt;br /&gt;
  ....&lt;br /&gt;
    end&lt;br /&gt;
    save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== '''CouchDB''' ===&lt;br /&gt;
CouchDB is often categorized as a “NoSQL” database. A CouchDB database lacks a schema, or rigid pre-defined data structures such as tables. &lt;br /&gt;
A CouchDB server hosts named databases, which stores documents. Data stored in CouchDB is a JSON document(s). The structure of the data, or document(s), can change dynamically to accommodate evolving needs. Each document is uniquely named in the database, and CouchDB provides a RESTful HTTP API for reading and updating (add, edit, delete) database documents.&lt;br /&gt;
Documents are the primary unit of data in CouchDB and consist of any number of fields and attachments. Documents also include metadata that’s maintained by the database system. Document fields are uniquely named and contain values of varying types (text, number, boolean, lists, etc), and there is no set limit to text size or element count.&lt;br /&gt;
User can just chuck arbitrary JSON objects up at this thing and it’ll store it. No setup, no schemas, no nothing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Key Charachteristics&lt;br /&gt;
&lt;br /&gt;
*'''Documents'''&lt;br /&gt;
A CouchDB document is a JSON object that consists of named fields. Field values may be strings, numbers, dates, or even ordered lists and associative maps. An example of a document would be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;Subject&amp;quot;: &amp;quot;Foo Bar&amp;quot;,&lt;br /&gt;
    &amp;quot;Author&amp;quot;: &amp;quot;John Doe&amp;quot;,&lt;br /&gt;
    &amp;quot;PostedDate&amp;quot;: &amp;quot;10/7/2013&amp;quot;,&lt;br /&gt;
    &amp;quot;Tags&amp;quot;: [&amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;],&lt;br /&gt;
    &amp;quot;Body&amp;quot;: &amp;quot;Lorem Ipsum...&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A CouchDB database is a flat collection of these documents. Each document is identified by a unique ID.&lt;br /&gt;
&lt;br /&gt;
*'''Views'''&lt;br /&gt;
To address this problem of adding structure back to semi-structured data, CouchDB integrates a view model using JavaScript for description. Views are the method of aggregating and reporting on the documents in a database, and are built on-demand to aggregate, join and report on database documents. Views are built dynamically and don’t affect the underlying document; you can have as many different view representations of the same data as you like. Incremental updates to documents do not require full re-indexing of views.&lt;br /&gt;
&lt;br /&gt;
*'''Schema Free'''&lt;br /&gt;
Unlike SQL databases, which are designed to store and report on highly structured, interrelated data, CouchDB is designed to store and report on large amounts of semi-structured, document oriented data. CouchDB greatly simplifies the development of document oriented applications, such as collaborative web applications.&lt;br /&gt;
&lt;br /&gt;
In an SQL database, the schema and storage of the existing data must be updated as needs evolve. With CouchDB, no schema is required, so new document types with new meaning can be safely added alongside the old. However, for applications requiring robust validation of new documents custom validation functions are possible. The view engine is designed to easily handle new document types and disparate but similar documents.&lt;br /&gt;
&lt;br /&gt;
*'''Distributed'''&lt;br /&gt;
CouchDB is a peer based distributed database system. Any number of CouchDB hosts (servers and offline-clients) can have independent &amp;quot;replica copies&amp;quot; of the same database, where applications have full database interactivity (query, add, edit, delete). When back online or on a schedule, database changes can be replicated bi-directionally.&lt;br /&gt;
&lt;br /&gt;
CouchDB has built-in conflict detection and management and the replication process is incremental and fast, copying only documents changed since the previous replication. Most applications require no special planning to take advantage of distributed updates and replication.&lt;br /&gt;
&lt;br /&gt;
==== '''CouchDB on Rails'''&amp;lt;ref&amp;gt;http://www.couchrest.info/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
First of all you need install CouchDB.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install couchdb -y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or we can use the many pre compiled binaries on the CouchDB website.&lt;br /&gt;
&lt;br /&gt;
After installation, check if all work fine by curl request &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ curl http://localhost:5984&lt;br /&gt;
&lt;br /&gt;
{&amp;quot;couchdb&amp;quot;:&amp;quot;Welcome&amp;quot;,&amp;quot;version&amp;quot;:&amp;quot;1.1.1&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now install the Couchrest gem for ruby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install couchrest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To create a new model, we need to define a class that inherits from the CouchRest::Model::Base class in much the same way as an ActiveRecord model. Unlike a regular database mapper, CouchRest Model requires you to define the properties or attributes your model needs to use directly in the class. There are no migrations or automatic column detection in a Document Database. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person &amp;lt; CouchRest::Model::Base&lt;br /&gt;
  use_database 'people'&lt;br /&gt;
  property :first_name, String&lt;br /&gt;
  property :last_name, String&lt;br /&gt;
  timestamps!&lt;br /&gt;
  belongs_to :person&lt;br /&gt;
  collection_of :tags&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
CouchDB is accessed via HTTP requests, as such, there is no requirement to create a binary connection to a specific database. The use_database method tells the model which database it should use. This can be provided as a CouchRest::Database object or as simple string that will be concatenated to the connection prefix. A special property macro is available called timestamps! that will create the created_at and updated_at accessors.&lt;br /&gt;
&lt;br /&gt;
As you’d expect, CouchRest Model supports all the standard CRUD operations you’re used to in other object mappers. CouchRest Model supports a few basic queries for retrieving your data from the database.&lt;br /&gt;
&lt;br /&gt;
This is a somewhat controversial feature of CouchRest Model that some document database purists may cringe at. CouchDB does not yet povide many features to support relationships between documents but the fact of that matter is that its a very useful paradigm for modelling data systems.&lt;br /&gt;
&lt;br /&gt;
==== '''Embedding'''&amp;lt;ref&amp;gt;http://www.couchrest.info/&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
The CouchRest Model Embeddable module allows you to take full advantage of CouchDB’s ability to store complex documents and retrieve them. Simply include the module in a Class and set any properties you’d like to use.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class CatToy&lt;br /&gt;
  include CouchRest::Model::Embeddable&lt;br /&gt;
&lt;br /&gt;
  property :name, String&lt;br /&gt;
  property :purchased, Date&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Cat &amp;lt; CouchRest::Model::Base&lt;br /&gt;
  property :name, String&lt;br /&gt;
  property :toys, CatToy, :array =&amp;gt; true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
@cat = Cat.new(:name =&amp;gt; 'Felix', :toys =&amp;gt; [{:name =&amp;gt; 'mouse', :purchased =&amp;gt; 1.month.ago}])&lt;br /&gt;
@cat.toys.first.class == CatToy&lt;br /&gt;
@cat.toys.first.name == 'mouse'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
While Active Record's ORM is most prevelant other forms of databases provide considerable advantage over RDBMS. Other alternatives help us address issues such as scalability, flexibility and are more in-tune with the Cloud model of deploying apps.&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://mongoid.org/en/mongoid/index.html&lt;br /&gt;
*http://mongomapper.com/&lt;br /&gt;
*http://en.wikipedia.org/wiki/Object_database&lt;br /&gt;
*http://www.mongodb.org/&lt;br /&gt;
*http://couchdb.apache.org/&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sagarn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79915</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w44 s</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79915"/>
		<updated>2013-10-08T00:05:21Z</updated>

		<summary type="html">&lt;p&gt;Sagarn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Non-relational Databases in Rails Applications''' ==&lt;br /&gt;
&lt;br /&gt;
Active Record is basic to Rails and it is responsible to for allowing programs to treat records in relational dbs as objects. It employs Object-Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. While Active Record is efficient in what it does, the complexities of ORM make way for a new approach for databases with rails, that is to move to different Database Models namely Object-Oriented Databases and No-SQL Databases.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Overview''' ==&lt;br /&gt;
Rails, as a web development framework, and Ruby, as a programming language, can be used with a choice of operating systems (Linux, Mac OS X, Windows), databases (SQLite, MySQL, PostgreSQL, and others), and web servers (Apache, Nginx, and others).&lt;br /&gt;
The Rails stack can also include a variety of software libraries (gems) that add features to a website or make development easier. Sometimes the choice of components in a stack is driven by the requirements of an application&lt;br /&gt;
&lt;br /&gt;
Rails uses the Active Record pattern which describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. &lt;br /&gt;
&lt;br /&gt;
Active Record is the layer of the system responsible for representing business data and logic. It facilitates the creation and use of business objects whose data requires persistent storage to a database. It employs Object-Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. Using ORM, the properties and relationships of the objects in an application can be easily stored and retrieved from a database without writing SQL statements directly and with less overall database access code.&lt;br /&gt;
&lt;br /&gt;
Active Record gives us several mechanisms, the most important being the ability to:&lt;br /&gt;
:Represent models and their data.&lt;br /&gt;
:Represent associations between these models.&lt;br /&gt;
:Represent inheritance hierarchies through related models.&lt;br /&gt;
:Validate models before they get persisted to the database.&lt;br /&gt;
:Perform database operations in an object-oriented fashion.&lt;br /&gt;
&lt;br /&gt;
== '''Object-relational impedance mismatch''' ==&lt;br /&gt;
&lt;br /&gt;
The relational model on which Active Record relies on takes data and separates it into many interrelated tables that contain rows and columns. Tables reference each other through foreign keys that are stored in columns as well.  When looking up data, the desired information needs to be collected from many tables (often hundreds in today’s enterprise applications) and combined before it can be provided to the application. Similarly, when writing data, the write needs to be coordinated and performed on many tables.&lt;br /&gt;
&lt;br /&gt;
The Active Record pattern describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. The pattern has numerous limitations referred to as the Object-relational impedance mismatch. Some of these technical difficulties are structural. In OO programming, objects may be composed of other objects. The Active Record pattern maps these sub-objects to separate tables, thus introducing issues concerning the representation of relationships and encapsulated data. Active Record uses macros to create relationships between objects and single table inheritance to represent inheritance.&lt;br /&gt;
&lt;br /&gt;
Active Record is a solution for the Object-relational impedance mismatch, but this is assuming the datastore is relational. It’s also, fundamentally, a hack.&lt;br /&gt;
&lt;br /&gt;
== '''Non Relational Databases''' ==&lt;br /&gt;
=== '''Object Database''' ===&lt;br /&gt;
An object database (also object-oriented database management system). Object-Oriented Database Management System (OODBMS) is a Database Management System (DBMS) which allows information to be represented in the form of objects as used in object-oriented programming. OODBMSs provide an integrated application development environment by joining object-oriented programming with database technology. OODBMSs enforce object oriented programming concepts such as encapsulation, polymorphism and inheritance as well as database management concepts such as Atomicity, Consistency, Isolation and Durability. Since both the programming language and OODBMS use the same object-oriented model, the programmers can maintain the consistency easily between the two environments.&lt;br /&gt;
&lt;br /&gt;
==== '''Comparing RDBMS with Object Database''' ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Criteria !! RDBMS !! OODBMS&lt;br /&gt;
|-&lt;br /&gt;
| Object-oriented programming support || Poor || Extensive&lt;br /&gt;
|-&lt;br /&gt;
| Ease of Use || Table schemas easy to understand for everyone || Good for Programmers only&lt;br /&gt;
|-&lt;br /&gt;
| Ease in development || Independent from application || Objects are a natural way to model, can incorporate types and relationships&lt;br /&gt;
|-&lt;br /&gt;
| Extensiblity || Low || High&lt;br /&gt;
|-&lt;br /&gt;
| Data relationships || Hard to model || Easy to handle&lt;br /&gt;
|-&lt;br /&gt;
| Maturity || Very Mature || Relatively Mature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== '''No-SQL Databases''' ===&lt;br /&gt;
A NoSQL database provides a mechanism for storage and retrieval of data that is less constrained in its consistency models than traditional Relational Databases.&lt;br /&gt;
&lt;br /&gt;
NoSQL encompasses a wide variety of different database technologies but generally all NoSQL databases have a few features in common.&lt;br /&gt;
*'''Dynamic Schemas'''&lt;br /&gt;
Relational databases require that schemas be defined before you can add data. This fits poorly with agile development approaches, because each time you complete new features, the schema of your database often needs to change. Furthermore, if the database is large, this is a very slow process that involves significant downtime.&lt;br /&gt;
In contrast NoSQL databases are built to allow the insertion of data without a predefined schema. That makes it easy to make significant application changes in real-time, without worrying about service interruptions – which means development is faster, code integration is more reliable, and less database administrator time is needed.&lt;br /&gt;
*'''Sharding, Replication and Caching'''&lt;br /&gt;
Because of the way they are structured, relational databases usually scale vertically. his gets expensive quickly, places limits on scale nad is failure prone. &lt;br /&gt;
The solution is to scale horizontally, by adding servers instead of concentrating more capacity in a single server. NoSQL databases usually support auto-sharding, automatic replication, meaning that you get high availability and finally caching capabilities.&lt;br /&gt;
&lt;br /&gt;
NoSQL Database Types&lt;br /&gt;
:Document databases &lt;br /&gt;
:Graph stores&lt;br /&gt;
:Key-value stores&lt;br /&gt;
:Wide-column stores&lt;br /&gt;
&lt;br /&gt;
==== '''Comparing No-SQL DB with RDBMS'''&amp;lt;ref&amp;gt;http://www.couchbase.com/why-nosql/nosql-database&amp;lt;/ref&amp;gt; ====&lt;br /&gt;
Relational and Object database models are very different. &lt;br /&gt;
For example, a document-oriented database takes the data you want to store and aggregates it into documents using the JSON format. Each JSON document can be thought of as an object to be used by your application. A JSON document might, for example, take all the data stored in a row that spans 20 tables of a relational database and aggregate it into a single document/object. Aggregating this information may lead to duplication of  information, but since storage is no longer cost prohibitive, the resulting data model flexibility, ease of efficiently distributing the resulting documents and read and write performance improvements make it an easy trade-off for web-based applications.&lt;br /&gt;
&lt;br /&gt;
[[File:nosqlvsrdbms.jpg|frame|none|alt=Document Object Model equivalent to Relational tables|Document Object Model equivalent to Relational tables]]&lt;br /&gt;
&lt;br /&gt;
Another major difference is that relational technologies have rigid schemas. Relational technology requires strict definition of a schema prior to storing any data into a database. Changing the schema once data is inserted is a big deal, extremely disruptive and frequently avoided.&lt;br /&gt;
In comparison, document databases are schemaless, allowing you to freely add fields to JSON documents without having to first define changes. The format of the data being inserted can be changed at any time, without application disruption.&lt;br /&gt;
&lt;br /&gt;
== '''Examples in Rails Apps''' ==&lt;br /&gt;
&lt;br /&gt;
In this section we will see how to incorporate two Document Object Databases MongoDB and CouchDB it a rails app. We will also explore Embedding and Nesting for models to better exhibit their use.&lt;br /&gt;
&lt;br /&gt;
=== '''MongoDB''' ===&lt;br /&gt;
&lt;br /&gt;
MongoDB is a document database that provides high performance, high availability, and easy scalability. Key features:&lt;br /&gt;
*'''Flexibility'''&lt;br /&gt;
MongoDB stores data in JSON documents (which we serialize to BSON). JSON provides a rich data model that seamlessly maps to native programming language types, and the dynamic schema makes it easier to evolve your data model than with a system with enforced schemas such as a RDBMS.&lt;br /&gt;
*'''Power'''&lt;br /&gt;
MongoDB provides a lot of the features of a traditional RDBMS such as secondary indexes, dynamic queries, sorting, rich updates, upserts (update if document exists, insert if it doesn’t), and easy aggregation. This gives you the breadth of functionality that you are used to from an RDBMS, with the flexibility and scaling capability that the non-relational model allows.&lt;br /&gt;
*'''Speed/Scaling'''&lt;br /&gt;
By keeping related data together in documents, queries can be much faster than in a relational database where related data is separated into multiple tables and then needs to be joined later. MongoDB also makes it easy to scale out your database. Autosharding allows you to scale your cluster linearly by adding more machines. It is possible to increase capacity without any downtime, which is very important on the web when load can increase suddenly and bringing down the website for extended maintenance can cost your business large amounts of revenue.&lt;br /&gt;
*'''Ease of use'''&lt;br /&gt;
MongoDB works hard to be very easy to install, configure, maintain, and use. To this end, MongoDB provides few configuration options, and instead tries to automatically do the “right thing” whenever possible. This means that MongoDB works right out of the box, and you can dive right into developing your application, instead of spending a lot of time fine-tuning obscure database configurations.&lt;br /&gt;
&lt;br /&gt;
A MongoDB deployment hosts a number of databases. A database holds a set of collections. A collection holds a set of documents. A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.&lt;br /&gt;
&lt;br /&gt;
MongoDB stores all data in documents, which are JSON-style data structures composed of field-and-value pairs:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{ &amp;quot;item&amp;quot;: &amp;quot;pencil&amp;quot;, &amp;quot;qty&amp;quot;: 500, &amp;quot;type&amp;quot;: &amp;quot;no.2&amp;quot; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MongoDB stores documents on disk in the BSON serialization format. BSON is a binary representation of JSON documents, though contains more data types than does JSON&lt;br /&gt;
&lt;br /&gt;
MongoMapper and Mongoid are the two leading gems that make it possible use MongoDB as a datastore with Rails. MongoMapper is a simple ORM for MongoDB. Mongoid’s goal is to provide a familiar API to Active Record, while still leveraging MongoDB’s schema flexibility, document design, atomic modifiers, and rich query interface.&lt;br /&gt;
&lt;br /&gt;
==== '''MongoDB in Rails''' ====&lt;br /&gt;
&lt;br /&gt;
Firstly to create a new Rails app using MongoDB we need to ensure we create it without active record and install the necessary gems outlines before.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; rails new my_app --skip-active-record&lt;br /&gt;
&amp;gt; cd my_app&lt;br /&gt;
&amp;gt; gem install mongo&lt;br /&gt;
&amp;gt; gem install bson&lt;br /&gt;
&amp;gt; gem install bson_ext&lt;br /&gt;
&amp;gt; gem install mongomapper&lt;br /&gt;
&amp;gt; gem install mongoid&lt;br /&gt;
&amp;gt; rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rails model files are altered to not have the classes inherit from ActiveRecord::Base, must include a module MongoMapper::Document, and define the schema in the actual file. Database migrations are not necessary.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Story&lt;br /&gt;
 include MongoMapper::Document&lt;br /&gt;
&lt;br /&gt;
 key :title,     String&lt;br /&gt;
 key :url,       String&lt;br /&gt;
 key :voters,    Array&lt;br /&gt;
 key :votes,     Integer, :default =&amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
 # Cached values.&lt;br /&gt;
 key :comment_count, Integer, :default =&amp;gt; 0&lt;br /&gt;
 key :username,      String&lt;br /&gt;
&lt;br /&gt;
 # Note this: ids are of class ObjectId.&lt;br /&gt;
 key :user_id,   ObjectId&lt;br /&gt;
 timestamps!&lt;br /&gt;
&lt;br /&gt;
 # Relationships.&lt;br /&gt;
 belongs_to :user&lt;br /&gt;
&lt;br /&gt;
 # Validations.&lt;br /&gt;
 validates_presence_of :title, :url, :user_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, you have a number of configuration options available, such as allow_dynamic_fields that allows you to define attributes on an object that aren’t in the model file’s schema. You can then add some logic in your model file if you need to do something different depending on the existence or absence of this field.&lt;br /&gt;
&lt;br /&gt;
For fast lookups, we can create an index on this field. In the MongoDB shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
db.courses.ensureIndex('voters');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To find all the Courses by name:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Course.all(:conditions =&amp;gt; {:name =&amp;gt; @suject.name})&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In a relational database, comments are usually given their own table, related by foreign key to some parent table. This approach is occasionally necessary in MongoDB; however, it’s always best to try to embed first, as this will achieve greater query efficiency.&lt;br /&gt;
&lt;br /&gt;
*'''Linear Comments'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Story&lt;br /&gt;
  include MongoMapper::Document&lt;br /&gt;
  many :comments&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
 class Comment&lt;br /&gt;
  include MongoMapper::EmbeddedDocument&lt;br /&gt;
  key :body, String&lt;br /&gt;
&lt;br /&gt;
  belongs_to :story&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we were using the Ruby driver alone, we could save our structure like so:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@stories  = @db.collection('stories')&lt;br /&gt;
@document = {:title =&amp;gt; &amp;quot;MongoDB on Rails&amp;quot;,&lt;br /&gt;
             :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Revelatory! Loved it!&amp;quot;,&lt;br /&gt;
                            :username =&amp;gt; &amp;quot;Matz&amp;quot;&lt;br /&gt;
                           }&lt;br /&gt;
                          ]&lt;br /&gt;
            }&lt;br /&gt;
@stories.save(@document)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Nested Comments'''&lt;br /&gt;
To build threaded comments:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@stories  = @db.collection('stories')&lt;br /&gt;
@document = {:title =&amp;gt; &amp;quot;MongoDB on Rails&amp;quot;,&lt;br /&gt;
             :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Revelatory! Loved it!&amp;quot;,&lt;br /&gt;
                            :username =&amp;gt; &amp;quot;Matz&amp;quot;,&lt;br /&gt;
                            :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Agreed.&amp;quot;,&lt;br /&gt;
                                           :username =&amp;gt; &amp;quot;rubydev29&amp;quot;&lt;br /&gt;
                                          }&lt;br /&gt;
                                         ]&lt;br /&gt;
                           }&lt;br /&gt;
                          ]&lt;br /&gt;
            }&lt;br /&gt;
@stories.save(@document)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can also represent comments as their own collection. Relative to the other options, this incurs a small performance penalty while granting us the greatest flexibility. The tree structure can be represented by storing the unique path for each leaf.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Comment&lt;br /&gt;
  include MongoMapper::Document&lt;br /&gt;
&lt;br /&gt;
  key :body,       String&lt;br /&gt;
  key :depth,      Integer, :default =&amp;gt; 0&lt;br /&gt;
  key :path,       String,  :default =&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  # Note: we're intentionally storing parent_id as a string&lt;br /&gt;
  key :parent_id,  String&lt;br /&gt;
  key :story_id,   ObjectId&lt;br /&gt;
  timestamps!&lt;br /&gt;
&lt;br /&gt;
  # Relationships.&lt;br /&gt;
  belongs_to :story&lt;br /&gt;
&lt;br /&gt;
  # Callbacks.&lt;br /&gt;
  after_create :set_path&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Store the comment's path.&lt;br /&gt;
  def set_path&lt;br /&gt;
  ....&lt;br /&gt;
    end&lt;br /&gt;
    save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== '''CouchDB''' ===&lt;br /&gt;
CouchDB is often categorized as a “NoSQL” database. A CouchDB database lacks a schema, or rigid pre-defined data structures such as tables. &lt;br /&gt;
A CouchDB server hosts named databases, which stores documents. Data stored in CouchDB is a JSON document(s). The structure of the data, or document(s), can change dynamically to accommodate evolving needs. Each document is uniquely named in the database, and CouchDB provides a RESTful HTTP API for reading and updating (add, edit, delete) database documents.&lt;br /&gt;
Documents are the primary unit of data in CouchDB and consist of any number of fields and attachments. Documents also include metadata that’s maintained by the database system. Document fields are uniquely named and contain values of varying types (text, number, boolean, lists, etc), and there is no set limit to text size or element count.&lt;br /&gt;
User can just chuck arbitrary JSON objects up at this thing and it’ll store it. No setup, no schemas, no nothing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Key Charachteristics&lt;br /&gt;
&lt;br /&gt;
*'''Documents'''&lt;br /&gt;
A CouchDB document is a JSON object that consists of named fields. Field values may be strings, numbers, dates, or even ordered lists and associative maps. An example of a document would be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;Subject&amp;quot;: &amp;quot;Foo Bar&amp;quot;,&lt;br /&gt;
    &amp;quot;Author&amp;quot;: &amp;quot;John Doe&amp;quot;,&lt;br /&gt;
    &amp;quot;PostedDate&amp;quot;: &amp;quot;10/7/2013&amp;quot;,&lt;br /&gt;
    &amp;quot;Tags&amp;quot;: [&amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;],&lt;br /&gt;
    &amp;quot;Body&amp;quot;: &amp;quot;Lorem Ipsum...&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A CouchDB database is a flat collection of these documents. Each document is identified by a unique ID.&lt;br /&gt;
&lt;br /&gt;
*'''Views'''&lt;br /&gt;
To address this problem of adding structure back to semi-structured data, CouchDB integrates a view model using JavaScript for description. Views are the method of aggregating and reporting on the documents in a database, and are built on-demand to aggregate, join and report on database documents. Views are built dynamically and don’t affect the underlying document; you can have as many different view representations of the same data as you like. Incremental updates to documents do not require full re-indexing of views.&lt;br /&gt;
&lt;br /&gt;
*'''Schema Free'''&lt;br /&gt;
Unlike SQL databases, which are designed to store and report on highly structured, interrelated data, CouchDB is designed to store and report on large amounts of semi-structured, document oriented data. CouchDB greatly simplifies the development of document oriented applications, such as collaborative web applications.&lt;br /&gt;
&lt;br /&gt;
In an SQL database, the schema and storage of the existing data must be updated as needs evolve. With CouchDB, no schema is required, so new document types with new meaning can be safely added alongside the old. However, for applications requiring robust validation of new documents custom validation functions are possible. The view engine is designed to easily handle new document types and disparate but similar documents.&lt;br /&gt;
&lt;br /&gt;
*'''Distributed'''&lt;br /&gt;
CouchDB is a peer based distributed database system. Any number of CouchDB hosts (servers and offline-clients) can have independent &amp;quot;replica copies&amp;quot; of the same database, where applications have full database interactivity (query, add, edit, delete). When back online or on a schedule, database changes can be replicated bi-directionally.&lt;br /&gt;
&lt;br /&gt;
CouchDB has built-in conflict detection and management and the replication process is incremental and fast, copying only documents changed since the previous replication. Most applications require no special planning to take advantage of distributed updates and replication.&lt;br /&gt;
&lt;br /&gt;
==== '''CouchDB on Rails''' ====&lt;br /&gt;
First of all you need install CouchDB.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install couchdb -y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or we can use the many pre compiled binaries on the CouchDB website.&lt;br /&gt;
&lt;br /&gt;
After installation, check if all work fine by curl request &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ curl http://localhost:5984&lt;br /&gt;
&lt;br /&gt;
{&amp;quot;couchdb&amp;quot;:&amp;quot;Welcome&amp;quot;,&amp;quot;version&amp;quot;:&amp;quot;1.1.1&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now install the Couchrest gem for ruby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install couchrest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To create a new model, we need to define a class that inherits from the CouchRest::Model::Base class in much the same way as an ActiveRecord model. Unlike a regular database mapper, CouchRest Model requires you to define the properties or attributes your model needs to use directly in the class. There are no migrations or automatic column detection in a Document Database. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person &amp;lt; CouchRest::Model::Base&lt;br /&gt;
  use_database 'people'&lt;br /&gt;
  property :first_name, String&lt;br /&gt;
  property :last_name, String&lt;br /&gt;
  timestamps!&lt;br /&gt;
  belongs_to :person&lt;br /&gt;
  collection_of :tags&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
CouchDB is accessed via HTTP requests, as such, there is no requirement to create a binary connection to a specific database. The use_database method tells the model which database it should use. This can be provided as a CouchRest::Database object or as simple string that will be concatenated to the connection prefix. A special property macro is available called timestamps! that will create the created_at and updated_at accessors.&lt;br /&gt;
&lt;br /&gt;
As you’d expect, CouchRest Model supports all the standard CRUD operations you’re used to in other object mappers. CouchRest Model supports a few basic queries for retrieving your data from the database.&lt;br /&gt;
&lt;br /&gt;
This is a somewhat controversial feature of CouchRest Model that some document database purists may cringe at. CouchDB does not yet povide many features to support relationships between documents but the fact of that matter is that its a very useful paradigm for modelling data systems.&lt;br /&gt;
&lt;br /&gt;
The CouchRest Model Embeddable module allows you to take full advantage of CouchDB’s ability to store complex documents and retrieve them. Simply include the module in a Class and set any properties you’d like to use.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class CatToy&lt;br /&gt;
  include CouchRest::Model::Embeddable&lt;br /&gt;
&lt;br /&gt;
  property :name, String&lt;br /&gt;
  property :purchased, Date&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class Cat &amp;lt; CouchRest::Model::Base&lt;br /&gt;
  property :name, String&lt;br /&gt;
  property :toys, CatToy, :array =&amp;gt; true&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
@cat = Cat.new(:name =&amp;gt; 'Felix', :toys =&amp;gt; [{:name =&amp;gt; 'mouse', :purchased =&amp;gt; 1.month.ago}])&lt;br /&gt;
@cat.toys.first.class == CatToy&lt;br /&gt;
@cat.toys.first.name == 'mouse'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*http://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*http://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_programming_language&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sagarn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79900</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w44 s</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79900"/>
		<updated>2013-10-07T23:42:55Z</updated>

		<summary type="html">&lt;p&gt;Sagarn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Non-relational Databases in Rails Applications''' ==&lt;br /&gt;
&lt;br /&gt;
Active Record is basic to Rails and it is responsible to for allowing programs to treat records in relational dbs as objects. It employs Object-Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. While Active Record is efficient in what it does, the complexities of ORM make way for a new approach for databases with rails, that is to move to different Database Models namely Object-Oriented Databases and No-SQL Databases.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Overview''' ==&lt;br /&gt;
Rails, as a web development framework, and Ruby, as a programming language, can be used with a choice of operating systems (Linux, Mac OS X, Windows), databases (SQLite, MySQL, PostgreSQL, and others), and web servers (Apache, Nginx, and others).&lt;br /&gt;
The Rails stack can also include a variety of software libraries (gems) that add features to a website or make development easier. Sometimes the choice of components in a stack is driven by the requirements of an application&lt;br /&gt;
&lt;br /&gt;
Rails uses the Active Record pattern which describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. &lt;br /&gt;
&lt;br /&gt;
Active Record is the layer of the system responsible for representing business data and logic. It facilitates the creation and use of business objects whose data requires persistent storage to a database. It employs Object-Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. Using ORM, the properties and relationships of the objects in an application can be easily stored and retrieved from a database without writing SQL statements directly and with less overall database access code.&lt;br /&gt;
&lt;br /&gt;
Active Record gives us several mechanisms, the most important being the ability to:&lt;br /&gt;
:Represent models and their data.&lt;br /&gt;
:Represent associations between these models.&lt;br /&gt;
:Represent inheritance hierarchies through related models.&lt;br /&gt;
:Validate models before they get persisted to the database.&lt;br /&gt;
:Perform database operations in an object-oriented fashion.&lt;br /&gt;
&lt;br /&gt;
== '''Object-relational impedance mismatch''' ==&lt;br /&gt;
&lt;br /&gt;
The relational model on which Active Record relies on takes data and separates it into many interrelated tables that contain rows and columns. Tables reference each other through foreign keys that are stored in columns as well.  When looking up data, the desired information needs to be collected from many tables (often hundreds in today’s enterprise applications) and combined before it can be provided to the application. Similarly, when writing data, the write needs to be coordinated and performed on many tables.&lt;br /&gt;
&lt;br /&gt;
The Active Record pattern describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. The pattern has numerous limitations referred to as the Object-relational impedance mismatch. Some of these technical difficulties are structural. In OO programming, objects may be composed of other objects. The Active Record pattern maps these sub-objects to separate tables, thus introducing issues concerning the representation of relationships and encapsulated data. Active Record uses macros to create relationships between objects and single table inheritance to represent inheritance.&lt;br /&gt;
&lt;br /&gt;
Active Record is a solution for the Object-relational impedance mismatch, but this is assuming the datastore is relational. It’s also, fundamentally, a hack.&lt;br /&gt;
&lt;br /&gt;
== '''Non Relational Databases''' ==&lt;br /&gt;
=== '''Object Database''' ===&lt;br /&gt;
An object database (also object-oriented database management system). Object-Oriented Database Management System (OODBMS) is a Database Management System (DBMS) which allows information to be represented in the form of objects as used in object-oriented programming. OODBMSs provide an integrated application development environment by joining object-oriented programming with database technology. OODBMSs enforce object oriented programming concepts such as encapsulation, polymorphism and inheritance as well as database management concepts such as Atomicity, Consistency, Isolation and Durability. Since both the programming language and OODBMS use the same object-oriented model, the programmers can maintain the consistency easily between the two environments.&lt;br /&gt;
&lt;br /&gt;
==== '''Comparing RDBMS with Object Database''' ====&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Criteria !! RDBMS !! OODBMS&lt;br /&gt;
|-&lt;br /&gt;
| Object-oriented programming support || Poor || Extensive&lt;br /&gt;
|-&lt;br /&gt;
| Ease of Use || Table schemas easy to understand for everyone || Good for Programmers only&lt;br /&gt;
|-&lt;br /&gt;
| Ease in development || Independent from application || Objects are a natural way to model, can incorporate types and relationships&lt;br /&gt;
|-&lt;br /&gt;
| Extensiblity || Low || High&lt;br /&gt;
|-&lt;br /&gt;
| Data relationships || Hard to model || Easy to handle&lt;br /&gt;
|-&lt;br /&gt;
| Maturity || Very Mature || Relatively Mature&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== '''No-SQL Databases''' ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== '''Comparing No-SQL DB with RDBMS''' ====&lt;br /&gt;
Relational and Object database models are very different. &lt;br /&gt;
For example, a document-oriented database takes the data you want to store and aggregates it into documents using the JSON format. Each JSON document can be thought of as an object to be used by your application. A JSON document might, for example, take all the data stored in a row that spans 20 tables of a relational database and aggregate it into a single document/object. Aggregating this information may lead to duplication of  information, but since storage is no longer cost prohibitive, the resulting data model flexibility, ease of efficiently distributing the resulting documents and read and write performance improvements make it an easy trade-off for web-based applications.&lt;br /&gt;
&lt;br /&gt;
[[File:nosqlvsrdbms.jpg|frame|none|alt=Document Object Model equivalent to Relational tables|Document Object Model equivalent to Relational tables]]&lt;br /&gt;
&lt;br /&gt;
Another major difference is that relational technologies have rigid schemas. Relational technology requires strict definition of a schema prior to storing any data into a database. Changing the schema once data is inserted is a big deal, extremely disruptive and frequently avoided.&lt;br /&gt;
In comparison, document databases are schemaless, allowing you to freely add fields to JSON documents without having to first define changes. The format of the data being inserted can be changed at any time, without application disruption.&lt;br /&gt;
&lt;br /&gt;
== '''Examples in Rails Apps''' ==&lt;br /&gt;
&lt;br /&gt;
=== '''MongoDB''' ===&lt;br /&gt;
&lt;br /&gt;
MongoDB is a document database that provides high performance, high availability, and easy scalability. Key features:&lt;br /&gt;
*'''Flexibility'''&lt;br /&gt;
MongoDB stores data in JSON documents (which we serialize to BSON). JSON provides a rich data model that seamlessly maps to native programming language types, and the dynamic schema makes it easier to evolve your data model than with a system with enforced schemas such as a RDBMS.&lt;br /&gt;
*'''Power'''&lt;br /&gt;
MongoDB provides a lot of the features of a traditional RDBMS such as secondary indexes, dynamic queries, sorting, rich updates, upserts (update if document exists, insert if it doesn’t), and easy aggregation. This gives you the breadth of functionality that you are used to from an RDBMS, with the flexibility and scaling capability that the non-relational model allows.&lt;br /&gt;
*'''Speed/Scaling'''&lt;br /&gt;
By keeping related data together in documents, queries can be much faster than in a relational database where related data is separated into multiple tables and then needs to be joined later. MongoDB also makes it easy to scale out your database. Autosharding allows you to scale your cluster linearly by adding more machines. It is possible to increase capacity without any downtime, which is very important on the web when load can increase suddenly and bringing down the website for extended maintenance can cost your business large amounts of revenue.&lt;br /&gt;
*'''Ease of use'''&lt;br /&gt;
MongoDB works hard to be very easy to install, configure, maintain, and use. To this end, MongoDB provides few configuration options, and instead tries to automatically do the “right thing” whenever possible. This means that MongoDB works right out of the box, and you can dive right into developing your application, instead of spending a lot of time fine-tuning obscure database configurations.&lt;br /&gt;
&lt;br /&gt;
A MongoDB deployment hosts a number of databases. A database holds a set of collections. A collection holds a set of documents. A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.&lt;br /&gt;
&lt;br /&gt;
MongoDB stores all data in documents, which are JSON-style data structures composed of field-and-value pairs:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{ &amp;quot;item&amp;quot;: &amp;quot;pencil&amp;quot;, &amp;quot;qty&amp;quot;: 500, &amp;quot;type&amp;quot;: &amp;quot;no.2&amp;quot; }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
MongoDB stores documents on disk in the BSON serialization format. BSON is a binary representation of JSON documents, though contains more data types than does JSON&lt;br /&gt;
&lt;br /&gt;
MongoMapper and Mongoid are the two leading gems that make it possible use MongoDB as a datastore with Rails. MongoMapper is a simple ORM for MongoDB. Mongoid’s goal is to provide a familiar API to Active Record, while still leveraging MongoDB’s schema flexibility, document design, atomic modifiers, and rich query interface.&lt;br /&gt;
&lt;br /&gt;
==== '''MongoDB in Rails''' ====&lt;br /&gt;
&lt;br /&gt;
Firstly to create a new Rails app using MongoDB we need to ensure we create it without active record and install the necessary gems outlines before.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;gt; rails new my_app --skip-active-record&lt;br /&gt;
&amp;gt; cd my_app&lt;br /&gt;
&amp;gt; gem install mongo&lt;br /&gt;
&amp;gt; gem install bson&lt;br /&gt;
&amp;gt; gem install bson_ext&lt;br /&gt;
&amp;gt; gem install mongomapper&lt;br /&gt;
&amp;gt; gem install mongoid&lt;br /&gt;
&amp;gt; rails server&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Rails model files are altered to not have the classes inherit from ActiveRecord::Base, must include a module MongoMapper::Document, and define the schema in the actual file. Database migrations are not necessary.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Story&lt;br /&gt;
 include MongoMapper::Document&lt;br /&gt;
&lt;br /&gt;
 key :title,     String&lt;br /&gt;
 key :url,       String&lt;br /&gt;
 key :voters,    Array&lt;br /&gt;
 key :votes,     Integer, :default =&amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
 # Cached values.&lt;br /&gt;
 key :comment_count, Integer, :default =&amp;gt; 0&lt;br /&gt;
 key :username,      String&lt;br /&gt;
&lt;br /&gt;
 # Note this: ids are of class ObjectId.&lt;br /&gt;
 key :user_id,   ObjectId&lt;br /&gt;
 timestamps!&lt;br /&gt;
&lt;br /&gt;
 # Relationships.&lt;br /&gt;
 belongs_to :user&lt;br /&gt;
&lt;br /&gt;
 # Validations.&lt;br /&gt;
 validates_presence_of :title, :url, :user_id&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Additionally, you have a number of configuration options available, such as allow_dynamic_fields that allows you to define attributes on an object that aren’t in the model file’s schema. You can then add some logic in your model file if you need to do something different depending on the existence or absence of this field.&lt;br /&gt;
&lt;br /&gt;
For fast lookups, we can create an index on this field. In the MongoDB shell:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
db.courses.ensureIndex('voters');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To find all the Courses by name:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Course.all(:conditions =&amp;gt; {:name =&amp;gt; @suject.name})&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In a relational database, comments are usually given their own table, related by foreign key to some parent table. This approach is occasionally necessary in MongoDB; however, it’s always best to try to embed first, as this will achieve greater query efficiency.&lt;br /&gt;
&lt;br /&gt;
*'''Linear Comments'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Story&lt;br /&gt;
  include MongoMapper::Document&lt;br /&gt;
  many :comments&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
 class Comment&lt;br /&gt;
  include MongoMapper::EmbeddedDocument&lt;br /&gt;
  key :body, String&lt;br /&gt;
&lt;br /&gt;
  belongs_to :story&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we were using the Ruby driver alone, we could save our structure like so:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@stories  = @db.collection('stories')&lt;br /&gt;
@document = {:title =&amp;gt; &amp;quot;MongoDB on Rails&amp;quot;,&lt;br /&gt;
             :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Revelatory! Loved it!&amp;quot;,&lt;br /&gt;
                            :username =&amp;gt; &amp;quot;Matz&amp;quot;&lt;br /&gt;
                           }&lt;br /&gt;
                          ]&lt;br /&gt;
            }&lt;br /&gt;
@stories.save(@document)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Nested Comments'''&lt;br /&gt;
To build threaded comments:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
@stories  = @db.collection('stories')&lt;br /&gt;
@document = {:title =&amp;gt; &amp;quot;MongoDB on Rails&amp;quot;,&lt;br /&gt;
             :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Revelatory! Loved it!&amp;quot;,&lt;br /&gt;
                            :username =&amp;gt; &amp;quot;Matz&amp;quot;,&lt;br /&gt;
                            :comments =&amp;gt; [{:body     =&amp;gt; &amp;quot;Agreed.&amp;quot;,&lt;br /&gt;
                                           :username =&amp;gt; &amp;quot;rubydev29&amp;quot;&lt;br /&gt;
                                          }&lt;br /&gt;
                                         ]&lt;br /&gt;
                           }&lt;br /&gt;
                          ]&lt;br /&gt;
            }&lt;br /&gt;
@stories.save(@document)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can also represent comments as their own collection. Relative to the other options, this incurs a small performance penalty while granting us the greatest flexibility. The tree structure can be represented by storing the unique path for each leaf.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Comment&lt;br /&gt;
  include MongoMapper::Document&lt;br /&gt;
&lt;br /&gt;
  key :body,       String&lt;br /&gt;
  key :depth,      Integer, :default =&amp;gt; 0&lt;br /&gt;
  key :path,       String,  :default =&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  # Note: we're intentionally storing parent_id as a string&lt;br /&gt;
  key :parent_id,  String&lt;br /&gt;
  key :story_id,   ObjectId&lt;br /&gt;
  timestamps!&lt;br /&gt;
&lt;br /&gt;
  # Relationships.&lt;br /&gt;
  belongs_to :story&lt;br /&gt;
&lt;br /&gt;
  # Callbacks.&lt;br /&gt;
  after_create :set_path&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Store the comment's path.&lt;br /&gt;
  def set_path&lt;br /&gt;
  ....&lt;br /&gt;
    end&lt;br /&gt;
    save&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== '''CouchDB''' ===&lt;br /&gt;
CouchDB is often categorized as a “NoSQL” database. A CouchDB database lacks a schema, or rigid pre-defined data structures such as tables. &lt;br /&gt;
A CouchDB server hosts named databases, which stores documents. Data stored in CouchDB is a JSON document(s). The structure of the data, or document(s), can change dynamically to accommodate evolving needs. Each document is uniquely named in the database, and CouchDB provides a RESTful HTTP API for reading and updating (add, edit, delete) database documents.&lt;br /&gt;
Documents are the primary unit of data in CouchDB and consist of any number of fields and attachments. Documents also include metadata that’s maintained by the database system. Document fields are uniquely named and contain values of varying types (text, number, boolean, lists, etc), and there is no set limit to text size or element count.&lt;br /&gt;
User can just chuck arbitrary JSON objects up at this thing and it’ll store it. No setup, no schemas, no nothing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Key Charachteristics&lt;br /&gt;
&lt;br /&gt;
*'''Documents'''&lt;br /&gt;
A CouchDB document is a JSON object that consists of named fields. Field values may be strings, numbers, dates, or even ordered lists and associative maps. An example of a document would be:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;Subject&amp;quot;: &amp;quot;Foo Bar&amp;quot;,&lt;br /&gt;
    &amp;quot;Author&amp;quot;: &amp;quot;John Doe&amp;quot;,&lt;br /&gt;
    &amp;quot;PostedDate&amp;quot;: &amp;quot;10/7/2013&amp;quot;,&lt;br /&gt;
    &amp;quot;Tags&amp;quot;: [&amp;quot;foo&amp;quot;, &amp;quot;bar&amp;quot;],&lt;br /&gt;
    &amp;quot;Body&amp;quot;: &amp;quot;Lorem Ipsum...&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A CouchDB database is a flat collection of these documents. Each document is identified by a unique ID.&lt;br /&gt;
&lt;br /&gt;
*'''Views'''&lt;br /&gt;
To address this problem of adding structure back to semi-structured data, CouchDB integrates a view model using JavaScript for description. Views are the method of aggregating and reporting on the documents in a database, and are built on-demand to aggregate, join and report on database documents. Views are built dynamically and don’t affect the underlying document; you can have as many different view representations of the same data as you like. Incremental updates to documents do not require full re-indexing of views.&lt;br /&gt;
&lt;br /&gt;
*'''Schema Free'''&lt;br /&gt;
Unlike SQL databases, which are designed to store and report on highly structured, interrelated data, CouchDB is designed to store and report on large amounts of semi-structured, document oriented data. CouchDB greatly simplifies the development of document oriented applications, such as collaborative web applications.&lt;br /&gt;
&lt;br /&gt;
In an SQL database, the schema and storage of the existing data must be updated as needs evolve. With CouchDB, no schema is required, so new document types with new meaning can be safely added alongside the old. However, for applications requiring robust validation of new documents custom validation functions are possible. The view engine is designed to easily handle new document types and disparate but similar documents.&lt;br /&gt;
&lt;br /&gt;
*'''Distributed'''&lt;br /&gt;
CouchDB is a peer based distributed database system. Any number of CouchDB hosts (servers and offline-clients) can have independent &amp;quot;replica copies&amp;quot; of the same database, where applications have full database interactivity (query, add, edit, delete). When back online or on a schedule, database changes can be replicated bi-directionally.&lt;br /&gt;
&lt;br /&gt;
CouchDB has built-in conflict detection and management and the replication process is incremental and fast, copying only documents changed since the previous replication. Most applications require no special planning to take advantage of distributed updates and replication.&lt;br /&gt;
&lt;br /&gt;
==== '''CouchDB on Rails''' ====&lt;br /&gt;
First of all you need install CouchDB.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo apt-get install couchdb -y&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Or we can use the many pre compiled binaries on the CouchDB website.&lt;br /&gt;
&lt;br /&gt;
After installation, check if all work fine by curl request &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ curl http://localhost:5984&lt;br /&gt;
&lt;br /&gt;
{&amp;quot;couchdb&amp;quot;:&amp;quot;Welcome&amp;quot;,&amp;quot;version&amp;quot;:&amp;quot;1.1.1&amp;quot;}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We now install the Couchrest gem for ruby&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gem install couchrest&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To create a new model, we need to define a class that inherits from the CouchRest::Model::Base class in much the same way as an ActiveRecord model. Unlike a regular database mapper, CouchRest Model requires you to define the properties or attributes your model needs to use directly in the class. There are no migrations or automatic column detection in a Document Database. &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Person &amp;lt; CouchRest::Model::Base&lt;br /&gt;
  use_database 'people'&lt;br /&gt;
  property :first_name, String&lt;br /&gt;
  property :last_name, String&lt;br /&gt;
  timestamps!&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
CouchDB is accessed via HTTP requests, as such, there is no requirement to create a binary connection to a specific database. The use_database method tells the model which database it should use. This can be provided as a CouchRest::Database object or as simple string that will be concatenated to the connection prefix. A special property macro is available called timestamps! that will create the created_at and updated_at accessors.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*http://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*http://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_programming_language&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sagarn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79867</id>
		<title>CSC/ECE 517 Fall 2013/ch1 1w44 s</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013/ch1_1w44_s&amp;diff=79867"/>
		<updated>2013-10-07T21:57:40Z</updated>

		<summary type="html">&lt;p&gt;Sagarn: Created page with &amp;quot;== '''Non-relational Databases in Rails Applications''' ==  Active Record is basic to Rails and it is responsible to for allowing programs to treat records in relational dbs as o...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== '''Non-relational Databases in Rails Applications''' ==&lt;br /&gt;
&lt;br /&gt;
Active Record is basic to Rails and it is responsible to for allowing programs to treat records in relational dbs as objects. It employs Object-Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. While Active Record is efficient in what it does, the complexities of ORM make way for a new approach for databases with rails, that is to move to different Database Models namely Object-Oriented Databases and No-SQL Databases.&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== '''Overview''' ==&lt;br /&gt;
Rails, as a web development framework, and Ruby, as a programming language, can be used with a choice of operating systems (Linux, Mac OS X, Windows), databases (SQLite, MySQL, PostgreSQL, and others), and web servers (Apache, Nginx, and others).&lt;br /&gt;
The Rails stack can also include a variety of software libraries (gems) that add features to a website or make development easier. Sometimes the choice of components in a stack is driven by the requirements of an application&lt;br /&gt;
&lt;br /&gt;
Rails uses the Active Record pattern which describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. &lt;br /&gt;
&lt;br /&gt;
Active Record is the layer of the system responsible for representing business data and logic. It facilitates the creation and use of business objects whose data requires persistent storage to a database. It employs Object-Relational Mapping, commonly referred to as its abbreviation ORM, is a technique that connects the rich objects of an application to tables in a relational database management system. Using ORM, the properties and relationships of the objects in an application can be easily stored and retrieved from a database without writing SQL statements directly and with less overall database access code.&lt;br /&gt;
&lt;br /&gt;
Active Record gives us several mechanisms, the most important being the ability to:&lt;br /&gt;
:Represent models and their data.&lt;br /&gt;
:Represent associations between these models.&lt;br /&gt;
:Represent inheritance hierarchies through related models.&lt;br /&gt;
:Validate models before they get persisted to the database.&lt;br /&gt;
:Perform database operations in an object-oriented fashion.&lt;br /&gt;
&lt;br /&gt;
== '''Object-relational impedance mismatch''' ==&lt;br /&gt;
&lt;br /&gt;
The relational model on which Active Record relies on takes data and separates it into many interrelated tables that contain rows and columns. Tables reference each other through foreign keys that are stored in columns as well.  When looking up data, the desired information needs to be collected from many tables (often hundreds in today’s enterprise applications) and combined before it can be provided to the application. Similarly, when writing data, the write needs to be coordinated and performed on many tables.&lt;br /&gt;
&lt;br /&gt;
The Active Record pattern describes the mapping of an object instance to a row in a relational database table, using accessor methods to retrieve columns/properties, and the ability to create, update, read, and delete entities from the database. The pattern has numerous limitations referred to as the Object-relational impedance mismatch. Some of these technical difficulties are structural. In OO programming, objects may be composed of other objects. The Active Record pattern maps these sub-objects to separate tables, thus introducing issues concerning the representation of relationships and encapsulated data. Active Record uses macros to create relationships between objects and single table inheritance to represent inheritance.&lt;br /&gt;
&lt;br /&gt;
Active Record is a solution for the Object-relational impedance mismatch, but this is assuming the datastore is relational. It’s also, fundamentally, a hack. The obvious cleaner solution being using a Object Oriented datastore.&lt;br /&gt;
&lt;br /&gt;
== '''Object Database''' ==&lt;br /&gt;
An object database (also object-oriented database management system). Object-Oriented Database Management System (OODBMS) is a Database Management System (DBMS) which allows information to be represented in the form of objects as used in object-oriented programming. OODBMSs provide an integrated application development environment by joining object-oriented programming with database technology. OODBMSs enforce object oriented programming concepts such as encapsulation, polymorphism and inheritance as well as database management concepts such as Atomicity, Consistency, Isolation and Durability. Since both the programming language and OODBMS use the same object-oriented model, the programmers can maintain the consistency easily between the two environments.&lt;br /&gt;
&lt;br /&gt;
== '''Comparison with RDBMS''' ==&lt;br /&gt;
Relational and Object database models are very different. &lt;br /&gt;
For example, a document-oriented OODBMS takes the data you want to store and aggregates it into documents using the JSON format. Each JSON document can be thought of as an object to be used by your application. A JSON document might, for example, take all the data stored in a row that spans 20 tables of a relational database and aggregate it into a single document/object. Aggregating this information may lead to duplication of  information, but since storage is no longer cost prohibitive, the resulting data model flexibility, ease of efficiently distributing the resulting documents and read and write performance improvements make it an easy trade-off for web-based applications.&lt;br /&gt;
&lt;br /&gt;
[[File:nosqlvsrdbms.jpg|frame|none|alt=Document Object Model equivalent to Relational tables|Document Object Model equivalent to Relational tables]]&lt;br /&gt;
&lt;br /&gt;
Another major difference is that relational technologies have rigid schemas. Relational technology requires strict definition of a schema prior to storing any data into a database. Changing the schema once data is inserted is a big deal, extremely disruptive and frequently avoided.&lt;br /&gt;
In comparison, document databases are schemaless, allowing you to freely add fields to JSON documents without having to first define changes. The format of the data being inserted can be changed at any time, without application disruption.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Naming Guidelines&amp;lt;ref&amp;gt;http://itsignals.cascadia.com.au/?p=7&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Ruby uses the first character of the name to help it determine it’s intended use.&lt;br /&gt;
The standard Ruby file extension is .rb, although many people working on [http://en.wikipedia.org/wiki/Unix UNIX]-like systems don't bother with it for stand-alone scripts. Whether or not one uses it for scripts is up to them, but they will need to use it for library files or they will not be found by the interpreter.&lt;br /&gt;
&lt;br /&gt;
*'''Local Variables'''&lt;br /&gt;
:Should use lowercase letter followed by other characters. Naming convention states that it is better to use underscores rather than [http://en.wikipedia.org/wiki/CamelCase camelBack] for multiple word names, e.g. average, variable_xyz&lt;br /&gt;
*'''Instance Variables'''&lt;br /&gt;
:Instance variables are defined using the single &amp;quot;at&amp;quot; sign (@) followed by a name. It is suggested that a lowercase letter should succeed @, e.g. @color &lt;br /&gt;
*'''Instance Methods'''&lt;br /&gt;
:Method names should start with a lowercase letter, and may be followed by digits, underscores, and letters. The name should possibly be a verb e.g. move, display_details&lt;br /&gt;
*'''Class Variables'''&lt;br /&gt;
:Class variable names start with a double &amp;quot;at&amp;quot; sign (@@) and may be followed by digits, underscores, and letters, e.g. @@color&lt;br /&gt;
*'''Constant''' &lt;br /&gt;
:Constant names usually start with an uppercase letter followed by other characters. Constant objects are by convention named using all uppercase letters and underscores between words, e.g. THIS_IS_A_CONSTANT&lt;br /&gt;
*'''Class and Module''' &lt;br /&gt;
:Class names are recommended to be be nouns. In the case of modules, it's harder to make a clear recommendation. The names of [http://en.wikipedia.org/wiki/Mixin mix-ins] (which are just modules), however,  should probably be adjectives, such as the standard [http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Enumerable Enumerable] and [http://www.ruby-doc.org/core-2.0.0/Comparable.html Comparable] modules. Class and module names starts with an uppercase letter, by convention they are named using MixedCase, e.g. module Encryption, class MixedCase&lt;br /&gt;
*'''Global Variables'''&lt;br /&gt;
:Starts with a dollar ($) sign followed by other characters, e.g. $global&lt;br /&gt;
&lt;br /&gt;
Considering customer order information as the data being used for an application, below naming guidelines give an idea of good class/table/file names.&lt;br /&gt;
*'''Model Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Table: orders&lt;br /&gt;
Class: Order&lt;br /&gt;
File: /app/models/order.rb&lt;br /&gt;
Primary Key: id&lt;br /&gt;
Foreign Key: customer_id&lt;br /&gt;
Link Tables: items_orders&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Controller Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Class: OrdersController&lt;br /&gt;
File: /app/controllers/orders_controller.rb&lt;br /&gt;
Layout: /app/layouts/orders.html.erb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''View Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Helper: /app/helpers/orders_helper.rb&lt;br /&gt;
Helper Module: OrdersHelper&lt;br /&gt;
Views: /app/views/orders/… (list.html.erb for example)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*'''Tests Naming Convention'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Unit: /test/unit/order_test.rb&lt;br /&gt;
Functional: /test/functional/orders_controller_test.rb&lt;br /&gt;
Fixtures: /test/fixtures/orders.yml&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Class Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
A class in Ruby always starts with the keyword class followed by the name of the class. The name should always be in initial capitals. Class Customer can be displayed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class Customer&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A class is terminated by using the keyword end. All the data members in the class are between the class definition and the end keyword. &lt;br /&gt;
&lt;br /&gt;
Ruby blurs the distinction between design and implementation. Ideas that have to be expressed at the design level in other languages can be implemented directly in Ruby. To help in this process, Ruby has support for some design-level strategies. These strategies can be used to design classes accordingly as suitable for different types of  applications.&lt;br /&gt;
&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Visitor_pattern The Visitor pattern]''' is a way of traversing a collection without having to know the internal organization of that collection.&lt;br /&gt;
*'''[http://en.wikipedia.org/wiki/Delegation_pattern Delegation]''' is a way of composing classes more flexibly and dynamically than can be done using standard inheritance.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Singleton_pattern Singleton pattern]''' is a way of ensuring that only one instantiation of a particular class exists at a time.&lt;br /&gt;
*The '''[http://en.wikipedia.org/wiki/Observer_pattern Observer pattern]''' implements a protocol allowing one object to notify a set of interested objects when certain changes have occurred.&lt;br /&gt;
&lt;br /&gt;
Normally, all four of these strategies require explicit code each time they're implemented. With Ruby, they can be abstracted into a library and reused freely and transparently.&lt;br /&gt;
&lt;br /&gt;
=== Member Design Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
While defining class members, it is very important to keep in mind the access restrictions. Scope and life-time of class members are different for different restrictions, as illustrated below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public&lt;br /&gt;
totally accessible.&lt;br /&gt;
protected&lt;br /&gt;
accessible only by instances of class and direct descendants. Even through hasA relationships. (see below)&lt;br /&gt;
private&lt;br /&gt;
accessible only by instances of class (must be called nekkid no “self.” or anything else).&lt;br /&gt;
class A&lt;br /&gt;
  # Restriction used w/o arguments set the default access control.&lt;br /&gt;
  protected&lt;br /&gt;
&lt;br /&gt;
  def protected_method&lt;br /&gt;
    # nothing&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
class B &amp;lt; A&lt;br /&gt;
  def test_protected&lt;br /&gt;
    myA = A.new&lt;br /&gt;
    myA.protected_method&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Used with arguments, sets the access of the named methods and constants.&lt;br /&gt;
  public :test_protected&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
b = B.new.test_protected&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Maintainability Guidelines ===&lt;br /&gt;
----&lt;br /&gt;
Maintainability guidelines are important to programmers for a number of reasons:&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
*40%-80% of the lifetime cost of a piece of software goes to maintenance.&lt;br /&gt;
*Hardly any software is maintained for its whole life by the original author. &lt;br /&gt;
*Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly. &lt;br /&gt;
*If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create. &lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
The following guidelines are to be followed to improve the software maintainability&lt;br /&gt;
* '''Profile your code regularly'''&lt;br /&gt;
: If you profile your code regularly you’ll be able to tell if the latest change to the code will have an adverse effect on performance.  Integrate profiling into your testing process and make it automated to ensure that it’s not forgotten.  Like unit testing and BDD([http://en.wikipedia.org/wiki/Behavior-driven_development Behavior-driven development]) profiling goes a long way.&lt;br /&gt;
&lt;br /&gt;
=== Performance Guidelines&amp;lt;ref&amp;gt;http://blog.monitis.com/index.php/2012/02/08/20-ruby-performance-tips/&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
The key parameter on which a software application is rated is by its performance. It is the time taken by the application to respond to a user's request. Performance of ruby can be improved significantly by following certain coding guidelines, as below.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid nesting loops more than three levels deep'''&lt;br /&gt;
: Nesting affects the performance of the code proportionally with the increasing levels in loops. Limiting nesting to three levels is one good practice to keep the code's performance well.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary variable assignments'''&lt;br /&gt;
: New programmers, often use unwanted variables in code.  A great example is when someone defines a variable to store a return value and then returns that variable; just return the value directly.&lt;br /&gt;
&lt;br /&gt;
*'''Reduce usage of disk I/O'''&lt;br /&gt;
: Disk I/O is a very costly operation as far as computing is concerned. Keeping it to the minimal improves the application response time drastically. Using disk I/O, makes the application extremely slow. Using storage systems such as memcached reduces disk I/O operations to a great extent as lot of data is kept in memory. The speed improvement while using a memory caching system is tremendous.&lt;br /&gt;
&lt;br /&gt;
*'''Use Ruby Enterprise Edition'''&lt;br /&gt;
: Ruby Enterprise edition provides up to [http://www.rubyenterpriseedition.com/faq.html#thirty_three_percent_mem_reduction 33% lower memory] usage.  Though, to get benefited by this performance one needs to follow their guidelines.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid method calls as much as possible'''&lt;br /&gt;
: Method calls are expensive operations in ruby. They should be avoided to keep up the performance of the application.&lt;br /&gt;
&lt;br /&gt;
*'''Use interpolated strings instead of concatenated strings'''&lt;br /&gt;
: Concatenated strings calls a method to get executed. So, it affects the performance as it is one of the most frequently used operation. Its better to replace them with Interpolated strings which runs faster as it doesn't invoke a method call.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
put “Hello there, #{name}!”vs.puts “Hello there, ” &amp;lt;&amp;lt; name = “!”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Destructive operations are faster'''&lt;br /&gt;
: Ruby’s in-place methods that which modifies the actual value than working on a copy of the data are much faster. But this should be handled carefully as original data gets disturbed.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid unnecessary calls to uniq on arrays'''&lt;br /&gt;
: In many cases methods are already calling uniq on an array and there’s no need for you to call it yet again.&lt;br /&gt;
&lt;br /&gt;
*'''For loops are faster than .each'''&lt;br /&gt;
: .each uses an enumeration object behind the scene which adds a delay in execution. Using for instead of .each would improve performance but for short loops only.&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/6406112/why-are-ruby-method-calls-particularly-slow-in-comparison-to-other-languages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Use x.blank? over x.nil? || x.empty?'''&lt;br /&gt;
: When using ActionPack there’s no need for x.nil? or x.empty?; x.blank? checks for both of these.&lt;br /&gt;
&lt;br /&gt;
*'''Avoid calls to parse_date and strftime'''&lt;br /&gt;
: Both these calls are very expensive. using regular expressions would improve the time.&lt;br /&gt;
&lt;br /&gt;
*'''Know your gems'''&lt;br /&gt;
: All libraries are not efficient. Many gems may need to be removed to problem to fix a problem with the code. This is a common scenario when many gems are installed. So performing bench marking and testing a gem with others that perform same task would help in picking the right gem.&lt;br /&gt;
&lt;br /&gt;
*'''Improve your algorithms before you try to improve your code'''&lt;br /&gt;
: Algorithmic improvements results in evident improvements in performance of the code. It is always ideal to design an efficient algorithm without unwanted method calls.&lt;br /&gt;
&lt;br /&gt;
*'''Test the most frequently occurring case first'''&lt;br /&gt;
: While using if statements or a case statement always test the cases that occur most frequently. This allows less code to run before a decision is made.  It may not seem like much but over several hundred or thousand runs through the decision logic you’ll notice a definite performance gain.&lt;br /&gt;
&lt;br /&gt;
*'''Optimize the way you access global constants'''&lt;br /&gt;
: While accessing the global constants one should use namespace before the constants to avoid entire library search for the constant.&lt;br /&gt;
 &lt;br /&gt;
*'''Use explicit returns'''&lt;br /&gt;
: Even though the result of last operation is returned for a method, using explicit returns would speed up the code. Explicit returns are faster, especially in older Ruby versions such as 1.8.x.&lt;br /&gt;
&lt;br /&gt;
=== Documentation Guidelines&amp;lt;ref&amp;gt;http://guides.rubyonrails.org/api_documentation_guidelines.html&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Documentation comments&amp;lt;ref&amp;gt;http://www.jetbrains.com/ruby/webhelp/documenting-source-code-in-rubymine.html&amp;lt;/ref&amp;gt; can be created in accordance with [http://rdoc.sourceforge.net/ RDoc] and [http://yardoc.org/ YARD] syntax. Note that RDoc highlighting in documentation comments can be turned enabled or disabled in the Appearance page of the editor settings.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
The most common Documentation guidelines are listed below.&lt;br /&gt;
*Write simple, declarative sentences. Brevity is a plus: get to the point.&lt;br /&gt;
*Write in present tense: &amp;quot;Returns a hash that...&amp;quot;, rather than &amp;quot;Returned a hash that...&amp;quot; or &amp;quot;Will return a hash that...&amp;quot;.&lt;br /&gt;
*Start comments in upper case. Follow regular punctuation rules:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Declares an attribute reader backed by an internally-named &lt;br /&gt;
# instance variable.&lt;br /&gt;
def attr_internal_reader(*attrs)&lt;br /&gt;
  ...&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.&lt;br /&gt;
&lt;br /&gt;
Documentation has to be concise but comprehensive. Explore and document edge cases.&lt;br /&gt;
&lt;br /&gt;
=== Layout Guidelines&amp;lt;ref&amp;gt;http://www.caliban.org/ruby/rubyguide.shtml&amp;lt;/ref&amp;gt; ===&lt;br /&gt;
----&lt;br /&gt;
Designing the layout of any application determines the readability factor for other developers.&lt;br /&gt;
Most followed order of code is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
header block with author's name, Perforce Id tag and a brief description of what the program or library is for.&lt;br /&gt;
require statements&lt;br /&gt;
include statements&lt;br /&gt;
class and module definitions&lt;br /&gt;
main program section&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*'''Spreading Code Out and Lining it Up'''&lt;br /&gt;
:This is very important for readability. Basically the principle is to:&lt;br /&gt;
:*separate each component part by white space.&lt;br /&gt;
:*align everything meaningfully.&lt;br /&gt;
:As such one can easily scan up and down the code and see the patterns. This is very important not only for understanding the code, but also for looking for anomalies and as a tool for rationalizing and consolidating the code.&lt;br /&gt;
:Code that has a lot of 'noise' - a lot of unnecessary variation and untidiness - is code that one can waste a lot of time working on. Well written and formatted code is code that is easy and quick to work with. It is code that allows one to easily 'see the wood from the trees'.&lt;br /&gt;
&lt;br /&gt;
== '''Code Analysis Tools''' ==&lt;br /&gt;
&lt;br /&gt;
Ruby itself goes a long way towards helping developers write clear code.&lt;br /&gt;
&lt;br /&gt;
*'''The Ruby debugger''' is a library loaded into Ruby at run-time. &lt;br /&gt;
This is done as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ruby -r debug [&lt;br /&gt;
            options&lt;br /&gt;
            ] [&lt;br /&gt;
            programfile&lt;br /&gt;
            ] [&lt;br /&gt;
            arguments&lt;br /&gt;
            ]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The debugger can do all the usual things one would expect it to, such as set breakpoints, step into and over code, print out the call stack, etc.&lt;br /&gt;
&lt;br /&gt;
While tools for the mainstream languages such as Java and C++ have reached a certain maturity, tools for Ruby are still growing. And they might be needed more and more as Ruby's usage spreads from early adopters to the early majority, and SLOC (Source Lines Of Code) continues to increase. Automatic tools&amp;lt;ref&amp;gt;http://www.ruby-toolbox.com/categories/code_metrics&amp;lt;/ref&amp;gt; can be used to detect several types of problems including inconsistent style, long methods and repeated code.&lt;br /&gt;
&lt;br /&gt;
*[http://github.com/roodi/roodi/tree/master '''Roodi'''] (Ruby Object Oriented Design Inferometer) - this parses Ruby code and warns about design issues from the list  configured, ie: Class line count check, for loop check, parameter number check, cyclomatic checks and 10 other checks&lt;br /&gt;
*[http://github.com/troessner/reek '''Reek'''] - similar in concept to Roodi&lt;br /&gt;
*[http://saikuro.rubyforge.org/ '''Saikuro'''] - designed to check cyclomatic complexity&lt;br /&gt;
*[http://ruby.sadi.st/Flog.html '''Flog'''] - created by Ryan Davis, this computes a score of code written: the higher the score is, the worse your code is. ABC metrics (Assignments, Branches and Calls) are taken into account to compute the score&lt;br /&gt;
*[http://www.harukizaemon.com/simian/ '''Simian'''] - a similarity analyzer, this can be used for duplication identification (a $99 license is needed for commercial use)&lt;br /&gt;
*[http://ruby.sadi.st/Flay.html '''Flay'''] - this is another free tool from Ryan Davis that finds structural similarities in code&lt;br /&gt;
&lt;br /&gt;
[[File:Code Analysis Outputs.png|frame|none|alt=Code Analysis Tool Results|Code Analysis Tool Results]]&lt;br /&gt;
nosqlvsrdbms.jpg&lt;br /&gt;
== '''Summary''' ==&lt;br /&gt;
Ruby developers should follow a certain criteria or guidelines during software development. Coding standards are set of rules, guidelines and regulations on the manner of writing a code that helps programmers and developers read and understand quickly the source code that conforms to style and help avoid introducing misunderstanding and faults.&lt;br /&gt;
&lt;br /&gt;
Particularly in Ruby development, coding standards are extremely important; therefore Ruby developers should put an importance to them. This is because these standards offer higher uniformity and consistency when writing code by different programmers. This could result in a code that's simple to know and preserve, thus reducing the project’s overall expenses.&lt;br /&gt;
&lt;br /&gt;
Some of the benefits of using coding standards are:&lt;br /&gt;
&lt;br /&gt;
*Easy to understand and maintained&lt;br /&gt;
*Boost the code’s readability&lt;br /&gt;
*Maintainable applications&lt;br /&gt;
*Eradicates complexity&lt;br /&gt;
*Separate documents look more appropriate&lt;br /&gt;
&lt;br /&gt;
== '''See Also''' ==&lt;br /&gt;
*http://www.caliban.org/ruby/rubyguide.shtml&lt;br /&gt;
*http://github.com/styleguide/ruby&lt;br /&gt;
*http://www.ruby-doc.org/docs/ProgrammingRuby/&lt;br /&gt;
*http://www.ruby-lang.org/en/documentation/&lt;br /&gt;
*http://en.wikibooks.org/wiki/Ruby_programming_language&lt;br /&gt;
&lt;br /&gt;
== '''References''' ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Sagarn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Nosqlvsrdbms.jpg&amp;diff=79863</id>
		<title>File:Nosqlvsrdbms.jpg</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Nosqlvsrdbms.jpg&amp;diff=79863"/>
		<updated>2013-10-07T21:35:22Z</updated>

		<summary type="html">&lt;p&gt;Sagarn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Sagarn</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013&amp;diff=79821</id>
		<title>CSC/ECE 517 Fall 2013</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2013&amp;diff=79821"/>
		<updated>2013-10-07T20:30:44Z</updated>

		<summary type="html">&lt;p&gt;Sagarn: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [[ CSC/ECE 517 Fall 2012/ch1 1w23 ph ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w30 nn]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w21 w]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w01 aj]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w24 nv]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w29 rkld]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w25 aras]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w30 ps]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w19 rj]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w18 bs]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w17 pk]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w22 ss]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w12 vn]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w14 st]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w08 cc]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w10 ga ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w26 as ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w27 ma ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w13 aa ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w11 sv ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w07 d ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w20 gq ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w03 ss ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w28 nm ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w02 pp ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1  1w6 zs ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1  1w04 y ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w05 st ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w09 hs ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w32 av ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w48 x ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w43 av]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w46 ka]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w33 aa]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w35 sa ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w39 as ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w31 vm ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w43 sm ]]&lt;br /&gt;
* [[ CSC/ECE 517 Fall 2013/ch1 1w44 s ]]&lt;/div&gt;</summary>
		<author><name>Sagarn</name></author>
	</entry>
</feed>