cloudypg

package module
v0.0.24 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cloudy-pg

Postgresql implementation of Cloudy providers

Example

go get "github.com/cloudy-pg"

package main

import (
    "github.com/cloudy-pg"
    "github.com/cloudy"
)

func main() {
    ctx := cloudy.StartContext()

    localPG := "postgres://postgres:admin@localhost:5432/postgres"
    pgConfig := &PostgreSqlConfig{
        Connection: localPG,
        Database:   "sample",
        Table:      "sample",
    }

	ds := NewPostgreSqlJsonDataStore[tests.TestItem](ctx, pgConfig)

    testDoc := &TestItem{
		ID:   "12345",
		Name: "TEST",
	}

    fmt.Println("Saving")
	err := ds.Save(ctx, testDoc, testDoc.ID)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnStringFrom added in v0.0.14

func ConnStringFrom(ctx context.Context, cfg *PostgreSqlConfig) string

func Connect added in v0.0.12

func Connect(ctx context.Context, cfg *PostgreSqlConfig) (*pgx.Conn, error)

func ConnectionString added in v0.0.9

func ConnectionString(host string, user string, password string, database string, port ...int) string

func RemoveNullBytes added in v0.0.24

func RemoveNullBytes(data []byte) []byte

func SanitizeConnectionString

func SanitizeConnectionString(connectionString string) string

Types

type DedicatedPostgreSQLConnectionProvider added in v0.0.9

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

func NewDedicatedPostgreSQLConnectionProvider added in v0.0.9

func NewDedicatedPostgreSQLConnectionProvider(connstr string) *DedicatedPostgreSQLConnectionProvider

func (*DedicatedPostgreSQLConnectionProvider) Acquire added in v0.0.9

Acquire A connection

func (*DedicatedPostgreSQLConnectionProvider) Close added in v0.0.9

func (*DedicatedPostgreSQLConnectionProvider) Connect added in v0.0.9

func (*DedicatedPostgreSQLConnectionProvider) Return added in v0.0.9

Return a connection

type JsonDataStore added in v0.0.14

type JsonDataStore[T any] struct {
	ConnectionKey pgContextKey
	// contains filtered or unexported fields
}

func NewJsonDatastore added in v0.0.14

func NewJsonDatastore[T any](ctx context.Context, provider PostgresqlConnectionProvider, table string) *JsonDataStore[T]

func (*JsonDataStore[T]) Close added in v0.0.14

func (ds *JsonDataStore[T]) Close(ctx context.Context) error

Close should be called to cleanly close the datastore

func (*JsonDataStore[T]) Count added in v0.0.14

func (ds *JsonDataStore[T]) Count(ctx context.Context, query *datastore.SimpleQuery) (int, error)

func (*JsonDataStore[T]) CtxGetConnection added in v0.0.18

func (ds *JsonDataStore[T]) CtxGetConnection(ctx context.Context) *pgxpool.Conn

func (*JsonDataStore[T]) CtxSetConnection added in v0.0.18

func (ds *JsonDataStore[T]) CtxSetConnection(ctx context.Context, conn *pgxpool.Conn) context.Context

func (*JsonDataStore[T]) Delete added in v0.0.14

func (ds *JsonDataStore[T]) Delete(ctx context.Context, key string) error

Deletes an item

func (*JsonDataStore[T]) DeleteAll added in v0.0.21

func (ds *JsonDataStore[T]) DeleteAll(ctx context.Context, key []string) error

Deletes an item

func (*JsonDataStore[T]) DeleteQuery added in v0.0.21

func (m *JsonDataStore[T]) DeleteQuery(ctx context.Context, query *datastore.SimpleQuery) ([]string, error)

func (*JsonDataStore[T]) Exists added in v0.0.14

func (ds *JsonDataStore[T]) Exists(ctx context.Context, key string) (bool, error)

Checks to see if a key exists

func (*JsonDataStore[T]) Get added in v0.0.14

func (ds *JsonDataStore[T]) Get(ctx context.Context, key string) (*T, error)

Get retrieves an item by it's unique id

func (*JsonDataStore[T]) GetAll added in v0.0.14

func (ds *JsonDataStore[T]) GetAll(ctx context.Context) ([]*T, error)

Gets all the items in the store.

func (*JsonDataStore[T]) GetMetadata added in v0.0.24

func (ds *JsonDataStore[T]) GetMetadata(ctx context.Context, key ...string) ([]*datastore.RowMetadata, error)

func (*JsonDataStore[T]) OnCreate added in v0.0.24

func (ds *JsonDataStore[T]) OnCreate(fn func(ctx context.Context, ds datastore.JsonDataStore[T]) error)

DONT USE THIS

func (*JsonDataStore[T]) Open added in v0.0.14

func (ds *JsonDataStore[T]) Open(ctx context.Context, config any) error

Open will open the datastore for usage. This should only be done once per datastore

func (*JsonDataStore[T]) Query added in v0.0.14

func (ds *JsonDataStore[T]) Query(ctx context.Context, query *datastore.SimpleQuery) ([]*T, error)

Sends a simple Query

func (*JsonDataStore[T]) QueryAndUpdate added in v0.0.14

func (ds *JsonDataStore[T]) QueryAndUpdate(ctx context.Context, query *datastore.SimpleQuery, updater func(ctx context.Context, items []*T) ([]*T, error)) ([]*T, error)

func (*JsonDataStore[T]) QueryAsMap added in v0.0.14

func (ds *JsonDataStore[T]) QueryAsMap(ctx context.Context, query *datastore.SimpleQuery) ([]map[string]any, error)

func (*JsonDataStore[T]) QueryTable added in v0.0.14

func (ds *JsonDataStore[T]) QueryTable(ctx context.Context, query *datastore.SimpleQuery) ([][]interface{}, error)

func (*JsonDataStore[T]) Save added in v0.0.14

func (ds *JsonDataStore[T]) Save(ctx context.Context, item *T, key string) error

Save stores an item in the datastore. There is no difference between an insert and an update.

func (*JsonDataStore[T]) SaveAll added in v0.0.21

func (m *JsonDataStore[T]) SaveAll(ctx context.Context, items []*T, key []string) error

type KeyValueStore added in v0.0.12

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

func NewKeyValueStore added in v0.0.12

func NewKeyValueStore(ctx context.Context, tablename string, conn *pgx.Conn) (*KeyValueStore, error)

func NewSecretKeyValueStore added in v0.0.12

func NewSecretKeyValueStore(ctx context.Context, tablename string, conn *pgx.Conn, encryptionKey string) (*KeyValueStore, error)

func (*KeyValueStore) Delete added in v0.0.12

func (kv *KeyValueStore) Delete(key string) error

func (*KeyValueStore) Get added in v0.0.12

func (kv *KeyValueStore) Get(key string) (string, error)

--- KeyValueStore

func (*KeyValueStore) GetAll added in v0.0.12

func (kv *KeyValueStore) GetAll() (map[string]string, error)

func (*KeyValueStore) GetSecure added in v0.0.12

func (kv *KeyValueStore) GetSecure(key string) (strfmt.Password, error)

func (*KeyValueStore) GetWithPrefix added in v0.0.12

func (kv *KeyValueStore) GetWithPrefix(prefix string) (map[string]string, error)

--- FilteredKeyValueStore

func (*KeyValueStore) Init added in v0.0.12

func (kv *KeyValueStore) Init(ctx context.Context) error

func (*KeyValueStore) Set added in v0.0.12

func (kv *KeyValueStore) Set(key string, value string) error

--- WritableKeyValueStore

func (*KeyValueStore) SetMany added in v0.0.12

func (kv *KeyValueStore) SetMany(items map[string]string) error

func (*KeyValueStore) SetSecure added in v0.0.12

func (kv *KeyValueStore) SetSecure(key string, value strfmt.Password) error

type PgLeader added in v0.0.9

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

func NewPgLeader added in v0.0.9

func NewPgLeader() *PgLeader

func (*PgLeader) Connect added in v0.0.9

func (pgl *PgLeader) Connect(cfg interface{}) error

func (*PgLeader) ConnectPg added in v0.0.9

func (pgl *PgLeader) ConnectPg(cfg *PostgreSqlConfig) error

func (*PgLeader) ConnectStr added in v0.0.9

func (pgl *PgLeader) ConnectStr(connStr string) error

func (*PgLeader) Elect added in v0.0.9

func (pgl *PgLeader) Elect(onElection func(isLeader bool))

func (*PgLeader) IsLeader added in v0.0.9

func (pgl *PgLeader) IsLeader() bool

type PgQueryConverter

type PgQueryConverter struct {
}

func (*PgQueryConverter) Convert

func (qc *PgQueryConverter) Convert(q *datastore.SimpleQuery, table string) string

func (*PgQueryConverter) ConvertASort

func (qc *PgQueryConverter) ConvertASort(c *datastore.SortBy) string

func (*PgQueryConverter) ConvertCondition

func (qc *PgQueryConverter) ConvertCondition(c *datastore.SimpleQueryCondition) string

func (*PgQueryConverter) ConvertConditionGroup

func (qc *PgQueryConverter) ConvertConditionGroup(cg *datastore.SimpleQueryConditionGroup) string

func (*PgQueryConverter) ConvertDelete added in v0.0.21

func (qc *PgQueryConverter) ConvertDelete(q *datastore.SimpleQuery, table string) string

func (*PgQueryConverter) ConvertSelect

func (qc *PgQueryConverter) ConvertSelect(c *datastore.SimpleQuery, table string) string

func (*PgQueryConverter) ConvertSort

func (qc *PgQueryConverter) ConvertSort(sortbys []*datastore.SortBy) string

func (*PgQueryConverter) ToColumnName

func (qc *PgQueryConverter) ToColumnName(name string) string

type PgxConnection added in v0.0.14

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

func (*PgxConnection) Acquire added in v0.0.14

func (pgxc *PgxConnection) Acquire(ctx context.Context) (*pgxpool.Conn, error)

Acquire A connection

func (*PgxConnection) Close added in v0.0.14

func (pgxc *PgxConnection) Close(ctx context.Context) error

Close Database

func (*PgxConnection) Return added in v0.0.14

func (pgxc *PgxConnection) Return(ctx context.Context, conn *pgxpool.Conn)

Return a connection

type PostgreSqlConfig

type PostgreSqlConfig struct {
	Table      string
	Connection string
	User       string
	Host       string
	Password   string
	Database   string
	Port       uint16
}

func CreateDefaultPostgresqlContainer added in v0.0.9

func CreateDefaultPostgresqlContainer(t *testing.T) *PostgreSqlConfig

func CreatePostgresqlContainer added in v0.0.9

func CreatePostgresqlContainer(t *testing.T, config *PostgreSqlConfig) *PostgreSqlConfig

func (*PostgreSqlConfig) GetConnectionString

func (cfg *PostgreSqlConfig) GetConnectionString() string

type PostgresqlConnectionProvider added in v0.0.9

type PostgresqlConnectionProvider interface {
	// Acquire A connection
	Acquire(ctx context.Context) (*pgxpool.Conn, error)

	// Return a connection
	Return(ctx context.Context, conn *pgxpool.Conn)

	// Close Database
	Close(ctx context.Context) error
}

type SecureKeyValueStore added in v0.0.24

type SecureKeyValueStore struct {
	KeyValueStore
}

Jump to

Keyboard shortcuts

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