Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
338 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
database/migrations/2018_09_24_002000_create_sense_request_db_queries_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Laravel Sense. | ||
* | ||
* (c) Anton Komarev <a.komarev@cybercog.su> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateSenseRequestDbQueriesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('sense_request_db_queries', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->unsignedBigInteger('request_id'); | ||
$table->unsignedBigInteger('statement_id'); | ||
$table->string('connection'); | ||
$table->mediumText('sql'); | ||
$table->json('bindings'); | ||
$table->double('time', 6, 2); | ||
$table->timestamps(); | ||
|
||
$table->index('request_id'); | ||
$table->index('statement_id'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('sense_request_db_queries'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@extends('sense::app') | ||
|
||
@section('content') | ||
<h2 class="mt-4 mb-4">Queries</h2> | ||
<table class="table"> | ||
<tr> | ||
<th> | ||
# | ||
</th> | ||
<th class="uuid"> | ||
Correlation ID | ||
</th> | ||
<th> | ||
Connection | ||
</th> | ||
<th> | ||
SQL | ||
</th> | ||
<th> | ||
Time | ||
</th> | ||
<th> | ||
Created at | ||
</th> | ||
<th> | ||
Updated at | ||
</th> | ||
</tr> | ||
@foreach($queries as $query) | ||
<tr> | ||
<td class="text-center"> | ||
{{ $query->id }} | ||
</td> | ||
<td class="uuid"> | ||
<a href="/sense/requests/{{ $query->request->correlation_id }}"> | ||
{{ $query->request->correlation_id }} | ||
</a> | ||
</td> | ||
<td class="text-center"> | ||
{{ $query->connection }} | ||
</td> | ||
<td> | ||
{{ $query->sql }} | ||
</td> | ||
<td class="text-center"> | ||
{{ $query->time }} | ||
</td> | ||
<td class="text-center"> | ||
{{ $query->created_at }} | ||
</td> | ||
<td class="text-center"> | ||
{{ $query->updated_at }} | ||
</td> | ||
</tr> | ||
@endforeach | ||
</table> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Laravel Sense. | ||
* | ||
* (c) Anton Komarev <a.komarev@cybercog.su> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cog\Laravel\Sense\Db\Query\Models; | ||
|
||
use Cog\Laravel\Sense\Request\Models\Request; | ||
use Cog\Laravel\Sense\Statement\Models\Statement; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
class Query extends Model | ||
{ | ||
protected $connection = 'sense'; | ||
|
||
protected $table = 'sense_request_db_queries'; | ||
|
||
protected $fillable = [ | ||
'statement_id', | ||
'connection', | ||
'sql', | ||
'bindings', | ||
'time', | ||
]; | ||
|
||
protected $casts = [ | ||
'bindings' => 'json', | ||
]; | ||
|
||
public function request(): BelongsTo | ||
{ | ||
return $this->belongsTo(Request::class, 'request_id'); | ||
} | ||
|
||
public function statement(): BelongsTo | ||
{ | ||
return $this->belongsTo(Statement::class, 'statement_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Laravel Sense. | ||
* | ||
* (c) Anton Komarev <a.komarev@cybercog.su> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cog\Laravel\Sense\Http\Controllers\Queries\Collect; | ||
|
||
use Cog\Laravel\Sense\Db\Query\Models\Query; | ||
use Cog\Laravel\Sense\Http\Controllers\Controller; | ||
|
||
class Action extends Controller | ||
{ | ||
public function __invoke(Request $request) | ||
{ | ||
$query = Query::query(); | ||
|
||
if ($requestId = $request->input('filter.request.id')) { | ||
$query->where('request_id', $requestId); | ||
} | ||
if ($statementId = $request->input('filter.statement.id')) { | ||
$query->where('statement_id', $statementId); | ||
} | ||
|
||
$query->with([ | ||
]); | ||
|
||
$queries = $query->latest('id')->get(); | ||
|
||
return new Response($queries); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Laravel Sense. | ||
* | ||
* (c) Anton Komarev <a.komarev@cybercog.su> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cog\Laravel\Sense\Http\Controllers\Queries\Collect; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class Request extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Laravel Sense. | ||
* | ||
* (c) Anton Komarev <a.komarev@cybercog.su> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cog\Laravel\Sense\Http\Controllers\Queries\Collect; | ||
|
||
use Illuminate\Contracts\Support\Responsable; | ||
|
||
class Response implements Responsable | ||
{ | ||
/** | ||
* @var \Cog\Laravel\Sense\Db\Query\Models\Query[] | ||
*/ | ||
private $queries; | ||
|
||
public function __construct($queries) | ||
{ | ||
$this->queries = $queries; | ||
} | ||
|
||
public function toResponse($request) | ||
{ | ||
return $request->wantsJson() ? $this->toJson() : $this->toHtml(); | ||
} | ||
|
||
private function toHtml() | ||
{ | ||
return view('sense::queries.index', [ | ||
'queries' => $this->queries, | ||
]); | ||
} | ||
|
||
private function toJson() | ||
{ | ||
return []; | ||
} | ||
} |
Oops, something went wrong.