Can we Convert N1QL to shEL query for Spring use

爷,独闯天下 提交于 2019-12-11 13:42:47

问题


I am working on spring and couchbase and now want to upload data to couchbase with the help of my spring API but got to know that spring does not support N1QL, So is there any other way to achieve that or a shEL query

insert into bucket1(key,value)
values("Aman--12/04/1995",
{
  "English":[{ "midterm": 34, "endterm": 67 }],
  "Maths":[{ "midterm": 20, "endterm": 40 }],
  "Computer":[{ "midterm": 48, "endterm": 90 }]
})

UPDATE bucketName USE KEYS id 
SET arrayname = ARRAY_PUT(IFNULL(Arrayname[]),{"Sports": "89"})

回答1:


If you can't do something via spEL you can always use pure n1ql for it:

    @Override
public void updateAreaName(String areaName, String areaId) {

    String queryString = "UPDATE "+getBucketName()+" set areaName = '"+areaName+"' WHERE "+getClassFilter()+" " +
            " and areaId = '"+areaId+"' RETURNING meta().id";

    N1qlParams params = N1qlParams.build().consistency(ScanConsistency.REQUEST_PLUS).adhoc(true);
    ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);
    resourceRepository.getCouchbaseOperations().getCouchbaseBucket().query(query);

}

private String getBucketName() {
    return resourceRepository.getCouchbaseOperations().getCouchbaseBucket().bucketManager().info().name();
}

private String getClassFilter(){
    return "_class = '" + QResource.class.getName() + "' ";
}


来源:https://stackoverflow.com/questions/55095570/can-we-convert-n1ql-to-shel-query-for-spring-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!