ddbrew

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2022 License: MIT Imports: 21 Imported by: 0

README

test

ddbrew

Simple DynamoDB utility CLI🍺.

Installation

Homebrew
brew tap shuntaka9576/tap
brew install shuntaka9576/tap/ddbrew
Build from source
go install github.com/shuntaka9576/ddbrew/cmd/ddbrew@latest

Usage

Backup

Retrieves the records of the table specified in the argument and saves them to a file. The format of the file is jsonl, and if not specified, the file is created with the file name backup_tableName_yyyyymmdd-HHMMSS.jsonl. Use each option to adjust RCU/RRU.

ddbrew backup fooTable
Restore

Reads the jsonl file and writes it to the table. The RRUs to be consumed can be checked with the --dry-run option. To limit the number of writes, use the --limit option

ddbrew restore fooTable \
  --file ./testdata/1.jsonl
Delete

Read jsonl file and delete table data. Note that the deletion also consumes RUC/RRU.

ddbrew delete fooTable \
  --file ./testdata/1.jsonl
Use DynamoDB Local

If you use DynamoDB Local, please use the --local option

ddbrew restore fooTable \
  --file testdata/1.jsonl \
  --local http://localhost:8000

Documentation

Index

Constants

View Source
const (
	BATCH_RECORD_NUM_LIMIT     = 25
	RECORD_BYTE_SIZE_LIMIT     = 1000000 // 1MB
	READ_BUF_SIZE              = 1000000 // 4KB
	LF_BYTE                    = 10
	DEFAULT_UNIT_SIZE      int = 100 // 4(WWU) * 25 = 100(WWU)
)
View Source
const (
	WU_UNIT = 1000 // 1KB
	RU_UNIT = 4000 // 4KB
)
View Source
const GB_UNIT = 1000000000
View Source
const KB_UNIT = 1000
View Source
const LIMIT_SCAN_INTERVAL = 1 * time.Second
View Source
const MB_UNIT = 1000000
View Source
const (
	RETRY_NUMBER = 3
)
View Source
const (
	WRITE_LIMIT_BYTE_SIZE = 400000 // 400KB
)

Variables

View Source
var (
	OnDemand    = DDBMode("OnDemand")
	Provisioned = DDBMode("Provisioned")
)
View Source
var (
	ErrBatchEOF = errors.New("BatchEOF")
)

Functions

func Backup

func Backup(ctx context.Context, opt *BackupOption) error

func InitClient

func InitClient(opt *DDBClientOption) error

func PrittyPrintBytes

func PrittyPrintBytes(size int) *string

Types

type BackupOption

type BackupOption struct {
	TableName string
	FilePath  string
	Limit     *int
}

type BatchRequest added in v0.0.4

type BatchRequest struct {
	TableName     string
	WriteRequests []types.WriteRequest

	ByteSize int
	Retry    int
	// contains filtered or unexported fields
}

func (*BatchRequest) AddWriteRequest added in v0.0.4

func (b *BatchRequest) AddWriteRequest(ddbItem DDBItem) error

func (*BatchRequest) BatchWriteItemInput added in v0.0.4

func (b *BatchRequest) BatchWriteItemInput() *dynamodb.BatchWriteItemInput

func (*BatchRequest) Number added in v0.0.4

func (b *BatchRequest) Number() int

func (*BatchRequest) Reset added in v0.0.4

func (b *BatchRequest) Reset()

func (*BatchRequest) Size added in v0.0.4

func (b *BatchRequest) Size() int

type BatchRequestGenerator added in v0.0.4

type BatchRequestGenerator struct {
	// contains filtered or unexported fields
}

func (*BatchRequestGenerator) Init added in v0.0.4

type BatchRequestGeneratorOption added in v0.0.4

type BatchRequestGeneratorOption struct {
	File   *os.File
	Action DDBAction
	Table  *Table
}

type BatchResult added in v0.0.4

type BatchResult struct {
	Content BatchWriteOutput
	Error   error
}

type BatchWriteOutput added in v0.0.4

type BatchWriteOutput struct {
	SuccessCount      int
	UnprocessedRecord []string
}

type BatchWriter added in v0.0.4

type BatchWriter struct {
	Table       *Table
	File        *os.File
	DDBAction   DDBAction
	LimitUnit   *int
	RemainCount *int64
	Results     chan *BatchResult
	Done        chan struct{}
}

func (*BatchWriter) BatchWrite added in v0.0.4

func (b *BatchWriter) BatchWrite(ctx context.Context) error

type DDBAction added in v0.0.4

type DDBAction string
const (
	DDB_ACTION_PUT    DDBAction = "PUT"
	DDB_ACTION_DELETE DDBAction = "DELETE"
	DDB_ACTION_READ   DDBAction = "READ"
)

type DDBClient

type DDBClient struct {
	*dynamodb.Client
}
var DdbClient *DDBClient

func (*DDBClient) BatchWrite added in v0.0.4

func (d *DDBClient) BatchWrite(ctx context.Context, req BatchRequest) (output BatchWriteOutput, err error)

type DDBClientOption

type DDBClientOption struct {
	Local string
}

type DDBItem added in v0.0.4

type DDBItem struct {
	Action         DDBAction
	AttributeValue map[string]types.AttributeValue
	Keys           []string
	Unit           int
	ByteSize       int
}

func (*DDBItem) DeleteRequest added in v0.0.4

func (d *DDBItem) DeleteRequest() types.WriteRequest

func (*DDBItem) PutRequest added in v0.0.4

func (d *DDBItem) PutRequest() types.WriteRequest

func (*DDBItem) WriteReuest added in v0.0.4

func (d *DDBItem) WriteReuest() types.WriteRequest

type DDBMode

type DDBMode = string

type ItemResult

type ItemResult struct {
	Size      int
	ReadUnit  int
	WriteUnit int
}

func GetItemSizeByJSON

func GetItemSizeByJSON(json map[string]interface{}) (*ItemResult, error)

type SimulateOpt

type SimulateOpt struct {
	Reader io.Reader
	Mode   DDBMode
}

type SimulateResult

type SimulateResult struct {
	ConsumeRRU    *int
	ConsumeWRU    *int
	ConsumeRCU    *int
	ConsumeWCU    *int
	TotalItemSize int
}

func Simulate

func Simulate(opt *SimulateOpt) (*SimulateResult, error)

type Table added in v0.0.4

type Table struct {
	Name string
	Keys []string
	Mode DDBMode
}

func (*Table) DDBItemFromString added in v0.0.4

func (t *Table) DDBItemFromString(jsonString string, action DDBAction) (item DDBItem, err error)

func (*Table) Init added in v0.0.4

func (t *Table) Init(output *dynamodb.DescribeTableOutput)

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL