Skip to content

Commit

Permalink
feat(database/online): implement CreateTable for dynamoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
jinghancc committed Jan 26, 2022
1 parent 118cc7d commit b28d3d9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
37 changes: 37 additions & 0 deletions internal/database/online/dynamodb/create_table.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dynamodb

import (
"context"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
"github.com/oom-ai/oomstore/internal/database/online"
"github.com/oom-ai/oomstore/pkg/errdefs"
)

func (db *DB) CreateTable(ctx context.Context, opt online.CreateTableOpt) error {
_, err := db.Client.CreateTable(ctx, &dynamodb.CreateTableInput{
TableName: aws.String(opt.TableName),
KeySchema: []types.KeySchemaElement{
{
AttributeName: aws.String(opt.EntityName),
KeyType: types.KeyTypeHash,
},
},
AttributeDefinitions: []types.AttributeDefinition{
{
AttributeName: aws.String(opt.EntityName),
AttributeType: types.ScalarAttributeTypeS,
},
},
ProvisionedThroughput: &types.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(10),
WriteCapacityUnits: aws.Int64(10),
},
})
if err != nil {
return errdefs.WithStack(err)
}
return nil
}
7 changes: 1 addition & 6 deletions internal/database/online/dynamodb/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
"github.com/oom-ai/oomstore/pkg/errdefs"

"github.com/oom-ai/oomstore/internal/database/online"
"github.com/oom-ai/oomstore/pkg/errdefs"
"github.com/oom-ai/oomstore/pkg/oomstore/types"
)

Expand Down Expand Up @@ -55,8 +55,3 @@ func (db *DB) Ping(ctx context.Context) error {
func (db *DB) Close() error {
return nil
}

func (db *DB) CreateTable(ctx context.Context, opt online.CreateTableOpt) error {
//TODO implement me
panic("implement me")
}
4 changes: 4 additions & 0 deletions internal/database/online/dynamodb/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ func TestPrepareStreamTable(t *testing.T) {
func TestPush(t *testing.T) {
test_impl.TestPush(t, prepareStore, destroyStore(t))
}

func TestCreateTable(t *testing.T) {
test_impl.TestCreateTable(t, prepareStore, destroyStore(t))
}

0 comments on commit b28d3d9

Please sign in to comment.