PHP code example of victormmeloc / datalayer

1. Go to this page and download the library: Download victormmeloc/datalayer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

victormmeloc / datalayer example snippets


// INSERE O AUTOLOAD
ayer;

// DEFINE A TABELA
Datalayer::setTable('users');  

//DEFINE AS CONFIGURAÇÕES DO BANCO DE DADOS
Datalayer::config(
    'localhost',
    'datalayer',
    'root',
    'pass',
    '3306'
);
new Datalayer;

Datalayer::pagination($page,$quantity,$filter,$columns);

// RETORNO
$arr = [
    'previus' => página anterior, caso não tenha retornará null,
    'next' => próxima página, caso não tenha retornará null,
    'current' => página atual,
    'quantityRows' => quantidade de linhas gerais da consulta,
    'quantityPages' => quantidade de páginas,
    'start' => linha inicial,
    'end' => linha final,
    'data' => objeto com os dados,
];

// PARAMETROS

/**
 * PAGE
 * a página que deseja fazer a pesquisa
 * @param int $page
 * valor default é '1'
 */
$page = 1;

/**
 * QUANTITY
 * a quantidade de retornos por página
 * @param int $quantity
 * valor default é '50'
 */
$quantity = 50;

/**
 * FILTER
 * os filtros da consulta. Esse filtro representa a cláusula WHERE da consultar
 * @param array $filter
 * valor default é '[]'
 */
$filter = [
    'name' => [
        'operator' => '=',
        'value' => 'Victor'
    ],
    'email' => [
        'operator' => 'LIKE',
        'value' => 'M%'
    ]
];

/**
 * COLUMNS (opcional)
 * as colunas que deseja retornar
 * @param string $columns
 * valor default é '*'
 */
$columns = 'name,email';

Datalayer::get(array $filter = [], string $columns = '*');
$data = Datalayer::run();
return $data;

// PARAMETROS
/**
 * FILTER
 * os filtros da consulta. Esse filtro representa a cláusula WHERE da consultar
 * @param array $filter
 * valor default é '[]'
 */
$filter = [
    'name' => [
        'operator' => '=',
        'value' => 'Victor'
    ],
    'email' => [
        'operator' => 'LIKE',
        'value' => 'M%'
    ]
];

/**
 * COLUMNS (opcional)
 * as colunas que deseja retornar
 * @param string $columns
 * valor default é '*'
 */
$columns = 'name,email';

$data = Datalayer::find(string $filter,string $column = 'id');
return $data;

// PARAMETROS
/**
 * FILTER (obrigatório)
 * o identificador do item a ser consultado
 * @param string $filter
 */
$filter = '[email protected]';

/**
 * COLUMN (opcional)
 * a coluna que deseja retornar
 * @param string $column
 * valor default é 'id'
 */
$column = 'email';

$request = [
    'nome' => 'Primeiro',
    'email' => 'Segundo Sobrenome',
];

$id = Datalayer::create($request);

$request = [
    'first_name' => 'Raul',
    'last_name' => 'da Silva Sauro',
    'genre' => 'M'
];
Datalayer::update($request, $id);

Datalayer::delete($id);

$columns = Datalayer::describe();