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


Golang Server.NewTable方法代码示例

本文整理汇总了Golang中github.com/crowdmob/goamz/dynamodb.Server.NewTable方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.NewTable方法的具体用法?Golang Server.NewTable怎么用?Golang Server.NewTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/crowdmob/goamz/dynamodb.Server的用法示例。


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: MakeDynamoDBStore

func MakeDynamoDBStore(awsAccessKey, awsSecretKey string) *TDynamoDBStore {
	var (
		auth aws.Auth
		pk   dynamodb.PrimaryKey
	)
	contract.RequireNoErrors(
		func() (err error) {
			auth, err = aws.GetAuth(awsAccessKey, awsSecretKey, auth.Token(), auth.Expiration())
			return
		},
		func() (err error) {
			desc := DynamoDBDemoTableDescription()
			pk, err = desc.BuildPrimaryKey()
			return
		})

	dynamo := dynamodb.Server{auth, aws.USWest2} // hardcode ftw
	table := dynamo.NewTable(DynamoDbDemoTable, pk)
	return &TDynamoDBStore{&dynamo, table}
}
开发者ID:superduper,项目名称:gosandbox,代码行数:20,代码来源:dynamodb.go


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