Skip to content

Commit

Permalink
Merge pull request #4 from PortableStudios/feature/make-driver-agnostic
Browse files Browse the repository at this point in the history
Make the model agnostic of the driver, and parse objects appropriately
  • Loading branch information
kyoungportable authored Sep 6, 2023
2 parents b86cbfb + a7edaf8 commit 929760a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 26 deletions.
7 changes: 7 additions & 0 deletions src/Eloquent/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ public function zohoUpsert(string $toTable, array $data, array|string $key): int
$key = [$key];
}

foreach ($data as $rowIndex => $row) {
foreach ($row as $field => $value) {
$row[$field] = $value instanceof \Stringable ? (string) $value : $value;
}
$data[$rowIndex] = $row;
}

return $this->getClient()->importUpsert($toTable, $data, $key);
}

Expand Down
19 changes: 0 additions & 19 deletions src/Eloquent/ZohoModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Date;
use Portable\EloquentZoho\Casts\ZohoInteger;
use Portable\EloquentZoho\Eloquent\Query\Builder as QueryBuilder;

abstract class ZohoModel extends Model
{
Expand All @@ -26,24 +25,6 @@ public function __construct(array $attributes = [])
$this->casts = array_merge($this->casts, ['id' => ZohoInteger::class]);
}

/**
* {@inheritdoc}
*/
public function newEloquentBuilder($query)
{
return new Builder($query);
}

/**
* {@inheritdoc}
*/
protected function newBaseQueryBuilder()
{
$connection = $this->getConnection();

return new QueryBuilder($connection, $connection->getQueryGrammar(), $connection->getPostProcessor());
}

/**
* Get the current connection name for the model.
*
Expand Down
11 changes: 4 additions & 7 deletions src/Providers/ZohoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Portable\EloquentZoho\Providers;

use Illuminate\Support\ServiceProvider;
use Portable\EloquentZoho\Eloquent\Connection;
use Portable\EloquentZoho\Eloquent\Connection as ZohoConnection;
use Illuminate\Database\Connection;

class ZohoServiceProvider extends ServiceProvider
{
Expand All @@ -17,12 +18,8 @@ public function register(): void
'eloquent-zoho'
);
// Add database driver.
$this->app->resolving('db', function ($db) {
$db->extend('zoho', function ($config, $name) {
$config['name'] = $name;

return new Connection($config);
});
Connection::resolverFor('zoho', function ($connection, $database, $prefix, $config) {
return new ZohoConnection($config);
});
}

Expand Down

0 comments on commit 929760a

Please # to comment.