当前位置: 首页>>代码示例>>Golang>>正文


Golang dynago.Client类代码示例

本文整理汇总了Golang中github.com/underarmour/dynago.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Example_marshaling

func Example_marshaling(client *dynago.Client) {
	type MyStruct struct {
		Id          int64
		Name        string
		Description string
		Tags        []string
		Address     struct {
			City  string
			State string
		}
	}

	var data MyStruct

	doc := dynago.Document{
		// Basic fields like numbers and strings get marshaled automatically
		"Id":          data.Id,
		"Name":        data.Name,
		"Description": data.Description,
		// StringSet is compatible with []string so we can simply cast it
		"Tags": dynago.StringSet(data.Tags),
		// We don't automatically marshal structs, nest it in a document
		"Address": dynago.Document{
			"City":  data.Address.City,
			"State": data.Address.State,
		},
	}

	client.PutItem("Table", doc).Execute()
}
开发者ID:natebrennand,项目名称:dynago,代码行数:30,代码来源:example_test.go

示例2: batchAddPosts

func batchAddPosts(client *dynago.Client, userId, start, end int) error {
	// Add some posts
	writer := client.BatchWrite()
	for i := start; i < end; i++ {
		writer = writer.Put("Posts", dynago.Document{"UserId": userId, "Dated": i})
	}
	_, err := writer.Execute()
	return err
}
开发者ID:natebrennand,项目名称:dynago,代码行数:9,代码来源:functional_test.go

示例3: ExampleClient_CreateTable_basic

func ExampleClient_CreateTable_basic(client *dynago.Client) {
	// NewCreateRequest creates a table with simple defaults.
	// You can use chaining to set the hash and range keys.
	table1 := schema.NewCreateRequest("TableName").
		HashKey("UserId", schema.Number).
		RangeKey("Date", schema.String)

	table1.ProvisionedThroughput.ReadCapacityUnits = 45
	client.CreateTable(table1)
}
开发者ID:natebrennand,项目名称:dynago,代码行数:10,代码来源:example_client_test.go

示例4: ExampleClient_UpdateItem

func ExampleClient_UpdateItem(client *dynago.Client) {
	_, err := client.UpdateItem("Person", dynago.HashKey("Id", 42)).
		UpdateExpression("SET Name=:name").
		Param(":name", "Joe").
		Execute()

	if err != nil {
		fmt.Printf("UpdateItem failed: %v", err)
	}
}
开发者ID:natebrennand,项目名称:dynago,代码行数:10,代码来源:example_client_test.go

示例5: ExampleClient_BatchWrite

func ExampleClient_BatchWrite(client *dynago.Client) {
	record1 := dynago.Document{"Id": 1, "Name": "Person1"}
	record2 := dynago.Document{"Id": 2, "Name": "Person2"}

	// We can put and delete at the same time to multiple tables.
	client.BatchWrite().
		Put("Table1", record1, record2).
		Put("Table2", dynago.Document{"Name": "Other"}).
		Delete("Table2", dynago.HashKey("Id", 42)).
		Execute()
}
开发者ID:natebrennand,项目名称:dynago,代码行数:11,代码来源:example_client_test.go

示例6: ExampleClient_ListTables_paging

func ExampleClient_ListTables_paging(client *dynago.Client) {
	cursor := client.ListTables().Limit(100)
	for cursor != nil {
		response, err := cursor.Execute()
		if err != nil {
			break
		}
		fmt.Printf("%v", response.TableNames)
		cursor = response.Next()
	}
}
开发者ID:natebrennand,项目名称:dynago,代码行数:11,代码来源:example_client_test.go

示例7: ExampleClient_UpdateItem_atomicIncrement

func ExampleClient_UpdateItem_atomicIncrement(client *dynago.Client, key dynago.Document) {
	result, err := client.UpdateItem("Products", key).
		UpdateExpression("SET ViewCount = ViewCount + :incr").
		Param(":incr", 5).
		ReturnValues(dynago.ReturnUpdatedNew).
		Execute()

	if err == nil {
		fmt.Printf("View count is now %d", result.Attributes["ViewCount"])
	}
}
开发者ID:natebrennand,项目名称:dynago,代码行数:11,代码来源:example_client_test.go

示例8: ExampleClient_Query

func ExampleClient_Query(client *dynago.Client) {
	result, err := client.Query("table").
		KeyConditionExpression("Foo = :val AND begins_with(Title, :prefix)").
		Param(":val", 45).Param(":prefix", "The adventures of").
		Execute()

	if err == nil {
		for _, row := range result.Items {
			fmt.Printf("ID: %s, Foo: %d", row["Id"], row["Foo"])
		}
	}
}
开发者ID:natebrennand,项目名称:dynago,代码行数:12,代码来源:example_client_test.go

示例9: ExampleClient_PutItem

func ExampleClient_PutItem(client *dynago.Client) {
	doc := dynago.Document{
		"Id":   42,
		"Name": "Bob",
		"Address": dynago.Document{
			"City":  "Boston",
			"State": "MA",
		},
	}
	_, err := client.PutItem("Person", doc).Execute()
	if err != nil {
		fmt.Printf("PUT failed: %v", err)
	}
}
开发者ID:natebrennand,项目名称:dynago,代码行数:14,代码来源:example_client_test.go

示例10: ExampleClient_Scan_parallel

func ExampleClient_Scan_parallel(client *dynago.Client) {
	numSegments := 10
	baseScan := client.Scan("Table").Limit(1000)

	// spin up numSegments goroutines each working on a table segment
	for i := 0; i < numSegments; i++ {
		go func(scan *dynago.Scan) {
			for scan != nil {
				result, _ := scan.Execute()
				// do something with result.Items
				scan = result.Next()
			}
		}(baseScan.Segment(i, numSegments))
	}
}
开发者ID:natebrennand,项目名称:dynago,代码行数:15,代码来源:example_client_test.go

示例11: ExampleClient_Query_pagination

func ExampleClient_Query_pagination(client *dynago.Client) {
	query := client.Query("table").
		KeyConditionExpression("Foo = :val").
		Limit(50)

	// Keep getting results in a loop until there are no more.
	for query != nil {
		result, err := query.Execute()
		if err != nil {
			break
		}
		for _, item := range result.Items {
			fmt.Printf("Result ID %d\n", item["Id"])
		}
		query = result.Next()
	}
}
开发者ID:natebrennand,项目名称:dynago,代码行数:17,代码来源:example_client_test.go

示例12: makeTables

func makeTables(t *testing.T, client *dynago.Client) {
	complexIndexed := complexIndexedSchema()
	hashTable := schema.NewCreateRequest("Person").HashKey("Id", schema.Number)
	hashRange := schema.NewCreateRequest("Posts").
		HashKey("UserId", schema.Number).
		RangeKey("Dated", schema.Number)

	tables := []*schema.CreateRequest{hashTable, hashRange, complexIndexed}
	for _, table := range tables {
		_, err := client.CreateTable(table)
		if err != nil {
			if e, ok := err.(*dynago.Error); ok && e.Type == dynago.ErrorResourceInUse {
				continue
			}
			panic(err)
		}
	}
}
开发者ID:natebrennand,项目名称:dynago,代码行数:18,代码来源:functional_test.go

示例13: ExampleClient_CreateTable_full

func ExampleClient_CreateTable_full(client *dynago.Client) {
	// Most of the time we don't need the full syntax for making create requests
	// It's shown here mostly for purpose of documentation
	req := &schema.CreateRequest{
		TableName: "PersonalPages",
		AttributeDefinitions: []schema.AttributeDefinition{
			{"UserId", schema.Number},
			{"Title", schema.String},
		},
		KeySchema: []schema.KeySchema{
			{"UserId", schema.HashKey},
			{"Title", schema.RangeKey},
		},
		ProvisionedThroughput: schema.ProvisionedThroughput{
			ReadCapacityUnits:  45,
			WriteCapacityUnits: 72,
		},
	}
	if response, err := client.CreateTable(req); err == nil {
		fmt.Printf("table created, status %s", response.TableDescription.TableStatus)
	}
}
开发者ID:natebrennand,项目名称:dynago,代码行数:22,代码来源:example_client_test.go


注:本文中的github.com/underarmour/dynago.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。