sqlc

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcquireResourceParams

type AcquireResourceParams struct {
	ID            string
	ResourceIndex interface{}
}

type CreateNumpoolParams

type CreateNumpoolParams struct {
	ID                string
	MaxResourcesCount int32
	Metadata          []byte
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type EnqueueWaitingClientParams

type EnqueueWaitingClientParams struct {
	ID       string
	WaiterID string
}

type NotifyAndDequeueFirstWaiterParams added in v0.4.5

type NotifyAndDequeueFirstWaiterParams struct {
	ID          string
	ChannelName string
}

type NotifyWaitersParams added in v0.2.0

type NotifyWaitersParams struct {
	ChannelName string
	WaiterID    string
}

type Numpool

type Numpool struct {
	// ID is a unique identifier for the numpool.
	// It is used to identify the numpool in the database.
	ID string
	// MaxResourcesCount is the maximum number of resources that can be allocated.
	// It is used to limit the number of resources that can be created.
	// The value must be between 1 and 64, inclusive.
	MaxResourcesCount int32
	// ResourceUsageStatus is a bitmask representing the usage of resources.
	// Each bit corresponds to a resource, where 1 means the resource is in use and 0 means it is free.
	// The length of the bitmask is equal to MaxResourcesCount.
	// For example, if MaxResourcesCount is 8, then ResourceUsageStatus can be a value from 0 to 64, where each bit represents the usage of a resource.
	ResourceUsageStatus pgtype.Bits
	// WaitQueue is a list of client ids waiting for the numpool.
	WaitQueue []string
	// Metadata is a JSONB field that can store additional information about the numpool.
	// It can be used to store any additional data that is relevant to the numpool, such as
	// configuration settings, descriptions, or other metadata that does not fit into the other fields.
	Metadata []byte
}

Numpool represents an abstract pool of resources.

func (*Numpool) FindUnusedResourceIndex

func (n *Numpool) FindUnusedResourceIndex() int

FindUnusedResourceIndex finds the first unused resource index by examining the resource usage bitmap. Returns the index of the first free resource, or -1 if no resources are available.

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) AcquireAdvisoryLock added in v0.2.0

func (q *Queries) AcquireAdvisoryLock(ctx context.Context, lockID int64) error

func (*Queries) AcquireResource

func (q *Queries) AcquireResource(ctx context.Context, arg AcquireResourceParams) (int64, error)

AcquireResource attempts to acquire a resource from the numpool. It returns the id of the numpool if successful, or NULL if no resources are available.

func (*Queries) CheckNumpoolExists added in v0.2.0

func (q *Queries) CheckNumpoolExists(ctx context.Context, id string) (bool, error)

CheckNumpoolExists checks if a numpool with the given id exists.

func (*Queries) CheckNumpoolTableExist added in v0.2.0

func (q *Queries) CheckNumpoolTableExist(ctx context.Context) (bool, error)

CheckNumpoolTableExist checks if "public"."numpool" exists.

func (*Queries) CreateNumpool

func (q *Queries) CreateNumpool(ctx context.Context, arg CreateNumpoolParams) error

CreateNumpool creates a new numpool with the specified id and max_resources_count.

func (*Queries) CreateTable added in v0.2.0

func (q *Queries) CreateTable(ctx context.Context) error

CreateTable creates the numpool table in the database.

func (*Queries) DeleteNumpool

func (q *Queries) DeleteNumpool(ctx context.Context, id string) (int64, error)

DeleteNumpool deletes the numpool with the specified id.

func (*Queries) DropNumpoolTable added in v0.4.1

func (q *Queries) DropNumpoolTable(ctx context.Context) error

DropNumpoolTable drops the numpool table if it exists.

func (*Queries) EnqueueWaitingClient

func (q *Queries) EnqueueWaitingClient(ctx context.Context, arg EnqueueWaitingClientParams) error

EnqueueWaitingClient adds a waiter ID to the wait queue.

func (*Queries) GetNumpool

func (q *Queries) GetNumpool(ctx context.Context, id string) (Numpool, error)

GetNumpoolForUpdate retrieves the numpool row with the given id without locking it.

func (*Queries) GetNumpoolForUpdate

func (q *Queries) GetNumpoolForUpdate(ctx context.Context, id string) (Numpool, error)

GetNumpoolForUpdate retrieves the numpool row with the given id and locks it for update.

func (*Queries) ListPools added in v0.4.4

func (q *Queries) ListPools(ctx context.Context, prefix pgtype.Text) ([]string, error)

ListPools returns a list of pool names that start with the given prefix. If prefix is empty, returns all pools ordered by pool name.

func (*Queries) LockNumpoolTableInShareMode added in v0.2.0

func (q *Queries) LockNumpoolTableInShareMode(ctx context.Context) error

func (*Queries) NotifyAndDequeueFirstWaiter added in v0.4.5

func (q *Queries) NotifyAndDequeueFirstWaiter(ctx context.Context, arg NotifyAndDequeueFirstWaiterParams) error

NotifyAndDequeueFirstWaiter atomically dequeues the first waiter and notifies them. This prevents the race condition where multiple releases notify the same waiter.

func (*Queries) NotifyWaiters added in v0.2.0

func (q *Queries) NotifyWaiters(ctx context.Context, arg NotifyWaitersParams) error

func (*Queries) ReleaseResource

func (q *Queries) ReleaseResource(ctx context.Context, arg ReleaseResourceParams) (int64, error)

ReleaseResource releases a resource back to the numpool.

func (*Queries) RemoveFromWaitQueue

func (q *Queries) RemoveFromWaitQueue(ctx context.Context, arg RemoveFromWaitQueueParams) error

RemoveFromWaitQueue removes a specific waiter UUID from the wait queue.

func (*Queries) UpdateNumpoolMetadata added in v0.2.0

func (q *Queries) UpdateNumpoolMetadata(ctx context.Context, arg UpdateNumpoolMetadataParams) error

UpdateNumpoolMetadata updates the metadata of the numpool with the specified id.

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type ReleaseResourceParams

type ReleaseResourceParams struct {
	ID            string
	ResourceIndex interface{}
}

type RemoveFromWaitQueueParams

type RemoveFromWaitQueueParams struct {
	ID       string
	WaiterID interface{}
}

type UpdateNumpoolMetadataParams added in v0.2.0

type UpdateNumpoolMetadataParams struct {
	ID       string
	Metadata []byte
}

Jump to

Keyboard shortcuts

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