pgx

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(ctx context.Context, connURL string) (storage.Driver, error)

Types

type Bind

type Bind struct {
	sql.BindAbstract
	// contains filtered or unexported fields
}

func NewBind

func NewBind(
	conn pgpoolIface,
	dbnum int,
	syntax Syntax,
	pattern, getQuery, listQuery, upsertQuery, delQuery string,
	datatypesMapping []storage.DatatypeMapper,
) *Bind

NewBind create new sql bind instance for the specified database

func NewBindFromTableName

func NewBindFromTableName(
	conn pgpoolIface,
	dbnum int,
	syntax Syntax,
	pattern, tableName, whereExt string,
	datatypesMapping []storage.DatatypeMapper,
	readonly bool,
) *Bind

NewBindFromTableName create new sql bind instance for the specified database

func (*Bind) Del

func (b *Bind) Del(ctx context.Context, ectx keypattern.ExecContext) error

func (*Bind) Get

func (b *Bind) Get(ctx context.Context, ectx keypattern.ExecContext) (Record, error)

func (*Bind) List

func (b *Bind) List(ctx context.Context, ectx keypattern.ExecContext) ([]Record, error)

func (*Bind) Upsert

func (b *Bind) Upsert(ctx context.Context, ectx keypattern.ExecContext, value []byte) error

type DataFields

type DataFields = sql.DataFields

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

func (*Driver) Bind

func (pg *Driver) Bind(ctx context.Context, conf *storage.BindConfig) error

func (*Driver) Close

func (pg *Driver) Close() error

func (*Driver) Del

func (pg *Driver) Del(ctx context.Context, dbnum int, key string) error

func (*Driver) Get

func (pg *Driver) Get(ctx context.Context, dbnum int, key string) ([]byte, error)

func (*Driver) Keys

func (pg *Driver) Keys(ctx context.Context, dbnum int, pattern string) ([]string, error)

func (*Driver) List added in v0.9.0

func (pg *Driver) List(ctx context.Context, dbnum int, pattern string) ([]byte, error)

func (*Driver) ListenUpdateNotifies

func (pg *Driver) ListenUpdateNotifies(ctx context.Context, chanelName string, notifyFnk func(ctx context.Context, key string)) error

SQL Example: CREATE OR REPLACE FUNCTION notify_event() RETURNS TRIGGER AS $$

DECLARE
    data json;
    notification json;

BEGIN

    -- Convert the old or new row to JSON, based on the kind of action.
    -- Action = DELETE?             -> OLD row
    -- Action = INSERT or UPDATE?   -> NEW row
    IF (TG_OP = 'DELETE') THEN
        data = row_to_json(OLD);
    ELSE
        data = row_to_json(NEW);
    END IF;

    -- Contruct the notification as a JSON string.
    notification = json_build_object(
                      'table',TG_TABLE_NAME,
                      'action', TG_OP,
                      'data', data);

    -- Execute pg_notify(channel, notification)
    PERFORM pg_notify('redify_update', notification::text);

    -- Result is ignored since this is an AFTER trigger
    RETURN NULL;
END;

$$ LANGUAGE plpgsql;

CREATE TRIGGER products_notify_event AFTER INSERT OR UPDATE OR DELETE ON products

FOR EACH ROW EXECUTE PROCEDURE notify_event();

func (*Driver) Set

func (pg *Driver) Set(ctx context.Context, dbnum int, key string, value []byte) error

type Notification

type Notification struct {
	Table string          `json:"table"`
	Data  json.RawMessage `json:"data"`
}

type Record

type Record = storage.Record

type Syntax

type Syntax = sql.Syntax

type WhereStmt

type WhereStmt = sql.WhereStmt

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL