postgres

package
v0.0.0-...-1aff2ea Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

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

Backend holds the state of the backend.

Has to be initializes with New().

func New

func New(ctx context.Context, connString string) (*Backend, error)

New creates a new connection pool.

func (*Backend) Clear

func (b *Backend) Clear(ctx context.Context, pollID int) error

Clear removes all data about a poll from the database.

func (*Backend) ClearAll

func (b *Backend) ClearAll(ctx context.Context) error

ClearAll removes all vote related data from postgres.

It does this by dropping vote vote-schema. If other services would write thinks in this schema or hava a relation to this schema, then this would also delete this tables.

Since the schema is deleted and afterwards recreated this command can also be used, if the db-schema has changed. It is kind of a migration.

func (*Backend) Close

func (b *Backend) Close()

Close closes all connections. It blocks, until all connection are closed.

func (*Backend) LiveVotes

func (b *Backend) LiveVotes(ctx context.Context) (map[int]map[int][]byte, error)

LiveVotes returns all votes from each user.

This this is impossible for the current implementation, it only returns nil for each vote.

func (*Backend) Migrate

func (b *Backend) Migrate(ctx context.Context) error

Migrate creates the database schema.

func (*Backend) Start

func (b *Backend) Start(ctx context.Context, pollID int) error

Start starts a poll.

func (*Backend) Stop

func (b *Backend) Stop(ctx context.Context, pollID int) ([][]byte, []int, error)

Stop ends a poll and returns all vote objects and users who have voted.

If an transaction error happens, the poll is stopped again. This is done until either the poll is stopped or the given context is canceled.

func (*Backend) String

func (b *Backend) String() string

func (*Backend) Vote

func (b *Backend) Vote(ctx context.Context, pollID int, userID int, object []byte) error

Vote adds a vote to a poll.

If an transaction error happens, the vote is saved again. This is done until either the vote is saved or the given context is canceled.

func (*Backend) Wait

func (b *Backend) Wait(ctx context.Context)

Wait blocks until a connection to postgres can be established.

Jump to

Keyboard shortcuts

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