godynamo

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2024 License: MIT Imports: 24 Imported by: 1

README

godynamo

Go Report Card PkgGoDev ci codecov GitHub release (latest by date)

Go driver for AWS DynamoDB which can be used with the standard database/sql package.

Forked from github.com/btnguyen2k/godynamo.

Usage

package main

import (
	"database/sql"
	"fmt"

	_ "github.com/himgang/godynamo"
)

func main() {
	driver := "godynamo"
	dsn := "Region=<aws-region>;AkId=<access-key-id>;SecretKey=<secret-key>"
	db, err := sql.Open(driver, dsn)
	if err != nil {
		panic(err)
	}
	defer db.Close()

	// db instance is ready to use 
	dbRows, err := db.Query(`LIST TABLES`)
	if err != nil {
		panic(err)
	}
	for dbRows.Next() {
		var val interface{}
		err := dbRows.Scan(&val)
		if err != nil {
			panic(err)
		}
		fmt.Println(val)
	}
}

Data Source Name (DSN) format for AWS DynamoDB

Note: line-break is for readability only!

Region=<aws-region>
;AkId=<aws-access-key-id>
;Secret_Key=<aws-secret-key>
[;Endpoint=<aws-dynamodb-endpoint>]
[TimeoutMs=<timeout-in-milliseconds>]
  • Region: AWS region, for example us-east-1. If not supplied, the value of the environment AWS_REGION is used.
  • AkId: AWS Access Key ID, for example AKIA1234567890ABCDEF. If not supplied, the value of the environment AWS_ACCESS_KEY_ID is used.
  • Secret_Key: AWS Secret Key, for example 0A1B2C3D4E5F. If not supplied, the value of the environment AWS_SECRET_ACCESS_KEY is used.
  • Endpoint: (optional) AWS DynamoDB endpoint, for example http://localhost:8000; useful when AWS DynamoDB is running on local machine.
  • TimeoutMs: (optional) timeout in milliseconds. If not specified, default value is 10000.

Using aws.Config:

Since v1.3.0, godynamo supports using aws.Config to create the connection to DynamoDB:

package main

import (
	"database/sql"
	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/himgang/godynamo"
)

func main() {
	driver := "godynamo"
	awscfg := aws.Config{
        Region: "<aws-region>",
        Credentials: aws.StaticCredentialsProvider{
            Value: aws.Credentials{
                AccessKeyID:     "<access-key-id>",
                SecretAccessKey: "<secret-key>",
			},
		},
    }
	godynamo.RegisterAWSConfig(awscfg)
	
	db, err := sql.Open(driver, "dummy")
	if err != nil {
		panic(err)
	}
	defer db.Close()
	
	// db instance is ready to use
}

Supported statements:

  • Table:

    • CREATE TABLE
    • LIST TABLES
    • DESCRIBE TABLE
    • ALTER TABLE
    • DROP TABLE
  • Index:

    • DESCRIBE LSI
    • CREATE GSI
    • DESCRIBE GSI
    • ALTER GSI
    • DROP GSI
  • Document:

    • INSERT
    • SELECT
    • UPDATE
    • DELETE

Transaction support

godynamo supports transactions that consist of write statements (e.g. INSERT, UPDATE and DELETE) since v0.2.0. Please note the following:

  • Any limitation set by DynamoDB/PartiQL will apply.
  • Table and Index statements are not supported.
  • UPDATE/DELETE with RETURNING and SELECT statements are not supported.

Example:

tx, err := db.Begin()
if err != nil {
	panic(err)
}
defer tx.Rollback()
result1, _ := tx.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'active': ?}`, "app0", "user1", true)
result2, _ := tx.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'duration': ?}`, "app0", "user2", 1.23)
err = tx.Commit()
if err != nil {
	panic(err)
}

rowsAffected1, err1 := fmt.Println(result1.RowsAffected())
if err1 != nil {
	panic(err1)
}
fmt.Println("RowsAffected:", rowsAffected1) // output "RowsAffected: 1"

rowsAffected2, err2 := fmt.Println(result2.RowsAffected())
if err2 != nil {
	panic(err2)
}
fmt.Println("RowsAffected:", rowsAffected2) // output "RowsAffected: 1"

If a statement's condition check fails (e.g. deleting non-existing item), the whole transaction will also fail. This behaviour is different from executing statements in non-transactional mode where failed condition check results in 0 affected row without error.

You can use EXISTS function for condition checking.

Notes on transactions:

  • Results of INSERT/UPDATE/DELETE statements are not available until the transaction is committed. Which means, calling RowsAffected() before Commit() will return 0, ErrInTx.
  • If the connection which has a non-commit/non-rollback transaction is used to execute another statement, the statement is added to the transaction. If the transaction is being committed or rolled back, the execution of the statement will fail with error ErrInTx. For example:
conn, _ := db.Conn(context.Background())
tx, err := conn.BeginTx(context.Background(), nil)
if err != nil {
	panic(err)
}
result1, _ := tx.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'active': ?}`, "app0", "user1", true)

// the statement is added to the existing transaction
// also, result2.RowsAffected() is not available until the transaction is committed
result2, _ := conn.ExecContext(context.Background(), `INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'duration': ?}`, "app0", "user2", 1.23)

err = tx.Commit()
if err != nil {
	panic(err)
}

rowsAffected1, err1 := fmt.Println(result1.RowsAffected())
if err1 != nil {
	panic(err1)
}
fmt.Println("RowsAffected:", rowsAffected1) // output "RowsAffected: 1"

rowsAffected2, err2 := fmt.Println(result2.RowsAffected())
if err2 != nil {
	panic(err2)
}
fmt.Println("RowsAffected:", rowsAffected2) // output "RowsAffected: 1"

Caveats

Numerical values are stored in DynamoDB as floating point numbers. Hence, numbers are always read back as float64. See DynamoDB document for details on DynamoDB's supported data types.

A single query can only return up to 1MB of data. In the case of SELECT query, the driver automatically issues additional queries to fetch the remaining data if needed. However, returned rows may not be in the expected order specified by ORDER BY clause. That means, rows returned from the query SELECT * FROM table_name WHERE category='Laptop' ORDER BY id may not be in the expected order if all matched rows do not fit in 1MB of data.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Support and Contribution

Feel free to create pull requests or issues to report bugs or suggest new features. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or feature request as a new issue.

If you find this project useful, please star it.

Documentation

Overview

Package godynamo provides database/sql driver for AWS DynamoDB.

Index

Constants

View Source
const (
	// Version holds the semantic version number of this module.
	Version = "1.3.0"
)

Variables

View Source
var (
	ErrInTx           = errors.New("there is an ongoing transaction, new transaction/statement or fetching result is not allowed")
	ErrInvalidTxStage = errors.New("invalid transaction stage")
	ErrNoTx           = errors.New("no transaction is in progress")
	ErrTxCommitting   = errors.New("transaction is being committed")
	ErrTxRollingBack  = errors.New("transaction is being rolled back")
)
View Source
var (
	TableColumnDesiredTypesMapKey = "go_dynamo_table_column_desired_types_map"
	TableNameKey                  = "go_dynamo_table_name"
)
View Source
var (
	ErrNotValidInsertStm       = errors.New("input is not an invalid INSERT statement")
	ErrFieldsAndValuesNotMatch = errors.New("number of fields and values mismatch")
)

Functions

func DeregisterAWSConfig

func DeregisterAWSConfig()

DeregisterAWSConfig removes the registered aws.Config.

@Available since v1.3.0

func IsAwsError

func IsAwsError(err error, awsErrCode string) bool

IsAwsError returns true if err is an AWS-specific error, and it matches awsErrCode.

func RegisterAWSConfig

func RegisterAWSConfig(conf aws.Config)

RegisterAWSConfig registers aws.Config to be used by the dynamodb client.

The following configurations do not apply even if they are set in aws.Config.

  • HTTPClient

@Available since v1.3.0

func ToAttributeValue

func ToAttributeValue(value interface{}) (types.AttributeValue, error)

ToAttributeValue marshals a Go value to AWS AttributeValue.

func ToAttributeValueUnsafe

func ToAttributeValueUnsafe(value interface{}) types.AttributeValue

ToAttributeValueUnsafe marshals a Go value to AWS AttributeValue, ignoring error.

@Available since v0.2.0

func TransformInsertStmToPartiQL

func TransformInsertStmToPartiQL(insStm string) (string, error)

TransformInsertStmToPartiQL converts an INSERT statement to a PartiQL statement.

e.g. INSERT INTO table_name (field1, field2, field3) VALUES ('val1', ?, 3) will be converted to INSERT INTO table_name VALUE {'field1': 'val1', 'field2': ?, 'field3': 3}

Note:

  • table name is automatically double-quoted per PartiQL syntax.
  • field name is automatically single-quoted per PartiQL syntax.
  • value is automatically single-quoted if it is a string per PartiQL syntax.
  • Order of fields after conversion is the same as the order of fields in the original INSERT statement.
  • Other than the above, the value is kept as-is! It is the caller's responsibility to ensure the value is valid.
  • PartiQL syntax for INSERT statement: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.insert.html

@Available since v1.1.0

func ValuesToNamedValues

func ValuesToNamedValues(values []driver.Value) []driver.NamedValue

ValuesToNamedValues transforms a []driver.Value to []driver.NamedValue.

@Available since v0.2.0

func WaitForGSIStatus

func WaitForGSIStatus(ctx context.Context, db *sql.DB, tableName, gsiName string, statusList []string, sleepTime time.Duration) error

WaitForGSIStatus periodically checks if table's GSI status reaches a desired value, or timeout.

  • statusList: list of desired statuses. This function returns nil if one of the desired statuses is reached.
  • delay: sleep for this amount of time after each status check. Supplied value of 0 or negative means 'no sleep'.
  • timeout is controlled via ctx.
  • Note: this function treats GSI status as "" if it does not exist. Thus, supply value "" to statusList to wait for GSI to be deleted.

@Available since v1.1.0

func WaitForTableStatus

func WaitForTableStatus(ctx context.Context, db *sql.DB, tableName string, statusList []string, sleepTime time.Duration) error

WaitForTableStatus periodically checks if table status reaches a desired value, or timeout.

  • statusList: list of desired statuses. This function returns nil if one of the desired statuses is reached.
  • delay: sleep for this amount of time after each status check. Supplied value of 0 or negative means 'no sleep'.
  • timeout is controlled via ctx.
  • Note: this function treats table status as "" if it does not exist. Thus, supply value "" to statusList to wait for table to be deleted.

@Available since v1.1.0

Types

type Conn

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

Conn is AWS DynamoDB implementation of driver.Conn.

func (*Conn) Begin

func (c *Conn) Begin() (driver.Tx, error)

Begin implements driver.Conn/Begin.

func (*Conn) BeginTx

func (c *Conn) BeginTx(_ context.Context, _ driver.TxOptions) (driver.Tx, error)

BeginTx implements driver.Conn/BeginTx.

@Available since v0.2.0

func (*Conn) CheckNamedValue

func (c *Conn) CheckNamedValue(_ *driver.NamedValue) error

CheckNamedValue implements driver.NamedValueChecker/CheckNamedValue.

func (*Conn) Close

func (c *Conn) Close() error

Close implements driver.Conn/Close.

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (driver.Stmt, error)

Prepare implements driver.Conn/Prepare.

func (*Conn) PrepareContext

func (c *Conn) PrepareContext(_ context.Context, query string) (driver.Stmt, error)

PrepareContext implements driver.ConnPrepareContext/PrepareContext.

Note: since v1.2.0, this function returns ErrInTx if there is an outgoing transaction.

@Available since v0.2.0

type Driver

type Driver struct {
}

Driver is AWS DynamoDB implementation of driver.Driver.

func (*Driver) Open

func (d *Driver) Open(connStr string) (driver.Conn, error)

Open implements driver.Driver/Open.

connStr is expected in the following format:

Region=<region>;AkId=<aws-key-id>;Secret_Key=<aws-secret-key>[;Endpoint=<dynamodb-endpoint>][;TimeoutMs=<timeout-in-milliseconds>]

If not supplied, default value for TimeoutMs is 10 seconds.

type OptStrings

type OptStrings []string

func (OptStrings) BoolAt

func (s OptStrings) BoolAt(i int) bool

func (OptStrings) FirstBool

func (s OptStrings) FirstBool() bool

func (OptStrings) FirstString

func (s OptStrings) FirstString() string

func (OptStrings) StringAt

func (s OptStrings) StringAt(i int) string

type ResultNoResultSet

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

ResultNoResultSet captures the result from statements that do not expect a ResultSet to be returned.

func (*ResultNoResultSet) LastInsertId

func (r *ResultNoResultSet) LastInsertId() (int64, error)

LastInsertId implements driver.Result/LastInsertId.

func (*ResultNoResultSet) RowsAffected

func (r *ResultNoResultSet) RowsAffected() (int64, error)

RowsAffected implements driver.Result/RowsAffected.

type ResultResultSet

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

ResultResultSet captures the result from statements that expect a ResultSet to be returned.

func (*ResultResultSet) Close

func (r *ResultResultSet) Close() error

Close implements driver.Rows/Close.

func (*ResultResultSet) ColumnTypeDatabaseTypeName

func (r *ResultResultSet) ColumnTypeDatabaseTypeName(index int) string

ColumnTypeDatabaseTypeName implements driver.RowsColumnTypeDatabaseTypeName/ColumnTypeDatabaseTypeName

@since v0.3.0 ColumnTypeDatabaseTypeName returns DynamoDB's native data types (e.g. B, N, S, SS, NS, BS, BOOL, L, M, NULL).

func (*ResultResultSet) ColumnTypeScanType

func (r *ResultResultSet) ColumnTypeScanType(index int) reflect.Type

ColumnTypeScanType implements driver.RowsColumnTypeScanType/ColumnTypeScanType

func (*ResultResultSet) Columns

func (r *ResultResultSet) Columns() []string

Columns implements driver.Rows/Columns.

func (*ResultResultSet) Next

func (r *ResultResultSet) Next(dest []driver.Value) error

Next implements driver.Rows/Next.

type RowsDescribeIndex

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

RowsDescribeIndex captures the result from DESCRIBE LSI or DESCRIBE GSI statement.

func (*RowsDescribeIndex) Close

func (r *RowsDescribeIndex) Close() error

Close implements driver.Rows/Close.

func (*RowsDescribeIndex) ColumnTypeDatabaseTypeName

func (r *RowsDescribeIndex) ColumnTypeDatabaseTypeName(index int) string

ColumnTypeDatabaseTypeName implements driver.RowsColumnTypeDatabaseTypeName/ColumnTypeDatabaseTypeName

@since v0.3.0 ColumnTypeDatabaseTypeName returns DynamoDB's native data types (e.g. B, N, S, SS, NS, BS, BOOL, L, M, NULL).

func (*RowsDescribeIndex) ColumnTypeScanType

func (r *RowsDescribeIndex) ColumnTypeScanType(index int) reflect.Type

ColumnTypeScanType implements driver.RowsColumnTypeScanType/ColumnTypeScanType

func (*RowsDescribeIndex) Columns

func (r *RowsDescribeIndex) Columns() []string

Columns implements driver.Rows/Columns.

func (*RowsDescribeIndex) Next

func (r *RowsDescribeIndex) Next(dest []driver.Value) error

Next implements driver.Rows/Next.

type RowsDescribeTable

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

RowsDescribeTable captures the result from DESCRIBE TABLE statement.

func (*RowsDescribeTable) Close

func (r *RowsDescribeTable) Close() error

Close implements driver.Rows/Close.

func (*RowsDescribeTable) ColumnTypeDatabaseTypeName

func (r *RowsDescribeTable) ColumnTypeDatabaseTypeName(index int) string

ColumnTypeDatabaseTypeName implements driver.RowsColumnTypeDatabaseTypeName/ColumnTypeDatabaseTypeName

@since v0.3.0 ColumnTypeDatabaseTypeName returns DynamoDB's native data types (e.g. B, N, S, SS, NS, BS, BOOL, L, M, NULL).

func (*RowsDescribeTable) ColumnTypeScanType

func (r *RowsDescribeTable) ColumnTypeScanType(index int) reflect.Type

ColumnTypeScanType implements driver.RowsColumnTypeScanType/ColumnTypeScanType

func (*RowsDescribeTable) Columns

func (r *RowsDescribeTable) Columns() []string

Columns implements driver.Rows/Columns.

func (*RowsDescribeTable) Next

func (r *RowsDescribeTable) Next(dest []driver.Value) error

Next implements driver.Rows/Next.

type RowsListTables

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

RowsListTables captures the result from LIST TABLES statement.

func (*RowsListTables) Close

func (r *RowsListTables) Close() error

Close implements driver.Rows/Close.

func (*RowsListTables) ColumnTypeDatabaseTypeName

func (r *RowsListTables) ColumnTypeDatabaseTypeName(_ int) string

ColumnTypeDatabaseTypeName implements driver.RowsColumnTypeDatabaseTypeName/ColumnTypeDatabaseTypeName

func (*RowsListTables) ColumnTypeScanType

func (r *RowsListTables) ColumnTypeScanType(_ int) reflect.Type

ColumnTypeScanType implements driver.RowsColumnTypeScanType/ColumnTypeScanType

func (*RowsListTables) Columns

func (r *RowsListTables) Columns() []string

Columns implements driver.Rows/Columns.

func (*RowsListTables) Next

func (r *RowsListTables) Next(dest []driver.Value) error

Next implements driver.Rows/Next.

type Stmt

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

Stmt is AWS DynamoDB abstract implementation of driver.Stmt.

func (*Stmt) Close

func (s *Stmt) Close() error

Close implements driver.Stmt/Close.

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

NumInput implements driver.Stmt/NumInput.

type StmtAlterGSI

type StmtAlterGSI struct {
	*Stmt
	// contains filtered or unexported fields
}

StmtAlterGSI implements "ALTER GSI" statement.

Syntax:

	ALTER GSI <index-name> ON <table-name>
	WITH wcu=<number>[,] WITH rcu=<number>

- RCU: an integer specifying DynamoDB's read capacity.
- WCU: an integer specifying DynamoDB's write capacity.
- Note: The provisioned throughput settings of a GSI are separate from those of its base table.
- Note: GSI inherit the RCU and WCU mode from the base table. That means if the base table is in on-demand mode, then DynamoDB also creates the GSI in on-demand mode.
- Note: there must be at least one space before the WITH keyword.

func (*StmtAlterGSI) Exec

func (s *StmtAlterGSI) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec.

func (*StmtAlterGSI) ExecContext

func (s *StmtAlterGSI) ExecContext(ctx context.Context, _ []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/ExecContext.

@Available since v0.2.0

func (*StmtAlterGSI) Query

func (s *StmtAlterGSI) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query. This function is not implemented, use Exec instead.

func (*StmtAlterGSI) QueryContext

func (s *StmtAlterGSI) QueryContext(_ context.Context, _ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext. This function is not implemented, use ExecContext instead.

type StmtAlterTable

type StmtAlterTable struct {
	*Stmt
	// contains filtered or unexported fields
}

StmtAlterTable implements "ALTER TABLE" statement.

Syntax:

	ALTER TABLE <table-name>
	[WITH RCU=rcu[,] WITH WCU=wcu]
	[[,] WITH CLASS=<table-class>]

- RCU: an integer specifying DynamoDB's read capacity.
- WCU: an integer specifying DynamoDB's write capacity.
- CLASS: table class, either STANDARD (default) or STANDARD_IA.
- Note: if RCU and WRU are both 0, table's billing mode will be updated to PAY_PER_REQUEST; otherwise billing mode will be updated to PROVISIONED.
- Note: there must be at least one space before the WITH keyword.

func (*StmtAlterTable) Exec

func (s *StmtAlterTable) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec.

func (*StmtAlterTable) ExecContext

func (s *StmtAlterTable) ExecContext(ctx context.Context, _ []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/ExecContext.

@Available since v0.2.0

func (*StmtAlterTable) Query

func (s *StmtAlterTable) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query. This function is not implemented, use Exec instead.

func (*StmtAlterTable) QueryContext

func (s *StmtAlterTable) QueryContext(_ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext. This function is not implemented, use ExecContext instead.

type StmtCreateGSI

type StmtCreateGSI struct {
	*Stmt
	// contains filtered or unexported fields
}

StmtCreateGSI implements "CREATE GSI" statement.

Syntax:

	CREATE GSI [IF NOT EXISTS] <index-name> ON <table-name>
	<WITH PK=pk-attr-name:data-type>
	[[,] WITH SK=sk-attr-name:data-type]
	[[,] WITH wcu=<number>[,] WITH rcu=<number>]
	[[,] WITH projection=*|attr1,attr2,attr3,...]

- PK: GSI's partition key, format name:type (type is one of String, Number, Binary).
- SK: GSI's sort key, format name:type (type is one of String, Number, Binary).
- RCU: an integer specifying DynamoDB's read capacity.
- WCU: an integer specifying DynamoDB's write capacity.
- PROJECTION:
  - if not supplied, GSI will be created with projection setting KEYS_ONLY.
  - if equal to "*", GSI will be created with projection setting ALL.
  - if supplied with comma-separated attribute list, for example "attr1,attr2,attr3", GSI will be created with projection setting INCLUDE.
- If "IF NOT EXISTS" is specified, Exec will silently swallow the error "Attempting to create an index which already exists".
- Note: The provisioned throughput settings of a GSI are separate from those of its base table.
- Note: GSI inherit the RCU and WCU mode from the base table. That means if the base table is in on-demand mode, then DynamoDB also creates the GSI in on-demand mode.
- Note: there must be at least one space before the WITH keyword.

func (*StmtCreateGSI) Exec

func (s *StmtCreateGSI) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec.

func (*StmtCreateGSI) ExecContext

func (s *StmtCreateGSI) ExecContext(ctx context.Context, _ []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/ExecContext.

@Available since v0.2.0

func (*StmtCreateGSI) Query

func (s *StmtCreateGSI) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query. This function is not implemented, use Exec instead.

func (*StmtCreateGSI) QueryContext

func (s *StmtCreateGSI) QueryContext(_ context.Context, _ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext. This function is not implemented, use ExecContext instead.

type StmtCreateTable

type StmtCreateTable struct {
	*Stmt
	// contains filtered or unexported fields
}

StmtCreateTable implements "CREATE TABLE" statement.

Syntax:

	CREATE TABLE [IF NOT EXISTS] <table-name>
	<WITH PK=pk-attr-name:data-type>
	[[,] WITH SK=sk-attr-name:data-type]
	[[,] WITH wcu=<number>[,] WITH rcu=<number>]
	[[,] WITH LSI=index-name1:attr-name1:data-type]
	[[,] WITH LSI=index-name2:attr-name2:data-type:*]
	[[,] WITH LSI=index-name2:attr-name2:data-type:nonKeyAttr1,nonKeyAttr2,nonKeyAttr3,...]
	[[,] WITH LSI...]
	[[,] WITH CLASS=<table-class>]

- PK: partition key, format name:type (type is one of String, Number, Binary).
- SK: sort key, format name:type (type is one of String, Number, Binary).
- LSI: local secondary index, format index-name:attr-name:type[:projectionAttrs], where:
	- type is one of String, Number, Binary.
	- projectionAttrs=*: all attributes from the original table are included in projection (ProjectionType=ALL).
	- projectionAttrs=attr1,attr2,...: specified attributes from the original table are included in projection (ProjectionType=INCLUDE).
	- projectionAttrs is not specified: only key attributes are included in projection (ProjectionType=KEYS_ONLY).
- RCU: an integer specifying DynamoDB's read capacity.
- WCU: an integer specifying DynamoDB's write capacity.
- CLASS: table class, either STANDARD (default) or STANDARD_IA.
- If "IF NOT EXISTS" is specified, Exec will silently swallow the error "ResourceInUseException".
- Note: if RCU and WRU are both 0 or not specified, table will be created with PAY_PER_REQUEST billing mode; otherwise table will be creatd with PROVISIONED mode.
- Note: there must be at least one space before the WITH keyword.

func (*StmtCreateTable) Exec

func (s *StmtCreateTable) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec.

func (*StmtCreateTable) ExecContext

func (s *StmtCreateTable) ExecContext(ctx context.Context, _ []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/Exec.

@Available since v0.2.0

func (*StmtCreateTable) Query

func (s *StmtCreateTable) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query. This function is not implemented, use Exec instead.

func (*StmtCreateTable) QueryContext

func (s *StmtCreateTable) QueryContext(_ context.Context, _ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext. This function is not implemented, use ExecContext instead.

type StmtDelete

type StmtDelete struct {
	*StmtExecutable
}

StmtDelete implements "DELETE" statement.

Syntax: follow "PartiQL delete statements for DynamoDB" https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.delete.html

Note: StmtDelete returns the deleted item by appending "RETURNING ALL OLD *" to the statement.

func (*StmtDelete) Exec

func (s *StmtDelete) Exec(values []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec.

func (*StmtDelete) ExecContext

func (s *StmtDelete) ExecContext(ctx context.Context, values []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/ExecContext.

@Available since v0.2.0

func (*StmtDelete) Query

func (s *StmtDelete) Query(values []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query.

func (*StmtDelete) QueryContext

func (s *StmtDelete) QueryContext(ctx context.Context, values []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext.

@Available since v0.2.0

type StmtDescribeGSI

type StmtDescribeGSI struct {
	*Stmt
	// contains filtered or unexported fields
}

StmtDescribeGSI implements "DESCRIBE GSI" statement.

Syntax:

DESCRIBE GSI <index-name> ON <table-name>

func (*StmtDescribeGSI) Exec

func (s *StmtDescribeGSI) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec. This function is not implemented, use Query instead.

func (*StmtDescribeGSI) ExecContext

func (s *StmtDescribeGSI) ExecContext(_ context.Context, _ []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/ExecContext. This function is not implemented, use QueryContext instead.

func (*StmtDescribeGSI) Query

func (s *StmtDescribeGSI) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query.

func (*StmtDescribeGSI) QueryContext

func (s *StmtDescribeGSI) QueryContext(ctx context.Context, _ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext.

@Available since v0.2.0

type StmtDescribeLSI

type StmtDescribeLSI struct {
	*Stmt
	// contains filtered or unexported fields
}

StmtDescribeLSI implements "DESCRIBE LSI" statement.

Syntax:

DESCRIBE LSI <index-name> ON <table-name>

func (*StmtDescribeLSI) Exec

func (s *StmtDescribeLSI) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec. This function is not implemented, use Query instead.

func (*StmtDescribeLSI) ExecContext

func (s *StmtDescribeLSI) ExecContext(_ context.Context, _ []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/ExecContext. This function is not implemented, use QueryContext instead.

func (*StmtDescribeLSI) Query

func (s *StmtDescribeLSI) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query.

func (*StmtDescribeLSI) QueryContext

func (s *StmtDescribeLSI) QueryContext(ctx context.Context, _ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext.

@Available since v0.2.0

type StmtDescribeTable

type StmtDescribeTable struct {
	*Stmt
	// contains filtered or unexported fields
}

StmtDescribeTable implements "DESCRIBE TABLE" operation.

Syntax:

DESCRIBE TABLE <table-name>

func (*StmtDescribeTable) Exec

func (s *StmtDescribeTable) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec. This function is not implemented, use Query instead.

func (*StmtDescribeTable) ExecContext

ExecContext implements driver.StmtExecContext/ExecContext. This function is not implemented, use QueryContext instead.

func (*StmtDescribeTable) Query

func (s *StmtDescribeTable) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query.

func (*StmtDescribeTable) QueryContext

func (s *StmtDescribeTable) QueryContext(ctx context.Context, _ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/Query.

@Available since v0.2.0

type StmtDropGSI

type StmtDropGSI struct {
	*Stmt
	// contains filtered or unexported fields
}

StmtDropGSI implements "DROP GSI" statement.

Syntax:

DROP GSI [IF EXISTS] <index-name> ON <table-name>

If "IF EXISTS" is specified, Exec will silently swallow the error "ResourceNotFoundException".

func (*StmtDropGSI) Exec

func (s *StmtDropGSI) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec.

func (*StmtDropGSI) ExecContext

func (s *StmtDropGSI) ExecContext(ctx context.Context, _ []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/ExecContext.

@Available since v0.2.0

func (*StmtDropGSI) Query

func (s *StmtDropGSI) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query. This function is not implemented, use Exec instead.

func (*StmtDropGSI) QueryContext

func (s *StmtDropGSI) QueryContext(_ context.Context, _ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext. This function is not implemented, use ExecContext instead.

type StmtDropTable

type StmtDropTable struct {
	*Stmt
	// contains filtered or unexported fields
}

StmtDropTable implements "DROP TABLE" statement.

Syntax:

DROP TABLE [IF EXISTS] <table-name>

If "IF EXISTS" is specified, Exec will silently swallow the error "ResourceNotFoundException".

func (*StmtDropTable) Exec

func (s *StmtDropTable) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec.

func (*StmtDropTable) ExecContext

func (s *StmtDropTable) ExecContext(ctx context.Context, _ []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/Exec.

@Available since v0.2.0

func (*StmtDropTable) Query

func (s *StmtDropTable) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query. This function is not implemented, use Exec instead.

func (*StmtDropTable) QueryContext

func (s *StmtDropTable) QueryContext(_ context.Context, _ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext. This function is not implemented, use ExecContext instead.

type StmtExecutable

type StmtExecutable struct {
	*Stmt
}

StmtExecutable is the base implementation for INSERT, SELECT, UPDATE and DELETE statements.

type StmtInsert

type StmtInsert struct {
	*StmtExecutable
}

StmtInsert implements "INSERT" statement.

Syntax: follow "PartiQL insert statements for DynamoDB" https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.insert.html

func (*StmtInsert) Exec

func (s *StmtInsert) Exec(values []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec.

func (*StmtInsert) ExecContext

func (s *StmtInsert) ExecContext(ctx context.Context, values []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/ExecContext.

@Available since v0.2.0

func (*StmtInsert) Query

func (s *StmtInsert) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query. This function is not implemented, use Exec instead.

func (*StmtInsert) QueryContext

func (s *StmtInsert) QueryContext(_ context.Context, _ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext. This function is not implemented, use ExecContext instead.

type StmtListTables

type StmtListTables struct {
	*Stmt
}

StmtListTables implements "LIST TABLES" statement.

Syntax:

LIST TABLES|TABLE

func (*StmtListTables) Exec

func (s *StmtListTables) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec. This function is not implemented, use Query instead.

func (*StmtListTables) ExecContext

func (s *StmtListTables) ExecContext(_ context.Context, _ []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/Exec. This function is not implemented, use QueryContext instead.

func (*StmtListTables) Query

func (s *StmtListTables) Query(_ []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query.

func (*StmtListTables) QueryContext

func (s *StmtListTables) QueryContext(ctx context.Context, _ []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext.

@Available since v0.2.0

type StmtSelect

type StmtSelect struct {
	*StmtExecutable
	// contains filtered or unexported fields
}

StmtSelect implements "SELECT" statement.

Syntax: follow "PartiQL select statements for DynamoDB" https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.select.html

@Since v0.3.0 support LIMIT clause

@Since v0.4.0 support WITH consistency=strong clause

func (*StmtSelect) Exec

func (s *StmtSelect) Exec(_ []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec. This function is not implemented, use Query instead.

func (*StmtSelect) ExecContext

func (s *StmtSelect) ExecContext(_ context.Context, _ []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/ExecContext. This function is not implemented, use QueryContext instead.

func (*StmtSelect) Query

func (s *StmtSelect) Query(values []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query.

func (*StmtSelect) QueryContext

func (s *StmtSelect) QueryContext(ctx context.Context, values []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext.

@Available since v0.2.0

type StmtUpdate

type StmtUpdate struct {
	*StmtExecutable
}

StmtUpdate implements "UPDATE" statement.

Syntax: follow "PartiQL update statements for DynamoDB" https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ql-reference.update.html

Note: StmtUpdate returns the updated item by appending "RETURNING ALL OLD *" to the statement.

func (*StmtUpdate) Exec

func (s *StmtUpdate) Exec(values []driver.Value) (driver.Result, error)

Exec implements driver.Stmt/Exec.

func (*StmtUpdate) ExecContext

func (s *StmtUpdate) ExecContext(ctx context.Context, values []driver.NamedValue) (driver.Result, error)

ExecContext implements driver.StmtExecContext/ExecContext.

@Available since v0.2.0

func (*StmtUpdate) Query

func (s *StmtUpdate) Query(values []driver.Value) (driver.Rows, error)

Query implements driver.Stmt/Query.

func (*StmtUpdate) QueryContext

func (s *StmtUpdate) QueryContext(ctx context.Context, values []driver.NamedValue) (driver.Rows, error)

QueryContext implements driver.StmtQueryContext/QueryContext.

@Available since v0.2.0

type Tx

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

Tx is AWS DynamoDB implementation of driver.Tx.

@Available since v0.2.0

func (*Tx) Commit

func (t *Tx) Commit() error

Commit implements driver.Tx/Commit

func (*Tx) Rollback

func (t *Tx) Rollback() error

Rollback implements driver.Tx/Rollback

type TxResultNoResultSet

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

TxResultNoResultSet is transaction-aware version of ResultNoResultSet.

@Available since v0.2.0

func (*TxResultNoResultSet) LastInsertId

func (t *TxResultNoResultSet) LastInsertId() (int64, error)

LastInsertId implements driver.Result/LastInsertId.

func (*TxResultNoResultSet) RowsAffected

func (t *TxResultNoResultSet) RowsAffected() (int64, error)

RowsAffected implements driver.Result/RowsAffected.

Jump to

Keyboard shortcuts

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