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); } /** * @return Attach[] */ public function findAll($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); } /** * @param string $userId * @param int $noteId * @throws \OCP\AppFramework\Db\DoesNotExistException if not found * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result * @return Attach */ public function findFileAttachFromNote($userId, $noteId, $fileId): Attach { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->tableName) ->where( $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)), $qb->expr()->eq('note_id', $qb->createNamedParameter($noteId, IQueryBuilder::PARAM_INT)), $qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)) ); return $this->findEntity($qb); } /** * @return bool */ public function fileAttachExists(string $userId, int $noteId, $fileId): bool { try { $this->findFileAttachFromNote($userId, $noteId, $fileId); } catch (DoesNotExistException $e) { return false; } return true; } /** * @param string $userId * @param int $noteId * @throws \OCP\AppFramework\Db\DoesNotExistException if not found * @return Attach[] */ public function findFromNote($userId, $noteId): array { $qb = $this->db->getQueryBuilder(); $qb->select('*') ->from($this->tableName) ->where( $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)), $qb->expr()->eq('note_id', $qb->createNamedParameter($noteId, IQueryBuilder::PARAM_INT)) ); return $this->findEntities($qb); } }