Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miyamo2/dynmgrm
GORM DynamoDB Driver
https://github.com/miyamo2/dynmgrm
aws aws-dynamodb dynamo dynamodb go golang gorm orm orm-library partiql
Last synced: 1 day ago
JSON representation
GORM DynamoDB Driver
- Host: GitHub
- URL: https://github.com/miyamo2/dynmgrm
- Owner: miyamo2
- License: mit
- Created: 2024-03-09T19:23:00.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-01-13T16:44:18.000Z (13 days ago)
- Last Synced: 2025-01-20T01:47:50.200Z (7 days ago)
- Topics: aws, aws-dynamodb, dynamo, dynamodb, go, golang, gorm, orm, orm-library, partiql
- Language: Go
- Homepage:
- Size: 1.45 MB
- Stars: 22
- Watchers: 1
- Forks: 2
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# dynmgrm - GORM DynamoDB Driver
[![Go Reference](https://pkg.go.dev/badge/github.com/miyamo2/dynmgrm.svg)](https://pkg.go.dev/github.com/miyamo2/dynmgrm)
[![GitHub go.mod Go version (subdirectory of monorepo)](https://img.shields.io/github/go-mod/go-version/miyamo2/dynmgrm?logo=go)](https://img.shields.io/github/go-mod/go-version/miyamo2/dynmgrm?logo=go)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/miyamo2/dynmgrm)](https://img.shields.io/github/v/release/miyamo2/dynmgrm)
[![codecov](https://codecov.io/gh/miyamo2/dynmgrm/graph/badge.svg?token=QLIVB3ESVD)](https://codecov.io/gh/miyamo2/dynmgrm)
[![Go Report Card](https://goreportcard.com/badge/github.com/miyamo2/dynmgrm)](https://goreportcard.com/report/github.com/miyamo2/dynmgrm)
[![GitHub License](https://img.shields.io/github/license/miyamo2/dynmgrm?&color=blue)](https://img.shields.io/github/license/miyamo2/dynmgrm?&color=blue)dynmgrm is the driver to issue PartiQL Statement to DynamoDB with GORM⚡
## Features
### Supports the following PartiQL statements
- [x] Select
- [x] With Secondary Index
- [x] With `begins_with` function
- [x] With `contains` function
- [x] With `size` function
- [x] With `attribute_type` function
- [x] With `MISSING` operator
- [x] Insert
- [x] Update
- [x] With `SET` clause
- [x] With `list_append` function
- [x] `ListAppend()`
- [x] With `set_add` function
- [x] With `set_delete` function
- [ ] With `REMOVE` clause
- [x] Delete
- [x] Create Table ※ proprietary PartiQL syntax by [`miyamo2/godynamo`](https://github.com/miyamo2/godynamo)
- [x] Create GSI ※ proprietary PartiQL syntax by [`miyamo2/godynamo`](https://github.com/miyamo2/godynamo)### Supports the following GORM features
- Query
- [x] `Select`
- [x] `Find`
- [x] `Scan`- Update
- [x] `Update`
- [x] `Updates`
- [x] `Save`- Create
- [x] `Create`
- Delete
- [x] `Delete`- Condition
- [x] `Where`
- [x] `Not`
- [x] `Or`- Table/Model
- [x] `Table`
- [x] `Model` ※ Combination with Secondary Index are not supported.
- Transaction ※ Supports only Insert, Update, and Delete.
- [x] `Begin`
- [x] `Commit`
- [x] `Rollback`
- [x] `Transaction`- [Migration](.docs/MIGRATION.md)
- [ ] `AutoMigrate`
- [ ] `CurrentDatabase`
- [x] `FullDataTypeOf`
- [x] `CreateTable`
- [ ] `DropTable`
- [ ] `HasTable`
- [ ] `GetTables`
- [ ] `HasColumn`
- [ ] `ColumnTypes`
- [x] `CreateIndex`
- [ ] `DropIndex`
- [ ] `HasIndex`### Custom Clause
- `SecondaryIndex`
### Custom Serializer
- `dynamo-nested`
[What is about GORM Serializer?](https://gorm.io/docs/serializer.html)
## Quick Start
### Installation
```sh
go get github.com/miyamo2/dynmgrm
```### Usage
> [!TIP]
>
> `miyamo2/dynmgrm` is recommended to be used in with [`miyamo2/sqldav`](https://github.com/miyamo2/sqldav).
>
> [`miyamo2/sqldav`](https://github.com/miyamo2/sqldav) provides Defined Type of slice/map that implements `sql.Scanner` and `driver.Valuer`.
>
> These are as the equivalent to `Set`, `List`, `Map` and `TypedList` included in `miyamo2/dynmgrm` before `v0.9.0`.```go
package mainimport (
"github.com/miyamo2/dynmgrm"
"github.com/miyamo2/sqldav"
"gorm.io/gorm"
)type Event struct {
Name string `gorm:"primaryKey"`
Date string `gorm:"primaryKey"`
Host string
Guest sqldav.Set[string]
}func main() {
db, err := gorm.Open(dynmgrm.New())
if err != nil {
panic(err)
}var dynamoDBWorkshop Event
db.Table("events").
Where(`name=?`, "DynamoDB Workshop").
Where(`date=?`, "2024/3/25").
Scan(&dynamoDBWorkshop)dynamoDBWorkshop.Guest = append(dynamoDBWorkshop.Guest, "Alice")
db.Save(&dynamoDBWorkshop)carolBirthday := Event{
Name: "Carol's Birthday",
Date: "2024/4/1",
Host: "Charlie",
Guest: []string{"Alice", "Bob"},
}
db.Create(carolBirthday)var daveSchedule []Event
db.Table("events").
Where(`date=?`, "2024/4/1").
Where(`( ? )`,
db.Where(`host=?`, "Dave").Or(`CONTAINS("guest", ?)`, "Dave")).
Scan(&daveSchedule)tx := db.Begin()
for _, event := range daveSchedule {
if event.Host == "Dave" {
tx.Delete(&event)
} else {
tx.Model(&event).Update("guest", gorm.Expr("set_delete(guest, ?)", sqldav.Set[string]{"Dave"}))
}
}
tx.Model(&carolBirthday).Update("guest", gorm.Expr("set_add(guest, ?)", sqldav.Set[string]{"Dave"}))
tx.Commit()var hostDateIndex []Event
db.Table("events").Clauses(
dynmgrm.SecondaryIndex("host-date-index"),
).Where(`host=?`, "Bob").Scan(&hostDateIndex)
}
```## Contributing
Feel free to open a PR or an Issue.
However, you must promise to follow our [Code of Conduct](https://github.com/miyamo2/dynmgrm/blob/main/CODE_OF_CONDUCT.md).
See [here](https://github.com/miyamo2/dynmgrm/blob/main/CONTRIBUTING.md) for more details on contributing.
## License
**dynmgrm** released under the [MIT License](https://github.com/miyamo2/dynmgrm/blob/main/LICENSE)
## Credits
### Go gopher
The Go gopher was designed by [Renee French.](http://reneefrench.blogspot.com/)
The design is licensed under the Creative Commons 3.0 Attributions license.
Read this article for more [details](https://go.dev/blog/gopher)### Special Thanks
- [btnguyen2k/godynamo](https://github.com/btnguyen2k/godynamo)
`dynmgrm` connects to `database/sql` by `miyamo2/godynamo` that forked from `btnguyen2k/godynamo`.
- [JetBrainsMono](https://github.com/JetBrains/JetBrainsMono)
JetBrainsMono is used for the caption of the dynmgrm logo.