3
3
namespace LaravelEnso \DataImport \app \Tables \Builders ;
4
4
5
5
use Illuminate \Database \Eloquent \Builder ;
6
+ use Illuminate \Support \Facades \DB ;
6
7
use LaravelEnso \DataImport \app \Models \DataImport ;
7
8
use LaravelEnso \DataImport \app \Models \RejectedImportSummary ;
8
9
use LaravelEnso \Tables \app \Contracts \Table ;
@@ -13,25 +14,32 @@ class DataImportTable implements Table
13
14
14
15
public function query (): Builder
15
16
{
16
- return DataImport::selectRaw ('
17
+ return DataImport::selectRaw ("
17
18
data_imports.id, data_imports.type, data_imports.status, data_imports.status as computedStatus,
18
19
files.original_name as name, data_imports.successful, data_imports.failed, data_imports.created_at,
19
20
TIME(data_imports.created_at) as time, people.name as createdBy, rejected_imports.id as rejectedId,
20
- sec_to_time(timestampdiff(second, data_imports.created_at, data_imports.updated_at)) as duration
21
- ' )->join ('files ' , function ($ join ) {
21
+ { $ this -> rawDuration ()} as duration
22
+ " )->join ('files ' , function ($ join ) {
22
23
$ join ->on ('files.attachable_id ' , 'data_imports.id ' )
23
24
->where ('files.attachable_type ' , DataImport::class);
24
25
})->join ('users ' , 'files.created_by ' , '= ' , 'users.id ' )
25
26
->join ('people ' , 'users.person_id ' , '= ' , 'people.id ' )
26
27
->leftJoin ('rejected_imports ' , 'data_imports.id ' , '= ' , 'rejected_imports.data_import_id ' )
27
28
->leftJoin ('files as rejected_files ' , function ($ join ) {
28
29
$ join ->on ('rejected_files.attachable_id ' , 'rejected_imports.id ' )
29
- ->where ('rejected_files.attachable_type ' , RejectedImportSummary::class);
30
+ ->where ('rejected_files.attachable_type ' , RejectedImportSummary::class);
30
31
});
31
32
}
32
33
33
34
public function templatePath (): string
34
35
{
35
36
return static ::TemplatePath;
36
37
}
38
+
39
+ private function rawDuration ()
40
+ {
41
+ return DB ::getDriverName () === 'sqlite '
42
+ ? '0 '
43
+ : 'sec_to_time(timestampdiff(second, data_imports.created_at, data_imports.updated_at)) ' ;
44
+ }
37
45
}
0 commit comments