Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
fogfish committed Aug 23, 2021
1 parent dcb86ef commit 8f191d0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode/

43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ trait KeyVal[T] {

## Getting started

The latest version of the library is available at its `main` branch. All development, including new features and bug fixes, take place on the `main` branch using forking and pull requests as described in contribution guidelines.
The latest version of the library is available at its `main` branch. All development, including new features and bug fixes, take place on the `main` branch using forking and pull requests as described in contribution guidelines. The stable version is available via Golang modules.


- [Getting Started](#getting-started)
- [Data types definition](#data-types-definition)
Expand All @@ -38,7 +39,9 @@ The latest version of the library is available at its `main` branch. All develop
- [Hierarchical structures](#hierarchical-structures)
- [Sequences and Pagination](#sequences-and-pagination)
- [Linked data](#linked-data)
- [Custom codecs for core domain types](#custom-codecs-for-core-domain-types)
- [Optimistic Locking](#optimistic-locking)
- [Local and Global Secondary Indexes](#local-and-global-secondary-indexes)
- [Configure DynamoDB](#configure-dynamodb)
- [Other storages](#other-storages)

Expand Down Expand Up @@ -137,7 +140,6 @@ It is not convenient either to inject `dynamo.ID` or re-define a new type just t

```go
type Person struct {
ID string `dynamodbav:"-"`
Name string `dynamodbav:"name,omitempty"`
Age int `dynamodbav:"age,omitempty"`
Address string `dynamodbav:"address,omitempty"`
Expand Down Expand Up @@ -225,13 +227,38 @@ Cross-linking of structured data is an essential part of type safe domain driven
```go
type Person struct {
dynamo.ID
Account *dynamo.IRI `dynamodbav:"name,omitempty"`
Account *dynamo.IRI `dynamodbav:"account,omitempty"`
}
```

`dynamo.ID` and `dynamo.IRI` are sibling, equivalent data types. `ID` is only used as primary key, `IRI` is a "pointer" to linked-data.


### Custom codecs for core domain types

Development of complex Golang application might lead developers towards [Standard Package Layout](https://medium.com/@benbjohnson/standard-package-layout-7cdbc8391fc1). It becomes extremely difficult to isolate dependencies from core data types to this library and AWS SDK. The library support serialization of core type to dynamo using custom codecs

```go
// core.go
type Person struct {
ID curie.IRI `dynamodbav:"-"`
Account *curie.Safe `dynamodbav:"account,omitempty"`
}

// ddb.go
type dbPerson Person

func (x dbPerson) MarshalDynamoDBAttributeValue(av *dynamodb.AttributeValue) error {
type tStruct dbPerson
return dynamo.Encode(av, x.ID, tStruct(x))
}

func (x *dbPerson) UnmarshalDynamoDBAttributeValue(av *dynamodb.AttributeValue) error {
type tStruct *dbPerson
return dynamo.Decode(av, &x.ID, tStruct(x))
}
```

### Optimistic Locking

Optimistic Locking is a lightweight approach to ensure causal ordering of read, write operations to database. AWS made a great post about [Optimistic Locking with Version Number](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBMapper.OptimisticLocking.html).
Expand Down Expand Up @@ -278,6 +305,9 @@ default:
See the [go doc](https://pkg.go.dev/github.com/fogfish/dynamo?tab=doc) for all supported constrains.


### Local and Global Secondary Indexes


### Configure DynamoDB

The `dynamo` library is optimized to operate with generic Dynamo DB that declares both partition and sort keys with fixed names. Use the following schema:
Expand All @@ -291,6 +321,13 @@ const Schema = (): ddb.TableProps => ({
})
```

If table uses other names for `partitionKey` and `sortKey` then connect URI allows to re-declare them

```go
//
// Create client and bind it with DynamoDB the table
db := dynamo.Must(dynamo.New("ddb:///my-table?prefix=someHashKey&suffix=someSortKey"))
```

### Other storages

Expand Down

0 comments on commit 8f191d0

Please sign in to comment.