interfaces.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package gorm
  2. import (
  3. "context"
  4. "database/sql"
  5. "gorm.io/gorm/clause"
  6. "gorm.io/gorm/schema"
  7. )
  8. // Dialector GORM database dialector
  9. type Dialector interface {
  10. Name() string
  11. Initialize(*DB) error
  12. Migrator(db *DB) Migrator
  13. DataTypeOf(*schema.Field) string
  14. DefaultValueOf(*schema.Field) clause.Expression
  15. BindVarTo(writer clause.Writer, stmt *Statement, v interface{})
  16. QuoteTo(clause.Writer, string)
  17. Explain(sql string, vars ...interface{}) string
  18. }
  19. // Plugin GORM plugin interface
  20. type Plugin interface {
  21. Name() string
  22. Initialize(*DB) error
  23. }
  24. type ParamsFilter interface {
  25. ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{})
  26. }
  27. // ConnPool db conns pool interface
  28. type ConnPool interface {
  29. PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
  30. ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
  31. QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
  32. QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
  33. }
  34. // SavePointerDialectorInterface save pointer interface
  35. type SavePointerDialectorInterface interface {
  36. SavePoint(tx *DB, name string) error
  37. RollbackTo(tx *DB, name string) error
  38. }
  39. // TxBeginner tx beginner
  40. type TxBeginner interface {
  41. BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
  42. }
  43. // ConnPoolBeginner conn pool beginner
  44. type ConnPoolBeginner interface {
  45. BeginTx(ctx context.Context, opts *sql.TxOptions) (ConnPool, error)
  46. }
  47. // TxCommitter tx committer
  48. type TxCommitter interface {
  49. Commit() error
  50. Rollback() error
  51. }
  52. // Tx sql.Tx interface
  53. type Tx interface {
  54. ConnPool
  55. TxCommitter
  56. StmtContext(ctx context.Context, stmt *sql.Stmt) *sql.Stmt
  57. }
  58. // Valuer gorm valuer interface
  59. type Valuer interface {
  60. GormValue(context.Context, *DB) clause.Expr
  61. }
  62. // GetDBConnector SQL db connector
  63. type GetDBConnector interface {
  64. GetDBConn() (*sql.DB, error)
  65. }
  66. // Rows rows interface
  67. type Rows interface {
  68. Columns() ([]string, error)
  69. ColumnTypes() ([]*sql.ColumnType, error)
  70. Next() bool
  71. Scan(dest ...interface{}) error
  72. Err() error
  73. Close() error
  74. }
  75. type ErrorTranslator interface {
  76. Translate(err error) error
  77. }