Exemplo n.º 1
0
func ExampleClient_CreateTable_basic(client *dynago.Client) {
	// NewCreateRequest creates a table with simple defaults.
	// You can use chaining to set the hash and range keys.
	table1 := schema.NewCreateRequest("TableName").
		HashKey("UserId", schema.Number).
		RangeKey("Date", schema.String)

	table1.ProvisionedThroughput.ReadCapacityUnits = 45
	client.CreateTable(table1)
}
Exemplo n.º 2
0
func makeTables(t *testing.T, client *dynago.Client) {
	complexIndexed := complexIndexedSchema()
	hashTable := schema.NewCreateRequest("Person").HashKey("Id", schema.Number)
	hashRange := schema.NewCreateRequest("Posts").
		HashKey("UserId", schema.Number).
		RangeKey("Dated", schema.Number)

	tables := []*schema.CreateRequest{hashTable, hashRange, complexIndexed}
	for _, table := range tables {
		_, err := client.CreateTable(table)
		if err != nil {
			if e, ok := err.(*dynago.Error); ok && e.Type == dynago.ErrorResourceInUse {
				continue
			}
			panic(err)
		}
	}
}
Exemplo n.º 3
0
func ExampleClient_CreateTable_full(client *dynago.Client) {
	// Most of the time we don't need the full syntax for making create requests
	// It's shown here mostly for purpose of documentation
	req := &schema.CreateRequest{
		TableName: "PersonalPages",
		AttributeDefinitions: []schema.AttributeDefinition{
			{"UserId", schema.Number},
			{"Title", schema.String},
		},
		KeySchema: []schema.KeySchema{
			{"UserId", schema.HashKey},
			{"Title", schema.RangeKey},
		},
		ProvisionedThroughput: schema.ProvisionedThroughput{
			ReadCapacityUnits:  45,
			WriteCapacityUnits: 72,
		},
	}
	if response, err := client.CreateTable(req); err == nil {
		fmt.Printf("table created, status %s", response.TableDescription.TableStatus)
	}
}