Skip to content

Commit

Permalink
let gorm support limit and offset binding parameters,change the BindV…
Browse files Browse the repository at this point in the history
…ar of postgres driver (#239)

* Update postgres.go

if limit and offset use the parameter  in new gorm version,must remove config vars before bindvar to ,and then restore them.

* optimise the BindVarTo code to ensure   the code  more efficient

* fix"for bug "  for bindvar

* remove cases

* remove for logic

* just check the 0 index
  • Loading branch information
jasonchuan authored Feb 4, 2024
1 parent 438e4fd commit dc711bd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@ func (dialector Dialector) DefaultValueOf(field *schema.Field) clause.Expression

func (dialector Dialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{}) {
writer.WriteByte('$')
writer.WriteString(strconv.Itoa(len(stmt.Vars)))
index := 0
varLen := len(stmt.Vars)
if varLen > 0 {
switch stmt.Vars[0].(type) {
case pgx.QueryExecMode:
index++
}
}
writer.WriteString(strconv.Itoa(varLen - index))
}

func (dialector Dialector) QuoteTo(writer clause.Writer, str string) {
Expand Down

0 comments on commit dc711bd

Please sign in to comment.