github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/db/db_local/notify.go (about) 1 package db_local 2 3 import ( 4 "context" 5 "encoding/json" 6 "fmt" 7 "log" 8 9 "github.com/jackc/pgx/v5" 10 "github.com/turbot/steampipe-plugin-sdk/v5/sperr" 11 "github.com/turbot/steampipe/pkg/constants" 12 ) 13 14 // SendPostgresNotification send a postgres notification that the schema has chganged 15 func SendPostgresNotification(_ context.Context, conn *pgx.Conn, notification any) error { 16 notificationBytes, err := json.Marshal(notification) 17 if err != nil { 18 return sperr.WrapWithMessage(err, "error marshalling Postgres notification") 19 } 20 21 log.Printf("[TRACE] Send update notification") 22 23 sql := fmt.Sprintf("select pg_notify('%s', $1)", constants.PostgresNotificationChannel) 24 _, err = conn.Exec(context.Background(), sql, notificationBytes) 25 if err != nil { 26 return sperr.WrapWithMessage(err, "error sending Postgres notification") 27 } 28 return nil 29 }