本文整理汇总了Golang中github.com/crowdmob/goamz/dynamodb.NewStringAttribute函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStringAttribute函数的具体用法?Golang NewStringAttribute怎么用?Golang NewStringAttribute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewStringAttribute函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestGetItem
func TestGetItem(t *testing.T) {
if !*amazon {
t.Log("Amazon tests not enabled")
return
}
auth, err := aws.EnvAuth()
if err != nil {
t.Log(err)
t.FailNow()
}
server := dynamodb.Server{auth, aws.USEast}
primary := dynamodb.NewStringAttribute("domain", "")
key := dynamodb.PrimaryKey{primary, nil}
table := server.NewTable("production_storyarc-accelerator-sites",
key)
item, err := table.GetItem(&dynamodb.Key{HashKey: "ac-news.speedup.storytellerhq.com"})
if err != nil {
t.Log(err)
t.FailNow()
}
fmt.Printf("Item : %s\n", item)
}
开发者ID:rvitale,项目名称:goamz,代码行数:29,代码来源:table_test.go
示例2: TestGetItemRange
func TestGetItemRange(t *testing.T) {
if !*amazon {
return
}
if !*amazon {
t.Log("Amazon tests not enabled")
return
}
auth, err := aws.EnvAuth()
if err != nil {
t.Log(err)
t.FailNow()
}
server := dynamodb.Server{auth, aws.USEast}
primary := dynamodb.NewStringAttribute("uuid_type", "")
rangeK := dynamodb.NewNumericAttribute("time", "")
key := dynamodb.PrimaryKey{primary, rangeK}
table := server.NewTable("production_storyarc-accelerator-analytics",
key)
item, err := table.GetItem(&dynamodb.Key{HashKey: "aee5df14-6961-4baa-bad1-a1150576594f_MISSES", RangeKey: "1348187524"})
if err != nil {
t.Log(err)
t.FailNow()
}
fmt.Printf("Item : %s\n", item)
}
开发者ID:rvitale,项目名称:goamz,代码行数:34,代码来源:table_test.go
示例3: TestGetItemQuery
func (s *QueryBuilderSuite) TestGetItemQuery(c *gocheck.C) {
primary := dynamodb.NewStringAttribute("domain", "")
key := dynamodb.PrimaryKey{primary, nil}
table := s.server.NewTable("sites", key)
q := dynamodb.NewQuery(table)
q.AddKey(table, &dynamodb.Key{HashKey: "test"})
queryJson, err := simplejson.NewJson([]byte(q.String()))
if err != nil {
c.Fatal(err)
}
expectedJson, err := simplejson.NewJson([]byte(`
{
"Key": {
"domain": {
"S": "test"
}
},
"TableName": "sites"
}
`))
if err != nil {
c.Fatal(err)
}
c.Check(queryJson, gocheck.DeepEquals, expectedJson)
}
开发者ID:nabeken,项目名称:goamz,代码行数:28,代码来源:query_builder_test.go
示例4: TestConditionalAddAttributesItem
func (s *ItemSuite) TestConditionalAddAttributesItem(c *check.C) {
if s.WithRange {
// No rangekey test required
return
}
attrs := []dynamodb.Attribute{
*dynamodb.NewNumericAttribute("AttrN", "10"),
}
pk := &dynamodb.Key{HashKey: "NewHashKeyVal"}
// Put
if ok, err := s.table.PutItem("NewHashKeyVal", "", attrs); !ok {
c.Fatal(err)
}
{
// Put with condition failed
expected := []dynamodb.Attribute{
*dynamodb.NewNumericAttribute("AttrN", "0").SetExists(true),
*dynamodb.NewStringAttribute("AttrNotExists", "").SetExists(false),
}
// Add attributes with condition failed
if ok, err := s.table.ConditionalAddAttributes(pk, attrs, expected); ok {
c.Errorf("Expect condition does not meet.")
} else {
c.Check(err.Error(), check.Matches, "ConditionalCheckFailedException.*")
}
}
}
开发者ID:WIZARD-CXY,项目名称:golang-devops-stuff,代码行数:31,代码来源:item_test.go
示例5: TestAddUpdates
func TestAddUpdates(t *testing.T) {
auth := &aws.Auth{AccessKey: "", SecretKey: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"}
server := dynamodb.Server{*auth, aws.USEast}
primary := dynamodb.NewStringAttribute("domain", "")
key := dynamodb.PrimaryKey{primary, nil}
table := server.NewTable("sites", key)
q := dynamodb.NewQuery(table)
q.AddKey(table, &dynamodb.Key{HashKey: "test"})
attr := dynamodb.NewStringSetAttribute("StringSet", []string{"str", "str2"})
q.AddUpdates([]dynamodb.Attribute{*attr}, "ADD")
queryString := []byte(q.String())
json, err := simplejson.NewJson(queryString)
if err != nil {
t.Logf("JSON err : %s\n", err)
t.Fatalf("Invalid JSON : %s\n", queryString)
}
attributeUpdates := json.Get("AttributeUpdates")
if _, err := attributeUpdates.Map(); err != nil {
t.Fatalf("Expected a AttributeUpdates found")
}
attributesModified := attributeUpdates.Get("StringSet")
if _, err := attributesModified.Map(); err != nil {
t.Fatalf("Expected a StringSet found : %s", err)
}
action := attributesModified.Get("Action")
if v, err := action.String(); err != nil {
t.Fatalf("Expected a action to be string : %s", err)
} else if v != "ADD" {
t.Fatalf("Expected a action to be ADD : %s", v)
}
value := attributesModified.Get("Value")
if _, err := value.Map(); err != nil {
t.Fatalf("Expected a Value found : %s", err)
}
string_set := value.Get("SS")
string_set_ary, err := string_set.StringArray()
if err != nil {
t.Fatalf("Expected a string set found : %s", err)
}
if len(string_set_ary) != 2 {
t.Fatalf("Expected a string set length to be 2 was : %d", len(string_set_ary))
}
for _, v := range string_set_ary {
if v != "str" && v != "str2" {
t.Fatalf("Expected a string to be str OR str2 was : %s", v)
}
}
}
开发者ID:noahcampbell,项目名称:goamz,代码行数:59,代码来源:query_builder_test.go
示例6: TestPutGetDeleteItem
func (s *ItemSuite) TestPutGetDeleteItem(c *gocheck.C) {
attrs := []dynamodb.Attribute{
*dynamodb.NewStringAttribute("Attr1", "Attr1Val"),
}
var rk string
if s.WithRange {
rk = "1"
}
// Put
if ok, err := s.table.PutItem("NewHashKeyVal", rk, attrs); !ok {
c.Fatal(err)
}
// Get to verify Put operation
pk := &dynamodb.Key{HashKey: "NewHashKeyVal", RangeKey: rk}
item, err := s.table.GetItem(pk)
if err != nil {
c.Fatal(err)
}
if val, ok := item["TestHashKey"]; ok {
c.Check(val, gocheck.DeepEquals, dynamodb.NewStringAttribute("TestHashKey", "NewHashKeyVal"))
} else {
c.Error("Expect TestHashKey to be found")
}
if s.WithRange {
if val, ok := item["TestRangeKey"]; ok {
c.Check(val, gocheck.DeepEquals, dynamodb.NewNumericAttribute("TestRangeKey", "1"))
} else {
c.Error("Expect TestRangeKey to be found")
}
}
// Delete
if ok, _ := s.table.DeleteItem(pk); !ok {
c.Fatal(err)
}
// Get to verify Delete operation
_, err = s.table.GetItem(pk)
c.Check(err.Error(), gocheck.Matches, "Item not found")
}
开发者ID:nabeken,项目名称:goamz,代码行数:45,代码来源:item_test.go
示例7: TestAddExpectedQuery
func (s *QueryBuilderSuite) TestAddExpectedQuery(c *gocheck.C) {
primary := dynamodb.NewStringAttribute("domain", "")
key := dynamodb.PrimaryKey{primary, nil}
table := s.server.NewTable("sites", key)
q := dynamodb.NewQuery(table)
q.AddKey(table, &dynamodb.Key{HashKey: "test"})
expected := []dynamodb.Attribute{
*dynamodb.NewStringAttribute("domain", "expectedTest").SetExists(true),
*dynamodb.NewStringAttribute("testKey", "").SetExists(false),
}
q.AddExpected(expected)
queryJson, err := simplejson.NewJson([]byte(q.String()))
if err != nil {
c.Fatal(err)
}
expectedJson, err := simplejson.NewJson([]byte(`
{
"Expected": {
"domain": {
"Exists": "true",
"Value": {
"S": "expectedTest"
}
},
"testKey": {
"Exists": "false"
}
},
"Key": {
"domain": {
"S": "test"
}
},
"TableName": "sites"
}
`))
if err != nil {
c.Fatal(err)
}
c.Check(queryJson, gocheck.DeepEquals, expectedJson)
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:45,代码来源:query_builder_test.go
示例8: TestAddKeyConditions
func TestAddKeyConditions(t *testing.T) {
auth := &aws.Auth{AccessKey: "", SecretKey: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"}
server := dynamodb.Server{*auth, aws.USEast}
primary := dynamodb.NewStringAttribute("domain", "")
key := dynamodb.PrimaryKey{primary, nil}
table := server.NewTable("sites", key)
q := dynamodb.NewQuery(table)
acs := []dynamodb.AttributeComparison{
*dynamodb.NewStringAttributeComparison("domain", "EQ", "example.com"),
*dynamodb.NewStringAttributeComparison("path", "EQ", "/"),
}
q.AddKeyConditions(acs)
queryString := []byte(q.String())
json, err := simplejson.NewJson(queryString)
if err != nil {
t.Logf("JSON err : %s\n", err)
t.Fatalf("Invalid JSON : %s\n", queryString)
}
expected_json, err := simplejson.NewJson([]byte(`
{
"KeyConditions": {
"domain": {
"AttributeValueList": [
{
"S": "example.com"
}
],
"ComparisonOperator": "EQ"
},
"path": {
"AttributeValueList": [
{
"S": "/"
}
],
"ComparisonOperator": "EQ"
}
},
"TableName": "sites"
}
`))
if err != nil {
t.Logf("JSON err : %s\n", err)
t.Fatalf("Invalid JSON : %s\n", expected_json)
}
if !reflect.DeepEqual(json, expected_json) {
t.Fatalf("Unexpected KeyConditions structure")
}
}
开发者ID:rkononov,项目名称:goamz,代码行数:53,代码来源:query_builder_test.go
示例9: TestUpdateQuery
func TestUpdateQuery(t *testing.T) {
auth := &aws.Auth{"", "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"}
server := dynamodb.Server{*auth, aws.USEast}
primary := dynamodb.NewStringAttribute("domain", "")
rangek := dynamodb.NewNumericAttribute("time", "")
key := dynamodb.PrimaryKey{primary, rangek}
table := server.NewTable("sites", key)
countAttribute := dynamodb.NewNumericAttribute("count", "4")
attributes := []dynamodb.Attribute{*countAttribute}
q := dynamodb.NewQuery(table)
q.AddKey(table, "test", "1234")
q.AddUpdates(attributes, "ADD")
queryString := []byte(q.String())
json, err := simplejson.NewJson(queryString)
if err != nil {
t.Logf("JSON err : %s\n", err)
t.Fatalf("Invalid JSON : %s\n", queryString)
}
tableName := json.Get("TableName").MustString()
if tableName != "sites" {
t.Fatalf("Expected tableName to be sites was : %s", tableName)
}
keyMap, err := json.Get("Key").Map()
if err != nil {
t.Fatalf("Expected a Key")
}
hashRangeKey := keyMap["HashKeyElement"]
if hashRangeKey == nil {
t.Fatalf("Expected a HashKeyElement found : %s", keyMap)
}
rangeKey := keyMap["RangeKeyElement"]
if rangeKey == nil {
t.Fatalf("Expected a RangeKeyElement found : %s", keyMap)
}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:49,代码来源:query_builder_test.go
示例10: TestAddQueryFilterConditions
func (s *QueryBuilderSuite) TestAddQueryFilterConditions(c *check.C) {
primary := dynamodb.NewStringAttribute("domain", "")
key := dynamodb.PrimaryKey{primary, nil}
table := s.server.NewTable("sites", key)
q := dynamodb.NewQuery(table)
acs := []dynamodb.AttributeComparison{
*dynamodb.NewStringAttributeComparison("domain", "EQ", "example.com"),
}
qf := []dynamodb.AttributeComparison{
*dynamodb.NewNumericAttributeComparison("count", dynamodb.COMPARISON_GREATER_THAN, 5),
}
q.AddKeyConditions(acs)
q.AddQueryFilter(qf)
queryJson, err := simplejson.NewJson([]byte(q.String()))
if err != nil {
c.Fatal(err)
}
expectedJson, err := simplejson.NewJson([]byte(`
{
"KeyConditions": {
"domain": {
"AttributeValueList": [
{
"S": "example.com"
}
],
"ComparisonOperator": "EQ"
}
},
"QueryFilter": {
"count": {
"AttributeValueList": [
{ "N": "5" }
],
"ComparisonOperator": "GT"
}
},
"TableName": "sites"
}
`))
if err != nil {
c.Fatal(err)
}
c.Check(queryJson, check.DeepEquals, expectedJson)
}
开发者ID:crash2burn,项目名称:goamz,代码行数:48,代码来源:query_builder_test.go
示例11: NewDynamoStoreWithRegionObj
func NewDynamoStoreWithRegionObj(accessKey string, secretKey string, tableName string, region aws.Region, keyPairs ...[]byte) (*DynamoStore, error) {
awsAuth := aws.Auth{
AccessKey: accessKey,
SecretKey: secretKey,
}
server := dynamodb.New(awsAuth, region)
table := server.NewTable(tableName, dynamodb.PrimaryKey{KeyAttribute: dynamodb.NewStringAttribute("Id", "")})
dynStore := &DynamoStore{
Table: table,
Codecs: securecookie.CodecsFromPairs(keyPairs...),
}
return dynStore, nil
}
开发者ID:stevenbooru,项目名称:stevenbooru,代码行数:16,代码来源:dynamostore.go
示例12: main
func main() {
hashKey := "java"
rangeKey := "de1ece0a-28e9-429c-a9a5-b2fc5e2fc3f9"
usr, err := user.Current()
homeDir := "."
if err != nil {
log.Println("Error gettingcurrent user ", err)
} else {
homeDir = usr.HomeDir
log.Println(" User ", usr, " Home Dir := ", homeDir)
}
authCreds, err = aws.CredentialFileAuth(homeDir+"/.aws/credentials", "default", defaultExpiration)
awsRegion = aws.Regions[defaultAwsRegionName]
if err != nil {
log.Println(" Error getting Authentication Creds : ", err)
}
dynamoDBServer = dynamodb.Server{}
dynamoDBServer.Auth = authCreds
dynamoDBServer.Region = awsRegion
dynamoDBTable = dynamodb.Table{}
dynamoDBTable.Name = dynamoDBTableName
dynamoDBTable.Server = &dynamoDBServer
primaryKey := dynamodb.PrimaryKey{}
primaryKey.KeyAttribute = dynamodb.NewStringAttribute("languageId", "S")
primaryKey.RangeAttribute = dynamodb.NewStringAttribute("cuid", "S")
attributes := make([]dynamodb.Attribute, 4)
attributes[0] = *dynamodb.NewStringAttribute("languageId", "S")
attributes[1] = *dynamodb.NewStringAttribute("cuid", "SK")
attributes[2] = *dynamodb.NewStringAttribute("myKey", "1234")
attributes[3] = *dynamodb.NewStringAttribute("another_Attr", "Sample")
created, err := dynamoDBTable.PutItem(hashKey, rangeKey, attributes)
if err != nil {
log.Fatal("Error creating the Dynamo DB Table : ", err.Error())
} else {
log.Println("Create Item Status : ", created)
}
dynamoDBTable.Key = primaryKey
key := dynamodb.Key{}
key.HashKey = hashKey
key.RangeKey = rangeKey
item, err := dynamoDBTable.GetItem(&key)
if err != nil || item == nil {
log.Println("Error getting Item (Key = ", key, ") : ", err)
} else {
log.Println(" Got the Item ", item)
}
log.Println("Deleting the same item now !")
deleted, err := dynamoDBTable.DeleteItem(&key)
if err != nil {
log.Fatal("Error deleting the item : ", err.Error())
} else {
log.Println("Item Delete Status := ", deleted)
}
}
开发者ID:venkatesh-tr,项目名称:samplego,代码行数:55,代码来源:dynamodbdemo.go
示例13: TestGetItemQuery
func TestGetItemQuery(t *testing.T) {
auth := &aws.Auth{"", "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"}
server := dynamodb.Server{*auth, aws.USEast}
primary := dynamodb.NewStringAttribute("domain", "")
key := dynamodb.PrimaryKey{primary, nil}
table := server.NewTable("sites", key)
q := dynamodb.NewQuery(table)
q.AddKey(table, "test", "")
queryString := []byte(q.String())
json, err := simplejson.NewJson(queryString)
if err != nil {
t.Logf("JSON err : %s\n", err)
t.Fatalf("Invalid JSON : %s\n", queryString)
}
tableName := json.Get("TableName").MustString()
if tableName != "sites" {
t.Fatalf("Expected tableName to be sites was : %s", tableName)
}
keyMap, err := json.Get("Key").Map()
if err != nil {
t.Fatalf("Expected a Key")
}
hashRangeKey := keyMap["HashKeyElement"]
if hashRangeKey == nil {
t.Fatalf("Expected a HashKeyElement found : %s", keyMap)
}
if v, ok := hashRangeKey.(map[string]interface{}); ok {
if val, ok := v["S"].(string); ok {
if val != "test" {
t.Fatalf("Expected HashKeyElement to have the value 'test' found : %s", val)
}
}
} else {
t.Fatalf("HashRangeKeyt had the wrong type found : %s", hashRangeKey)
}
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:47,代码来源:query_builder_test.go
示例14: TestAddKeyConditions
func (s *QueryBuilderSuite) TestAddKeyConditions(c *gocheck.C) {
primary := dynamodb.NewStringAttribute("domain", "")
key := dynamodb.PrimaryKey{primary, nil}
table := s.server.NewTable("sites", key)
q := dynamodb.NewQuery(table)
acs := []dynamodb.AttributeComparison{
*dynamodb.NewStringAttributeComparison("domain", "EQ", "example.com"),
*dynamodb.NewStringAttributeComparison("path", "EQ", "/"),
}
q.AddKeyConditions(acs)
queryJson, err := simplejson.NewJson([]byte(q.String()))
if err != nil {
c.Fatal(err)
}
expectedJson, err := simplejson.NewJson([]byte(`
{
"KeyConditions": {
"domain": {
"AttributeValueList": [
{
"S": "example.com"
}
],
"ComparisonOperator": "EQ"
},
"path": {
"AttributeValueList": [
{
"S": "/"
}
],
"ComparisonOperator": "EQ"
}
},
"TableName": "sites"
}
`))
if err != nil {
c.Fatal(err)
}
c.Check(queryJson, gocheck.DeepEquals, expectedJson)
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:45,代码来源:query_builder_test.go
示例15: TestAddWriteRequestItems
func TestAddWriteRequestItems(t *testing.T) {
auth := &aws.Auth{AccessKey: "", SecretKey: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY"}
server := dynamodb.Server{*auth, aws.USEast}
primary := dynamodb.NewStringAttribute("WidgetFoo", "")
secondary := dynamodb.NewNumericAttribute("Created", "")
key := dynamodb.PrimaryKey{primary, secondary}
table := server.NewTable("FooData", key)
primary2 := dynamodb.NewStringAttribute("TestHashKey", "")
secondary2 := dynamodb.NewNumericAttribute("TestRangeKey", "")
key2 := dynamodb.PrimaryKey{primary2, secondary2}
table2 := server.NewTable("TestTable", key2)
q := dynamodb.NewEmptyQuery()
attribute1 := dynamodb.NewNumericAttribute("testing", "4")
attribute2 := dynamodb.NewNumericAttribute("testingbatch", "2111")
attribute3 := dynamodb.NewStringAttribute("testingstrbatch", "mystr")
item1 := []dynamodb.Attribute{*attribute1, *attribute2, *attribute3}
attribute4 := dynamodb.NewNumericAttribute("testing", "444")
attribute5 := dynamodb.NewNumericAttribute("testingbatch", "93748249272")
attribute6 := dynamodb.NewStringAttribute("testingstrbatch", "myotherstr")
item2 := []dynamodb.Attribute{*attribute4, *attribute5, *attribute6}
attributeDel1 := dynamodb.NewStringAttribute("TestHashKeyDel", "DelKey")
attributeDel2 := dynamodb.NewNumericAttribute("TestRangeKeyDel", "7777777")
itemDel := []dynamodb.Attribute{*attributeDel1, *attributeDel2}
attributeTest1 := dynamodb.NewStringAttribute("TestHashKey", "MyKey")
attributeTest2 := dynamodb.NewNumericAttribute("TestRangeKey", "0193820384293")
itemTest := []dynamodb.Attribute{*attributeTest1, *attributeTest2}
tableItems := map[*dynamodb.Table]map[string][][]dynamodb.Attribute{}
actionItems := make(map[string][][]dynamodb.Attribute)
actionItems["Put"] = [][]dynamodb.Attribute{item1, item2}
actionItems["Delete"] = [][]dynamodb.Attribute{itemDel}
tableItems[table] = actionItems
actionItems2 := make(map[string][][]dynamodb.Attribute)
actionItems2["Put"] = [][]dynamodb.Attribute{itemTest}
tableItems[table2] = actionItems2
q.AddWriteRequestItems(tableItems)
desiredString := "{\"RequestItems\":{\"FooData\":[{\"PutRequest\":{\"Item\":{\"testing\":{\"N\":\"4\"},\"testingbatch\":{\"N\":\"2111\"},\"testingstrbatch\":{\"S\":\"mystr\"}}}},{\"PutRequest\":{\"Item\":{\"testing\":{\"N\":\"444\"},\"testingbatch\":{\"N\":\"93748249272\"},\"testingstrbatch\":{\"S\":\"myotherstr\"}}}},{\"DeleteRequest\":{\"Key\":{\"TestHashKeyDel\":{\"S\":\"DelKey\"},\"TestRangeKeyDel\":{\"N\":\"7777777\"}}}}],\"TestTable\":[{\"PutRequest\":{\"Item\":{\"TestHashKey\":{\"S\":\"MyKey\"},\"TestRangeKey\":{\"N\":\"0193820384293\"}}}}]}}"
queryString := q.String()
if queryString != desiredString {
t.Fatalf("Unexpected Query String : %s\n", queryString)
}
}
开发者ID:jbert,项目名称:goamz,代码行数:52,代码来源:query_builder_test.go
示例16: TestUpdateQuery
func (s *QueryBuilderSuite) TestUpdateQuery(c *gocheck.C) {
primary := dynamodb.NewStringAttribute("domain", "")
rangek := dynamodb.NewNumericAttribute("time", "")
key := dynamodb.PrimaryKey{primary, rangek}
table := s.server.NewTable("sites", key)
countAttribute := dynamodb.NewNumericAttribute("count", "4")
attributes := []dynamodb.Attribute{*countAttribute}
q := dynamodb.NewQuery(table)
q.AddKey(table, &dynamodb.Key{HashKey: "test", RangeKey: "1234"})
q.AddUpdates(attributes, "ADD")
queryJson, err := simplejson.NewJson([]byte(q.String()))
if err != nil {
c.Fatal(err)
}
expectedJson, err := simplejson.NewJson([]byte(`
{
"AttributeUpdates": {
"count": {
"Action": "ADD",
"Value": {
"N": "4"
}
}
},
"Key": {
"domain": {
"S": "test"
},
"time": {
"N": "1234"
}
},
"TableName": "sites"
}
`))
if err != nil {
c.Fatal(err)
}
c.Check(queryJson, gocheck.DeepEquals, expectedJson)
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:43,代码来源:query_builder_test.go
示例17: main
func main() {
// This assumes you have ENV vars: AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
auth, err := aws.EnvAuth()
if err != nil {
log.Fatal(err.Error())
}
// aws.USEast.DynamoDBEndpoint = "http://localhost:3300"
log.Printf("%+v", aws.USEast.DynamoDBEndpoint)
server := dynamodb.Server{auth, aws.USEast}
tables, err := server.ListTables()
if err != nil {
panic(err.Error())
}
if len(tables) == 0 {
panic("Expected table to be returned")
}
fmt.Printf("tables %+v\n", tables)
primary := dynamodb.NewStringAttribute("v", "")
key := dynamodb.PrimaryKey{primary, nil}
table := server.NewTable(tables[0], key)
fmt.Printf("tables %+v\n", table)
desc, err := table.DescribeTable()
if err != nil {
panic(err.Error())
}
if desc.TableSizeBytes > 0 {
log.Println("TableSizeBytes > 0", desc.TableSizeBytes)
}
if desc.ItemCount > 0 {
log.Println("ItemCount > 0", desc.ItemCount)
}
fmt.Printf("tables %+v\n", desc)
}
开发者ID:npaton,项目名称:dynamockdb,代码行数:42,代码来源:dynamock_client_testing.go
示例18: TestAddUpdates
func (s *QueryBuilderSuite) TestAddUpdates(c *gocheck.C) {
primary := dynamodb.NewStringAttribute("domain", "")
key := dynamodb.PrimaryKey{primary, nil}
table := s.server.NewTable("sites", key)
q := dynamodb.NewQuery(table)
q.AddKey(table, &dynamodb.Key{HashKey: "test"})
attr := dynamodb.NewStringSetAttribute("StringSet", []string{"str", "str2"})
q.AddUpdates([]dynamodb.Attribute{*attr}, "ADD")
queryJson, err := simplejson.NewJson([]byte(q.String()))
if err != nil {
c.Fatal(err)
}
expectedJson, err := simplejson.NewJson([]byte(`
{
"AttributeUpdates": {
"StringSet": {
"Action": "ADD",
"Value": {
"SS": ["str", "str2"]
}
}
},
"Key": {
"domain": {
"S": "test"
}
},
"TableName": "sites"
}
`))
if err != nil {
c.Fatal(err)
}
c.Check(queryJson, gocheck.DeepEquals, expectedJson)
}
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:39,代码来源:query_builder_test.go
示例19: StringAttr
func StringAttr(name, value string) dynamodb.Attribute {
return *dynamodb.NewStringAttribute(name, value)
}
开发者ID:superduper,项目名称:gosandbox,代码行数:3,代码来源:dynamodb.go
示例20: TestAddWriteRequestItems
func (s *QueryBuilderSuite) TestAddWriteRequestItems(c *gocheck.C) {
primary := dynamodb.NewStringAttribute("WidgetFoo", "")
secondary := dynamodb.NewNumericAttribute("Created", "")
key := dynamodb.PrimaryKey{primary, secondary}
table := s.server.NewTable("FooData", key)
primary2 := dynamodb.NewStringAttribute("TestHashKey", "")
secondary2 := dynamodb.NewNumericAttribute("TestRangeKey", "")
key2 := dynamodb.PrimaryKey{primary2, secondary2}
table2 := s.server.NewTable("TestTable", key2)
q := dynamodb.NewEmptyQuery()
attribute1 := dynamodb.NewNumericAttribute("testing", "4")
attribute2 := dynamodb.NewNumericAttribute("testingbatch", "2111")
attribute3 := dynamodb.NewStringAttribute("testingstrbatch", "mystr")
item1 := []dynamodb.Attribute{*attribute1, *attribute2, *attribute3}
attribute4 := dynamodb.NewNumericAttribute("testing", "444")
attribute5 := dynamodb.NewNumericAttribute("testingbatch", "93748249272")
attribute6 := dynamodb.NewStringAttribute("testingstrbatch", "myotherstr")
item2 := []dynamodb.Attribute{*attribute4, *attribute5, *attribute6}
attributeDel1 := dynamodb.NewStringAttribute("TestHashKeyDel", "DelKey")
attributeDel2 := dynamodb.NewNumericAttribute("TestRangeKeyDel", "7777777")
itemDel := []dynamodb.Attribute{*attributeDel1, *attributeDel2}
attributeTest1 := dynamodb.NewStringAttribute("TestHashKey", "MyKey")
attributeTest2 := dynamodb.NewNumericAttribute("TestRangeKey", "0193820384293")
itemTest := []dynamodb.Attribute{*attributeTest1, *attributeTest2}
tableItems := map[*dynamodb.Table]map[string][][]dynamodb.Attribute{}
actionItems := make(map[string][][]dynamodb.Attribute)
actionItems["Put"] = [][]dynamodb.Attribute{item1, item2}
actionItems["Delete"] = [][]dynamodb.Attribute{itemDel}
tableItems[table] = actionItems
actionItems2 := make(map[string][][]dynamodb.Attribute)
actionItems2["Put"] = [][]dynamodb.Attribute{itemTest}
tableItems[table2] = actionItems2
q.AddWriteRequestItems(tableItems)
queryJson, err := simplejson.NewJson([]byte(q.String()))
if err != nil {
c.Fatal(err)
}
expectedJson, err := simplejson.NewJson([]byte(`
{
"RequestItems": {
"TestTable": [
{
"PutRequest": {
"Item": {
"TestRangeKey": {
"N": "0193820384293"
},
"TestHashKey": {
"S": "MyKey"
}
}
}
}
],
"FooData": [
{
"PutRequest": {
"Item": {
"testingstrbatch": {
"S": "mystr"
},
"testingbatch": {
"N": "2111"
},
"testing": {
"N": "4"
}
}
}
},
{
"PutRequest": {
"Item": {
"testingstrbatch": {
"S": "myotherstr"
},
"testingbatch": {
"N": "93748249272"
},
"testing": {
"N": "444"
}
}
}
},
{
"DeleteRequest": {
"Key": {
"TestRangeKeyDel": {
//.........这里部分代码省略.........
开发者ID:nkts,项目名称:golang-devops-stuff,代码行数:101,代码来源:query_builder_test.go
注:本文中的github.com/crowdmob/goamz/dynamodb.NewStringAttribute函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论