Last active
June 20, 2016 13:51
-
-
Save daschl/955a9b4b56d5615be65b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.couchbase.client.java.Bucket; | |
import com.couchbase.client.java.Cluster; | |
import com.couchbase.client.java.CouchbaseCluster; | |
import com.couchbase.client.java.document.JsonDocument; | |
import com.couchbase.client.java.document.json.JsonObject; | |
import com.couchbase.client.java.query.N1qlParams; | |
import com.couchbase.client.java.query.N1qlQuery; | |
import com.couchbase.client.java.query.N1qlQueryResult; | |
import com.couchbase.client.java.query.consistency.ScanConsistency; | |
import static com.couchbase.client.java.query.Select.select; | |
import static com.couchbase.client.java.query.dsl.Expression.i; | |
import static com.couchbase.client.java.query.dsl.Expression.s; | |
import static com.couchbase.client.java.query.dsl.Expression.x; | |
public class ReadYourWriteExample { | |
public static void main(String[] args) { | |
// Connect to the Cluster | |
Cluster cluster = CouchbaseCluster.create(); | |
// Open the travel-sample bucket | |
Bucket bucket = cluster.openBucket("travel-sample"); | |
// Create a new airline (document) | |
bucket.upsert(JsonDocument.create("airline_000", JsonObject.create() | |
.put("id", "000") | |
.put("type", "airline") | |
.put("name", "Couchbase Airways") | |
.put("iata", "CBX") | |
.put("icao", "CBX") | |
.put("callsign", "COUCH-BASE") | |
.put("country", "United States") | |
)); | |
// Perform the Query | |
N1qlQueryResult result = bucket.query( | |
N1qlQuery.simple(select("*").from(i(bucket.name())).where(x("iata").eq(s("CBX"))), | |
N1qlParams.build().consistency(ScanConsistency.REQUEST_PLUS)) | |
); | |
// Prints | |
// [{"country":"United States","iata":"CBX",...,"icao":"CBX","id":"000","type":"airline"}] | |
System.out.println(result.allRows()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment