noitran/rql

RQL - Resource Query Language package for laravel / lumen projects

0.2.0 2019-02-26 22:04 UTC

This package is auto-updated.

Last update: 2024-11-05 07:21:42 UTC


README

Coverage Status Quality Score Software License Latest Version Total Downloads

About

Package allows to use Resource Query Language (RQL) with Laravel's Eloquent ORM. Providers a simple and light-weight API for adding dynamic querying capabilities to HTTP based applications. Package functions as connector between HTTP requests and ORM. Currently only Eloquent Processor is included, but pacakge capabilities can be easly extended by adding new Processor.

Install

  • Install as composer package
$ composer require noitran/rql

Usage

use Noitran\RQL\Tests\Stubs\Models\User;
use Noitran\RQL\ExprQueue;
use Noitran\RQL\Processors\EloquentProcessor;

// Getting builder instance of model, or builder 
// instance from noitran/repositories also can be passed.
$builder = User::query();

$queue = new ExprQueue();

// Creating expression
$exprClasses = $this->queue->enqueue(
	new \Noitran\RQL\Expressions\EqExpr(null, 'name', 'John')
);

// Attaching expression into builder
$query = (new EloquentProcessor($this->builder))->process($exprClasses);

// Thats it! Expression has been applied. Can be checked by dumping query.
// Example:
dd($query->toSql());

// Dumps attached expression to sql:
// select * from "users" where "name" = ?

All samples can be viewed in testfile: Noitran\RQL\Tests\Processors\EloquentProcessorTest

Todo

  • Add request / input parsers.
  • Improve relation / column bindings.
  • Improve docs and add more samples.