This is an automated email from the ASF dual-hosted git repository.

zhangliang2022 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new 61d65eac refactor(dal): rename Raw to RawCursor / cleanup comments 
(#2399)
61d65eac is described below

commit 61d65eac4027af01ce8374b990df90a100af4e31
Author: Klesh Wong <[email protected]>
AuthorDate: Fri Jul 1 11:16:23 2022 +0800

    refactor(dal): rename Raw to RawCursor / cleanup comments (#2399)
---
 impl/dalgorm/dalgorm.go                                 |  6 +++---
 plugins/core/dal/dal.go                                 | 12 +++++-------
 plugins/refdiff/tasks/refs_pr_cherry_pick_calculator.go |  2 +-
 plugins/starrocks/tasks.go                              |  7 ++++---
 4 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/impl/dalgorm/dalgorm.go b/impl/dalgorm/dalgorm.go
index f46d04f1..eb68c0a4 100644
--- a/impl/dalgorm/dalgorm.go
+++ b/impl/dalgorm/dalgorm.go
@@ -73,8 +73,8 @@ func buildTx(tx *gorm.DB, clauses []dal.Clause) *gorm.DB {
 
 var _ dal.Dal = (*Dalgorm)(nil)
 
-// Exec executes raw sql query
-func (d *Dalgorm) Raw(query string, params ...interface{}) (*sql.Rows, error) {
+// RawCursor executes raw sql query and returns a database cursor
+func (d *Dalgorm) RawCursor(query string, params ...interface{}) (*sql.Rows, 
error) {
        return d.db.Raw(query, params...).Rows()
 }
 
@@ -83,7 +83,7 @@ func (d *Dalgorm) Exec(query string, params ...interface{}) 
error {
        return d.db.Exec(query, params...).Error
 }
 
-// CreateTable creates a table with gorm definition from `entity`
+// AutoMigrate runs auto migration for given models
 func (d *Dalgorm) AutoMigrate(entity interface{}, clauses ...dal.Clause) error 
{
        return buildTx(d.db, clauses).AutoMigrate(entity)
 }
diff --git a/plugins/core/dal/dal.go b/plugins/core/dal/dal.go
index a8790860..4b297f59 100644
--- a/plugins/core/dal/dal.go
+++ b/plugins/core/dal/dal.go
@@ -26,16 +26,14 @@ type Clause struct {
        Data interface{}
 }
 
-// Dal aims to facilitate an isolation of Database Access Layer by defining a 
set of operations should a
-// Database Access Layer provide
-// This is inroduced by the fact that mocking *gorm.DB is hard, and `gomonkey` 
is not working on macOS
+// Dal aims to facilitate an isolation between DBS and our System by defining 
a set of operations should a DBS provide
 type Dal interface {
-       // Raw executes raw sql query with sql.Rows and error return
-       Raw(query string, params ...interface{}) (*sql.Rows, error)
+       // AutoMigrate runs auto migration for given entity
+       AutoMigrate(entity interface{}, clauses ...Clause) error
        // Exec executes raw sql query
        Exec(query string, params ...interface{}) error
-       // CreateTable creates a table with gorm definition from `entity`R
-       AutoMigrate(entity interface{}, clauses ...Clause) error
+       // RawCursor executes raw sql query and returns a database cursor
+       RawCursor(query string, params ...interface{}) (*sql.Rows, error)
        // Cursor returns a database cursor, cursor is especially useful when 
handling big amount of rows of data
        Cursor(clauses ...Clause) (*sql.Rows, error)
        // Fetch loads row data from `cursor` into `dst`
diff --git a/plugins/refdiff/tasks/refs_pr_cherry_pick_calculator.go 
b/plugins/refdiff/tasks/refs_pr_cherry_pick_calculator.go
index 1d85f249..d4e800db 100644
--- a/plugins/refdiff/tasks/refs_pr_cherry_pick_calculator.go
+++ b/plugins/refdiff/tasks/refs_pr_cherry_pick_calculator.go
@@ -110,7 +110,7 @@ func CalculatePrCherryPick(taskCtx core.SubTaskContext) 
error {
                taskCtx.IncProgress(1)
        }
 
-       cursor2, err := db.Raw(
+       cursor2, err := db.RawCursor(
                `
                        SELECT pr2.pull_request_key                 AS 
parent_pr_key,
                               pr1.parent_pr_id                     AS 
parent_pr_id,
diff --git a/plugins/starrocks/tasks.go b/plugins/starrocks/tasks.go
index 83c7e7d4..a63a5de5 100644
--- a/plugins/starrocks/tasks.go
+++ b/plugins/starrocks/tasks.go
@@ -21,11 +21,12 @@ import (
        "database/sql"
        "encoding/json"
        "fmt"
-       "github.com/apache/incubator-devlake/plugins/core"
-       "github.com/apache/incubator-devlake/plugins/core/dal"
        "io/ioutil"
        "net/http"
        "strings"
+
+       "github.com/apache/incubator-devlake/plugins/core"
+       "github.com/apache/incubator-devlake/plugins/core/dal"
 )
 
 func LoadData(c core.SubTaskContext) error {
@@ -55,7 +56,7 @@ func LoadData(c core.SubTaskContext) error {
 func loadData(starrocks *sql.DB, c core.SubTaskContext, table string, db 
dal.Dal, config *StarRocksConfig) error {
        var data []map[string]interface{}
        // select data from db
-       rows, err := db.Raw(fmt.Sprintf("select * from %s", table))
+       rows, err := db.RawCursor(fmt.Sprintf("select * from %s", table))
        if err != nil {
                return err
        }

Reply via email to