Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conf ¶
type Conf struct { Driver string `yaml:"driver"` // Database driver (e.g., "mysql", "postgres", etc.). DSN string `yaml:"dsn"` // Data Source Name (DSN) for connecting to the database. }
Conf represents the configuration structure for opening a connection to the database. It includes fields for specifying the database driver and Data Source Name (DSN) for connecting to the database.
type Connector ¶
Connector is a struct representing a database connector. It embeds a *sql.DB to provide the functionalities of a SQL database connection.
func FactoryConnector ¶
FactoryConnector creates and returns a new *Connector by opening a connection to the SQL database using the provided Conf configuration. It returns the initialized Connector and an error if the connection cannot be established. The function uses the database driver and Data Source Name (DSN) specified in the configuration.
func (*Connector) Commit ¶
Commit commits the provided SQL transaction. It takes a *sql.Tx parameter and attempts to commit the transaction. If the commit is successful, the function returns nil; otherwise, it returns an error with relevant information.
func (*Connector) Exec ¶
Exec executes the provided SQL query within the specified transaction. It takes a *sql.Tx, a query string, and optional query arguments. The function prepares the query, executes the prepared statement with the given arguments, and returns the sql.Result. If any error occurs during preparation or execution, the function returns an error with relevant information.
func (*Connector) ExecQueryRow ¶
ExecQueryRow executes the provided SQL query within the specified transaction and returns a *sql.Row representing the result. It takes a *sql.Tx, a query string, and optional query arguments. The function prepares the query, creates a *sql.Row with the prepared statement and the given arguments, and returns it. If any error occurs during preparation, the function returns an error with relevant information.
func (*Connector) TryConnection ¶
TryConnection attempts to establish a connection to the SQL database by repeatedly pinging it within a specified time duration. It takes an integer parameter 't' representing the maximum time duration in seconds for attempting the connection. The function returns an error if the connection cannot be established within the specified time or if an error occurs during the connection attempt.