finisher_api.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package gorm
  2. import (
  3. "database/sql"
  4. )
  5. func (db *DB) Count(sql string, values ...interface{}) (tx *DB) {
  6. tx = db.getInstance()
  7. return
  8. }
  9. // First find first record that match given conditions, order by primary key
  10. func (db *DB) First(out interface{}, where ...interface{}) (tx *DB) {
  11. tx = db.getInstance()
  12. return
  13. }
  14. // Take return a record that match given conditions, the order will depend on the database implementation
  15. func (db *DB) Take(out interface{}, where ...interface{}) (tx *DB) {
  16. tx = db.getInstance()
  17. return
  18. }
  19. // Last find last record that match given conditions, order by primary key
  20. func (db *DB) Last(out interface{}, where ...interface{}) (tx *DB) {
  21. tx = db.getInstance()
  22. return
  23. }
  24. // Find find records that match given conditions
  25. func (db *DB) Find(out interface{}, where ...interface{}) (tx *DB) {
  26. tx = db.getInstance()
  27. return
  28. }
  29. // Scan scan value to a struct
  30. func (db *DB) Row() *sql.Row {
  31. // TODO
  32. return nil
  33. }
  34. func (db *DB) Rows() (*sql.Rows, error) {
  35. // TODO
  36. return nil, nil
  37. }
  38. func (db *DB) Scan(dest interface{}) (tx *DB) {
  39. tx = db.getInstance()
  40. return
  41. }
  42. func (db *DB) ScanRows(rows *sql.Rows, result interface{}) error {
  43. return nil
  44. }
  45. // Create insert the value into database
  46. func (db *DB) Create(value interface{}) (tx *DB) {
  47. tx = db.getInstance()
  48. return
  49. }
  50. // Save update value in database, if the value doesn't have primary key, will insert it
  51. func (db *DB) Save(value interface{}) (tx *DB) {
  52. tx = db.getInstance()
  53. return
  54. }
  55. // Update update attributes with callbacks, refer: https://jinzhu.github.io/gorm/crud.html#update
  56. func (db *DB) Update(column string, value interface{}) (tx *DB) {
  57. tx = db.getInstance()
  58. return
  59. }
  60. // Updates update attributes with callbacks, refer: https://jinzhu.github.io/gorm/crud.html#update
  61. func (db *DB) Updates(values interface{}) (tx *DB) {
  62. tx = db.getInstance()
  63. return
  64. }
  65. func (db *DB) UpdateColumn(attrs ...interface{}) (tx *DB) {
  66. tx = db.getInstance()
  67. return
  68. }
  69. func (db *DB) UpdateColumns(values interface{}) (tx *DB) {
  70. tx = db.getInstance()
  71. return
  72. }
  73. func (db *DB) FirstOrCreate(out interface{}, where ...interface{}) (tx *DB) {
  74. tx = db.getInstance()
  75. return
  76. }
  77. func (db *DB) FirstOrInit(out interface{}, where ...interface{}) (tx *DB) {
  78. tx = db.getInstance()
  79. return
  80. }
  81. // Delete delete value match given conditions, if the value has primary key, then will including the primary key as condition
  82. func (db *DB) Delete(value interface{}, where ...interface{}) (tx *DB) {
  83. tx = db.getInstance()
  84. return
  85. }
  86. func (db *DB) Related(value interface{}, foreignKeys ...string) (tx *DB) {
  87. tx = db.getInstance()
  88. return
  89. }
  90. func (db *DB) Transaction(fc func(tx *DB) error, opts ...*sql.TxOptions) (err error) {
  91. panicked := true
  92. tx := db.Begin(opts...)
  93. defer func() {
  94. // Make sure to rollback when panic, Block error or Commit error
  95. if panicked || err != nil {
  96. tx.Rollback()
  97. }
  98. }()
  99. err = fc(tx)
  100. if err == nil {
  101. err = tx.Commit().Error
  102. }
  103. panicked = false
  104. return
  105. }
  106. func (db *DB) Begin(opts ...*sql.TxOptions) (tx *DB) {
  107. tx = db.getInstance()
  108. return
  109. }
  110. func (db *DB) Commit() (tx *DB) {
  111. tx = db.getInstance()
  112. return
  113. }
  114. func (db *DB) Rollback() (tx *DB) {
  115. tx = db.getInstance()
  116. return
  117. }
  118. func (db *DB) Exec(sql string, values ...interface{}) (tx *DB) {
  119. tx = db.getInstance()
  120. return
  121. }
  122. func (db *DB) Association(column string) *Association {
  123. return nil
  124. }