user repo 24 - srujanabala/springboot-couchbase GitHub Wiki

package com.example.repository;

import java.util.List;

import org.springframework.data.couchbase.core.query.N1qlPrimaryIndexed; import org.springframework.data.couchbase.core.query.Query; import org.springframework.data.couchbase.core.query.ViewIndexed; import org.springframework.data.couchbase.repository.CouchbaseRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository;

import com.example.model.Student;

@N1qlPrimaryIndexed @ViewIndexed(designDoc = "student", viewName = "all") @Repository public interface UserRepository extends CouchbaseRepository<Student, String> {

List<Student> findByName(String name);

@Query("SELECT META(Test).id as _ID, META(Test).cas as _CAS,"
		+ " Test.* FROM Test WHERE Test.name = $1")
List<Student> findByTheQuery(@Param("name") String name);

@Query(value = "select META(Test).id as _ID,META(Test).cas as _CAS, Test.* from Test ORDER BY Test.name")
List<Student> getAllOrderAndGroup();

@Query(value = "SELECT META(t).id as _ID, META(t).cas as _CAS\n" + 
		"FROM Test t\n" + 
		"ORDER BY META(t).id;")
List<String> getMetaData();

@Query(value = "SELECT META(Test).id as _ID, META(Test).cas as _CAS, Test.* FROM Test")
List<Student> getAllByQuery();

// sub query example
@Query(value = "SELECT MAX(t1.age) FROM Test as t1 where t1.age < (SELECT MAX(t2.age) FROM Test as t2)")
Integer getSecondHighestAgeStudent();

}

⚠️ **GitHub.com Fallback** ⚠️