Switchout DB to CockroachDB
This commit is contained in:
@@ -7,13 +7,15 @@ namespace App\Traits;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
use App\Classes\FTN\Message;
|
||||
use App\Models\Setup;
|
||||
|
||||
trait MsgID
|
||||
{
|
||||
public function save(array $options = [])
|
||||
{
|
||||
if (! $this->exists) {
|
||||
// Only create a MSGID for locally generated conetnt
|
||||
if ((! $this->exists) && ($this->flags & Message::FLAG_LOCAL)) {
|
||||
$ftns = Setup::findOrFail(config('app.id'))->system->match($this->fftn->zone)->first();
|
||||
|
||||
if (is_null(Arr::get($this->attributes,'msgid')))
|
||||
|
17
app/Traits/QueryCacheableConfig.php
Normal file
17
app/Traits/QueryCacheableConfig.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Set defaults of QueryCacheable
|
||||
*/
|
||||
namespace App\Traits;
|
||||
|
||||
use Rennokki\QueryCache\Traits\QueryCacheable;
|
||||
|
||||
trait QueryCacheableConfig
|
||||
{
|
||||
use QueryCacheable;
|
||||
|
||||
public $cacheFor = 900; // cache time, in seconds
|
||||
protected static $flushCacheOnUpdate = TRUE;
|
||||
public $cacheDriver = 'memcached';
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Models that store data in Mongo
|
||||
*/
|
||||
namespace App\Traits;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait UseMongo
|
||||
{
|
||||
/**
|
||||
* Resolve a connection instance.
|
||||
* We need to do this, because our relations are in pgsql and somehow loading a relation changes this models
|
||||
* connection information. Using protected $connection is not enough.
|
||||
*
|
||||
* @param string|null $connection
|
||||
*/
|
||||
public static function resolveConnection($connection = null)
|
||||
{
|
||||
return static::$resolver->connection('mongodb');
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getMsgAttribute($value): string
|
||||
{
|
||||
return utf8_decode($value);
|
||||
}
|
||||
|
||||
public function setMsgAttribute($value): void
|
||||
{
|
||||
$this->attributes['msg'] = utf8_encode($value);
|
||||
}
|
||||
|
||||
public function getSubjectAttribute($value): string
|
||||
{
|
||||
return utf8_decode($value);
|
||||
}
|
||||
|
||||
public function setSubjectAttribute($value): void
|
||||
{
|
||||
$this->attributes['subject'] = utf8_encode($value);
|
||||
}
|
||||
|
||||
/* METHODS */
|
||||
|
||||
public static function countGroupBy(array $fields,array $where=[]): Collection
|
||||
{
|
||||
$query = collect();
|
||||
|
||||
if (count($where)) {
|
||||
$where_condition = [];
|
||||
|
||||
foreach ($where as $key => $values) {
|
||||
if (! is_array($values))
|
||||
throw new \Exception('Where values must be an array.');
|
||||
|
||||
switch ($x=Arr::get($values,0)) {
|
||||
case '$gt':
|
||||
case '$gte':
|
||||
$where_condition[$key] = [ $x => Arr::get($values,1)];
|
||||
break;
|
||||
|
||||
case '$in':
|
||||
default:
|
||||
$where_condition[$key] = ['$in' => $values];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$query->push([
|
||||
'$match' => [ '$and'=> [$where_condition]]
|
||||
]);
|
||||
}
|
||||
|
||||
$gb = collect();
|
||||
foreach ($fields as $field)
|
||||
if (is_array($field)) {
|
||||
foreach ($field as $k=>$v) {
|
||||
$gb->put('datetime',['$dateToString'=>['format'=>$v,'date'=>'$'.$k]]);
|
||||
}
|
||||
|
||||
} else {
|
||||
$gb->put($field,'$'.$field);
|
||||
}
|
||||
|
||||
$query->push([
|
||||
'$group' => [
|
||||
'_id' => $gb->toArray(),
|
||||
'count' => ['$sum' => 1]
|
||||
]
|
||||
]);
|
||||
|
||||
return (new self)
|
||||
->groupBy($field)
|
||||
->raw(function($collection) use ($query) {
|
||||
return $collection->aggregate(
|
||||
$query->toArray()
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Models that store data in Postgres
|
||||
*/
|
||||
namespace App\Traits;
|
||||
|
||||
trait UsePostgres
|
||||
{
|
||||
/**
|
||||
* Resolve a connection instance.
|
||||
* We need to do this, because our relations are in pgsql and somehow loading a relation changes this models
|
||||
* connection information. Using protected $connection is not enough.
|
||||
*
|
||||
* @param string|null $connection
|
||||
*/
|
||||
public static function resolveConnection($connection = null)
|
||||
{
|
||||
return static::$resolver->connection('pgsql');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user