interface.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Package mysql is a MySQL Client API written entirely in Go without any external dependences.
  2. package mysql
  3. import (
  4. "net"
  5. "time"
  6. )
  7. // ConnCommon is a common interface for the connection.
  8. // See mymysql/native for method documentation.
  9. type ConnCommon interface {
  10. Start(sql string, params ...interface{}) (Result, error)
  11. Prepare(sql string) (Stmt, error)
  12. Ping() error
  13. ThreadId() uint32
  14. Escape(txt string) string
  15. Query(sql string, params ...interface{}) ([]Row, Result, error)
  16. QueryFirst(sql string, params ...interface{}) (Row, Result, error)
  17. QueryLast(sql string, params ...interface{}) (Row, Result, error)
  18. }
  19. // Dialer can be used to dial connections to MySQL. If Dialer returns (nil, nil)
  20. // the hook is skipped and normal dialing proceeds.
  21. type Dialer func(proto, laddr, raddr string, timeout time.Duration) (net.Conn, error)
  22. // Conn represents connection to the MySQL server.
  23. // See mymysql/native for method documentation.
  24. type Conn interface {
  25. ConnCommon
  26. Clone() Conn
  27. SetTimeout(time.Duration)
  28. Connect() error
  29. NetConn() net.Conn
  30. SetDialer(Dialer)
  31. Close() error
  32. IsConnected() bool
  33. Reconnect() error
  34. Use(dbname string) error
  35. Register(sql string)
  36. SetMaxPktSize(new_size int) int
  37. NarrowTypeSet(narrow bool)
  38. FullFieldInfo(full bool)
  39. Status() ConnStatus
  40. Credentials() (user, passwd string)
  41. Begin() (Transaction, error)
  42. }
  43. // Transaction represents MySQL transaction.
  44. // See mymysql/native for method documentation.
  45. type Transaction interface {
  46. ConnCommon
  47. Commit() error
  48. Rollback() error
  49. Do(st Stmt) Stmt
  50. IsValid() bool
  51. }
  52. // Stmt represents MySQL prepared statement.
  53. // See mymysql/native for method documentation.
  54. type Stmt interface {
  55. Bind(params ...interface{})
  56. Run(params ...interface{}) (Result, error)
  57. Delete() error
  58. Reset() error
  59. SendLongData(pnum int, data interface{}, pkt_size int) error
  60. Fields() []*Field
  61. NumParam() int
  62. WarnCount() int
  63. Exec(params ...interface{}) ([]Row, Result, error)
  64. ExecFirst(params ...interface{}) (Row, Result, error)
  65. ExecLast(params ...interface{}) (Row, Result, error)
  66. }
  67. // Result represents one MySQL result set.
  68. // See mymysql/native for method documentation.
  69. type Result interface {
  70. StatusOnly() bool
  71. ScanRow(Row) error
  72. GetRow() (Row, error)
  73. MoreResults() bool
  74. NextResult() (Result, error)
  75. Fields() []*Field
  76. Map(string) int
  77. Message() string
  78. AffectedRows() uint64
  79. InsertId() uint64
  80. WarnCount() int
  81. MakeRow() Row
  82. GetRows() ([]Row, error)
  83. End() error
  84. GetFirstRow() (Row, error)
  85. GetLastRow() (Row, error)
  86. }
  87. // New can be used to establish a connection. It is set by imported engine
  88. // (see mymysql/native, mymysql/thrsafe).
  89. var New func(proto, laddr, raddr, user, passwd string, db ...string) Conn