db->getQueryBuilder(); $qb->select('*') ->from($this->tableName) ->where( $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)), $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) ); return $this->findEntity($qb); } /** * @param string $userId * @param string $queryStr * @param int|null $offset * @param int|null $limit * * @throws \OCP\AppFramework\Db\DoesNotExistException if not found * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result * * @return Note[] */ public function findLike($userId, $queryStr, ?int $offset = null, ?int $limit = null): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->tableName) ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))) ->andWhere( $qb->expr()->orX( $qb->expr()->like($qb->func()->lower('title'), $qb->createParameter('query')), $qb->expr()->like($qb->func()->lower('content'), $qb->createParameter('query')) ) ); $query = '%' . $this->db->escapeLikeParameter(strtolower($queryStr)) . '%'; $qb->setParameter('query', $query); $qb->setFirstResult($offset); $qb->setMaxResults($limit); return $this->findEntities($qb); } /** * @param int $id * @throws \OCP\AppFramework\Db\DoesNotExistException if not found * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result * @return Note */ public function findShared($id): Note { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->tableName) ->where( $qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)) ); return $this->findEntity($qb); } /** * @return Note[] */ public function findAll(string $userId): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->tableName) ->where( $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)) ); return $this->findEntities($qb); } /** * @return int */ public function colorIdCount(int $colorid): int { $qb = $this->db->getQueryBuilder(); $qb->select('id') ->from($this->tableName) ->where( $qb->expr()->eq('color_id', $qb->createNamedParameter($colorid, IQueryBuilder::PARAM_INT)) ); return count($this->findEntities($qb)); } }