a1comms/eloquent-datastore

此包已弃用,不再维护。作者建议使用affordablemobiles/eloquent-datastore包。

用于将Google Datastore用作数据库驱动程序的包。

v11.0.4 2024-09-12 15:08 UTC

README

Latest Stable Version License

用于将Google Datastore用作数据库驱动程序的包。

使用此包,您可以使用查询构建器eloquent来访问数据存储中的数据。

安装

此包需要Laravel 9.x和PHP 8.1作为最低要求。

您可以通过composer安装此包

composer require affordablemobiles/eloquent-datastore

如果您使用Laravel包自动发现,则无需手动添加ServiceProvider。

无自动发现

如果您不使用自动发现,请将以下ServiceProvider添加到config/app.php文件中的$providers数组中。

AffordableMobiles\EloquentDatastore\DatastoreServiceProvider::class,

路线图

  • 使用查询构建器读取数据。
  • 使用Eloquent模型读取数据。
  • 使用Eloquent模型插入数据。
  • 使用Eloquent模型更新数据。
  • 删除数据。
  • 键查询。
  • 自动生成的主键。
  • 使用Datastore游标读取多页数据。
  • 从Eloquent集合批量更新。
  • 游标分页。
  • 祖先键关系。
  • Datastore命名空间(多租户)。

用法

您需要在config/database.php文件中添加datastore连接。

'connections' => [
    ...
    'datastore' => [
        'driver' => 'datastore',
        'transport' => env('DATASTORE_TRANSPORT', 'grpc'),
    ],
    ...
],

使用Eloquent模型访问

您需要扩展AffordableMobiles\EloquentDatastore\Eloquent\Model类,而不是Laravel的默认Eloquent模型类。

示例-

<?php

namespace App\Models;

use AffordableMobiles\EloquentDatastore\Eloquent\Model;

class Project extends Model
{
    // Your works here
}

使用查询构建器访问

示例-

DB::connection('datastore')
    ->table('projects')
    ->where('project_id', '>', 5)
    ->skip(3)
    ->take(5)
    ->get();

它将返回一个集合。

测试过的构建器函数

  • connection
  • table
  • from
  • namespace(Datastore命名空间:多租户)
  • select(用于投影查询)
  • kind(与table相同)
  • where(可用:=, >, <, >=, <=)
  • limit / take
  • skip
  • orderBy
  • distinct
  • get
  • pluck
  • exists
  • count
  • simplePaginate
  • paginate(与simplePaginate作用相同)
  • first
  • delete
  • insert
  • _upsert(不同于默认的upsert
  • find / lookup
  • chunk / chunkMap / each
  • lazy / cursor

贡献指南

您可以通过报告错误、修复错误、提交和审查pull请求来做出贡献。

转到问题部分,您可以立即开始处理问题。

许可证

MIT许可证(MIT)。请参阅许可证文件以获取更多信息。