Skip to content

Commit

Permalink
Merge pull request #149 from btnguyen2k/release
Browse files Browse the repository at this point in the history
Merge to main after releasing new version 1.2.1
  • Loading branch information
btnguyen2k authored Mar 21, 2024
2 parents 208ba42 + d2380c4 commit 2394e7f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 41 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ jobs:
RELEASE_NOTES: ${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}
steps:
- uses: actions/checkout@v4
- name: Update module meta
- name: Update module metadata
run: |
RESULT='${{ needs.ReleaseDryRun.outputs.RESULT }}'
VERSION='${{ needs.ReleaseDryRun.outputs.VERSION }}'
RELEASE_NOTES='${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}'
echo "🕘 Updating module meta..."
echo "🕘 Updating module metadata..."
echo " - RESULT: ${RESULT}"
echo " - VERSION: ${VERSION}"
echo " - RELEASE_NOTES: ${RELEASE_NOTES}"
Expand All @@ -82,8 +82,9 @@ jobs:
echo ========== content of ${FILE_MODULE} ==========
cat ${FILE_MODULE}
echo ========== update .go files ==========
echo ========== update .go/.md files ==========
sed -i -E "s/<<VERSION>>/v${VERSION}/" ./*.go
sed -i -E "s/<<VERSION>>/v${VERSION}/" ./*.md
echo ========== commit updates ==========
git config --global user.email "<>"
Expand Down Expand Up @@ -120,6 +121,21 @@ jobs:
prerelease: false,
});
console.log('✅ Created release: ', release);
- name: Cleanup file .semrelease/this_release
run: |
RESULT='${{ needs.ReleaseDryRun.outputs.RESULT }}'
if [ "${RESULT}" == "SUCCESS" ]; then
VERSION='${{ needs.ReleaseDryRun.outputs.VERSION }}'
echo "🕘 Cleaning up file .semrelease/this_release..."
echo > .semrelease/this_release
git config --global user.email "<>"
git config --global user.name "CI Build"
git commit -am "Cleanup file .semrelease/this_release post-releasing version ${VERSION}"
git push -f
echo "✅ Done."
else
echo "❎ SKIPPED."
fi
MergeToMain:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .semrelease/this_release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# godynamo release notes

## 2024-03-21 - v1.2.1

### Fixed/Improvement

- Fix #146: Columns are not sorted in the order of selection.

## 2024-01-06 - v1.2.0

### Added/Refactoring
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.2.0"
Version = "1.2.1"
)

// This file contains module's metadata only, which is package level documentation and module Version string.
Expand Down
2 changes: 1 addition & 1 deletion module_test/stmt_document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func Test_Query_Select_with_columns_selection(t *testing.T) {
active bool
)
expected := []interface{}{1.0, "app", "Linux", true}
dbresult.Scan(&duration, &app, &os, &active)
_ = dbresult.Scan(&duration, &app, &os, &active)
if !reflect.DeepEqual([]interface{}{duration, app, os, active}, expected) {
t.Fatalf("%s failed: expected %#v but received %#v", testName+"/select", expected, []interface{}{duration, app, os, active})
}
Expand Down
3 changes: 3 additions & 0 deletions stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,12 @@ func (r *ResultResultSet) init() *ResultResultSet {
}
}
}

if len(r.columnList) > 0 {
// #146: if column list was provided in the SELECT statement, keep the order as specified
return r
}

// save column names, sorted
r.columnList = make([]string, 0, len(colMap))
for col := range colMap {
Expand Down
64 changes: 28 additions & 36 deletions stmt_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

var (
// rePlaceholder = regexp.MustCompile(`(?m)\?\s*[,})\]\s]`)
rePlaceholder = regexp.MustCompile(`\?`)
reReturning = regexp.MustCompile(`(?im)\s+RETURNING\s+((ALL\s+OLD)|(MODIFIED\s+OLD)|(ALL\s+NEW)|(MODIFIED\s+NEW))\s+\*\s*$`)
reLimit = regexp.MustCompile(`(?im)\s+LIMIT\s+(\S+)\s*`)
Expand All @@ -37,20 +36,6 @@ func (s *StmtExecutable) parse() error {
matches := rePlaceholder.FindAllString(queryWithRemovedStringLiteral+" ", -1)
s.numInput = len(matches)

// // Parse WITH options
// withOptString := reSelectWithOpts.FindAllString(s.query, -1)
// for _, str := range withOptString {
// s.withOptString += " " + str
// }
//
// // Remove WITH options from query
// s.query = reSelectWithOpts.ReplaceAllString(s.query, "")

// // Parse WITH options
// err := s.parseWithOpts(s.withOptsStr)
// if err != nil {
// return err
// }
return nil
}

Expand Down Expand Up @@ -167,6 +152,34 @@ func (s *StmtSelect) QueryContext(ctx context.Context, values []driver.NamedValu
return result, err
}

// extractSelectedColumnList returns a slice of selected column names from the query.
// If the query contains "*" or no selected column, an empty slice is returned.
func extractSelectedColumnList(query string) []string {
emptySelectedColumnList := make([]string, 0)

selectedListMatch := reSelectedList.FindStringSubmatch(query)
if len(selectedListMatch) == 0 {
return emptySelectedColumnList
}

selectedColumnList := make([]string, 0)
selectedListStr := selectedListMatch[1]
for _, v := range strings.Split(selectedListStr, ",") {
for {
t := strings.Trim(strings.Trim(strings.TrimSpace(v), `"`), `'`)
if t == v {
break
}
v = t
}
if v == "*" {
return emptySelectedColumnList
}
selectedColumnList = append(selectedColumnList, v)
}
return selectedColumnList
}

/*----------------------------------------------------------------------*/

// StmtUpdate implements "UPDATE" statement.
Expand Down Expand Up @@ -282,24 +295,3 @@ func (s *StmtDelete) ExecContext(ctx context.Context, values []driver.NamedValue
}
return &ResultNoResultSet{err: err, affectedRows: affectedRows}, err
}

// extractSelectedColumnList returns a slice of selected column names from the query.
// If the query contains "*" or no selected column, an empty slice is returned.
func extractSelectedColumnList(query string) []string {
selectedColumnList := make([]string, 0)
selectedListMatch := reSelectedList.FindStringSubmatch(query)
if len(selectedListMatch) < 1 {
return selectedColumnList
}
selectedListStr := selectedListMatch[1]
if strings.Contains(selectedListStr, "*") {
return selectedColumnList
}
for _, v := range strings.Split(selectedListStr, ",") {
v = strings.TrimSpace(v)
v = strings.Trim(v, `"`)
v = strings.Trim(v, `'`)
selectedColumnList = append(selectedColumnList, v)
}
return selectedColumnList
}

0 comments on commit 2394e7f

Please sign in to comment.