本文整理汇总了Golang中github.com/crowdmob/goamz/dynamodb.NewQuery函数的典型用法代码示例。如果您正苦于以下问题:Golang NewQuery函数的具体用法?Golang NewQuery怎么用?Golang NewQuery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewQuery函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例3: 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
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例8: 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
示例9: 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
示例10: 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
注:本文中的github.com/crowdmob/goamz/dynamodb.NewQuery函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论