Skip to content

Commit

Permalink
Merge pull request #92 from btnguyen2k/release
Browse files Browse the repository at this point in the history
Merge to main after releasing new version 1.1.0
  • Loading branch information
btnguyen2k authored Dec 31, 2023
2 parents 6744c4d + 9172d97 commit c05a23f
Show file tree
Hide file tree
Showing 19 changed files with 1,362 additions and 177 deletions.
12 changes: 12 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# godynamo release notes

## 2023-12-31 - v1.1.0

### Added/Refactoring

- Add function WaitForTableStatus
- Add function WaitForGSIStatus
- Add method TransformInsertStmToPartiQL

### Fixed/Improvement

- Fix: empty LSI should be nil

## 2023-12-27 - v1.0.0

### Changed
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.16.13
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.12.13
github.com/aws/smithy-go v1.19.0
github.com/btnguyen2k/consu/g18 v0.0.2
github.com/btnguyen2k/consu/reddo v0.1.8
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.10 h1:h8uw
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.10/go.mod h1:LZKVtMBiZfdvUWgwg61Qo6kyAmE5rn9Dw36AqnycvG8=
github.com/aws/smithy-go v1.19.0 h1:KWFKQV80DpP3vJrrA9sVAHQ5gc2z8i4EzrLhLlWXcBM=
github.com/aws/smithy-go v1.19.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE=
github.com/btnguyen2k/consu/g18 v0.0.2 h1:HzP10nyoSotdaie4orKT/Sgq+rHFSouRwGtJvzRKna4=
github.com/btnguyen2k/consu/g18 v0.0.2/go.mod h1:gTPcr87XdCLDISusRQyDey22/ZOw6bLh6EChxTLx6/c=
github.com/btnguyen2k/consu/reddo v0.1.8 h1:pEAkB6eadp/q+ONy97/JkAAyj058uIgkSu8b862Fwug=
github.com/btnguyen2k/consu/reddo v0.1.8/go.mod h1:pdY5oIVX3noZIaZu3nvoKZ59+seXL/taXNGWh9xJDbg=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
Expand Down
2 changes: 1 addition & 1 deletion module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package godynamo

const (
// Version holds the semantic version number of this module.
Version = "1.0.0"
Version = "1.1.0"
)

// This file contains module's metadata only, which is package level documentation and module Version string.
Expand Down
1 change: 1 addition & 0 deletions module_test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ require (
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.18.6 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.10 // indirect
github.com/btnguyen2k/consu/g18 v0.0.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
)
2 changes: 2 additions & 0 deletions module_test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.10 h1:h8uw
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.10/go.mod h1:LZKVtMBiZfdvUWgwg61Qo6kyAmE5rn9Dw36AqnycvG8=
github.com/aws/smithy-go v1.19.0 h1:KWFKQV80DpP3vJrrA9sVAHQ5gc2z8i4EzrLhLlWXcBM=
github.com/aws/smithy-go v1.19.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE=
github.com/btnguyen2k/consu/g18 v0.0.2 h1:HzP10nyoSotdaie4orKT/Sgq+rHFSouRwGtJvzRKna4=
github.com/btnguyen2k/consu/g18 v0.0.2/go.mod h1:gTPcr87XdCLDISusRQyDey22/ZOw6bLh6EChxTLx6/c=
github.com/btnguyen2k/consu/reddo v0.1.7/go.mod h1:pdY5oIVX3noZIaZu3nvoKZ59+seXL/taXNGWh9xJDbg=
github.com/btnguyen2k/consu/reddo v0.1.8 h1:pEAkB6eadp/q+ONy97/JkAAyj058uIgkSu8b862Fwug=
github.com/btnguyen2k/consu/reddo v0.1.8/go.mod h1:pdY5oIVX3noZIaZu3nvoKZ59+seXL/taXNGWh9xJDbg=
Expand Down
74 changes: 37 additions & 37 deletions module_test/stmt_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Test_Query_Insert(t *testing.T) {
db := _openDb(t, testName)
defer db.Close()

_, err := db.Query("INSERT INTO table VALUE {}")
_, err := db.Query(fmt.Sprintf(`INSERT INTO %s VALUE {}`, tblTestTemp))
if err == nil || strings.Index(err.Error(), "not supported") < 0 {
t.Fatalf("%s failed: expected 'not support' error, but received %#v", testName, err)
}
Expand All @@ -29,16 +29,16 @@ func Test_Exec_Insert(t *testing.T) {
defer db.Close()
_initTest(db)

db.Exec(`CREATE TABLE tbltest WITH pk=id:string WITH rcu=1 WITH wcu=1`)
db.Exec(fmt.Sprintf(`CREATE TABLE %s WITH pk=id:string WITH rcu=1 WITH wcu=1`, tblTestTemp))

testData := []struct {
name string
sql string
params []interface{}
affectedRows int64
}{
{name: "basic", sql: `INSERT INTO "tbltest" VALUE {'id': '1', 'name': 'User 1'}`, affectedRows: 1},
{name: "parameterized", sql: `INSERT INTO "tbltest" VALUE {'id': ?, 'name': ?, 'active': ?, 'grade': ?, 'list': ?, 'map': ?}`, affectedRows: 1,
{name: "basic", sql: fmt.Sprintf(`INSERT INTO "%s" VALUE {'id': '1', 'name': 'User 1'}`, tblTestTemp), affectedRows: 1},
{name: "parameterized", sql: fmt.Sprintf(`INSERT INTO "%s" VALUE {'id': ?, 'name': ?, 'active': ?, 'grade': ?, 'list': ?, 'map': ?}`, tblTestTemp), affectedRows: 1,
params: []interface{}{"2", "User 2", true, 10, []interface{}{1.2, false, "3"}, map[string]interface{}{"N": -3.4, "B": false, "S": "3"}}},
}

Expand Down Expand Up @@ -68,7 +68,7 @@ func Test_Exec_Select(t *testing.T) {
db := _openDb(t, testName)
defer db.Close()

_, err := db.Exec(`SELECT * FROM "table" WHERE id='a'`)
_, err := db.Exec(fmt.Sprintf(`SELECT * FROM "%s" WHERE id='a'`, tblTestTemp))
if err == nil || strings.Index(err.Error(), "not supported") < 0 {
t.Fatalf("%s failed: expected 'not support' error, but received %#v", testName, err)
}
Expand All @@ -80,16 +80,16 @@ func Test_Query_Select(t *testing.T) {
defer db.Close()
_initTest(db)

_, err := db.Exec(`CREATE TABLE tbltest WITH PK=app:string WITH SK=user:string WITH rcu=100 WITH wcu=100`)
_, err := db.Exec(fmt.Sprintf(`CREATE TABLE %s WITH PK=app:string WITH SK=user:string WITH rcu=3 WITH wcu=3`, tblTestTemp))
if err != nil {
t.Fatalf("%s failed: %s", testName, err)
}
_, err = db.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'os': ?, 'active': ?, 'duration': ?}`, "app0", "user1", "Linux", true, 12.34)
_, err = db.Exec(fmt.Sprintf(`INSERT INTO "%s" VALUE {'app': ?, 'user': ?, 'os': ?, 'active': ?, 'duration': ?}`, tblTestTemp), "app0", "user1", "Linux", true, 12.34)
if err != nil {
t.Fatalf("%s failed: %s", testName, err)
}

dbresult, err := db.Query(`SELECT * FROM "tbltest" WHERE app=?`, "app0")
dbresult, err := db.Query(fmt.Sprintf(`SELECT * FROM "%s" WHERE app=?`, tblTestTemp), "app0")
if err != nil {
t.Fatalf("%s failed: %s", testName, err)
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func Test_Query_Select_withLimit(t *testing.T) {
defer db.Close()
_initTest(db)

_, err := db.Exec(`CREATE TABLE tbltest WITH PK=app:string WITH SK=user:string WITH rcu=100 WITH wcu=100`)
_, err := db.Exec(fmt.Sprintf(`CREATE TABLE %s WITH PK=app:string WITH SK=user:string WITH rcu=5 WITH wcu=5`, tblTestTemp))
if err != nil {
t.Fatalf("%s failed: %s", testName, err)
}
Expand All @@ -128,13 +128,13 @@ func Test_Query_Select_withLimit(t *testing.T) {
{"app", "user3", "MacOS", true, 4.56},
}
for _, data := range insData {
_, err = db.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'os': ?, 'active': ?, 'duration': ?}`, data...)
_, err = db.Exec(fmt.Sprintf(`INSERT INTO "%s" VALUE {'app': ?, 'user': ?, 'os': ?, 'active': ?, 'duration': ?}`, tblTestTemp), data...)
if err != nil {
t.Fatalf("%s failed: %s", testName+"/insert", err)
}
}

dbresult, err := db.Query(`SELECT * FROM "tbltest" WHERE app=?`, "app")
dbresult, err := db.Query(fmt.Sprintf(`SELECT * FROM "%s" WHERE app=?`, tblTestTemp), "app")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/select", err)
}
Expand All @@ -146,7 +146,7 @@ func Test_Query_Select_withLimit(t *testing.T) {
t.Fatalf("%s failed: expected %#v row but received %#v", testName+"/select", len(insData), len(allRows))
}

dbresult, err = db.Query(`SELECT * FROM "tbltest" WHERE app=? LIMIT 2`, "app")
dbresult, err = db.Query(fmt.Sprintf(`SELECT * FROM "%s" WHERE app=? LIMIT 2`, tblTestTemp), "app")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/select", err)
}
Expand All @@ -166,26 +166,26 @@ func Test_Exec_Delete(t *testing.T) {
_initTest(db)

// setup table
db.Exec(`DROP TABLE IF EXISTS tbltest`)
db.Exec(`CREATE TABLE tbltest WITH PK=app:string WITH SK=user:string WITH rcu=100 WITH wcu=100`)
_, err := db.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'os': ?, 'active': ?, 'duration': ?}`, "app0", "user1", "Ubuntu", true, 12.34)
db.Exec(fmt.Sprintf(`DROP TABLE IF EXISTS %s`, tblTestTemp))
db.Exec(fmt.Sprintf(`CREATE TABLE %s WITH PK=app:string WITH SK=user:string WITH rcu=5 WITH wcu=5`, tblTestTemp))
_, err := db.Exec(fmt.Sprintf(`INSERT INTO "%s" VALUE {'app': ?, 'user': ?, 'os': ?, 'active': ?, 'duration': ?}`, tblTestTemp), "app0", "user1", "Ubuntu", true, 12.34)
if err != nil {
t.Fatalf("%s failed: %s", testName+"/insert", err)
}
_, err = db.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'platform': ?, 'location': ?}`, "app0", "user2", "Windows", "AU")
_, err = db.Exec(fmt.Sprintf(`INSERT INTO "%s" VALUE {'app': ?, 'user': ?, 'platform': ?, 'location': ?}`, tblTestTemp), "app0", "user2", "Windows", "AU")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/insert", err)
}

// make sure table has 2 rows
dbRows1, _ := db.Query(`SELECT * FROM "tbltest"`)
dbRows1, _ := db.Query(fmt.Sprintf(`SELECT * FROM "%s"`, tblTestTemp))
rows1, _ := _fetchAllRows(dbRows1)
if len(rows1) != 2 {
t.Fatalf("%s failed: expected 2 rows in table, but there is %#v", testName, len(rows1))
}

// delete 1 row
sql := `DELETE FROM "tbltest" WHERE "app"=? AND "user"=?`
sql := fmt.Sprintf(`DELETE FROM "%s" WHERE "app"=? AND "user"=?`, tblTestTemp)
result1, err := db.Exec(sql, "app0", "user1")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/delete", err)
Expand All @@ -199,7 +199,7 @@ func Test_Exec_Delete(t *testing.T) {
}

// make sure table has 1 row
dbRows2, _ := db.Query(`SELECT * FROM "tbltest"`)
dbRows2, _ := db.Query(fmt.Sprintf(`SELECT * FROM "%s"`, tblTestTemp))
rows2, _ := _fetchAllRows(dbRows2)
if len(rows2) != 1 {
t.Fatalf("%s failed: expected 1 rows in table, but there is %#v", testName, len(rows1))
Expand All @@ -226,26 +226,26 @@ func Test_Query_Delete(t *testing.T) {
_initTest(db)

// setup table
db.Exec(`DROP TABLE IF EXISTS tbltest`)
db.Exec(`CREATE TABLE tbltest WITH PK=app:string WITH SK=user:string WITH rcu=100 WITH wcu=100`)
_, err := db.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'os': ?, 'active': ?, 'duration': ?}`, "app0", "user1", "Ubuntu", true, 12.34)
db.Exec(fmt.Sprintf(`DROP TABLE IF EXISTS %s`, tblTestTemp))
db.Exec(fmt.Sprintf(`CREATE TABLE %s WITH PK=app:string WITH SK=user:string WITH rcu=5 WITH wcu=5`, tblTestTemp))
_, err := db.Exec(fmt.Sprintf(`INSERT INTO "%s" VALUE {'app': ?, 'user': ?, 'os': ?, 'active': ?, 'duration': ?}`, tblTestTemp), "app0", "user1", "Ubuntu", true, 12.34)
if err != nil {
t.Fatalf("%s failed: %s", testName+"/insert", err)
}
_, err = db.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'platform': ?, 'location': ?}`, "app0", "user2", "Windows", "AU")
_, err = db.Exec(fmt.Sprintf(`INSERT INTO "%s" VALUE {'app': ?, 'user': ?, 'platform': ?, 'location': ?}`, tblTestTemp), "app0", "user2", "Windows", "AU")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/insert", err)
}

// make sure table has 2 rows
dbRows1, _ := db.Query(`SELECT * FROM "tbltest"`)
dbRows1, _ := db.Query(fmt.Sprintf(`SELECT * FROM "%s"`, tblTestTemp))
rows1, _ := _fetchAllRows(dbRows1)
if len(rows1) != 2 {
t.Fatalf("%s failed: expected 2 rows in table, but there is %#v", testName, len(rows1))
}

// delete 1 row
sql := `DELETE FROM "tbltest" WHERE "app"=? AND "user"=? RETURNING ALL OLD *`
sql := fmt.Sprintf(`DELETE FROM "%s" WHERE "app"=? AND "user"=? RETURNING ALL OLD *`, tblTestTemp)
result1, err := db.Query(sql, "app0", "user1")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/delete", err)
Expand All @@ -264,7 +264,7 @@ func Test_Query_Delete(t *testing.T) {
}

// make sure table has 1 row
dbRows2, _ := db.Query(`SELECT * FROM "tbltest"`)
dbRows2, _ := db.Query(fmt.Sprintf(`SELECT * FROM "%s"`, tblTestTemp))
rows2, _ := _fetchAllRows(dbRows2)
if len(rows2) != 1 {
t.Fatalf("%s failed: expected 1 rows in table, but there is %#v", testName, len(rows1))
Expand All @@ -291,15 +291,15 @@ func Test_Exec_Update(t *testing.T) {
_initTest(db)

// setup table
db.Exec(`DROP TABLE IF EXISTS tbltest`)
db.Exec(`CREATE TABLE tbltest WITH PK=app:string WITH SK=user:string WITH rcu=100 WITH wcu=100`)
_, err := db.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'platform': ?, 'location': ?}`, "app0", "user0", "Linux", "AU")
db.Exec(fmt.Sprintf(`DROP TABLE IF EXISTS %s`, tblTestTemp))
db.Exec(fmt.Sprintf(`CREATE TABLE %s WITH PK=app:string WITH SK=user:string WITH rcu=5 WITH wcu=5`, tblTestTemp))
_, err := db.Exec(fmt.Sprintf(`INSERT INTO "%s" VALUE {'app': ?, 'user': ?, 'platform': ?, 'location': ?}`, tblTestTemp), "app0", "user0", "Linux", "AU")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/insert", err)
}

// update 1 row
sql := `UPDATE "tbltest" SET location=? SET os=? WHERE "app"=? AND "user"=?`
sql := fmt.Sprintf(`UPDATE "%s" SET location=? SET os=? WHERE "app"=? AND "user"=?`, tblTestTemp)
result1, err := db.Exec(sql, "VN", "Ubuntu", "app0", "user0")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/update", err)
Expand Down Expand Up @@ -333,15 +333,15 @@ func Test_Query_Update(t *testing.T) {
_initTest(db)

// setup table
db.Exec(`DROP TABLE IF EXISTS tbltest`)
db.Exec(`CREATE TABLE tbltest WITH PK=app:string WITH SK=user:string WITH rcu=100 WITH wcu=100`)
_, err := db.Exec(`INSERT INTO "tbltest" VALUE {'app': ?, 'user': ?, 'platform': ?, 'location': ?}`, "app0", "user0", "Linux", "AU")
db.Exec(fmt.Sprintf(`DROP TABLE IF EXISTS %s`, tblTestTemp))
db.Exec(fmt.Sprintf(`CREATE TABLE %s WITH PK=app:string WITH SK=user:string WITH rcu=5 WITH wcu=5`, tblTestTemp))
_, err := db.Exec(fmt.Sprintf(`INSERT INTO "%s" VALUE {'app': ?, 'user': ?, 'platform': ?, 'location': ?}`, tblTestTemp), "app0", "user0", "Linux", "AU")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/insert", err)
}

// update 1 row
sql := `UPDATE "tbltest" SET location=? SET os=? WHERE "app"=? AND "user"=?`
sql := fmt.Sprintf(`UPDATE "%s" SET location=? SET os=? WHERE "app"=? AND "user"=?`, tblTestTemp)
dbrows1, err := db.Query(sql+" RETURNING MODIFIED OLD *", "VN", "Ubuntu", "app0", "user0")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/update", err)
Expand Down Expand Up @@ -379,7 +379,7 @@ func TestResultResultSet_ColumnTypeDatabaseTypeName(t *testing.T) {
defer db.Close()
_initTest(db)

db.Exec(`CREATE TABLE tbltest WITH pk=id:string WITH rcu=1 WITH wcu=1`)
db.Exec(fmt.Sprintf(`CREATE TABLE %s WITH pk=id:string WITH rcu=1 WITH wcu=1`, tblTestTemp))
testData := map[string]struct {
val interface{}
typ string
Expand Down Expand Up @@ -407,7 +407,7 @@ func TestResultResultSet_ColumnTypeDatabaseTypeName(t *testing.T) {
"val_bool": {val: true, typ: "BOOL"},
"val_bool_1": {val: types.AttributeValueMemberBOOL{Value: false}, typ: "BOOL"},
}
sql := `INSERT INTO "tbltest" VALUE {'id': 'myid'`
sql := fmt.Sprintf(`INSERT INTO "%s" VALUE {'id': 'myid'`, tblTestTemp)
params := make([]interface{}, 0)
for col, data := range testData {
sql += fmt.Sprintf(", '%s': ?", col)
Expand All @@ -419,7 +419,7 @@ func TestResultResultSet_ColumnTypeDatabaseTypeName(t *testing.T) {
t.Fatalf("%s failed: %s", testName+"/insert", err)
}

dbrows, err := db.Query(`SELECT * FROM "tbltest" WHERE id=?`, "myid")
dbrows, err := db.Query(fmt.Sprintf(`SELECT * FROM "%s" WHERE id=?`, tblTestTemp), "myid")
if err != nil {
t.Fatalf("%s failed: %s", testName+"/select", err)
}
Expand Down
Loading

0 comments on commit c05a23f

Please sign in to comment.