Skip to content

Commit

Permalink
expose select type
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Dec 1, 2024
1 parent 175c21a commit 874c781
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
12 changes: 6 additions & 6 deletions database/gdb/gdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,21 +701,21 @@ func getConfigNodeByWeight(cg ConfigGroup) *ConfigNode {
}
// Exclude the right border value.
var (
min = 0
max = 0
random = grand.N(0, total-1)
minWeight = 0
maxWeight = 0
random = grand.N(0, total-1)
)
for i := 0; i < len(cg); i++ {
max = min + cg[i].Weight*100
if random >= min && random < max {
maxWeight = minWeight + cg[i].Weight*100
if random >= minWeight && random < maxWeight {
// ====================================================
// Return a COPY of the ConfigNode.
// ====================================================
node := ConfigNode{}
node = cg[i]
return &node
}
min = max
minWeight = maxWeight
}
return nil
}
Expand Down
11 changes: 6 additions & 5 deletions database/gdb/gdb_model_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ type internalParamHookDelete struct {
// which is usually not be interesting for upper business hook handler.
type HookSelectInput struct {
internalParamHookSelect
Model *Model // Current operation Model.
Table string // The table name that to be used. Update this attribute to change target table name.
Schema string // The schema name that to be used. Update this attribute to change target schema name.
Sql string // The sql string that to be committed.
Args []interface{} // The arguments of sql.
Model *Model // Current operation Model.
Table string // The table name that to be used. Update this attribute to change target table name.
Schema string // The schema name that to be used. Update this attribute to change target schema name.
Sql string // The sql string that to be committed.
Args []interface{} // The arguments of sql.
SelectType SelectType // The type of this SELECT operation.
}

// HookInsertInput holds the parameters for insert hook operation.
Expand Down
9 changes: 5 additions & 4 deletions database/gdb/gdb_model_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,11 @@ func (m *Model) doGetAllBySql(
},
handler: m.hookHandler.Select,
},
Model: m,
Table: m.tables,
Sql: sql,
Args: m.mergeArguments(args),
Model: m,
Table: m.tables,
Sql: sql,
Args: m.mergeArguments(args),
SelectType: selectType,
}
if result, err = in.Next(ctx); err != nil {
return
Expand Down

0 comments on commit 874c781

Please sign in to comment.