pgsql

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IT_TEXT     = "text"
	IT_TEXTAREA = "textarea"
	IT_NUMBER   = "number"
	IT_CHECKBOX = "checkbox"
	IT_DATETIME = "datetime-local"
	IT_SELECT   = "select"
)

Variables

This section is empty.

Functions

func NewPgSQLDatabase

func NewPgSQLDatabase(ctx context.Context, secretProvider secret.SecretProvider, idGenerator port.BigintGenerator) (data.DatabaseRepository, error)

Types

type QueryServicePgsql

type QueryServicePgsql struct {
	Client      *pgxpool.Pool
	Queries     map[string]string
	IdGenerator port.BigintGenerator
}

func (*QueryServicePgsql) GenID

func (s *QueryServicePgsql) GenID() int64

func (*QueryServicePgsql) Query

func (s *QueryServicePgsql) Query(ctx context.Context, queryName string, args ...any) (*model.QueryResult, error)

type RepositoryPgsql

type RepositoryPgsql struct {
	data.AbstractRepository
	Secrets secret.SecretProvider
	Client  *pgxpool.Pool
}

func (*RepositoryPgsql) BeginTx

func (r *RepositoryPgsql) BeginTx(ctx context.Context, queries map[string]string) (data.TxQueryService, error)

func (*RepositoryPgsql) Connect

func (r *RepositoryPgsql) Connect(ctx context.Context) error

func (*RepositoryPgsql) CreateTableService

func (r *RepositoryPgsql) CreateTableService(ctx context.Context, table *model.TableDefinition) data.TableService

func (*RepositoryPgsql) GetQueryService

func (r *RepositoryPgsql) GetQueryService(ctx context.Context, queries map[string]string) data.QueryService

func (*RepositoryPgsql) LoadColumns

func (r *RepositoryPgsql) LoadColumns(ctx context.Context) (map[string][]*model.TableColumn, error)

func (*RepositoryPgsql) RunInTx

func (r *RepositoryPgsql) RunInTx(ctx context.Context, fn func(view data.TxView) error) (err error)

RunInTx runs fn inside a Postgres transaction. The TxView passed to fn yields tx-bound copies of every TableService registered on the repository, so multi-table writes (RelationAPI.Post's parent + children batch) all land in the same transaction.

Commits on a nil return; rolls back on any error or panic. The rollback path uses a fresh background context so a parent-context cancellation during fn doesn't also block the rollback itself.

type TableServicePgsql

type TableServicePgsql struct {
	data.AbstractTableService
	// Client is a pgxQuerier — usually a *pgxpool.Pool, but inside a
	// RunInTx callback Client is a pgx.Tx so the same struct can drive
	// either pooled or transactional writes. Keep this as an
	// interface, not a concrete type — the interface widening was
	// the whole point of the v0.4.2 P1-35 refactor.
	Client pgxQuerier
	Schema string
	// contains filtered or unexported fields
}

func (*TableServicePgsql) Delete

func (s *TableServicePgsql) Delete(ctx context.Context, partnerID int64, userID int, where map[string]any) error

func (*TableServicePgsql) Get

func (s *TableServicePgsql) Get(ctx context.Context, partnerID int64, userID int, where map[string]any, orderby string) ([]any, error)

func (*TableServicePgsql) Init

func (s *TableServicePgsql) Init() error

func (*TableServicePgsql) Insert

func (s *TableServicePgsql) Insert(ctx context.Context, partnerID int64, userID int, item any) ([]int64, error)

Insert writes one row (when item is a scalar) or many (when item is a slice) and returns the sequence-assigned ids. Tables without a sequence return an empty slice rather than `[-1]` (P1-43) so callers can distinguish "row inserted, no id" from "row inserted with an int64 id".

func (*TableServicePgsql) InsertSingle

func (s *TableServicePgsql) InsertSingle(ctx context.Context, partnerID int64, userID int, item any) (int64, error)

func (*TableServicePgsql) Placeholder

func (s *TableServicePgsql) Placeholder(idx int) string

func (*TableServicePgsql) Post

func (s *TableServicePgsql) Post(ctx context.Context, partnerID int64, userID int, data ...any) error

func (*TableServicePgsql) Update

func (s *TableServicePgsql) Update(ctx context.Context, userID int, item any) error

func (*TableServicePgsql) WithTx

func (s *TableServicePgsql) WithTx(tx pgx.Tx) *TableServicePgsql

WithTx returns a shallow copy of the receiver with Client replaced by tx. All cached SQL strings, schema metadata, and abstract-base state are shared — only the connection underneath is different. The returned value is only safe to use for the lifetime of tx.

type TxQueryServicePgsql

type TxQueryServicePgsql struct {
	Tx          pgx.Tx
	Queries     map[string]string
	IdGenerator port.BigintGenerator
}

func (*TxQueryServicePgsql) Commit

func (s *TxQueryServicePgsql) Commit(ctx context.Context) error

func (*TxQueryServicePgsql) GenID

func (s *TxQueryServicePgsql) GenID() int64

func (*TxQueryServicePgsql) Query

func (s *TxQueryServicePgsql) Query(ctx context.Context, queryName string, args ...any) (*model.QueryResult, error)

func (*TxQueryServicePgsql) Rollback

func (s *TxQueryServicePgsql) Rollback(ctx context.Context) error

Jump to

Keyboard shortcuts

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