This is a listing of various examples used for the Couchbase Go SDK GA Release Blog.
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
| /** | |
| * Copyright (C) 2009-2013 Couchbase, Inc. | |
| * | |
| * Permission is hereby granted, free of charge, to any person obtaining a copy | |
| * of this software and associated documentation files (the "Software"), to deal | |
| * in the Software without restriction, including without limitation the rights | |
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| * copies of the Software, and to permit persons to whom the Software is | |
| * furnished to do so, subject to the following conditions: | |
| * |
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
| package com.couchbase.client.demo; | |
| import com.couchbase.client.CouchbaseClient; | |
| import java.io.IOException; | |
| import java.net.URI; | |
| import java.util.Arrays; | |
| import java.util.List; | |
| import java.util.concurrent.TimeUnit; | |
| import java.util.concurrent.TimeoutException; |
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
| """ Retrieve the user to change the email address """ | |
| user = cb.get("ingenthr") | |
| """ Change the email and store the user """ | |
| user.value['email'] = "ingenthr@couchbase.com" | |
| cb.set(user.key, user.value, cas=user.cas) # concurrent safe! | |
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
| /** | |
| * Copyright (C) 2014 Couchbase, Inc. | |
| * Copyright (C) 2006-2009 Dustin Sallings | |
| * | |
| * Permission is hereby granted, free of charge, to any person obtaining a copy | |
| * of this software and associated documentation files (the "Software"), to deal | |
| * in the Software without restriction, including without limitation the rights | |
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| * copies of the Software, and to permit persons to whom the Software is | |
| * furnished to do so, subject to the following conditions: |
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
| cluster, _ := gocb.Connect("couchbase://localhost") | |
| bucket, _ := cluster.OpenBucket("default", "") | |
| query := gocb.NewN1qlQuery("SELECT * FROM default") | |
| rows := bucket.ExecuteViewQuery(query) | |
| var row interface{} | |
| for rows.Next(&row) { | |
| fmt.Printf("Row: %+v\n", row) | |
| } |
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
| // Read | |
| Observable loadedFromId = bucket.get("id"); // async using RxJava | |
| JsonDocument found = bucket.get("notexisting").toBlocking().singleOrDefault(null); // sync | |
| // Write | |
| JsonDocument found = bucket.get("notexisting").toBlocking().singleOrDefault(null); // | |
| // Query |
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
| /** Returns an RDD based on email address extracted from the document */ | |
| def CreateMappableRdd(s: (String, String)): (String, JsonDocument) = { | |
| val return_doc = JsonDocument.create(s._1, JsonObject.fromJson(s._2)) | |
| (return_doc.content().getString("email"), return_doc) | |
| } |
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 java.util.concurrent.TimeUnit; | |
| /** | |
| * Created by ingenthr on 12/16/15. | |
| */ | |
| public class Main { |
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
| #!/usr/bin/env bash | |
| set -xe | |
| # Setup Services | |
| curl -i -u Administrator:password -X POST \ | |
| http://127.0.0.1:8091/node/controller/setupServices \ | |
| -d 'services=kv%2Cn1ql%2Cindex' | |
| # Initialize Node with /couchbase for index and data path | |
| curl -i -u Administrator:password -X POST \ |