a1comms/eloquent-datastore

This package is abandoned and no longer maintained. The author suggests using the affordablemobiles/eloquent-datastore package instead.

A package for using Google Datastore as a database driver.

v11.0.2 2024-04-03 15:03 UTC

README

Latest Stable Version License

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 default upsert)
  • 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.