phpvms/app/Services/DatabaseService.php
2018-06-20 11:18:30 -05:00

79 lines
1.7 KiB
PHP

<?php
namespace App\Services;
use App\Interfaces\Service;
use App\Support\Database;
use Carbon\Carbon;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\DB;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\Yaml\Yaml;
use Webpatser\Uuid\Uuid;
/**
* Class DatabaseService
* @package App\Services
*/
class DatabaseService extends Service
{
protected $time_fields = [
'created_at',
'updated_at'
];
protected $uuid_tables = [
'acars',
'flights',
'pireps',
];
/**
* @return string
*/
protected function time(): string
{
return Carbon::now('UTC'); //->format('Y-m-d H:i:s');
}
/**
* @param $yaml_file
* @param bool $ignore_errors
* @return array
* @throws \Exception
*/
public function seed_from_yaml_file($yaml_file, $ignore_errors = false): array
{
return Database::seed_from_yaml_file($yaml_file, $ignore_errors);
}
/**
* @param $yml
* @param bool $ignore_errors
* @return array
* @throws \Exception
*/
public function seed_from_yaml($yml, $ignore_errors = false): array
{
return Database::seed_from_yaml($yml, $ignore_errors);
}
/**
* @param $table
* @param $row
* @return mixed
* @throws \Exception
*/
public function insert_row($table, $row) {
# see if this table uses a UUID as the PK
# if no ID is specified
if (\in_array($table, $this->uuid_tables, true)) {
if (!array_key_exists('id', $row)) {
$row['id'] = Uuid::generate()->string;
}
}
return Database::insert_row($table, $row);
}
}