Files
nextcloud-app-api/lib/Db/TextProcessing/TextProcessingProviderQueueMapper.php
Alexander Piskun a44f8c4624 Refactor Speech2Text Provider flow (#209)
The same as in #208 but for SpeechToText Provider
2024-01-12 16:41:42 +03:00

53 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\AppAPI\Db\TextProcessing;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/**
* @template-extends QBMapper<TextProcessingProviderQueue>
*/
class TextProcessingProviderQueueMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'ex_text_processing_q');
}
/**
* @param int $id
*
* @throws DoesNotExistException if not found
* @throws MultipleObjectsReturnedException if more than one result
* @throws Exception
*
* @return TextProcessingProviderQueue
*/
public function getById(int $id): TextProcessingProviderQueue {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('id', $qb->createNamedParameter($id))
);
return $this->findEntity($qb);
}
/**
* @throws Exception
*/
public function removeAllOlderThenThat(int $overdueTime): int {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where(
$qb->expr()->gte($qb->createNamedParameter(time() - $overdueTime, IQueryBuilder::PARAM_INT), 'created_time')
);
return $qb->executeStatement();
}
}