mirror of
https://github.com/nextcloud/server.git
synced 2026-02-19 02:38:40 -05:00
refactor: Prefer using IFunctionBuilder than createFunction
Signed-off-by: Carl Schwan <carlschwan@kde.org>
This commit is contained in:
parent
dd8b274550
commit
b4dfdf6492
7 changed files with 22 additions and 9 deletions
|
|
@ -798,7 +798,7 @@ class Manager implements ICommentsManager {
|
|||
|
||||
$query = $this->dbConn->getQueryBuilder();
|
||||
$query->select('actor_id')
|
||||
->selectAlias($query->createFunction('MAX(' . $query->getColumnName('creation_timestamp') . ')'), 'last_comment')
|
||||
->selectAlias($query->func()->max('creation_timestamp'), 'last_comment')
|
||||
->from('comments')
|
||||
->where($query->expr()->eq('object_type', $query->createNamedParameter($objectType)))
|
||||
->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId)))
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use OCP\DB\QueryBuilder\IFunctionBuilder;
|
|||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
use OCP\DB\QueryBuilder\IQueryFunction;
|
||||
use OCP\IDBConnection;
|
||||
use Override;
|
||||
|
||||
class FunctionBuilder implements IFunctionBuilder {
|
||||
/** @var IDBConnection|Connection */
|
||||
|
|
@ -105,4 +106,9 @@ class FunctionBuilder implements IFunctionBuilder {
|
|||
public function least($x, $y): IQueryFunction {
|
||||
return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function now(): IQueryFunction {
|
||||
return new QueryFunction('NOW()');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -990,7 +990,7 @@ class QueryBuilder implements IQueryBuilder {
|
|||
* </code>
|
||||
*
|
||||
* @param string $column The column into which the value should be inserted.
|
||||
* @param IParameter|string $value The value that should be inserted into the column.
|
||||
* @param IParameter|IQueryFunction|string $value The value that should be inserted into the column.
|
||||
*
|
||||
* @return $this This QueryBuilder instance.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ class CacheQueryBuilder extends ExtendedQueryBuilder {
|
|||
public function selectTagUsage(): self {
|
||||
$this
|
||||
->select('systemtag.name', 'systemtag.id', 'systemtag.visibility', 'systemtag.editable', 'systemtag.etag', 'systemtag.color')
|
||||
->selectAlias($this->createFunction('COUNT(filecache.fileid)'), 'number_files')
|
||||
->selectAlias($this->createFunction('MAX(filecache.fileid)'), 'ref_file_id')
|
||||
->selectAlias($this->func()->count('filecache.fileid'), 'number_files')
|
||||
->selectAlias($this->func()->max('filecache.fileid'), 'ref_file_id')
|
||||
->from('filecache', 'filecache')
|
||||
->leftJoin('filecache', 'systemtag_object_mapping', 'systemtagmap', $this->expr()->andX(
|
||||
$this->expr()->eq('filecache.fileid', $this->expr()->castColumn('systemtagmap.objectid', IQueryBuilder::PARAM_INT)),
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class MetadataRequestService {
|
|||
->setValue('file_id', $qb->createNamedParameter($filesMetadata->getFileId(), IQueryBuilder::PARAM_INT))
|
||||
->setValue('json', $qb->createNamedParameter(json_encode($filesMetadata->jsonSerialize())))
|
||||
->setValue('sync_token', $qb->createNamedParameter($this->generateSyncToken()))
|
||||
->setValue('last_update', (string)$qb->createFunction('NOW()'));
|
||||
->setValue('last_update', $qb->func()->now());
|
||||
$qb->executeStatement();
|
||||
}
|
||||
|
||||
|
|
@ -159,7 +159,7 @@ class MetadataRequestService {
|
|||
->hintShardKey('files_metadata', $this->getStorageId($filesMetadata))
|
||||
->set('json', $qb->createNamedParameter(json_encode($filesMetadata->jsonSerialize())))
|
||||
->set('sync_token', $qb->createNamedParameter($this->generateSyncToken()))
|
||||
->set('last_update', $qb->createFunction('NOW()'))
|
||||
->set('last_update', $qb->func()->now())
|
||||
->where(
|
||||
$expr->andX(
|
||||
$expr->eq('file_id', $qb->createNamedParameter($filesMetadata->getFileId(), IQueryBuilder::PARAM_INT)),
|
||||
|
|
|
|||
|
|
@ -170,4 +170,10 @@ interface IFunctionBuilder {
|
|||
* @since 18.0.0
|
||||
*/
|
||||
public function least($x, $y): IQueryFunction;
|
||||
|
||||
/**
|
||||
* Get the current date and time as a UNIX timestamp.
|
||||
* @since 34.0.0
|
||||
*/
|
||||
public function now(): IQueryFunction;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -770,7 +770,7 @@ interface IQueryBuilder {
|
|||
* </code>
|
||||
*
|
||||
* @param string $column The column into which the value should be inserted.
|
||||
* @param IParameter|string $value The value that should be inserted into the column.
|
||||
* @param IParameter|IQueryFunction|string $value The value that should be inserted into the column.
|
||||
*
|
||||
* @return $this This QueryBuilder instance.
|
||||
* @since 8.2.0
|
||||
|
|
@ -1001,9 +1001,10 @@ interface IQueryBuilder {
|
|||
public function createParameter($name);
|
||||
|
||||
/**
|
||||
* Creates a new function
|
||||
* Creates a new function.
|
||||
*
|
||||
* Attention: Column names inside the call have to be quoted before hand
|
||||
* @warning Column names inside the call have to be quoted beforehand. In most
|
||||
* case you can use the IFunctionBuilder instead.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
|
|
|
|||
Loading…
Reference in a new issue