cloudypg

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 17 Imported by: 0

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

View Source
const PostgresProviderID = "postgresql"

Variables

This section is empty.

Functions

func ConnectionString added in v0.0.9

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

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 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(c *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) 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 PostgreSqlConfig

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

func ConfigFromEnv

func ConfigFromEnv(env *cloudy.Environment) (*PostgreSqlConfig, error)

func ConfigFromMap

func ConfigFromMap(m map[string]interface{}) (*PostgreSqlConfig, error)

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) ForTable

func (cfg *PostgreSqlConfig) ForTable(table string) *PostgreSqlConfig

func (*PostgreSqlConfig) GetConnectionString

func (cfg *PostgreSqlConfig) GetConnectionString() string

type PostgreSqlJsonDataStore

type PostgreSqlJsonDataStore[T any] struct {

	// client           *pgx.Conn
	Database string

	ConnectionKey pgContextKey
	// contains filtered or unexported fields
}

func NewPostgreSqlJsonDataStore

func NewPostgreSqlJsonDataStore[T any](ctx context.Context, config *PostgreSqlConfig) *PostgreSqlJsonDataStore[T]

func (*PostgreSqlJsonDataStore[T]) Check

func (m *PostgreSqlJsonDataStore[T]) Check(ctx context.Context) error

func (*PostgreSqlJsonDataStore[T]) Close

func (m *PostgreSqlJsonDataStore[T]) Close(ctx context.Context) error

func (*PostgreSqlJsonDataStore[T]) Delete

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

func (*PostgreSqlJsonDataStore[T]) Exists

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

func (*PostgreSqlJsonDataStore[T]) Get

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

func (*PostgreSqlJsonDataStore[T]) GetAll

func (m *PostgreSqlJsonDataStore[T]) GetAll(ctx context.Context) ([]*T, error)

func (*PostgreSqlJsonDataStore[T]) NewConnectionContext

func (m *PostgreSqlJsonDataStore[T]) NewConnectionContext(ctx context.Context) (context.Context, error)

For Transactions and long operations with the datastore consider Creating a new context with the connection stored as an attribute This will keep the connection from being returned to the pool If you do this you must explicitly end the connection.

TODO: Determine if this should be safe to call multiple times. If

so then we need a reference counter or something

func (*PostgreSqlJsonDataStore[T]) OnCreate

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

func (*PostgreSqlJsonDataStore[T]) Open

func (m *PostgreSqlJsonDataStore[T]) Open(ctx context.Context, config interface{}) error

func (*PostgreSqlJsonDataStore[T]) Query

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

func (*PostgreSqlJsonDataStore[T]) ReturnConnectionContext

func (m *PostgreSqlJsonDataStore[T]) ReturnConnectionContext(ctx context.Context)

func (*PostgreSqlJsonDataStore[T]) Save

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

Save an item to the MongoDB. This is implemented as an Upsert to this will work for new items as well as updates.

type PostgreSqlJsonDataStoreFactory added in v0.0.9

type PostgreSqlJsonDataStoreFactory struct {
	PostgreSqlConfig
}

func (*PostgreSqlJsonDataStoreFactory) Create added in v0.0.9

func (*PostgreSqlJsonDataStoreFactory) CreateJsonDatastore added in v0.0.9

func (c *PostgreSqlJsonDataStoreFactory) CreateJsonDatastore(ctx context.Context, typename string, prefix string, idField string) datastore.UntypedJsonDataStore

func (*PostgreSqlJsonDataStoreFactory) FromEnv added in v0.0.9

func (c *PostgreSqlJsonDataStoreFactory) FromEnv(env *cloudy.Environment) (interface{}, error)

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 UntypedPostgreSqlConfig

type UntypedPostgreSqlConfig struct {
	PostgreSqlConfig
}

type UntypedPostgreSqlJsonDataStore

type UntypedPostgreSqlJsonDataStore struct {
	ConnectionKey pgContextKey
	// contains filtered or unexported fields
}

func NewUntypedPostgreSqlJsonDataStoreWithProvider added in v0.0.9

func NewUntypedPostgreSqlJsonDataStoreWithProvider(ctx context.Context, table string, provider PostgresqlConnectionProvider) *UntypedPostgreSqlJsonDataStore

func (*UntypedPostgreSqlJsonDataStore) Close

func (*UntypedPostgreSqlJsonDataStore) Delete

func (*UntypedPostgreSqlJsonDataStore) Exists

func (*UntypedPostgreSqlJsonDataStore) Get

func (*UntypedPostgreSqlJsonDataStore) GetAll

func (*UntypedPostgreSqlJsonDataStore) NewConnectionContext

func (m *UntypedPostgreSqlJsonDataStore) NewConnectionContext(ctx context.Context) (context.Context, error)

For Transactions and long operations with the datastore consider Creating a new context with the connection stored as an attribute This will keep the connection from being returned to the pool If you do this you must explicitly end the connection.

TODO: Determine if this should be safe to call multiple times. If

so then we need a reference counter or something

SAME

func (*UntypedPostgreSqlJsonDataStore) OnCreate

func (*UntypedPostgreSqlJsonDataStore) Open

func (m *UntypedPostgreSqlJsonDataStore) Open(ctx context.Context, config interface{}) error

SAME

func (*UntypedPostgreSqlJsonDataStore) Query

func (*UntypedPostgreSqlJsonDataStore) ReturnConnectionContext

func (m *UntypedPostgreSqlJsonDataStore) ReturnConnectionContext(ctx context.Context)

func (*UntypedPostgreSqlJsonDataStore) Save

func (m *UntypedPostgreSqlJsonDataStore) Save(ctx context.Context, item []byte, key string) error

Save an item to the MongoDB. This is implemented as an Upsert to this will work for new items as well as updates.

Jump to

Keyboard shortcuts

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