-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathExAppConfigMapper.php
More file actions
91 lines (82 loc) · 2.55 KB
/
Copy pathExAppConfigMapper.php
File metadata and controls
91 lines (82 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\AppAPI\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
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<ExAppConfig>
*/
class ExAppConfigMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'appconfig_ex');
}
/**
* @throws Exception
*/
public function findAllByAppid(string $appId): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where($qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR)));
return $this->findEntities($qb);
}
/**
* @param string $appId
* @param string $configKey
*
* @throws DoesNotExistException if not found
* @throws MultipleObjectsReturnedException if more than one result
* @throws Exception
*
* @return ExAppConfig
*/
public function findByAppConfigKey(string $appId, string $configKey): Entity {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('configkey', $qb->createNamedParameter($configKey, IQueryBuilder::PARAM_STR))
);
return $this->findEntity($qb);
}
/**
* @param string $appId
* @param array $configKeys
*
* @throws Exception
*
* @return ExAppConfig[]
*/
public function findByAppConfigKeys(string $appId, array $configKeys): array {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR)),
$qb->expr()->in('configkey', $qb->createNamedParameter($configKeys, IQueryBuilder::PARAM_STR_ARRAY), IQueryBuilder::PARAM_STR)
);
return $this->findEntities($qb);
}
/**
* @throws Exception
*/
public function deleteByAppidConfigkeys(string $appId, array $configKeys): int {
$qb = $this->db->getQueryBuilder();
return $qb->delete($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR)),
$qb->expr()->in('configkey', $qb->createNamedParameter($configKeys, IQueryBuilder::PARAM_STR_ARRAY), IQueryBuilder::PARAM_STR)
)
->executeStatement();
}
}