affordablemobiles / eloquent-datastore
一个用于将Google Datastore用作数据库驱动程序的包。
    v11.0.4
    2024-09-12 15:08 UTC
Requires
- php: ^8.3
- ext-json: *
- affordablemobiles/laravel-eloquent-query-cache: ~11
- google/cloud-datastore: ^1.28.0
- illuminate/database: ~11
- illuminate/http: ~11
- illuminate/pagination: ~11
- illuminate/support: ~11
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.6
- phpunit/phpunit: ^10
This package is auto-updated.
Last update: 2024-09-12 15:09:14 UTC
README
一个用于将Google Datastore用作数据库驱动程序的包。
使用此包,您可以使用 查询构建器 和 eloquent 访问数据存储中的数据。
安装
此包至少需要Laravel 9.x 和 PHP 8.1。
您可以通过composer安装此包
composer require affordablemobiles/eloquent-datastore
如果您使用Laravel Package Auto-Discovery,则无需手动添加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(数据存储命名空间:多租户)
-  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
贡献指南
您可以通过报告错误、修复错误、提交和审查拉取请求来贡献。
前往 问题 部分,您可以直接开始处理一个问题。
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。