33namespace LaravelEnso \DataImport \app \Tables \Builders ;
44
55use Illuminate \Database \Eloquent \Builder ;
6+ use Illuminate \Support \Facades \DB ;
67use LaravelEnso \DataImport \app \Models \DataImport ;
78use LaravelEnso \DataImport \app \Models \RejectedImportSummary ;
89use LaravelEnso \Tables \app \Contracts \Table ;
@@ -13,25 +14,32 @@ class DataImportTable implements Table
1314
1415 public function query (): Builder
1516 {
16- return DataImport::selectRaw ('
17+ return DataImport::selectRaw ("
1718 data_imports.id, data_imports.type, data_imports.status, data_imports.status as computedStatus,
1819 files.original_name as name, data_imports.successful, data_imports.failed, data_imports.created_at,
1920 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 ) {
2223 $ join ->on ('files.attachable_id ' , 'data_imports.id ' )
2324 ->where ('files.attachable_type ' , DataImport::class);
2425 })->join ('users ' , 'files.created_by ' , '= ' , 'users.id ' )
2526 ->join ('people ' , 'users.person_id ' , '= ' , 'people.id ' )
2627 ->leftJoin ('rejected_imports ' , 'data_imports.id ' , '= ' , 'rejected_imports.data_import_id ' )
2728 ->leftJoin ('files as rejected_files ' , function ($ join ) {
2829 $ 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);
3031 });
3132 }
3233
3334 public function templatePath (): string
3435 {
3536 return static ::TemplatePath;
3637 }
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+ }
3745}
0 commit comments