@@ -74,7 +74,7 @@ type SqlHistoryWriter struct {
7474}
7575
7676func NewSqlDiffReader (db * sql.DB , table string , entity string , entityType string , idNames []string , config DiffConfig , keyBuilder KeyBuilder , options ... func (int ) string ) * SqlDiffReader {
77- columnSelect := BuildQueryColumn (config )
77+ columnSelect := buildQueryColumns (config )
7878 driver := getDriver (db )
7979 var buildParam func (int ) string
8080 if len (options ) > 0 && options [0 ] != nil {
@@ -86,7 +86,7 @@ func NewSqlDiffReader(db *sql.DB, table string, entity string, entityType string
8686}
8787
8888func NewSqlDiffListReader (db * sql.DB , table string , entity string , entityType string , idNames []string , config DiffConfig , keyBuilder KeyBuilder , options ... func (int ) string ) * SqlDiffListReader {
89- columnSelect := BuildQueryColumn (config )
89+ columnSelect := buildQueryColumns (config )
9090 driver := getDriver (db )
9191 var buildParam func (int ) string
9292 if len (options ) > 0 && options [0 ] != nil {
@@ -235,7 +235,7 @@ func (r SqlDiffReader) getEntityById(ctx context.Context, key interface{}, idNam
235235 querySql := fmt .Sprintf ("select %s from %s where %s = %s and %s = %s" , r .columnSelect , r .Entity ,
236236 r .Config .Id , r .BuildParam (1 ),
237237 r .EntityType , r .BuildParam (2 ))
238- err := SqlQueryOne (ctx , r .DB , & result , querySql , key , r .Table )
238+ err := QueryDiff (ctx , r .DB , & result , querySql , key , r .Table )
239239 if err != nil {
240240 return nil , err
241241 }
@@ -245,16 +245,16 @@ func (r SqlDiffReader) getEntityById(ctx context.Context, key interface{}, idNam
245245 return & result , nil
246246}
247247
248- func BuildParameters (numCol int , buildParam func (int ) string ) string {
248+ func buildParameters (numCol int , buildParam func (int ) string ) string {
249249 var arrValue []string
250250 for i := 0 ; i < numCol ; i ++ {
251251 arrValue = append (arrValue , buildParam (i + 1 ))
252252 }
253253 return strings .Join (arrValue , "," )
254254}
255- func BuildQueryColumn (config DiffConfig ) string {
255+ func buildQueryColumns (config DiffConfig ) string {
256256 sqlsel := make ([]string , 0 )
257- colDiffModel := GetColumnNameDiffModel ()
257+ colDiffModel := getDiffColumnNames ()
258258 if config .Id != "" {
259259 sqlsel = append (sqlsel , config .Id + " as " + colDiffModel [0 ])
260260 }
@@ -270,7 +270,7 @@ func BuildQueryColumn(config DiffConfig) string {
270270 return strings .Join (sqlsel , "," )
271271}
272272
273- func GetColumnNameDiffModel () []string {
273+ func getDiffColumnNames () []string {
274274 ids := make ([]string , 0 )
275275 objectValue := reflect .Indirect (reflect .ValueOf (DiffModel {}))
276276 for i := 0 ; i < objectValue .NumField (); i ++ {
@@ -314,8 +314,8 @@ func (c SqlDiffListReader) getEntityByIds(ctx context.Context, keyBuilder KeyBui
314314 args = append (args , arrayKeys ... )
315315 args = append (args , c .Table )
316316 results := make ([]DiffModel , 0 )
317- querySql := fmt .Sprintf ("select %s from %s where %s IN (%s) and %s = %s" , c .columnSelect , c .Entity , c .Config .Id , BuildParameters (n , c .BuildParam ), c .EntityType , c .BuildParam (n + 1 ))
318- err := Query (ctx , c .DB , & results , querySql , args ... )
317+ querySql := fmt .Sprintf ("select %s from %s where %s IN (%s) and %s = %s" , c .columnSelect , c .Entity , c .Config .Id , buildParameters (n , c .BuildParam ), c .EntityType , c .BuildParam (n + 1 ))
318+ err := QueryDiffs (ctx , c .DB , & results , querySql , args ... )
319319 // map object id
320320 for i , result := range results {
321321 id := result .Id .(* string )
@@ -358,7 +358,7 @@ func (b *DefaultKeyBuilder) getPositionPrimaryKeys(modelType reflect.Type) []int
358358 return b .PositionPrimaryKeysMap [modelType ]
359359}
360360
361- func SqlQueryOne (ctx context.Context , db * sql.DB , result * DiffModel , sql string , values ... interface {}) error {
361+ func QueryDiff (ctx context.Context , db * sql.DB , result * DiffModel , sql string , values ... interface {}) error {
362362 driver := getDriver (db )
363363 suffix := " limit 1 "
364364 if driver == DriverOracle {
@@ -431,7 +431,7 @@ func convertStringToMap(str *string) (*map[string]interface{}, error) {
431431 return & p , err
432432}
433433
434- func Query (ctx context.Context , db * sql.DB , results * []DiffModel , sql string , values ... interface {}) error {
434+ func QueryDiffs (ctx context.Context , db * sql.DB , results * []DiffModel , sql string , values ... interface {}) error {
435435 rows , err := db .QueryContext (ctx , sql , values ... )
436436 if err != nil {
437437 return err
0 commit comments