oracle.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package database
  2. import "database/sql"
  3. type OracleDataBase struct {
  4. dbConn *sql.DB
  5. }
  6. func (a *OracleDataBase) Begin() (Tx, error) {
  7. tx, err := a.dbConn.Begin()
  8. if err != nil {
  9. return nil, err
  10. }
  11. return &SQLTxAdapter{tx: tx}, nil
  12. }
  13. func (a *OracleDataBase) Commit() error {
  14. // This is not applicable for sql.DB as it doesn't have a Commit method on the DB itself.
  15. // This method is here for interface consistency.
  16. return nil
  17. }
  18. func (a *OracleDataBase) Rollback() error {
  19. // This is not applicable for sql.DB as it doesn't have a Rollback method on the DB itself.
  20. // This method is here for interface consistency.
  21. return nil
  22. }
  23. func (a *OracleDataBase) Exec(query string, args ...interface{}) (sql.Result, error) {
  24. return a.dbConn.Exec(query, args...)
  25. }
  26. func (a *OracleDataBase) Query(query string, args ...interface{}) (*sql.Rows, error) {
  27. return a.dbConn.Query(query, args...)
  28. }
  29. type SQLTxAdapter struct {
  30. tx *sql.Tx
  31. }
  32. func (t *SQLTxAdapter) Commit() error {
  33. return t.tx.Commit()
  34. }
  35. func (t *SQLTxAdapter) Rollback() error {
  36. return t.tx.Rollback()
  37. }
  38. func (t *SQLTxAdapter) Exec(query string, args ...interface{}) (sql.Result, error) {
  39. return t.tx.Exec(query, args...)
  40. }
  41. func (t *SQLTxAdapter) Query(query string, args ...interface{}) (*sql.Rows, error) {
  42. return t.tx.Query(query, args...)
  43. }