iazaran/crudgeneratrix

1.0.7 2023-03-16 07:52 UTC

This package is auto-updated.

Last update: 2024-09-16 11:08:45 UTC


README

PHP CRUD Generatrix

在PHP中生成CRUD功能,可用于API项目以接受单个POST端点的请求。请查看samples.php

安装

  • 通过composer: composer require iazaran/crudgeneratrix

功能

  • 获取表和列的信息 使用information方法可以生成关于表和列的信息。这样前端就可以看到列及其类型。
  • 自动生成简单的CRUD createreadupdatedelete方法可以接受不同的参数,以确定要应用CRUD的目标表和列。您可以为特定的请求添加自定义方法以进行更多处理。
  • 可定制的搜索 search方法可用于根据某些条件列出记录。条件可以自定义,并通过不同类型的条件运算符相互连接。可以使用类似于read方法的关系。可以应用限制和偏移量来限制记录数和起始索引,这对于分页也很有用。
  • 可用于API的单个端点 此软件包不提供API功能,但您可以将端点设置为接受这些参数并执行类似于GraphQL的CRUD功能。有一个接受所有参数并实现此软件包任何类型功能的api方法。

运行Web应用

  • 这里有一个示例。您可以创建一个数据库和一些表以及记录。确保您还设置了外键。
  • 现在更新samples.php并运行php samples.php
  • 一些示例
// Getting information about a table and some columns
$generatrixCRUD::information(
    ['countries' => ['countryCode', 'countryName']]
);

// Reading a specific row from a table and related table(s) and columns based on different relationship directions
$generatrixCRUD::read(
    ['cities' => ['cityName']],
    30,
    ['hotels' => ['name']],
    'LEFT'
);
$generatrixCRUD::read(
    ['hotels' => ['name']],
    30,
    ['cities' => ['cityName']],
    'RIGHT'
);

// Using custom method as callback
// Without callback like: [{"cityName":"Al Ain","name":"Radisson Blu Hotel & Resort, Al Ain"},{"cityName":"Al Ain","name":"Danat Al Ain Resort"},{"cityName":"Al Ain","name":"Mercure Grand Jebel Hafeet Al Ain Hotel"}]
// With callback like: {"cityName":[{"name":"Radisson Blu Hotel & Resort, Al Ain"},{"name":"Danat Al Ain Resort"},{"name":"Mercure Grand Jebel Hafeet Al Ain Hotel"}]}
$generatrixCRUD::read(
    ['cities' => ['cityName']],
    30,
    ['hotels' => ['name']],
    'LEFT',
    ['CustomMethods', 'groupByFirstColumn']
);

// Create multiple rows
$generatrixCRUD::create(
    ['countries' => [
        'countryCode' => ['US', 'GB'],
        'countryName' => ['United State', 'Great Britain'],
    ]]
);

// Update specific row
$generatrixCRUD::update(
    ['countries' => [
        'countryCode' => 'ES',
        'countryName' => 'Spain',
    ]],
    237
);

// Delete specific row
$generatrixCRUD::delete(
    ['countries'],
    237
);

// Search for multiple columns (AND, OR, XOR, ...) of target table (=, LIKE, NOT, ...) and list them ('AND' will be considered for joining conditions of conditions) You can add relationships like read method
$generatrixCRUD::search(
    ['OR' => [
        '=' => ['cityName' => 'dubai'],
        'LIKE' => ['cityName' => 'old'],
    ]],
    ['cities' => ['cityName']],
    [],
    '',
    10,
    5
);

// To use as a single method for all type of features. You can use any method name in here as `type`
$generatrixCRUD::api(
    'search',
    ['cities' => ['cityName']],
    null,
    [],
    '',
    ['OR' => [
        '=' => ['cityName' => 'dubai'],
        'LIKE' => ['cityName' => 'old'],
    ]],
    10,
    5,
    []
);

eazaran@gmail.com