Skip to main content

provider.go

provider.go - Overview

  1. Overview The provider.go file implements the sqlstore.SQLStore interface for PostgreSQL. It creates and configures connections to a PostgreSQL database using pgxpool, sqlx, and bun. It also provides methods to access the database connections and run transactions.

  2. Detailed Documentation

type provider

  • Purpose: Represents the PostgreSQL provider, holding database connection details and configurations.
  • Fields:
    • settings: factory.ScopedProviderSettings - Provider settings.
    • sqldb: *sql.DB - Standard sql.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 accepts hookFactories 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 creating sqlstore.SQLStore instances.

func New

  • Purpose: Creates a new PostgreSQL sqlstore.SQLStore instance. It configures and establishes connections using pgxpool, sqlx, and bun.
  • 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 new sqlstore.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 standard sql.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.
  1. Code Examples

None

  1. Clarity and Accuracy

The documentation accurately reflects the code's functionality.

  1. Markdown & MDX Perfection

No issues found.

  1. Edge Cases To Avoid Breaking MDX

No issues found.

  1. Getting Started Relevance

Include in Getting Started: NO