import "github.com/egdaemon/eg/runtime/x/wasi/egpostgresql"
Package egpostgresql provides functionality for setting up a postgresql service within eg environments. Specifically allows for waiting for the postgresql service to become available and configuring local access.
func Auto(ctx context.Context, _ eg.Op) (err error)
Wait for postgresql to become available and then configure the instance for use by root and egd users.
package main
import (
"context"
"log"
"github.com/egdaemon/eg/runtime/wasi/eg"
"github.com/egdaemon/eg/runtime/x/wasi/egpostgresql"
)
func main() {
var (
err error
)
ctx := context.Background()
err = eg.Perform(
ctx,
egpostgresql.Auto, // wait for postgresql to become ready
egpostgresql.RecreateDatabase("example"), // create a database.
egpostgresql.InsertSuperuser("soandso"), // create a superuser to use.
)
if err != nil {
log.Fatalln(err)
}
}
func AutoLocatePort(ctx context.Context) int
attempts to determine what port postgresql is listening on
func Environ() []string
build a environment that sets up postgresql the standard postgresql variables.
func InsertSuperuser(name string) eg.OpFn
Create a superuser with the provided name.
func LocatePort(ctx context.Context, begin, end int) int
determine what port postgresql is listening on within a given range. if it can't determine the port it returns the default pg port 5432.
func RecreateDatabase(name string) eg.OpFn
Forcibly recreate a database.
func Restart(cmd string) eg.OpFn
command to restart postgresql
func Runtime() shell.Command
Create a shell runtime that properly sets up the postgresql environment.
func TestArchive() fs.FS
func Trust(v ...netip.Prefix) eg.OpFn
Add additional cidrs to hba.conf
func TrustHost() eg.OpFn
TrustHost configures postgresql's hba.conf to trust connections from the host machine as well as all IPv4 and IPv6 networks. This is intended for exposing a sandboxed postgresql instance to the host machine during local development and should not be used in environments reachable beyond the host.