An ArangoDb based model and Query builder for Cakephp 3.x

dev-master 2018-09-28 04:29 UTC

This package is not auto-updated.

Last update: 2024-09-29 06:20:11 UTC


README



##### Table of Contents

Description

This is the cakephp version of the arangodb-php lib. the cakephp client allows you to convert your models to arangodb supported models easily. the cakephp arangodb client also allows you to use cakephp find, save, delete, update and joins etc simillar to cake core functionality.


Requirements

  • Cakephp version 3.0 or higher

  • ArangoDB database server version 3.0 or higher.

  • PHP version 5.6 or higher

Note on PHP version support:


Installing the Cakephp arangodb client

To get started you need PHP 5.6 or higher plus an ArangoDB server running on any host that you can access.

There are two alternative ways to get the Cakephp ArangoDb client:

  • Using Composer
  • Cloning the git repository

Alternative 1: Using Composer

composer require cakephparangodb/arangodb

NOTE IF ANY ERROR THEN Add minimum-stability and prefer-stable to your composer.json

Example

{
    "minimum-stability": "dev",
    "prefer-stable": true
}

Alternative 2: Cloning the git repository

You need to have a git client installed. To clone this repository from github, execute the following command in your project directory:

git clone "https://github.com/shubham715/Cakephp-ArangoDb-Package.git"

This will create a subdirectory arangodb-php in your current directory. It contains all the files of the client library. It also includes a dedicated autoloader that you can use for autoloading the client libraries class files. To invoke this autoloader, add the following line to your PHP files that will use the library:

Alternative 3: Invoking the autoloader directly

If you do not wish to include autoload.php to load and setup the autoloader, you can invoke the autoloader directly:

require 'cakephparangodb/lib/ArangoDBClient/autoloader.php';
\ArangoDBClient\Autoloader::init();

How to use the CAKEPHP client

Setting up the connection options

In order to use Cakephp ArangoDB, you need to specify the connection options. currently its only available from core files of this client in future updates we will add functionality to change db config from app.php

For now you need to open yourProject/vendor/cakephparangodb/arangodb/lib/ArangoDBClient/Connect.php and change db config of $_options according to your db config.

Convert Cakephp Models to ArangoDb supported models. Change your cakephp models to like below example

Here for example i am changing UsersTable Model.

<?php
namespace App\Model\Table;

use ArangoDBClient\Connect;

class UsersTable extends \ArangoDBClient\Eloquent\Model
{

}
?>

Thats it. Now you can load model in your controller by using loadModel and use users Table of arangodb into controller like below example

##Here i am giving some examples that how you can use models in controller

##FIND QUERY

Using Find

$data = $this->Users->find('all');

Using Find with conditions

$data = $this->Users->find('all',['conditions'=>['name'=>'test','email'=>'test@gmail.com']]);

Using findById()

$data = $this->Users->findById(10);

Using Find with select

$data = $this->Users->find('all',['select'=>['name','email','status']]);

Using FindOne

$data = $this->Users->findOne('all',['conditions'=>['email'=> $email]]);

advanced find with select , sort , limit

$data = $this->Users->find('all',['select'=>['name','email','status']]);
$data = $this->Users->find('all', ['conditions'=>['email'=>'test@gmail.com'],'order'=>['paydate'=> 'ASC'],'select'=>['name','email','status']]);

Using isUnique

$data = $this->Users->isUnique(['conditions'=>['email'=> $email]]);

Using Count

$data = $this->Users->count(['conditions'=>['email'=> $email]]);

##Updation

Using updateById

$data = $this->Users->updateById(['email'=> $email],['id'=> 1]);

Using updateAll

$data = $this->Users->updateAll(['email'=> $email],['id'=> 1]);

##deletion

deleteById

Using deleteById

$data = $this->Users->deleteById(1);

deleteAll

Using deleteAll

$data = $this->Users->deleteAll(['email'=> $email]);

Using createOrUpdate()

$data = $this->Users->createOrUpdate(['email'=> $email,'id'=> 10]);

Join

$data = $this->Users->findWithJoin('all',['contain'=> 'userdetails', 'conditions'=>['c.userid'=> 'u.id']]);
//Here c is refer for base table and u is for join table.

##Save Data

$data = ['name'=>'shubham715', email'=> 'shubhamsharma715@gmail.com', 'status'=> 1];
$saveData = $this->Users->save($financeEntity);

Here lots of examples that we will update soon.