Git Product home page Git Product logo

couchbase-example-go's Introduction

Go 语言访问 Couchbase 示例

示例说明

本示例演示了如下操作:

  • 连接 Couchbase 集群
  • 嵌套 struct 结构和最终存储的 document 的映射
  • 通过 CRUD 接口对 projects._default._default collection 做 upsert 操作
  • 通过 CRUD 接口对插入的记录做 get 操作
  • 通过 Query 接口执行了 N1QL 查询,返回符合条件的 documents,并通过 cursor 进行遍历

准备初始数据

  • 创建名为 projects 的 bucket
  • 从 sample-data.json 中 import 数据到 projects bucket 中
  • 创建索引:
  CREATE INDEX idx_projects_team on projects(team);
  CREATE INDEX idx_projects_type on projects(type);
  CREATE INDEX idx_projects_projectId on projects(projectId);

(可选)创建访问账号

用户:projects-user1 密码:user111 权限:

    - Views Reader [projects] , 
    - Query Update [projects:*:*] , 
    - Query Select [projects:*:*] , 
    - Query Insert [projects:*:*] , 
    - Query Delete [projects:*:*] , 
    - Search Reader [projects:*:*] , 
    - Data Writer [projects:*:*] , 
    - Data Reader [projects:*:*] , 
    - Data DCP Reader [projects:*:*]

执行代码

go run main.go

couchbase-example-go's People

Contributors

wesleywu avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.