Skip to main content

provider.go

provider.go - Overview

  1. Overview This file implements a sqlstore.SQLStore provider for SQLite databases. It handles the creation and configuration of connections to a SQLite database using the go-sqlite3 driver, sqlx, and bun ORM. It also sets up database connection pooling and provides access to the underlying database connections and dialect.

  2. Detailed Documentation

type provider

  • Purpose: Represents the SQLite SQLStore provider. It holds the database connections, settings, and dialect information.
  • Fields:
    • settings (factory.ScopedProviderSettings): Provider settings including logger.
    • sqldb (*sql.DB): The standard Go SQL database connection.
    • bundb (*sqlstore.BunDB): Bun ORM database connection.
    • sqlxdb (*sqlx.DB): SQLx database connection.
    • dialect (*dialect): The SQL dialect implementation for SQLite.

func NewFactory

  • Purpose: Creates a new factory.ProviderFactory for the SQLite SQLStore provider.
  • Parameters:
    • hookFactories ([]factory.ProviderFactory[sqlstore.SQLStoreHook, sqlstore.Config]): A slice of factories for creating sqlstore.SQLStoreHook instances.
  • Returns:
    • factory.ProviderFactory[sqlstore.SQLStore, sqlstore.Config]: A factory that creates sqlstore.SQLStore instances.

func New

  • Purpose: Creates a new SQLite SQLStore provider.
  • Parameters:
    • ctx (context.Context): The context for the operation.
    • providerSettings (factory.ProviderSettings): The settings for the provider.
    • config (sqlstore.Config): The configuration for the SQLStore.
    • hooks (...sqlstore.SQLStoreHook): Optional hooks to be applied to the SQLStore.
  • Returns:
    • sqlstore.SQLStore: The new SQLite SQLStore provider.
    • error: An error if the provider could not be created.

func (*provider) BunDB

  • Purpose: Returns the Bun ORM database connection.
  • Parameters:
    • provider (*provider): The provider instance.
  • Returns:
    • *bun.DB: The Bun database connection.

func (*provider) SQLDB

  • Purpose: Returns the standard Go SQL database connection.
  • Parameters:
    • provider (*provider): The provider instance.
  • Returns:
    • *sql.DB: The SQL database connection.

func (*provider) SQLxDB

  • Purpose: Returns the SQLx database connection.
  • Parameters:
    • provider (*provider): The provider instance.
  • Returns:
    • *sqlx.DB: The SQLx database connection.

func (*provider) Dialect

  • Purpose: Returns the SQL dialect for SQLite.
  • Parameters:
    • provider (*provider): The provider instance.
  • Returns:
    • sqlstore.SQLDialect: The SQL dialect.

func (*provider) BunDBCtx

  • Purpose: Returns a Bun database connection with the given context.
  • Parameters:
    • ctx (context.Context): The context for the database operation.
    • provider (*provider): The provider instance.
  • Returns:
    • bun.IDB: The Bun database connection with context.

func (*provider) RunInTxCtx

  • Purpose: Executes a callback function within a database transaction.
  • Parameters:
    • ctx (context.Context): The context for the transaction.
    • opts (*sql.TxOptions): Transaction options.
    • cb (func(ctx context.Context) error): The callback function to execute within the transaction.
    • provider (*provider): The provider instance.
  • Returns:
    • error: An error if the transaction fails.
  1. Code Examples

No examples are necessary as the code is self-explanatory.

  1. Clarity and Accuracy

The documentation is based solely on the code provided.

  1. Markdown & MDX Perfection

The markdown syntax is correct.

  1. Edge Cases To Avoid Breaking MDX:

All edge cases are avoided.

  1. Getting Started Relevance Include in Getting Started: YES