Skip to content

Commit 5dc0fe6

Browse files
committed
updated readme
1 parent f3280a7 commit 5dc0fe6

File tree

1 file changed

+76
-60
lines changed

1 file changed

+76
-60
lines changed

README.md

Lines changed: 76 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
go-ds-dynamodb
2-
=======================
1+
# go-ds-dynamodb
32

4-
> A DynamoDB Datastore Implementation
3+
A DynamoDB Datastore Implementation
54

6-
This is an implementation of [go-datastore](https://github.com/ipfs/go-datastore) that is backed by DynamoDB.
5+
This is an implementation of go-datastore that is backed by DynamoDB.
76

8-
ddbds includes support for optimized prefix queries. When you setup your table's key schema correctly and register it with ddbds, then incoming queries that match the schema will be converted into DynamoDB queries instead of table scans, enabling high performance, ordered, high-cardinality prefix queries.
7+
ddbds includes support for optimized prefix queries. When you set up your table's key schema correctly and register it with ddbds, then incoming queries that match the schema will be converted into DynamoDB queries instead of table scans, enabling high-performance, ordered, high-cardinality prefix queries.
98

10-
Note that ddbds currently only stores values up to 400 kb (the DynamoDB maximum item size). This makes ddbds inappropriate for block storage. It could be extended to fall back to S3, but that is not yet implemented. Within the InterPlanetary ecosystem, it's designed for storing DHT records, IPNS records, peerstore records, etc.
9+
Note that ddbds currently only stores values up to 400 KB (the DynamoDB maximum item size). This makes ddbds inappropriate for block storage. It could be extended to fall back to S3, but that is not yet implemented. Within the InterPlanetary ecosystem, it's designed for storing DHT records, IPNS records, peerstore records, etc.
1110

12-
## Setup ##
11+
## Setup
12+
13+
### Simple Setup with Unoptimized Queries
1314

14-
### Simple Setup with Unoptimized Queries ###
1515
ddbds can be used as a simple key-value store, without optimized queries.
1616

1717
In this case, all datastore queries will result in full table scans using the ParallelScan API, and filtering/ordering/etc. will be performed client-side.
@@ -24,20 +24,19 @@ tableName := "datastore-table"
2424
ddbDS := ddbds.New(ddbClient, tableName)
2525
```
2626

27-
By default the expected partition key is `DSKey` of type `string`. The name can be customized with the `WithPartitionKey()` option.
27+
By default, the expected partition key is DSKey of type string. The name can be customized with the `WithPartitionKey()` option.
2828

29+
### Optimized Queries
2930

30-
### Optimized Queries ###
31-
To use optimized prefix queries, you must specify a sort key.
31+
To use optimized prefix queries, you must specify a sort key.
3232

33-
Also, elements written into the datastore should have at least 2 parts, such as `/a/b` and not `/a`.
33+
Also, elements written into the datastore should have at least two parts, such as `/a/b` and not `/a`.
3434

35-
`ddbds` splits the key into partition and sort keys. Examples:
35+
ddbds splits the key into partition and sort keys. Examples:
3636

37-
* `/a` -> error (not enough parts)
38-
* `/a/b` -> [`a`, `b`]
39-
* `/a/b/c` -> [`a`, `b/c`]
40-
* etc.
37+
- `/a` -> error (not enough parts)
38+
- `/a/b` -> `[a, b]`
39+
- `/a/b/c` -> `[a, b/c]`
4140

4241
To use optimized queries, simply specify the sort key name using the `WithSortKey()` option:
4342

@@ -52,78 +51,95 @@ ddbDS := ddbds.New(
5251
)
5352
```
5453

55-
### Composing Datastores ###
56-
This datastore can be composed using mount datastores for optimized prefix queries under different namespaces and DynamoDB tables.
54+
### Dynamic Table Names
55+
56+
This implementation now supports dynamic table names, allowing users to specify table names at runtime when mounting different namespaces. This flexibility enables better separation of concerns and fine-tuned access control.
57+
58+
#### Variables for Table Names
59+
To configure dynamic table names, the following variables should be passed:
60+
61+
- `providersTable`: Table name for `/providers` namespace.
62+
- `pinsTable`: Table name for `/pins` namespace.
63+
- `defaultTable`: Table name for all other data.
5764

5865
Example:
5966

6067
```go
68+
var ddbClient *dynamodb.DynamoDB = ...
69+
config := DDBConfig{
70+
providersTable: "datastore-providers",
71+
pinsTable: "datastore-pins",
72+
defaultTable: "datastore-default",
73+
}
74+
6175
ddbDS := mount.New([]mount.Mount{
6276
{
63-
Prefix: ds.NewKey("/peers/addrs"),
77+
Prefix: ds.NewKey("/providers"),
6478
Datastore: ddbds.New(
6579
ddbClient,
66-
"datastore-peers-addrs",
67-
ddbds.WithPartitionkey("PeerID"),
80+
config.providersTable,
81+
ddbds.WithPartitionKey("ContentHash"),
82+
ddbds.WithSortKey("ProviderID"),
6883
),
6984
},
7085
{
71-
Prefix: ds.NewKey("/providers"),
86+
Prefix: ds.NewKey("/pins"),
7287
Datastore: ddbds.New(
7388
ddbClient,
74-
"datastore-providers",
75-
ddbds.WithPartitionkey("ContentHash"),
76-
ddbds.WithSortKey("PeerID"),
89+
config.pinsTable,
90+
ddbds.WithPartitionKey("Hash"),
7791
),
7892
},
7993
{
8094
Prefix: ds.NewKey("/"),
8195
Datastore: ddbds.New(
8296
ddbClient,
83-
"datastore-all",
97+
config.defaultTable,
8498
),
8599
},
86100
})
87101
```
88102

89-
### IAM Permissions ###
103+
## IAM Permissions
104+
90105
The following describes the IAM actions and the datastore methods that use them:
91106

92-
* dynamodb:GetItem
93-
* `Get()`
94-
* `GetExpiration()`
95-
* `GetSize()`
96-
* `Has()`
97-
* dynamodb:PutItem
98-
* `Put()`
99-
* `PutWithTTL()`
100-
* dynamodb:DeleteItem
101-
* `Delete()`
102-
* dynamodb:Scan
103-
* `Scan()` (if there is no sort key defined)
104-
* dynamodb:Query
105-
* `Query()` (if there is a sort key defined)
106-
* dynamodb:DescribeTable
107-
* `DiskUsage()`
108-
* dynamodb:UpdateItem
109-
* `SetTTL()`
110-
* dynamodb:BatchWriteItem
111-
* `Batch.Commit()`
112-
113-
## Datastore Features ##
114-
115-
* [x] Batching
116-
* [x] TTL
117-
* [x] Disk Usage
118-
* [ ] Transactions
119-
* [ ] Checked (not applicable)
120-
* [ ] Scrubbed (not applicable)
121-
* [ ] GC (not applicable)
107+
- **dynamodb:GetItem**
108+
- `Get()`
109+
- `GetExpiration()`
110+
- `GetSize()`
111+
- `Has()`
112+
- **dynamodb:PutItem**
113+
- `Put()`
114+
- `PutWithTTL()`
115+
- **dynamodb:DeleteItem**
116+
- `Delete()`
117+
- **dynamodb:Scan** (if there is no sort key defined)
118+
- `Scan()`
119+
- **dynamodb:Query** (if there is a sort key defined)
120+
- `Query()`
121+
- **dynamodb:DescribeTable**
122+
- `DiskUsage()`
123+
- **dynamodb:UpdateItem**
124+
- `SetTTL()`
125+
- **dynamodb:BatchWriteItem**
126+
- `Batch.Commit()`
127+
128+
## Datastore Features
129+
130+
- Batching
131+
- TTL
132+
- Disk Usage
133+
- Transactions
134+
- Checked (not applicable)
135+
- Scrubbed (not applicable)
136+
- ❌ Garbage Collection (not applicable)
122137

123138
## Contributing
124139

125-
Contributions are welcome! This repository is part of the IPFS project and therefore governed by our [contributing guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md).
140+
Contributions are welcome! This repository is part of the IPFS project and therefore governed by our contributing guidelines.
126141

127142
## License
128143

129-
[SPDX-License-Identifier: Apache-2.0 OR MIT](LICENSE.md)
144+
SPDX-License-Identifier: Apache-2.0 OR MIT
145+

0 commit comments

Comments
 (0)