Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify SQL DB migration subsystem (for Postgres and SQLite) #3134

Merged
merged 12 commits into from
Sep 20, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,23 @@ import (

"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"

"github.com/dapr/components-contrib/state"
)

// dbAccess is a private interface which enables unit testing of PostgreSQL.
type dbAccess interface {
Init(ctx context.Context, metadata state.Metadata) error
Set(ctx context.Context, req *state.SetRequest) error
Get(ctx context.Context, req *state.GetRequest) (*state.GetResponse, error)
BulkGet(ctx context.Context, req []state.GetRequest) ([]state.BulkGetResponse, error)
Delete(ctx context.Context, req *state.DeleteRequest) error
ExecuteMulti(ctx context.Context, req *state.TransactionalStateRequest) error
Query(ctx context.Context, req *state.QueryRequest) (*state.QueryResponse, error)
Close() error // io.Closer
}

// Interface that contains methods for querying.
// Applies to *pgx.Conn, *pgxpool.Pool, and pgx.Tx
type dbquerier interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
}

// Interface that applies to *pgxpool.Pool.
// We need this to be able to mock the connection in tests.
type PGXPoolConn interface {
dbquerier

Begin(context.Context) (pgx.Tx, error)
BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
Ping(context.Context) error
Close()
}
Loading