Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var GetDeltaPath = func() (string, error) { cwd, err := os.Getwd() if err != nil { return "", &errschemer.SchemerErr{ Code: "0011", Message: "failed to get current working.", Err: err, } } return filepath.Join(cwd, "deltas"), nil }
GetDeltaPath returns the absolute path to the deltas directory. Assumes the deltas directory is located in the current working directory.
Returns:
- string: full path to the deltas directory
- error: non-nil if the current working directory cannot be resolved
var WithConn = func(connString string, fn func(*pgx.Conn, context.Context) error) error { ctx := context.Background() connection, err := pgx.Connect(ctx, connString) if err != nil { return &er.SchemerErr{ Code: "0008", Message: "failed to conntect with database.", Err: err, } } defer connection.Close(ctx) return fn(connection, ctx) }
WithConn establishes a pgx connection and executes the provided function with it. Automatically handles connection opening, context setup, and deferred closing.
Params:
- connString: PostgreSQL connection string
- fn: a callback function that receives the opened connection and context
Returns:
- error: any error encountered during connection or from the callback execution
Functions ¶
func ConnectDatabase ¶
ConnectDatabase opens and verifies a PostgreSQL connection using the given connection string. Uses the pgx driver and ensures the connection is valid by performing a ping.
Params:
- connString: PostgreSQL connection string
Returns:
- *sql.DB: an open and verified database connection
- error: non-nil if connection or ping fails
func CreateSchemerTable ¶
CreateSchemerTable creates the schemer tracking table if it does not already exist. Reads the table schema from schemer.sql located in the deltas directory.
Params:
- database: pointer to an open pgx.Conn
- ctx: context for executing the database operations
Returns:
- error: non-nil if the table check, file read, or table creation fails
func LoadDotEnv ¶
LoadDotEnv attempts to load environment variables from a .env file in the current directory. Logs a message if the file is missing (which is expected in production).
Returns:
- bool: true if the .env file was successfully loaded; false if it was not found
- error: non-nil if an error occurred while attempting to read the file (other than not found)
Types ¶
This section is empty.