provider.go
provider.go - Overview
-
Overview The
provider.go
file implements thesqlstore.SQLStore
interface for PostgreSQL. It creates and configures connections to a PostgreSQL database usingpgxpool
,sqlx
, andbun
. It also provides methods to access the database connections and run transactions. -
Detailed Documentation
type provider
- Purpose: Represents the PostgreSQL provider, holding database connection details and configurations.
- Fields:
settings
:factory.ScopedProviderSettings
- Provider settings.sqldb
:*sql.DB
- Standardsql.DB
connection.bundb
:*sqlstore.BunDB
- Bun ORM database connection.sqlxdb
:*sqlx.DB
- Sqlx database connection.dialect
:*dialect
- SQL dialect specific to PostgreSQL.
func NewFactory
- Purpose: Creates a
factory.ProviderFactory
for the PostgreSQL SQL store, allowing integration with a factory pattern. It also acceptshookFactories
to create hooks. - Parameters:
hookFactories
:...factory.ProviderFactory[sqlstore.SQLStoreHook, sqlstore.Config]
- Variadic list of provider factories for SQL store hooks.
- Returns:
factory.ProviderFactory[sqlstore.SQLStore, sqlstore.Config]
- A provider factory for creatingsqlstore.SQLStore
instances.
func New
- Purpose: Creates a new PostgreSQL
sqlstore.SQLStore
instance. It configures and establishes connections usingpgxpool
,sqlx
, andbun
. - Parameters:
ctx
:context.Context
- Context for managing the operation.providerSettings
:factory.ProviderSettings
- Provider settings.config
:sqlstore.Config
- Configuration containing PostgreSQL connection details.hooks
:...sqlstore.SQLStoreHook
- Variadic list of SQL store hooks.
- Returns:
(sqlstore.SQLStore, error)
- A newsqlstore.SQLStore
instance and an error, if any.
func (*provider) BunDB
- Purpose: Returns the
bun.DB
instance. - Parameters: None
- Returns:
*bun.DB
- The Bun ORM database connection.
func (*provider) SQLDB
- Purpose: Returns the standard
sql.DB
instance. - Parameters: None
- Returns:
*sql.DB
- The standardsql.DB
connection.
func (*provider) SQLxDB
- Purpose: Returns the
sqlx.DB
instance. - Parameters: None
- Returns:
*sqlx.DB
- The Sqlx database connection.
func (*provider) Dialect
- Purpose: Returns the
sqlstore.SQLDialect
instance. - Parameters: None
- Returns:
sqlstore.SQLDialect
- The SQL dialect.
func (*provider) BunDBCtx
- Purpose: Returns a
bun.IDB
instance with the given context. - Parameters:
ctx
:context.Context
- The context.
- Returns:
bun.IDB
- A Bun database instance with context.
func (*provider) RunInTxCtx
- Purpose: Executes a callback function
cb
within a database transaction with the given context and transaction options. - Parameters:
ctx
:context.Context
- The context.opts
:*sql.TxOptions
- Transaction options.cb
:func(ctx context.Context) error
- The callback function to execute within the transaction.
- Returns:
error
- An error, if any occurred during the transaction.
- Code Examples
None
- Clarity and Accuracy
The documentation accurately reflects the code's functionality.
- Markdown & MDX Perfection
No issues found.
- Edge Cases To Avoid Breaking MDX
No issues found.
- Getting Started Relevance
Include in Getting Started: NO