Installation
Installation steps for queryfi
.
This documentation showcase how to install the queryfi
packages and make use of them in you applications.
This package is dedicated specially for Laravel
applications as the server package is build for it.
However, if you have a backend which can communicate with queries the frontend package can also be used.
1
Install queryfi package
Go ahead and open your frontend typescript app and run the following.
npm install queryfi
2
Configuration
Assuming you have your model whith which you want to work, we'll go with a simple approach, with direct controller 🤔, not the best approach, but fastest and easiest.
If you want to check a better approach and a better DX overall, read this
UserController.php
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Z3rka\Queryfi\HasRelations;
class UserController extends Controller
{
# make use of this trait.
use HasRelations;
public function index(Request $request)
{
$model = User::getModel();
return $this->processModel($request, $model)->get();
}
}
3
Make use of it
In your frontend, whatever it is, use the frontend package you installed.
getUsers.ts
import {createQuery} from 'queryfi'
const query = createQuery<User>("/api/users", {
baseUrl: "http://localhost:8000/" // don't mind the extra / as it will be cleaned.
})
.with(["posts"])
.where([
["name", "like", "%Marisa%"],
["id", ">", 10],
])
.build();
const { data } = await axios.get(query)
//response example
// {
// "id": 50,
// "name": "Marques Kautzer",
// "email": "garrett.kiehn@example.com",
// "email_verified_at": "2024-12-10T16:16:18.000000Z",
// "created_at": "2024-12-10T16:16:18.000000Z",
// "updated_at": "2024-12-10T16:16:18.000000Z",
// "posts": [
// {
// "id": 99,
// "user_id": 50,
// "name": "Florida Kuhlman DDS",
// "status": "inactive",
// "content": "Eaque est qui natus ipsa hic. Nihil molestiae excepturi eos. Quos voluptatem modi voluptatem officiis voluptas. Magnam consequatur quod modi corporis.",
// "created_at": "2024-12-10T16:16:18.000000Z",
// "updated_at": "2024-12-10T16:16:18.000000Z"
// }
// ]
// },