postgres

package
v0.0.0-...-0177554 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustCreateClient

func MustCreateClient(opts ...ConnectionOption) *sql.DB

MustCreateClient panics when it fails to create a new database connection. By default, it will try to connect 3 times before returning an error.

func NewClient

func NewClient(opts ...ConnectionOption) (*sql.DB, error)

NewClient creates a new Postgres client. By default, it will try to connect 3 times before returning an error.

func NewPgxClient

func NewPgxClient(opts ...ConnectionOption) *pgxpool.Pool

NewPgxClient creates a new Postgres client via pgx. By default, it will try to connect 3 times before returning an error.

Types

type CollectionTokenRepository

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

CollectionTokenRepository is the repository for interacting with collections in a postgres database

func NewCollectionTokenRepository

func NewCollectionTokenRepository(db *sql.DB, queries *db.Queries) *CollectionTokenRepository

NewCollectionTokenRepository creates a new CollectionTokenRepository TODO another join for addresses

func (*CollectionTokenRepository) Create

Create creates a new collection in the database

func (*CollectionTokenRepository) Delete

func (c *CollectionTokenRepository) Delete(pCtx context.Context, pID persist.DBID, pUserID persist.DBID) error

Delete deletes a collection from the database

func (*CollectionTokenRepository) Update

func (c *CollectionTokenRepository) Update(pCtx context.Context, pID persist.DBID, pUserID persist.DBID, pUpdate interface{}) error

Update updates a collection in the database

func (*CollectionTokenRepository) UpdateTokens

UpdateTokens updates the nfts of a collection in the database

type CommentRepository

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

CommentRepository represents an comment repository in the postgres database

func NewCommentRepository

func NewCommentRepository(queries *db.Queries, pgx *pgxpool.Pool) *CommentRepository

NewCommentRepository creates a new postgres repository for interacting with comments

func (*CommentRepository) CreateComment

func (a *CommentRepository) CreateComment(ctx context.Context, feedEventID, postID, actorID persist.DBID, replyToID *persist.DBID, comment string, mentions []db.Mention) (persist.DBID, []db.Mention, error)

type CommunityRepository

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

CommunityRepository represents a community repository in the postgres database

func NewCommunityRepository

func NewCommunityRepository(queries *db.Queries) *CommunityRepository

NewCommunityRepository creates a new postgres repository for interacting with communities

func (*CommunityRepository) UpsertCommunities

func (c *CommunityRepository) UpsertCommunities(ctx context.Context, communities []db.Community) ([]db.Community, error)

UpsertCommunities upserts a list of communities

type ConnectionOption

type ConnectionOption func(params *connectionParams)

func WithDBName

func WithDBName(dbname string) ConnectionOption

func WithHost

func WithHost(host string) ConnectionOption

func WithNoRetries

func WithNoRetries() ConnectionOption

func WithPassword

func WithPassword(password string) ConnectionOption

func WithPort

func WithPort(port int) ConnectionOption

func WithRetries

func WithRetries(r retry.Retry) ConnectionOption

func WithUser

func WithUser(user string) ConnectionOption

type ContractGalleryRepository

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

ContractGalleryRepository represents a contract repository in the postgres database

func NewContractGalleryRepository

func NewContractGalleryRepository(db *sql.DB, queries *db.Queries) *ContractGalleryRepository

NewContractGalleryRepository creates a new postgres repository for interacting with contracts

func (*ContractGalleryRepository) BulkUpsert

func (c *ContractGalleryRepository) BulkUpsert(pCtx context.Context, contracts []db.Contract, canOverwriteOwnerAddress bool) ([]db.Contract, error)

BulkUpsert bulk upserts the contracts by address

func (*ContractGalleryRepository) Upsert

func (c *ContractGalleryRepository) Upsert(pCtx context.Context, contract db.Contract, canOverwriteOwnerAddress bool) (db.Contract, error)

type ContractRepository

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

ContractRepository represents a contract repository in the postgres database

func NewContractRepository

func NewContractRepository(db *sql.DB) *ContractRepository

NewContractRepository creates a new postgres repository for interacting with contracts

func (*ContractRepository) BulkUpsert

func (c *ContractRepository) BulkUpsert(pCtx context.Context, pContracts []persist.Contract) error

BulkUpsert bulk upserts the contracts by address

func (*ContractRepository) GetByAddress

func (c *ContractRepository) GetByAddress(pCtx context.Context, pAddress persist.EthereumAddress) (persist.Contract, error)

GetByAddress returns the contract with the given address

func (*ContractRepository) GetContractsOwnedByAddress

func (c *ContractRepository) GetContractsOwnedByAddress(ctx context.Context, addr persist.EthereumAddress) ([]persist.Contract, error)

GetContractsOwnedByAddress returns all contracts owned by the given address

func (*ContractRepository) MostRecentBlock

func (c *ContractRepository) MostRecentBlock(pCtx context.Context) (persist.BlockNumber, error)

MostRecentBlock returns the most recent block number of any token

func (*ContractRepository) UpdateByAddress

UpdateByAddress updates the given contract's metadata fields by its address field.

type EarlyAccessRepository

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

func NewEarlyAccessRepository

func NewEarlyAccessRepository(db *sql.DB, queries *db.Queries) *EarlyAccessRepository

func (*EarlyAccessRepository) IsAllowedByAddresses

func (u *EarlyAccessRepository) IsAllowedByAddresses(ctx context.Context, chainAddresses []persist.ChainAddress) (bool, error)

type ErrRoleDoesNotExist

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

func (ErrRoleDoesNotExist) Error

func (e ErrRoleDoesNotExist) Error() string

type EventRepository

type EventRepository struct {
	Queries *db.Queries
}

func (*EventRepository) Add

func (r *EventRepository) Add(ctx context.Context, event db.Event) (*db.Event, error)

func (*EventRepository) AddAdmireEvent

func (r *EventRepository) AddAdmireEvent(ctx context.Context, event db.Event) (*db.Event, error)

func (*EventRepository) AddCollectionEvent

func (r *EventRepository) AddCollectionEvent(ctx context.Context, event db.Event) (*db.Event, error)

func (*EventRepository) AddCommentEvent

func (r *EventRepository) AddCommentEvent(ctx context.Context, event db.Event) (*db.Event, error)

func (*EventRepository) AddCommunityEvent

func (r *EventRepository) AddCommunityEvent(ctx context.Context, event db.Event) (*db.Event, error)

func (*EventRepository) AddDataOnlyEvent

func (r *EventRepository) AddDataOnlyEvent(ctx context.Context, event db.Event) (*db.Event, error)

func (*EventRepository) AddGalleryEvent

func (r *EventRepository) AddGalleryEvent(ctx context.Context, event db.Event) (*db.Event, error)

func (*EventRepository) AddPostEvent

func (r *EventRepository) AddPostEvent(ctx context.Context, event db.Event) (*db.Event, error)

func (*EventRepository) AddTokenEvent

func (r *EventRepository) AddTokenEvent(ctx context.Context, event db.Event) (*db.Event, error)

func (*EventRepository) AddUserEvent

func (r *EventRepository) AddUserEvent(ctx context.Context, event db.Event) (*db.Event, error)

func (*EventRepository) EventsInWindow

func (r *EventRepository) EventsInWindow(ctx context.Context, eventID persist.DBID, windowSeconds int, actions persist.ActionList, includeSubject bool) ([]db.Event, error)

EventsInWindow returns events belonging to the same window of activity as the given eventID.

func (*EventRepository) EventsInWindowForGallery

func (r *EventRepository) EventsInWindowForGallery(ctx context.Context, eventID, galleryID persist.DBID, windowSeconds int, actions persist.ActionList, includeSubject bool) ([]db.Event, error)

EventsInWindow returns events belonging to the same window of activity as the given eventID.

func (*EventRepository) Get

func (r *EventRepository) Get(ctx context.Context, eventID persist.DBID) (db.Event, error)

func (*EventRepository) IsActorActionActive

func (r *EventRepository) IsActorActionActive(ctx context.Context, event db.Event, actions persist.ActionList, windowSize time.Duration) (bool, error)

func (*EventRepository) IsActorGalleryActive

func (r *EventRepository) IsActorGalleryActive(ctx context.Context, event db.Event, windowSize time.Duration) (bool, error)

func (*EventRepository) IsActorSubjectActionActive

func (r *EventRepository) IsActorSubjectActionActive(ctx context.Context, event db.Event, actions persist.ActionList, windowSize time.Duration) (bool, error)

func (*EventRepository) IsActorSubjectActive

func (r *EventRepository) IsActorSubjectActive(ctx context.Context, event db.Event, windowSize time.Duration) (bool, error)

type FeedRepository

type FeedRepository struct {
	Queries *db.Queries
}

func (*FeedRepository) Add

func (r *FeedRepository) Add(ctx context.Context, event db.FeedEvent) (*db.FeedEvent, error)

func (*FeedRepository) LastPublishedCollectionFeedEvent

func (r *FeedRepository) LastPublishedCollectionFeedEvent(ctx context.Context, ownerID persist.DBID, collectionID persist.DBID, before time.Time, actions []persist.Action) (*db.FeedEvent, error)

LastPublishedCollectionFeedEvent returns the most recent collection event for the given owner, action, and collection that occurred before time `since`.

func (*FeedRepository) LastPublishedTokenFeedEvent

func (r *FeedRepository) LastPublishedTokenFeedEvent(ctx context.Context, ownerID, tokenID persist.DBID, before time.Time, actions []persist.Action) (*db.FeedEvent, error)

func (*FeedRepository) LastPublishedUserFeedEvent

func (r *FeedRepository) LastPublishedUserFeedEvent(ctx context.Context, ownerID persist.DBID, before time.Time, actions []persist.Action) (*db.FeedEvent, error)

type GalleryRepository

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

GalleryRepository is the repository for interacting with galleries in a postgres database

func NewGalleryRepository

func NewGalleryRepository(queries *db.Queries) *GalleryRepository

NewGalleryRepository creates a new GalleryTokenRepository TODO another join to addresses

func (*GalleryRepository) AddCollections

func (g *GalleryRepository) AddCollections(pCtx context.Context, pID persist.DBID, pUserID persist.DBID, pCollections []persist.DBID) error

AddCollections adds the given collections to the gallery with the given ID

func (*GalleryRepository) Create

Create creates a new gallery

func (*GalleryRepository) Delete

Delete deletes a gallery and ensures that the collections of that gallery are passed on to another gallery

func (*GalleryRepository) GetPreviewsURLsByUserID

func (g *GalleryRepository) GetPreviewsURLsByUserID(pCtx context.Context, pUserID persist.DBID, limit int) ([]string, error)

func (*GalleryRepository) Update

Update updates the gallery with the given ID and ensures that gallery is owned by the given userID

type MembershipRepository

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

MembershipRepository is a repository for storing membership information in the database

func NewMembershipRepository

func NewMembershipRepository(db *sql.DB, queries *db.Queries) *MembershipRepository

NewMembershipRepository creates a new postgres repository for interacting with tiers

func (*MembershipRepository) GetAll

GetAll returns all the tiers

func (*MembershipRepository) GetByTokenID

GetByTokenID returns the tier with the given token ID

func (*MembershipRepository) UpsertByTokenID

func (m *MembershipRepository) UpsertByTokenID(pCtx context.Context, pTokenID persist.HexTokenID, pTier persist.MembershipTier) error

UpsertByTokenID upserts the given tier

type Repositories

type Repositories struct {
	UserRepository        *UserRepository
	GalleryRepository     *GalleryRepository
	CollectionRepository  *CollectionTokenRepository
	ContractRepository    *ContractGalleryRepository
	MembershipRepository  *MembershipRepository
	EarlyAccessRepository *EarlyAccessRepository
	WalletRepository      *WalletRepository
	CommentRepository     *CommentRepository
	EventRepository       *EventRepository
	CommunityRepository   *CommunityRepository
	// contains filtered or unexported fields
}

Repositories is the set of all available persistence repositories

func NewRepositories

func NewRepositories(pq *sql.DB, pgx *pgxpool.Pool) *Repositories

func (*Repositories) BeginTx

func (r *Repositories) BeginTx(ctx context.Context) (pgx.Tx, error)

type UserRepository

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

UserRepository represents a user repository in the postgres database

func NewUserRepository

func NewUserRepository(db *sql.DB, queries *db.Queries, pgx *pgxpool.Pool) *UserRepository

NewUserRepository creates a new postgres repository for interacting with users TODO joins for users to wallets and wallets to addresses

func (*UserRepository) AddFollower

func (u *UserRepository) AddFollower(pCtx context.Context, follower persist.DBID, followee persist.DBID) (refollowed bool, err error)

func (*UserRepository) AddWallet

func (u *UserRepository) AddWallet(pCtx context.Context, pUserID persist.DBID, pChainAddress persist.ChainAddress, pWalletType persist.WalletType, queries *db.Queries) error

AddWallet adds an address to user as well as ensures that the wallet and address exists

func (*UserRepository) Create

func (u *UserRepository) Create(pCtx context.Context, pUser persist.CreateUserInput, queries *db.Queries) (persist.DBID, error)

Create creates a new user

func (*UserRepository) Delete

func (u *UserRepository) Delete(pCtx context.Context, pID persist.DBID) error

Delete deletes the user with the given ID

func (*UserRepository) FillWalletDataForUser

func (u *UserRepository) FillWalletDataForUser(pCtx context.Context, user *persist.User) error

func (*UserRepository) GetByChainAddress

func (u *UserRepository) GetByChainAddress(pCtx context.Context, pChainAddress persist.L1ChainAddress) (persist.User, error)

GetByChainAddress gets the user who owns the wallet with the specified ChainAddress (if any)

func (*UserRepository) GetByID

func (u *UserRepository) GetByID(pCtx context.Context, pID persist.DBID) (persist.User, error)

GetByID gets the user with the given ID

func (*UserRepository) GetByIDs

func (u *UserRepository) GetByIDs(pCtx context.Context, pIDs []persist.DBID) ([]persist.User, error)

GetByIDs gets all the users with the given IDs

func (*UserRepository) GetByUsername

func (u *UserRepository) GetByUsername(pCtx context.Context, pUsername string) (persist.User, error)

GetByUsername gets the user with the given username

func (*UserRepository) GetByVerifiedEmail

func (u *UserRepository) GetByVerifiedEmail(pCtx context.Context, pEmail persist.Email) (persist.User, error)

GetByEmail gets the user with the given email address

func (*UserRepository) GetByWalletID

func (u *UserRepository) GetByWalletID(pCtx context.Context, pWalletID persist.DBID) (persist.User, error)

GetByWalletID gets the user with the given wallet in their list of addresses

func (*UserRepository) MergeUsers

func (u *UserRepository) MergeUsers(pCtx context.Context, pInitialUser persist.DBID, pSecondUser persist.DBID) error

MergeUsers merges the given users into the first user

func (*UserRepository) RemoveFollower

func (u *UserRepository) RemoveFollower(pCtx context.Context, follower persist.DBID, followee persist.DBID) error

func (*UserRepository) RemoveWallet

func (u *UserRepository) RemoveWallet(pCtx context.Context, pUserID persist.DBID, pWalletID persist.DBID) (bool, error)

RemoveWallet removes the specified wallet from a user. Returns true if the wallet exists and was successfully removed, false if the wallet does not exist or an error was encountered.

func (*UserRepository) UpdateByID

func (u *UserRepository) UpdateByID(pCtx context.Context, pID persist.DBID, pUpdate interface{}) error

UpdateByID updates the user with the given ID

type WalletRepository

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

WalletRepository is a repository for wallets

func NewWalletRepository

func NewWalletRepository(db *sql.DB, queries *db.Queries) *WalletRepository

NewWalletRepository creates a new postgres repository for interacting with wallets

func (*WalletRepository) GetByChainAddress

func (w *WalletRepository) GetByChainAddress(ctx context.Context, chainAddress persist.L1ChainAddress) (persist.Wallet, error)

GetByChainAddress returns a wallet by address and chain

func (*WalletRepository) GetByID

GetByID returns a wallet by its ID

func (*WalletRepository) GetByUserID

func (w *WalletRepository) GetByUserID(ctx context.Context, userID persist.DBID) ([]persist.Wallet, error)

GetByUserID returns all wallets owned by the specified user

Jump to

Keyboard shortcuts

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