{"modulePath":"github.com/GoPlugin/Plugin","version":"v0.0.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package postgres\n\n## Constants\n\n```go\nconst (\n\tAdvisoryLockClassID_EthBroadcaster int32 = 0\n\tAdvisoryLockClassID_JobSpawner     int32 = 1\n\tAdvisoryLockClassID_EthConfirmer   int32 = 2\n\n\t// ORM takes lock on 1027321974924625846 which splits into ClassID 239192036, ObjID 2840971190\n\tAdvisoryLockClassID_ORM int32 = 239192036\n\n\tAdvisoryLockObjectID_EthConfirmer int32 = 0\n)\n```\nNOTE: All advisory lock class IDs used by the Chainlink application MUST be kept here to avoid accidental re-use\n\n```go\nconst (\n\tChannelJobCreated   = \"insert_on_jobs\"\n\tChannelJobDeleted   = \"delete_from_jobs\"\n\tChannelRunStarted   = \"pipeline_run_started\"\n\tChannelRunCompleted = \"pipeline_run_completed\"\n\n\t// Postgres channel to listen for new eth_txes\n\tChannelInsertOnEthTx = \"insert_on_eth_txes\"\n)\n```\n\n```go\nconst (\n\t// LockTimeout controls the max time we will wait for any kind of database lock.\n\t// It's good to set this to _something_ because waiting for locks forever is really bad.\n\tLockTimeout = 15 * time.Second\n\t// IdleInTxSessionTimeout controls the max time we leave a transaction open and idle.\n\t// It's good to set this to _something_ because leaving transactions open forever is really bad.\n\tIdleInTxSessionTimeout = 1 * time.Hour\n)\n```\nNOTE: In an ideal world the timeouts below would be set to something sane in the postgres configuration by the user. Since we do not live in an ideal world, it is necessary to override them here.\n\nThey cannot easily be set at a session level due to how Go's connection pooling works.\n\n```go\nconst DefaultQueryTimeout = 10 * time.Second\n```\n\n## Variables\n\n```go\nvar (\n\tDefaultSqlTxOptions = sql.TxOptions{\n\n\t\tIsolation: sql.LevelReadCommitted,\n\t}\n)\n```\n\n```go\nvar (\n\tErrNoDeadlineSet = errors.New(\"no deadline set\")\n)\n```\n\n## Functions\n\n```go\nfunc DBWithDefaultContext(db *gorm.DB, fc func(db *gorm.DB) error) error\n```\n\n```go\nfunc DefaultQueryCtx() (ctx context.Context, cancel context.CancelFunc)\n```\nDefaultQueryCtx returns a context with a sensible sanity limit timeout for SQL queries\n\n```go\nfunc GormTransaction(ctx context.Context, db *gorm.DB, fc func(tx *gorm.DB) error, txOptss ...sql.TxOptions) (err error)\n```\n\n```go\nfunc GormTransactionWithDefaultContext(db *gorm.DB, fc func(tx *gorm.DB) error, txOptss ...sql.TxOptions) error\n```\n\n```go\nfunc GormTransactionWithoutContext(db *gorm.DB, fc func(tx *gorm.DB) error, txOptss ...sql.TxOptions) (err error)\n```\nWARNING: Only use for nested txes inside ORM methods where you expect db to already have a ctx with a deadline.\n\n```go\nfunc IsSerializationAnomaly(err error) bool\n```\n\n```go\nfunc MustSQLDB(db *gorm.DB) *sql.DB\n```\n\n```go\nfunc MustSQLTx(db *gorm.DB) *sql.Tx\n```\nMustSQLDB panics if there is an error getting the underlying SQL TX\n\n```go\nfunc NewEventBroadcaster(uri url.URL, minReconnectInterval time.Duration, maxReconnectDuration time.Duration) *eventBroadcaster\n```\n\n## Types\n\n```go\ntype AdvisoryLocker interface {\n\tUnlock(ctx context.Context, classID int32, objectID int32) error\n\tWithAdvisoryLock(ctx context.Context, classID int32, objectID int32, f func() error) error\n\tClose() error\n}\n```\n\n```go\nfunc NewAdvisoryLock(uri url.URL) AdvisoryLocker\n```\n\n```go\ntype Event struct {\n\tChannel string\n\tPayload string\n}\n```\n\n```go\ntype EventBroadcaster interface {\n\tservice.Service\n\tSubscribe(channel, payloadFilter string) (Subscription, error)\n\tNotify(channel string, payload string) error\n\tNotifyInsideGormTx(tx *gorm.DB, channel string, payload string) error\n}\n```\nEventBroadcaster opaquely manages a collection of Postgres event listeners and broadcasts events to subscribers (with an optional payload filter).\n\n```go\ntype NullAdvisoryLocker struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc (n *NullAdvisoryLocker) Close() error\n```\n\n```go\nfunc (*NullAdvisoryLocker) Unlock(ctx context.Context, classID int32, objectID int32) error\n```\n\n```go\nfunc (*NullAdvisoryLocker) WithAdvisoryLock(ctx context.Context, classID int32, objectID int32, f func() error) error\n```\n\n```go\ntype NullEventBroadcaster struct{}\n```\nNullEventBroadcaster implements null pattern for event broadcaster\n\n```go\nfunc (*NullEventBroadcaster) Close() error\n```\n\n```go\nfunc (*NullEventBroadcaster) Healthy() error\n```\n\n```go\nfunc (*NullEventBroadcaster) Notify(channel string, payload string) error\n```\n\n```go\nfunc (*NullEventBroadcaster) NotifyInsideGormTx(tx *gorm.DB, channel string, payload string) error\n```\n\n```go\nfunc (*NullEventBroadcaster) Ready() error\n```\n\n```go\nfunc (*NullEventBroadcaster) Start() error\n```\n\n```go\nfunc (*NullEventBroadcaster) Subscribe(channel, payloadFilter string) (Subscription, error)\n```\n\n```go\ntype Subscription interface {\n\tEvents() \u003c-chan Event\n\tClose()\n\n\tChannelName() string\n\tInterestedIn(event Event) bool\n\tSend(event Event)\n}\n```\nSubscription represents a subscription to a Postgres event channel\n\n","path":"github.com/GoPlugin/Plugin/core/services/postgres","name":"postgres","synopsis":"","isRedistributable":true}
