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


Golang dynamodb.DynamoDB类代码示例

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


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


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