A Song of Ice and FireAlphaGoAntivirusArtificial IntelligenceBashBod PressBusinessCharityChatbotChildrenComputerConflict ZoneCouchDBEbola VirusFM ReceiverGame of ThronesGeolocationGeorge R.R. MartinGuideIncorporationInformation SecurityIoTJavaScriptLawLearningLinus TorvaldsMedicine Mental IllnessNewsNoSQLOperating SystemRansomwareRansomware DayReviewRevolutionRobotsSHA-1San FranciscoScienceSmall BusinessSolar EclipseTechnologyThe Fourth Industrial RevolutionThe FutureTime ManagementUnix-likeVanilla ForumsWana Decrypt0rWelcomeWordpressWorld Bank GroupZero-day Vulnerability

Work with CouchDB on the JavaScript to-do List Sample App

At some time, I had to work with one of the document-oriented DBMS – Apache CouchDB, but I had some difficulties with the search of the documentation.

In this article, I want to talk about how to work in this DBMS from JavaScript on the example of a small "To-do List" app. Because the article is focused on ApacheCouchDB – I'm not going to show and tell about how the app works entirely.

The Model

The operating principle of this app is the following:

  1. When the page loads we send a request to the database server.
  2. We receive from it a JSON structure.
  3. Then we parse it on the page.
  4. As needed, we add any notes.
  5. When we press ‘Save’, we write the data to the database.

All page content is stored as the following:

model = {
items: [
{
_id: 1,
date: "11.11.11",
name: "test page #1",
does:[{
check : 'true',
name : 'Test 1',
time : '00:00'
}]
}
{
_id: 2,
date: "11.11.11",
name: "test page #2 ",
does:[{
check : 'true',
name : 'Test 2 ',
time : '00:00'
}]
}

]

Each of the elements of items keeps a worksheet that includes a list of the cases, in the example above each list contains one element (does).

So we have a model to store the data. The next step is directly working with DBMS.

CouchDB installation

The easiest way to install CouchDB is to go to the website and download the installation distributive for your operating system. When installing, it's necessary to pay attention to the viruses, so it's advisable to download antivirus with intelligent protection by Bod Security.

Functional testing

After installing CouchDB, it's needed to check it for serviceability, to do this, it's necessary to go to the address: 127.0.0.1:5984.

You can go to the next step.

Control panel

Working with a control panel CouchDB is carried out by using the Futon interface, the access to which can be done by typing in the address bar of your browser the following address: 127.0.0.1:5984/_utils.

If everything is correct, you will see the control panel (in version 2.x.x the control panel looks different).

Click on the button "Create Database, " and in the box, we enter the name of our DB.

All in all, our database is created, and the next step will be the engagement with this database, specifically from the app.

The engagement with DB from the app

I composed a functional part of the app, without the connecting to the database, that is, it operates in the offline mode after the reloading the page all the data are erased. We need to implement the record of the created data into the base, and the retrieving them from there when we download the app. Combed the official documentation, I found a plugin, which written for plain JavaScript, and also for JQuery. I decided to use the JQueryPlugin.

It is located in the CouchDB assembly that we downloaded, and you can find it at this address: 127.0.0.1:5984/_utils/script/jquery.couch.js.

Data record into the DB

When the app creates a model of our data, we need to log them into the DB. The first thing we need to specify the host and port of the DB:

$.couch.urlPrefix = "http://localhost:5984";

It's necessary to use the following function to access the database:

$.couch.db(“todo_model”).method

We need a saveDoc method which overwrites the document in the database if it has the same id as the input document has, and creates a new document if the id does not match any of the existing ones.

Next, it's necessary to cycle go through each element of the app model and write it to the database.


for(var i = 0; i < $scope.list.items.length; i++){ var doc = $scope.list.items[i]; doc._id = String(doc._id); $.couch.db("todo_model").saveDoc(doc, { success: function(data) { console.log(data); }, error: function(status) { console.log(status); } }); }

*The app was built using AngularJS framework. It's not recommended to use AngularJS and JQuery in conjunction for the real purposes.

There are documents in the database which are stored in the JSON format.

Thus, using the plugin JQueryCouchDB, we can easily record the data into the database. In the same way, we can get the data from the database, but I decided to show a slightly different way that can be used without connecting any third-party plugins.

The HTTP request to CouchDB

When the page loads I send the request to the server where our database is, as a response I receive the JSON structure with the necessary data:

$http.get('http://127.0.0.1:5984/todo_model/_all_docs').then(function(response){
$scope.model_len = response.data.rows.length
for (var i = 0; i < $scope.model_len; i++) { var p = response.data.rows[i].id

$http.get('http://127.0.0.1:5984/todo_model/' + p ).then(function(data){

model.items.push(data.data) }); } });

I get all the elements for fixing their number, then each of the elements I push into the model.

Conclusion

There is little documentation on this DBMS. I've shown one of the ways to work with it, and, hopefully, helped someone.

Related Coverage

(Sunrise space outer via Pixabay) It seems almost a lifetime ago that the US and Russia were locked in a desperate struggle to reach space. Fifty years hence, and it seems we .

24

Free Antivirus Software Over 8 years have gone after Windows 7 was introduced it's as yet the most mainstream Windows out there. In any case, the sudden rise of the substantial scale ransomware disease demonstrated to us some unquestionable security escape clauses in Microsoft's fan top choice. Fundamentally, a lot of clients set aside the way that the obsolete Security Essentials ca.

24

The Internet of Things has had a huge impact on the way many industries are approaching the future, with lots of research centred around IoT, and the success of smartwatches has shown the clear potential in wearable technology. Combining IoT with clothing makes a lot of sense, as it takes advantage of items that are on our person for long periods of the day. Over the next few years, wearable te.

22

October 4th, 1957: the Soviet Union launched the very first satellite, Sputnik 1, into Space. It was the first time humanity had sent any object in to space. Twelve years later, in July 1969, Neil Armstrong became the first person to walk on the moon, paving the way for increasingly bo.

80

Although there have been many smaller developments, and numerous aesthetic changes along the way, the face of transportation has looked fairly similar for the past few decades. Despite promises of hover cars, our roads are still lined with four-wheeled vehicles, trains still run on tracks, and planes are still cramped and noisy. There have been advancements, and in the next few years you can ex.

55

Legal issues At some point in life, everyone gets an idea of starting their own business – be it that of dealing in diamonds, opening a restaurant or simply starting a bar they always wanted to open! It is always exciting to start a small business of your own and dreaming about it.

199

One of the most challenging tasks in computer programming is developing an OS and frankly, is not for everyone except the most hard core geekheads among you. In order to start with creating your very own OS let us start by viewing the basic definitions of what a BIOS or boot loader is and does. An operating.

159
January 20, 11 AM
AlphaGo Beginner's Guide

AlphaGo Everyone knows that DeepMind's AlphaGo defeated 18 times world champion Lee Sedol on March 9 2016 at the ancient Chinese game- Go. What’s fascinating is that the game of Go has as many possible moves as there are atoms in the universe. This motivated us to find out more about AlphaGo.

181

Last month, the World Bank Group published the World Development Report (WDR) 2018, the first-ever edition entirely focused on education. The report warns of a learning crisis in global education and the severity of this in the deprived areas. Shockingly, there are still around 260 million children who aren’t even enrolled in primary or secondary schools. Education is meant to equip stud.

199

Medicine is the most rapidly growing area of expertise. In recent decades, new technologies and scientific discoveries have changed the idea of the body and its diseases and at the same time the approach to the treatment of the whole person.

415

he World Health Organization estimates that about 300 million people around the world are suffering from depression, 60 million from bipolar affective disorder, and 21 million from schizophrenia.

294

The Internet of Things The first three industrial revolutions were triggered by steam, electricity, and, and wired computers which transformed people’s way of life and manufacturing and brought digital capabilities to billions of people.

455

Opening your own business is a task that is certainly difficult and responsible, but experienced entrepreneurs will agree that real difficulties come when you start developing an already launched project.

220

Automation of business processes is no longer just an evolving trend in digital marketing. Today it is an integral part of a brand communication.

238

We all have stories about working in dysfunctional offices, with wacky colleagues and under stressful deadlines. But even this cannot compare to working in a conflict zone, a place that is ravaged by war.

458

Game of ThronesGeorge R.R. Martin is an American novelist, fantasy, sci-fi and short story writer. Most of the world got acquainted with him after screen adaptation of his epic saga "a Song of Ice and Fire".

383

Over the last years the art of time management gains popularity. Why so? The answer is very simple: we want to control our life. No wonder there are plenty of interesting techniques allowing us to properly schedule and manage our time.

214

Ebola Virus The Ebola virus causes a severe illness that is often lethal in the absence of treatment.

566
July 11, 09 AM
Welcome to Bod Press

Bod Press is a global social network for readers, journalists and companies engaged in writing and reading. The unique audience, fresh information, constructive communication, and collective creativity.

585

Bod Intelligent Antivirus This review is dedicated to the Bod Intelligent Antivirus developed by Bod Security. The purpose of the article is to show its functionality and demonstrate how it behaves in real conditions.

743 2

wordpress Automattic Company, the developer of WordPress, will no longer spend money on maintaining the office in San Francisco.

868

Computer Technology It seems that many years have passed, which made an eternity by the standards of the world of computer technology. And the reflection on past mistakes does not stop. And what would have happened if...

451

Robotic assistant Millions of American families buy automatic voice assistants to turn off the lights instead of themselves, order pizza and show movie program in the cinema.

428

The data about critical vulnerabilities in WordPress were published - they allow remote execution of shell commands and resetting the administrator password through the substitution of the Host header.

913 1

More than 60,000 computers were attacked and infected with a virus-extortionist Wana Decrypt0r.

377

The article describes how to work with push notifications about object events in browsers.

340

Imagine that you are sitting and waiting for someone in the car, and the poster of your favorite group has caught your eye.

325

We will organize the small distribution of free stuff for those who aspire to bring something good, kind, wise, and eternal to children.

308

Google's co-workers and the Centre of Mathematics and Computer Science in Amsterdam, presented the first algorithm generating collisions for SHA-1.

1051

The idea of editing the user environment variables to elevate the rights in penetration testing is as old as the world.

366
Never miss a story by Andrew Buren, when you sign up for Bod Press.
Sign up