2020-02-05 06:14:58 +03:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
2020-06-02 04:16:07 +03:00
|
|
|
"gorm.io/gorm"
|
2022-10-07 16:18:37 +03:00
|
|
|
"gorm.io/gorm/callbacks"
|
2020-06-02 04:16:07 +03:00
|
|
|
"gorm.io/gorm/clause"
|
|
|
|
"gorm.io/gorm/logger"
|
|
|
|
"gorm.io/gorm/schema"
|
2020-02-05 06:14:58 +03:00
|
|
|
)
|
|
|
|
|
2023-03-06 09:03:31 +03:00
|
|
|
type DummyDialector struct {
|
|
|
|
TranslatedErr error
|
|
|
|
}
|
2020-02-05 06:14:58 +03:00
|
|
|
|
2020-06-01 03:12:44 +03:00
|
|
|
func (DummyDialector) Name() string {
|
|
|
|
return "dummy"
|
|
|
|
}
|
|
|
|
|
2022-10-07 16:18:37 +03:00
|
|
|
func (DummyDialector) Initialize(db *gorm.DB) error {
|
|
|
|
callbacks.RegisterDefaultCallbacks(db, &callbacks.Config{
|
|
|
|
CreateClauses: []string{"INSERT", "VALUES", "ON CONFLICT", "RETURNING"},
|
|
|
|
UpdateClauses: []string{"UPDATE", "SET", "WHERE", "RETURNING"},
|
|
|
|
DeleteClauses: []string{"DELETE", "FROM", "WHERE", "RETURNING"},
|
|
|
|
LastInsertIDReversed: true,
|
|
|
|
})
|
|
|
|
|
2020-02-05 06:14:58 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-20 05:51:36 +03:00
|
|
|
func (DummyDialector) DefaultValueOf(field *schema.Field) clause.Expression {
|
|
|
|
return clause.Expr{SQL: "DEFAULT"}
|
|
|
|
}
|
|
|
|
|
2020-02-22 15:57:29 +03:00
|
|
|
func (DummyDialector) Migrator(*gorm.DB) gorm.Migrator {
|
2020-02-05 06:14:58 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-03-09 12:59:54 +03:00
|
|
|
func (DummyDialector) BindVarTo(writer clause.Writer, stmt *gorm.Statement, v interface{}) {
|
|
|
|
writer.WriteByte('?')
|
2020-02-05 06:14:58 +03:00
|
|
|
}
|
|
|
|
|
2020-03-09 12:07:00 +03:00
|
|
|
func (DummyDialector) QuoteTo(writer clause.Writer, str string) {
|
2021-09-11 11:22:35 +03:00
|
|
|
var (
|
|
|
|
underQuoted, selfQuoted bool
|
|
|
|
continuousBacktick int8
|
|
|
|
shiftDelimiter int8
|
|
|
|
)
|
|
|
|
|
|
|
|
for _, v := range []byte(str) {
|
|
|
|
switch v {
|
|
|
|
case '`':
|
|
|
|
continuousBacktick++
|
|
|
|
if continuousBacktick == 2 {
|
|
|
|
writer.WriteString("``")
|
|
|
|
continuousBacktick = 0
|
|
|
|
}
|
|
|
|
case '.':
|
|
|
|
if continuousBacktick > 0 || !selfQuoted {
|
|
|
|
shiftDelimiter = 0
|
|
|
|
underQuoted = false
|
|
|
|
continuousBacktick = 0
|
2022-03-17 17:54:30 +03:00
|
|
|
writer.WriteByte('`')
|
2021-09-11 11:22:35 +03:00
|
|
|
}
|
|
|
|
writer.WriteByte(v)
|
|
|
|
continue
|
|
|
|
default:
|
|
|
|
if shiftDelimiter-continuousBacktick <= 0 && !underQuoted {
|
|
|
|
writer.WriteByte('`')
|
|
|
|
underQuoted = true
|
|
|
|
if selfQuoted = continuousBacktick > 0; selfQuoted {
|
|
|
|
continuousBacktick -= 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for ; continuousBacktick > 0; continuousBacktick -= 1 {
|
|
|
|
writer.WriteString("``")
|
|
|
|
}
|
|
|
|
|
|
|
|
writer.WriteByte(v)
|
|
|
|
}
|
|
|
|
shiftDelimiter++
|
|
|
|
}
|
|
|
|
|
|
|
|
if continuousBacktick > 0 && !selfQuoted {
|
|
|
|
writer.WriteString("``")
|
|
|
|
}
|
2022-03-17 17:54:30 +03:00
|
|
|
writer.WriteByte('`')
|
2020-02-05 06:14:58 +03:00
|
|
|
}
|
2020-02-22 15:57:29 +03:00
|
|
|
|
2020-02-23 10:07:47 +03:00
|
|
|
func (DummyDialector) Explain(sql string, vars ...interface{}) string {
|
|
|
|
return logger.ExplainSQL(sql, nil, `"`, vars...)
|
|
|
|
}
|
|
|
|
|
2020-02-22 15:57:29 +03:00
|
|
|
func (DummyDialector) DataTypeOf(*schema.Field) string {
|
|
|
|
return ""
|
|
|
|
}
|
2023-03-06 09:03:31 +03:00
|
|
|
|
|
|
|
func (d DummyDialector) Translate(err error) error {
|
|
|
|
return d.TranslatedErr
|
|
|
|
}
|