sharded

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID          int64
	TenantID    int64
	DisplayName string
}

type Accounts

type Accounts interface {
	AccountsReader
	AccountsWriter
}

Accounts exposes all queries in its generated store group.

type AccountsReader

type AccountsReader interface {
	// GetAccount executes the generated GetAccount query.
	GetAccount(ctx context.Context, arg *GetAccountT, storeOptions ...QueryOption) (*Account, error)
}

AccountsReader exposes read queries in the Accounts store group.

type AccountsWriter

type AccountsWriter interface {
	// UpdateAccountName executes the generated UpdateAccountName query.
	UpdateAccountName(ctx context.Context, arg *UpdateAccountNameT, storeOptions ...QueryOption) (*Account, error)
	// UpsertAccount executes the generated UpsertAccount query.
	UpsertAccount(ctx context.Context, arg *UpsertAccountT, storeOptions ...QueryOption) (*Account, error)
}

AccountsWriter exposes write queries in the Accounts store group.

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 GetAccountParams

type GetAccountParams struct {
	TenantID int64
	ID       int64
}

type GetAccountT added in v0.0.3

type GetAccountT = GetAccountParams

GetAccountT is the store parameter type for GetAccount.

type Querier

type Querier interface {
	// kind: read
	// shard: tenant(tenant_id)
	// store: Reports
	CountAccounts(ctx context.Context, tenantID int64) (int64, error)
	// kind: read
	// shard: tenant(tenant_id)
	// store: Accounts
	GetAccount(ctx context.Context, arg *GetAccountParams) (*Account, error)
	// kind: write
	// shard: tenant(tenant_id)
	// store: Accounts
	UpdateAccountName(ctx context.Context, arg *UpdateAccountNameParams) (*Account, error)
	// kind: write
	// shard: tenant(tenant_id)
	// store: Accounts
	UpsertAccount(ctx context.Context, arg *UpsertAccountParams) (*Account, error)
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) CountAccounts

func (q *Queries) CountAccounts(ctx context.Context, tenantID int64) (int64, error)

kind: read shard: tenant(tenant_id) store: Reports

func (*Queries) GetAccount

func (q *Queries) GetAccount(ctx context.Context, arg *GetAccountParams) (*Account, error)

kind: read shard: tenant(tenant_id) store: Accounts

func (*Queries) UpdateAccountName

func (q *Queries) UpdateAccountName(ctx context.Context, arg *UpdateAccountNameParams) (*Account, error)

kind: write shard: tenant(tenant_id) store: Accounts

func (*Queries) UpsertAccount

func (q *Queries) UpsertAccount(ctx context.Context, arg *UpsertAccountParams) (*Account, error)

kind: write shard: tenant(tenant_id) store: Accounts

func (*Queries) WithTx

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

type QueryOption

type QueryOption func(*queryOptions)

QueryOption customizes routing for one generated query call.

func ReadFromPrimary

func ReadFromPrimary() QueryOption

ReadFromPrimary routes a read query to the primary database.

func WithTx

func WithTx(tx pgx.Tx) QueryOption

WithTx executes a query through tx and suppresses write mirrors.

type Reports

type Reports interface {
	ReportsReader
	ReportsWriter
}

Reports exposes all queries in its generated store group.

type ReportsReader

type ReportsReader interface {
	// CountAccounts executes the generated CountAccounts query.
	CountAccounts(ctx context.Context, tenantID int64, storeOptions ...QueryOption) (int64, error)
}

ReportsReader exposes read queries in the Reports store group.

type ReportsWriter

type ReportsWriter interface {
}

ReportsWriter exposes write queries in the Reports store group.

type ShardResolver

type ShardResolver[SK any] interface {
	// Tenant resolves the "tenant" shard route.
	Tenant(tenantID int64) SK
}

ShardResolver resolves generated query parameters to shard keys.

type ShardedOption

type ShardedOption func(*shardedOptions)

ShardedOption customizes a sharded topology.

func WithReplicaSet

func WithReplicaSet(name string, primary DBTX, replicas ...DBTX) ShardedOption

WithReplicaSet appends a named primary and its optional read replicas.

func WithVShardMapping

func WithVShardMapping(mainReplicaSet string, vshards []uint64, mirrorReplicaSets ...string) ShardedOption

WithVShardMapping maps virtual shards to a main replica set and optional ordered write mirrors.

type SingletonOption

type SingletonOption func(*singletonConfig)

SingletonOption customizes a single-database topology.

func WithDatabaseName

func WithDatabaseName(name string) SingletonOption

WithDatabaseName identifies the database in telemetry. An empty name defaults to "default".

func WithReadReplicas

func WithReadReplicas(databases ...DBTX) SingletonOption

WithReadReplicas appends databases used for round-robin reads.

func WithWriteMirrors

func WithWriteMirrors(databases ...DBTX) SingletonOption

WithWriteMirrors appends databases that synchronously receive writes.

type Store

type Store interface {
	// Accounts returns the Accounts query group.
	Accounts() Accounts
	// Reports returns the Reports query group.
	Reports() Reports
}

Store is the topology-independent generated query API.

func NewStore

func NewStore(ctx context.Context, topology Topology, options ...StoreOption) (Store, error)

NewStore creates the generated query API from an opaque topology configuration.

type StoreOption

type StoreOption func(*storeOptions)

StoreOption customizes a generated store.

func WithAccountsFactory added in v0.0.3

func WithAccountsFactory(createAccounts func(Accounts) Accounts) StoreOption

WithAccountsFactory configures an optional wrapper for the Accounts query group. A nil factory leaves the generated query group unwrapped.

func WithLogger

func WithLogger(logger *slog.Logger) StoreOption

WithLogger configures optional structured logging for routed queries. A nil logger disables logging.

func WithMeterProvider

func WithMeterProvider(provider metric.MeterProvider) StoreOption

WithMeterProvider configures the provider used for routed query metrics. A nil provider uses the global OpenTelemetry meter provider.

func WithReportsFactory added in v0.0.3

func WithReportsFactory(createReports func(Reports) Reports) StoreOption

WithReportsFactory configures an optional wrapper for the Reports query group. A nil factory leaves the generated query group unwrapped.

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) StoreOption

WithTracerProvider configures the provider used for routed query spans. A nil provider uses the global OpenTelemetry tracer provider.

type Topology

type Topology interface {
	// contains filtered or unexported methods
}

Topology is an opaque database topology for Store.

func Sharded

func Sharded[SK any](numVShards uint64, shardHasher pgmesh.ShardHasher[SK], resolver ShardResolver[SK], options ...ShardedOption) Topology

Sharded returns an opaque sharded topology.

func Singleton

func Singleton(primary DBTX, options ...SingletonOption) Topology

Singleton returns a topology with one primary database.

type UpdateAccountNameParams

type UpdateAccountNameParams struct {
	TenantID    int64
	ID          int64
	DisplayName string
}

type UpdateAccountNameT added in v0.0.3

type UpdateAccountNameT = UpdateAccountNameParams

UpdateAccountNameT is the store parameter type for UpdateAccountName.

type UpsertAccountParams

type UpsertAccountParams struct {
	ID          int64
	TenantID    int64
	DisplayName string
}

type UpsertAccountT added in v0.0.3

type UpsertAccountT = UpsertAccountParams

UpsertAccountT is the store parameter type for UpsertAccount.

Jump to

Keyboard shortcuts

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