• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang dynamodb.DynamoDB类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: CreateAdminTable

func CreateAdminTable() {
	var svc *dynamodb.DynamoDB = dbutil.CreateDynamoDBClient()

	params := &dynamodb.CreateTableInput{
		AttributeDefinitions: []*dynamodb.AttributeDefinition{
			{
				AttributeName: aws.String("AdminID"),
				AttributeType: aws.String("S"),
			},
		},
		KeySchema: []*dynamodb.KeySchemaElement{
			{
				AttributeName: aws.String("AdminID"),
				KeyType:       aws.String("HASH"),
			},
		},
		ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
			ReadCapacityUnits:  aws.Int64(1),
			WriteCapacityUnits: aws.Int64(1),
		},
		TableName: aws.String(AdminTableName),
	}

	resp, err := svc.CreateTable(params)
	if err != nil {
		log.Fatal(err)
	}

	log.Info(resp)
}
开发者ID:xtraclabs,项目名称:roll,代码行数:30,代码来源:ddl.go


示例2: CreateThreadTable

func CreateThreadTable(svc *dynamodb.DynamoDB) (*dynamodb.CreateTableOutput, error) {

	params := &dynamodb.CreateTableInput{
		TableName: aws.String("Thread"),
		AttributeDefinitions: []*dynamodb.AttributeDefinition{
			{
				AttributeName: aws.String("ForumName"),
				AttributeType: aws.String("S"),
			},
			{
				AttributeName: aws.String("Subject"),
				AttributeType: aws.String("S"),
			},
		},
		KeySchema: []*dynamodb.KeySchemaElement{
			{
				AttributeName: aws.String("ForumName"),
				KeyType:       aws.String("HASH"),
			},
			{
				AttributeName: aws.String("Subject"),
				KeyType:       aws.String("RANGE"),
			},
		},
		ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
			ReadCapacityUnits:  aws.Int64(10),
			WriteCapacityUnits: aws.Int64(5),
		},
	}

	return svc.CreateTable(params)
}
开发者ID:sinistersig,项目名称:go-dynamodb-create-table-example,代码行数:32,代码来源:createThreadTable.go


示例3: GetItemFromDynamoDb

func GetItemFromDynamoDb(svc *dynamodb.DynamoDB, productId string) string {
	params := &dynamodb.GetItemInput{
		Key: map[string]*dynamodb.AttributeValue{ // Required
			"productId": { // Required
				S: aws.String(productId),
			},
			// More values...
		},
		TableName: aws.String("ProductRecommendation"), // Required
		AttributesToGet: []*string{
			aws.String("boughtTogether"), // Required
			// More values...
		},
		ConsistentRead: aws.Bool(true),
		/*
			ExpressionAttributeNames: map[string]*string{
				"Key": aws.String("AttributeName"), // Required
				// More values...
			},
			ProjectionExpression:   aws.String("ProjectionExpression"),
			ReturnConsumedCapacity: aws.String("ReturnConsumedCapacity"),
		*/
	}
	resp, err := svc.GetItem(params)

	if err != nil {
		// Print the error, cast err to awserr.Error to get the Code and
		// Message from an error.
		glog.Errorln(err.Error())
		return "failed to query DynamoDb"
	}

	// Pretty-print the response data.
	return *resp.Item["boughtTogether"].S
}
开发者ID:jteng,项目名称:go-recengine,代码行数:35,代码来源:engine.go


示例4: getServices

func getServices(containerID string, svc *dynamodb.DynamoDB) ([]*Service, error) {
	context := Context{}
	params := &dynamodb.QueryInput{
		TableName: aws.String("Services"),
		KeyConditions: map[string]*dynamodb.Condition{
			"ContainerID": {
				ComparisonOperator: aws.String("EQ"), // Required
				AttributeValueList: []*dynamodb.AttributeValue{
					{
						S: aws.String(containerID),
					},
				},
			},
		},
	}
	resp, err := svc.Query(params)

	if err != nil {
		return context, err
	}
	// loop through the items and convert back to struct
	for _, item := range resp.Items {
		service := Service{}
		dynamodbattribute.ConvertFromMap(item, &service)
		context = append(context, &service)
	}
	return context, err
}
开发者ID:porcup,项目名称:ngproxy,代码行数:28,代码来源:dynamodb.go


示例5: fixturePost

func fixturePost(db *dynamodb.DynamoDB) error {
	params := &dynamodb.PutItemInput{
		Item: map[string]*dynamodb.AttributeValue{
			"id": {
				S: aws.String("pid123"),
			},
			"uid": {
				S: aws.String("uid123"),
			},
			"wall_id": {
				S: aws.String("1"),
			},
			"message": {
				S: aws.String("message"),
			},
			"created_at": {
				N: aws.String(strconv.FormatInt(time.Now().UnixNano(), 10)),
			},
		},
		TableName: aws.String("post"),
	}
	_, err := db.PutItem(params)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:blang,项目名称:posty,代码行数:28,代码来源:post_test.go


示例6: fixtureUser

func fixtureUser(db *dynamodb.DynamoDB) error {
	params := &dynamodb.PutItemInput{
		Item: map[string]*dynamodb.AttributeValue{
			"id": {
				S: aws.String("uid123"),
			},
			"oauthid": {
				S: aws.String("google:1234"),
			},
			"email": {
				S: aws.String("[email protected]"),
			},
			"username": {
				S: aws.String("username"),
			},
			"created_at": {
				N: aws.String("123456789"),
			},
			"lastlogin": {
				N: aws.String("123456789"),
			},
		},
		TableName: aws.String("user"),
	}
	_, err := db.PutItem(params)

	if err != nil {
		return err
	}

	return nil
}
开发者ID:blang,项目名称:posty,代码行数:32,代码来源:user_test.go


示例7: CheckRowCount

// CheckRowCount returns the number of records in a table.
func CheckRowCount(db *dynamodb.DynamoDB, tableName string) int {
	resp, err := db.Scan(&dynamodb.ScanInput{
		TableName: aws.String(tableName),
		Select:    aws.String(dynamodb.SelectCount),
	})
	if err != nil {
		return -1
	}
	return int(*resp.Count)
}
开发者ID:rcarver,项目名称:dynamis,代码行数:11,代码来源:check.go


示例8: deleteTable

func deleteTable(db *dynamodb.DynamoDB, table string) error {
	params := &dynamodb.DeleteTableInput{
		TableName: aws.String(table),
	}
	_, err := db.DeleteTable(params)
	if err != nil {
		return err
	}
	return nil

}
开发者ID:blang,项目名称:posty,代码行数:11,代码来源:model_integration_test.go


示例9: CreateAppTable

func CreateAppTable() {
	var svc *dynamodb.DynamoDB = dbutil.CreateDynamoDBClient()

	params := &dynamodb.CreateTableInput{
		AttributeDefinitions: []*dynamodb.AttributeDefinition{
			{
				AttributeName: aws.String("ClientID"),
				AttributeType: aws.String("S"),
			},
			{
				AttributeName: aws.String("DeveloperEmail"),
				AttributeType: aws.String("S"),
			},
		},
		KeySchema: []*dynamodb.KeySchemaElement{
			{
				AttributeName: aws.String("ClientID"),
				KeyType:       aws.String("HASH"),
			},
		},
		ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
			ReadCapacityUnits:  aws.Int64(1),
			WriteCapacityUnits: aws.Int64(1),
		},
		TableName: aws.String(ApplicationTableName),
		GlobalSecondaryIndexes: []*dynamodb.GlobalSecondaryIndex{
			{ // Required
				IndexName: aws.String("EMail-Index"),
				KeySchema: []*dynamodb.KeySchemaElement{
					{ // Required
						AttributeName: aws.String("DeveloperEmail"),
						KeyType:       aws.String("HASH"),
					},
					// More values...
				},
				Projection: &dynamodb.Projection{
					ProjectionType: aws.String("ALL"),
				},
				ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
					ReadCapacityUnits:  aws.Int64(1),
					WriteCapacityUnits: aws.Int64(1),
				},
			},
		},
	}

	resp, err := svc.CreateTable(params)
	if err != nil {
		log.Fatal(err)
	}

	log.Info(resp)
}
开发者ID:xtraclabs,项目名称:roll,代码行数:53,代码来源:ddl.go


示例10: putResource

func putResource(svc *dynamodb.DynamoDB, resource Resource, tableName string) error {
	item, err := dynamodbattribute.ConvertToMap(resource)
	if err != nil {
		return err
	}
	_, err = svc.PutItem(&dynamodb.PutItemInput{
		Item:      item,
		TableName: aws.String(tableName),
	})
	return err

}
开发者ID:porcup,项目名称:ngproxy,代码行数:12,代码来源:dynamodb.go


示例11: prepareDynamoDBTable

// prepareDynamoDBTable prepares DynamoDB table and it returns table name.
func prepareDynamoDBTable(dynamodbClient *dynamodb.DynamoDB) string {
	dummyTableName := randSeq(10)

	input := newTestCreateTableInput(dummyTableName)
	dynamodbClient.CreateTable(input)

	dynamodbClient.WaitUntilTableExists(&dynamodb.DescribeTableInput{
		TableName: aws.String(dummyTableName),
	})

	return dummyTableName
}
开发者ID:nabeken,项目名称:gorilla-sessions-dynamodb,代码行数:13,代码来源:dynamostore_test.go


示例12: createUserTable

func createUserTable(db *dynamodb.DynamoDB) error {
	params := &dynamodb.CreateTableInput{
		TableName: aws.String("user"),
		KeySchema: []*dynamodb.KeySchemaElement{
			{
				AttributeName: aws.String("id"),
				KeyType:       aws.String("HASH"),
			},
		},
		AttributeDefinitions: []*dynamodb.AttributeDefinition{
			{
				AttributeName: aws.String("id"),
				AttributeType: aws.String("S"),
			},
			{
				AttributeName: aws.String("oauthid"),
				AttributeType: aws.String("S"),
			},
		},
		ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
			ReadCapacityUnits:  aws.Int64(1),
			WriteCapacityUnits: aws.Int64(1),
		},
		GlobalSecondaryIndexes: []*dynamodb.GlobalSecondaryIndex{
			{ // Required
				IndexName: aws.String("AuthIDIndex"),
				KeySchema: []*dynamodb.KeySchemaElement{
					{ // Required
						AttributeName: aws.String("oauthid"),
						KeyType:       aws.String("HASH"),
					},
				},
				Projection: &dynamodb.Projection{
					ProjectionType: aws.String("INCLUDE"),
					NonKeyAttributes: []*string{
						aws.String("id"),
					},
				},
				ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
					ReadCapacityUnits:  aws.Int64(1),
					WriteCapacityUnits: aws.Int64(1),
				},
			},
		},
	}
	_, err := db.CreateTable(params)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:blang,项目名称:posty,代码行数:51,代码来源:user_test.go


示例13: createTable

func createTable(db *dynamodb.DynamoDB, createParams *dynamodb.CreateTableInput) error {
	_, err := db.CreateTable(createParams)
	if err != nil {
		return err
	}

	describeParams := &dynamodb.DescribeTableInput{
		TableName: aws.String(*createParams.TableName),
	}
	if err := db.WaitUntilTableExists(describeParams); err != nil {
		return err
	}

	return nil
}
开发者ID:uniplaces,项目名称:osin-dynamodb,代码行数:15,代码来源:osindynamodb.go


示例14: CheckRows

// CheckRows returns a Row accessor for every row in a table. The order of rows
// is unspecified. If an error occurs, the rows will be nil. The returned
// ValueDefiner can be used to define access to custom types across all rows.
func CheckRows(db *dynamodb.DynamoDB, tableName string) ([]Row, ValueDefiner) {
	resp, err := db.Scan(&dynamodb.ScanInput{
		TableName: aws.String(tableName),
	})
	if err != nil {
		return nil, nil
	}
	vd := newValueDefiner()
	rows := make([]Row, len(resp.Items))
	for i, item := range resp.Items {
		reader := valueReader{item, vd}
		rows[i] = Row{reader}
	}
	return rows, vd
}
开发者ID:rcarver,项目名称:dynamis,代码行数:18,代码来源:check.go


示例15: mockCRCResponse

func mockCRCResponse(svc *dynamodb.DynamoDB, status int, body, crc string) (req *aws.Request) {
	header := http.Header{}
	header.Set("x-amz-crc32", crc)

	req, _ = svc.ListTablesRequest(nil)
	req.Handlers.Send.PushBack(func(*aws.Request) {
		req.HTTPResponse = &http.Response{
			StatusCode: status,
			Body:       ioutil.NopCloser(bytes.NewReader([]byte(body))),
			Header:     header,
		}
	})
	req.Send()
	return
}
开发者ID:Talos208,项目名称:aws-sdk-go,代码行数:15,代码来源:customizations_test.go


示例16: getRecord

func getRecord(svc *dynamodb.DynamoDB, tableName string, key string) {
	params := &dynamodb.GetItemInput{
		Key: map[string]*dynamodb.AttributeValue{
			"key": {
				S: aws.String(key),
			},
		},
		TableName: aws.String(tableName),
	}
	_, err := svc.GetItem(params)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
}
开发者ID:davidporter-id-au,项目名称:debugging-node-aws-perf,代码行数:15,代码来源:test.go


示例17: UploadForumData

func UploadForumData(svc *dynamodb.DynamoDB) (*dynamodb.BatchWriteItemOutput, error) {
	params := &dynamodb.BatchWriteItemInput{
		RequestItems: map[string][]*dynamodb.WriteRequest{
			"Forum": {
				&dynamodb.WriteRequest{
					PutRequest: &dynamodb.PutRequest{
						Item: map[string]*dynamodb.AttributeValue{
							"Name": {
								S: aws.String("Amazon DynamoDB"),
							},
							"Category": {
								S: aws.String("Amazon Web Services"),
							},
							"Threads": {
								N: aws.String("0"),
							},
							"Messages": {
								N: aws.String("0"),
							},
							"Views": {
								N: aws.String("1"),
							},
						},
					},
				},
				&dynamodb.WriteRequest{
					PutRequest: &dynamodb.PutRequest{
						Item: map[string]*dynamodb.AttributeValue{
							"Name": {
								S: aws.String("Amazon S3"),
							},
							"Category": {
								S: aws.String("Amazon Web Services"),
							},
							"Threads": {
								N: aws.String("0"),
							},
						},
					},
				},
			},
		},
	}

	return svc.BatchWriteItem(params)
}
开发者ID:sinistersig,项目名称:go-dynamodb-add-data-example,代码行数:46,代码来源:uploadForumData.go


示例18: deleteTable

func deleteTable(db *dynamodb.DynamoDB, tableName string) error {
	params := &dynamodb.DeleteTableInput{
		TableName: aws.String(tableName),
	}
	_, err := db.DeleteTable(params)
	if err != nil {
		return err
	}

	describeParams := &dynamodb.DescribeTableInput{
		TableName: aws.String(tableName),
	}
	if err := db.WaitUntilTableNotExists(describeParams); err != nil {
		return err
	}

	return nil
}
开发者ID:uniplaces,项目名称:osin-dynamodb,代码行数:18,代码来源:osindynamodb.go


示例19: handleRemove

func handleRemove(subject string) {
	fmt.Println("Remove admin", subject)

	var client *dynamodb.DynamoDB = dbutil.CreateDynamoDBClient()
	params := &dynamodb.DeleteItemInput{
		TableName: aws.String(ddl.AdminTableName),
		Key: map[string]*dynamodb.AttributeValue{
			"AdminID": {S: aws.String(subject)},
		},
	}

	_, err := client.DeleteItem(params)

	if err != nil {
		fmt.Println(err.Error())
		return
	}
}
开发者ID:xtraclabs,项目名称:roll,代码行数:18,代码来源:admins.go


示例20: handleList

func handleList() {
	var client *dynamodb.DynamoDB = dbutil.CreateDynamoDBClient()
	params := &dynamodb.ScanInput{
		TableName: aws.String(ddl.AdminTableName),
		AttributesToGet: []*string{
			aws.String("AdminID"),
		},
	}

	resp, err := client.Scan(params)

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println(resp)
}
开发者ID:xtraclabs,项目名称:roll,代码行数:18,代码来源:admins.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang dynamodbattribute.ConvertToMap函数代码示例发布时间:2022-05-24
下一篇:
Golang dynamodb.AttributeValue类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap