Skip to content

Commit

Permalink
converted *sql.DB to use dblike interface instead, added transactionl…
Browse files Browse the repository at this point in the history
…ike for scheme
  • Loading branch information
Kansuler committed May 13, 2022
1 parent 2e3fd50 commit 40f19f9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions octobe.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@ type dblike interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

type transactionlike interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}

// Octobe struct that holds the database session
type Octobe struct {
// DB is the database instance
DB *sql.DB
DB dblike
}

// Option interface that tells what type of option it is
Expand All @@ -30,7 +37,7 @@ type option struct {
}

// New initiates a DB instance and connection.
func New(db *sql.DB) Octobe {
func New(db dblike) Octobe {
return Octobe{DB: db}
}

Expand All @@ -42,7 +49,7 @@ var ErrNeedInput = errors.New("insert method require at least one argument")

// Scheme holds context for the duration of the operation
type Scheme struct {
db dblike
db transactionlike
// ctx is a context that can be used to interrupt a query
ctx context.Context
}
Expand Down Expand Up @@ -85,7 +92,7 @@ type Segment struct {
// used specify if this segment already has been executed
used bool
// tx is the database transaction, initiated by BeginTx
db dblike
db transactionlike
// ctx is a context that can be used to interrupt a query
ctx context.Context
}
Expand Down

0 comments on commit 40f19f9

Please sign in to comment.