You are on page 1of 32

PRESENTER – VIJAY KUMAR

1ST FEBRUARY 2019


What is ArangoDB.
 ArangoDB is a native multi-model, open source database with flexible data models
for documents, graphs and key values. 

 Multi-model because ArangoDB provides the capabilities of a graph database, a


document database, a key-value store. 

 It’s native, because users can use and freely combine all supported data models and
access patterns in a single query

Installation:

To install ArangoDB, as first step, please download the package for your Operating System from
the official Download page of the ArangoDB web site.
HIGH-LEVEL OVERVIEW
Feature ArangoDB
Initial Release 2012
multi-model
Data Model
(documents, graphs, key-value)
Data Format JSON
Written in C++
License Apache 2 / Commercial
Data Storage  mostly memory
Schema free  Yes
Transactions ACID
Multi-Collection Transactions Yes
AQL
Declarative Query Language One sql-like query language
for all data-models
Joins Yes
Cluster ready Yes
Encryption TLS/SSL
Authentication Yes
Role-based access control*** Yes
TERMINOLOGY
BELOW IS A TABLE WITH THE TERMS OF BOTH SYSTEMS SQL &
AQL.

SQL AQL

database database

table collection

row document

column attribute

table joins collection joins

primary key (automatically present


primary key
on _key attribute)

index index
ArangoDB - Advantages

 Consolidation. As a native multi-model database, ArangoDB


eliminates the need to deploy multiple databases, and thus
decreases the number of components and their maintenance.
 Simplified Performance Scaling.
 Reduced Operational Complexity.
 Strong Data Consistency.
 Fault Tolerance.
 Lower Total Cost of Ownership.
 Transactions.
SQL / AQL - Comparison

INSERT
The INSERT keyword adds new documents to a collection.  It uses the following
syntax:

Inserting a single row / document

SQL AQL
INSERT INTO users (name, gender)  INSERT { name: "John Doe", gender: "m"
  VALUES ("John Doe", "m"); } 
  INTO users
Inserting multiple rows / documents

SQL AQL
INSERT INTO users (name, gender)  FOR user IN [ 
  VALUES ("John Doe", "m"),    { name: "John Doe", gender: "m" }, 
         ("Jane Smith", "f");   { name: "Jane Smith", gender: "f" } 
]
  INSERT user INTO users

Inserting rows / documents from a table / collection

SQL AQL
INSERT INTO backup (uid, name, gender)  FOR user IN users
  SELECT uid, name, gender    FILTER user.active == 1
  FROM users    INSERT user INTO backup
  WHERE active = 1;
SELECT /FOR
When you want to retrieve rows from a table in SQL, you query the database with
a SELECT statement. In AQL, you query documents from a collection using the FOR
 and RETURN keywords.

Here, FOR iterates over documents in a collection. RETURN determines what the


query returns to the client.

Selecting all rows / documents from a table / collection, with all columns /
attributes
SQL AQL
SELECT *  FOR user IN users
  FROM users;   RETURN user
UPDATE
The UPDATE keyword partially modifies documents in a collection. There are two syntaxes
available for this operation.

UPDATE document IN collection options


UPDATE keyExpression WITH document IN collection options

Updating a single row / document

SQL AQL
UPDATE users  UPDATE { _key: "1" }
  SET name = "John Smith"   WITH { name: "John Smith" }
  WHERE id = 1;   IN users

Adding a new column / attribute with a default value

SQL AQL
ALTER TABLE users  FOR user IN users
  ADD COLUMN numberOfLogins    UPDATE user
  INTEGER NOT NULL default 0;     WITH { numberOfLogins: 0 } IN users
DELETE / REMOVE
SQL uses DELETE statements to remove rows from a table. In AQL, the REMOVE
 keyword allows you to remove documents from a collection.

Deleting a single row / document

SQL AQL
DELETE FROM users REMOVE { _key:"1" } 
  WHERE id = 1;   IN users

Deleting multiple rows / documents

SQL AQL
DELETE FROM users FOR user IN users
  WHERE active = 1;   FILTER user.active == 1
  REMOVE user IN users
There are many more queries for following commands.

INSERT
SELECT / FOR
UPDATE
DELETE / REMOVE
REPLACE
AGGREGATION
JOINS
etc.

Please refer below link for more queries.

https://www.arangodb.com/why-arangodb/sql-aql-comparison/
How to create collection in arangodb interface.

Login with user name password in arangodb server.


Click on add collection and enter the name and save.
Angular, Spring Boot and ArangoDB Integration:

Below are the steps for the integration.

Step 1. Create a collection "users" in arangoDB from interface

Step 2. List of files require at angular side

1. user.model.ts

export class User {


   id: string;
   firstName: string;
   lastName: string;
   address: string;
}

2. app-constants.ts

export const environment = {


  production: false
  apiUrl: 'http://localhost:2020/user' 
};
3. user-service.ts

import {Injectable} from '@angular/core';


import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from '../constants/app-constants';
import { User } from '../models/user.model';

const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};

@Injectable()
export class UserService {
     constructor(private http:HttpClient) {}
     private userUrl =environment.apiUrl;

    public getUsers() {
        return this.http.get<User[]>(this.userUrl);
    }
    public createUser(user) {
        return this.http.post<User>(this.userUrl, user);
    }
}
4. user-component.ts

import { Component, OnInit } from '@angular/core';


import { Router } from '@angular/router';
import { UserService } from './user.service';
import { User } from '../models/user.model';

@Component({
selector: 'app-user',
templateUrl: './user.component.html',
styles: []
})

export class UserComponent implements OnInit {


   users: User[];
   constructor(private router: Router, private userService: UserService) {}

   ngOnInit() {
       this.userService.getUsers().subscribe( data => {
       this.users = data;
    });
};
5. user-component.html

<table class="table table-striped">


    <thead>
    <tr>
          <th class="hidden">Id</th>
          <th>FirstName</th>
          <th>LastName</th>
          <th>Address</th>
    </tr>
    </thead>
    <tbody>
    <tr *ngFor="let user of users">
           <td class="hidden">{{user.id}}</td>
           <td>{{user.firstName}}</td>
           <td>{{user.lastName}}</td>
          <td>{{user.address}}</td>
     </tr>
     </tbody>
</table>
Step 3. List of files required at Spring Boot side

1. pom.xml

Spring Data is a high level SpringSource project whose purpose is to unify and ease the access
to different kinds of persistence stores, both relational database systems and
NoSQL data stores.

<dependency>
       <groupId>com.arangodb</groupId>
       <artifactId>arangodb-spring-data</artifactId>
       <version>2.1.4</version>
</dependency>
2. ArangoUserController.java

package com.arango.arangoExample.controller;

@RestController
@RequestMapping({"/user"})
public class ArangoUserController {

    @Autowired
    private ArangoUserService arangoUserService ;

    @PostMapping
    public User create(@RequestBody User user){        
        return arangoUserService.create(user);
    }
    
    @GetMapping
    public List<User> findAll(){
        return arangoUserService.findAll();
    }
}
3. ArangoUserService.java

package com.arango.arangoExample.services;
@Service
public class ArangoUserService {
    @Autowired
    private ArangoUserRepository arangoUserRepository;
    
    public User create(User user) {
        return arangoUserRepository.save(user);
    }
    
    public List<User> findAll() {
        List<User> list = new ArrayList<User>();        
        Iterable<User> iterable = arangoUserRepository.findAll();
        Iterator<User> iter = iterable.iterator();
        while(iter.hasNext()){
            User user = iter.next();
            list.add(user);
        }        
        return list;
    }
}
4. ArangoUserRepository.java

package com.arango.arangoExample.repository;

import com.arango.arangoExample.model.User;
import com.arangodb.springframework.repository.ArangoRepository;

public interface ArangoUserRepository extends ArangoRepository<User> {

}
5. User.java

package com.arango.arangoExample.model;

import org.springframework.data.annotation.Id;
import com.arangodb.springframework.annotation.Document;

@Document("users")
public class User {
    
    @Id
    private String id;   
    private String firstName;    
    private String lastName;    
    private String address;
    
    Add setters and getters
}
6. arango.properties 

arango.datasource.hostname=127.0.0.1
arango.datasource.port=8529
arango.datasource.username=root
arango.datasource.password=root
arango.datasource.database=_system
7. ArangoConfiguration.java 

package com.arango.arangoExample;

@Configuration
@PropertySource("classpath:arango.properties")
@EnableArangoRepositories(basePackages = { "com.arango.arangoExample" })
public class ArangoConfiguration extends AbstractArangoConfiguration {    

    @Value("${arango.datasource.hostname}")
    private String hostname;
    
    @Value("${arango.datasource.port}")
    private int port;
    
    @Value("${arango.datasource.username}")
    private String username;
    
    @Value("${arango.datasource.password}")
    private String password;
    
    @Value("${arango.datasource.database}")
    private String database;
    @Override
    public Builder arango() {
        return new ArangoDB.Builder().host(hostname, port).user(username).password(password);
    }
     
    @Override
    public String database() {
        return database;
    }

Add setter & getter methods

}
FOXX Framework.

Foxx is a JavaScript framework for writing data-centric HTTP microservices that run
directly inside of ArangoDB.

Traditionally, server-side projects were developed as standalone applications that


guide communications between the client-side front-end and the database back-end.
Through the Foxx Microservice Framework, ArangoDB allows application developers
to write their data access and domain logic as microservices and running directly
within the database with native access to in-memory data.

Unlike this approach to storing logic in databases, these microservices can be


written as regular, structured JavaScript applications, easily distributed and version
controlled. Foxx can handle anything from optimized REST endpoints performing
complex data access to standalone applications running directly inside the database.
Benefits

Benefits of using Foxx include:

• Unified Data Storage Logic: Standardizing your data access and storage logic on a
consistent domain specific API, allowing clients to access the database using the
same performance optimized queries.

• Reduced Network Overhead: Running inside of ArangoDB itself, Foxx allows you to
bundle database queries with the logic necessary to handle requests in one place,
reducing the number of requests your applications need to send to the database.

• Restricting Access to Sensitive Data: Moving the authentication and authorization


processes from your application to ArangoDB, Foxx lets you isolate sensitive
information, ensuring that it never has to leave the database.

• Other Features: Foxx supports additional features, including automatically


generating documentation with Swagger, full-stack JavaScript, infinite extensibility
and integration with external services.
Create FOXX Services from arangodb server.

Go to Services tab -> click on add Services  -> enter the details and click on install.
Access FOXX Services

http://127.0.0.1:8529/_db/mydb/foxxService/foxxcollection
References.

https://www.tutorialspoint.com/arangodb/arangodb_quick_guide.htm
https://www.arangodb.com/wp-content/uploads/documents/Arango_vs_MongoDB_151119.pdf
https://www.arangodb.com/why-arangodb/sql-aql-comparison/
https://github.com/arangodb/velocypack
https://www.arangodb.com/why-arangodb/sql-aql-comparison/
https://docs.arangodb.com/3.4/Manual/Foxx/
https://www.arangodb.com/tutorials/spring-data/
https://github.com/arangodb/spring-data-demo#create-a-configuration-class"
https://www.arangodb.com/documentation/
https://github.com/arangodb/arangodb/issues
https://groups.google.com/forum/?hl=de#!forum/arangodb
https://stackoverflow.com/questions/tagged/arangodb
https://slack.arangodb.com/
https://www.arangodb.com/documentation/faq/

You might also like