To support sql comment.
Some dbproxy middleware use sql comment to make make a query on master node. Example: db.Table("test").Comment("/*m:master*/").Get( ptrObj ) The sql builder will output: /*m:master*/SELECT * from test ....;
This commit is contained in:
parent
4c806608ab
commit
41fb72d8d0
|
@ -57,6 +57,7 @@ type Session struct {
|
||||||
//beforeSQLExec func(string, ...interface{})
|
//beforeSQLExec func(string, ...interface{})
|
||||||
lastSQL string
|
lastSQL string
|
||||||
lastSQLArgs []interface{}
|
lastSQLArgs []interface{}
|
||||||
|
comment string
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
sessionType sessionType
|
sessionType sessionType
|
||||||
|
@ -157,6 +158,12 @@ func (session *Session) Table(tableNameOrBean interface{}) *Session {
|
||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set comment for select statement
|
||||||
|
func (session *Session) Comment(comment string) *Session {
|
||||||
|
session.comment = comment
|
||||||
|
return session
|
||||||
|
}
|
||||||
|
|
||||||
// Alias set the table alias
|
// Alias set the table alias
|
||||||
func (session *Session) Alias(alias string) *Session {
|
func (session *Session) Alias(alias string) *Session {
|
||||||
session.statement.Alias(alias)
|
session.statement.Alias(alias)
|
||||||
|
|
|
@ -20,6 +20,7 @@ func (session *Session) genQuerySQL(sqlOrArgs ...interface{}) (string, []interfa
|
||||||
return convertSQLOrArgs(sqlOrArgs...)
|
return convertSQLOrArgs(sqlOrArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sqlStr = session.comment + sqlStr
|
||||||
if session.statement.RawSQL != "" {
|
if session.statement.RawSQL != "" {
|
||||||
return session.statement.RawSQL, session.statement.RawParams, nil
|
return session.statement.RawSQL, session.statement.RawParams, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue