affordablemobiles / eloquent-datastore
A package for using Google Datastore as a database driver.
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-12-08 14:12:00 UTC
README
A package for using Google Datastore as a database driver.
By using this package, you can use query builder
and eloquent
to access data from datastore.
Installation
This package requires Laravel 9.x & PHP 8.1 as a minimum.
You can install the package via composer:
composer require affordablemobiles/eloquent-datastore
If you are using Laravel Package Auto-Discovery, you don't need you to manually add the ServiceProvider.
Without auto-discovery:
If you don't use auto-discovery, add the below ServiceProvider to the $providers
array in config/app.php
file.
AffordableMobiles\EloquentDatastore\DatastoreServiceProvider::class,
Roadmap
- Read data using query builder.
- Read data using Eloquent model.
- Insert data using Eloquent model.
- Update data using Eloquent model.
- Delete data.
- Keys only queries.
- Auto-generated primary key.
- Read multiple pages of data with Datastore cursors.
- Batch update from Eloquent collection.
- Cursor Paginate.
- Ancestor key relations.
- Datastore Namespaces (Multi-Tenancy).
Usage
You need to add datastore
connection in config/database.php
file.
'connections' => [ ... 'datastore' => [ 'driver' => 'datastore', 'transport' => env('DATASTORE_TRANSPORT', 'grpc'), ], ... ],
Access using Eloquent Model
You need to extend AffordableMobiles\EloquentDatastore\Eloquent\Model
class instead of Laravel's default Eloquent model class.
Example-
<?php namespace App\Models; use AffordableMobiles\EloquentDatastore\Eloquent\Model; class Project extends Model { // Your works here }
Access using Query Builder
Example-
DB::connection('datastore') ->table('projects') ->where('project_id', '>', 5) ->skip(3) ->take(5) ->get();
It will return a collection.
Tested Builder Functions
-
connection
-
table
-
from
-
namespace
(Datastore Namespace: Multi Tenancy) -
select
(for projection query) -
kind
(same as table) -
where
(Available: = , > , < , >= , <= ) -
limit
/take
-
skip
-
orderBy
-
distinct
-
get
-
pluck
-
exists
-
count
-
simplePaginate
-
paginate
(works same as simplePaginate) -
first
-
delete
-
insert
-
_upsert
(different and incompatible with defaultupsert
) -
find
/lookup
-
chunk
/chunkMap
/each
-
lazy
/cursor
Contribution Guide
You can contribute by reporting bugs, fixing bugs, submitting and reviewing pull requests.
Go to issues section, and you can start working on an issue immediately.
License
The MIT License (MIT). Please see License File for more information.