pgdb

package
v1.13.5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: Apache-2.0 Imports: 28 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectENV

func ConnectENV() (*sql.DB, error)

ConnectENV returns a DB instance. Used for testing, it requires the following environment variables to be set - POSTGRES_HOST - POSTGRES_PORT (will default to 5432 if missing) - POSTGRES_USER - POSTGRES_PASSWORD - PENNSIEVE_DB - POSTGRES_SSL_MODE (should be set to "disable" if the server is not https, left blank if it is)

func ConnectENVWithOrg

func ConnectENVWithOrg(orgId int) (*sql.DB, error)

func ConnectRDS

func ConnectRDS() (*sql.DB, error)

ConnectRDS returns a DB instance. The Lambda function leverages IAM roles to gain access to the DB Proxy. The function does NOT set the search_path to the organization schema. Requires following LAMBDA ENV VARIABLES:

  • RDS_PROXY_ENDPOINT
  • REGION
  • ENV

If ENV is set to DOCKER, the call is redirected to ConnectENV()

func ConnectRDSWithOrg

func ConnectRDSWithOrg(orgId int) (*sql.DB, error)

ConnectRDSWithOrg returns a DB instance. The Lambda function leverages IAM roles to gain access to the DB Proxy. The function DOES set the search_path to the organization schema.

func ContributorColumns added in v1.4.0

func ContributorColumns() []string

func ReadContributorColumns added in v1.4.0

func ReadContributorColumns() string

func WriteContributorColumns added in v1.4.0

func WriteContributorColumns() string

Types

type ContributorNotFoundError added in v1.4.0

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

func (ContributorNotFoundError) Error added in v1.4.0

func (e ContributorNotFoundError) Error() string

type CreateDatasetParams added in v1.4.0

type CreateDatasetParams struct {
	Name                         string
	Description                  string
	Status                       *pgdb.DatasetStatus
	AutomaticallyProcessPackages bool
	License                      string
	Tags                         []string
	DataUseAgreement             *pgdb.DataUseAgreement
	Type                         datasetType.DatasetType
}

type CreateDatasetReleaseParams added in v1.9.0

type CreateDatasetReleaseParams struct {
	Origin     string
	Url        string
	Label      string
	Marker     string
	Properties pgdb.Properties
	Tags       pgdb.Tags
}

type DBTX

type DBTX interface {
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}

DBTX Default interface with methods that are available for both DB adn TX sessions.

type DatasetNotFoundError added in v1.4.0

type DatasetNotFoundError struct {
	ErrorMessage string
}

func (DatasetNotFoundError) Error added in v1.4.0

func (e DatasetNotFoundError) Error() string

type DatasetReleaseNotFoundError added in v1.9.0

type DatasetReleaseNotFoundError struct {
	ErrorMessage string
}

func (DatasetReleaseNotFoundError) Error added in v1.9.0

type DatasetUserNotFoundError added in v1.4.0

type DatasetUserNotFoundError struct {
	ErrorMessage string
}

func (DatasetUserNotFoundError) Error added in v1.4.0

func (e DatasetUserNotFoundError) Error() string

type NewContributor added in v1.4.0

type NewContributor struct {
	FirstName     string
	MiddleInitial string
	LastName      string
	Degree        string
	EmailAddress  string
	Orcid         string
	UserId        int64
}

type OrganizationUserNotFoundError added in v1.4.0

type OrganizationUserNotFoundError struct {
	ErrorMessage string
}

func (OrganizationUserNotFoundError) Error added in v1.4.0

type Queries

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

Queries is a struct with a db object that implements the DBTX interface. This means that db can either be a direct DB connection or a TX transaction.

func New

func New(db DBTX) *Queries

New returns a Queries object backed by a DBTX interface (either DB or TX)

func (*Queries) AddContributor added in v1.4.0

func (q *Queries) AddContributor(ctx context.Context, newContributor NewContributor) (*pgdb.Contributor, error)

AddContributor will add a Contributor to the Organization's Contributors table.

func (*Queries) AddDatasetContributor added in v1.4.0

func (q *Queries) AddDatasetContributor(ctx context.Context, dataset *pgdb.Dataset, contributor *pgdb.Contributor) (*pgdb.DatasetContributor, error)

func (*Queries) AddDatasetRelease added in v1.11.0

func (q *Queries) AddDatasetRelease(ctx context.Context, release pgdb.DatasetRelease) (*pgdb.DatasetRelease, error)

func (*Queries) AddDatasetUser added in v1.4.0

func (q *Queries) AddDatasetUser(ctx context.Context, dataset *pgdb.Dataset, user *pgdb.User, role role.Role) (*pgdb.DatasetUser, error)

func (*Queries) AddFiles

func (q *Queries) AddFiles(ctx context.Context, files []pgdb.FileParams) ([]pgdb.File, error)

AddFiles add files to packages

func (*Queries) AddFolder

func (q *Queries) AddFolder(ctx context.Context, r pgdb.PackageParams) (*pgdb.Package, error)

AddFolder adds a single folder to a dataset.

func (*Queries) AddOrganizationUser added in v1.4.0

func (q *Queries) AddOrganizationUser(ctx context.Context, orgId int64, userId int64, permBit pgdb.DbPermission) (*pgdb.OrganizationUser, error)

func (*Queries) AddPackages

func (q *Queries) AddPackages(ctx context.Context, records []pgdb.PackageParams) ([]pgdb.Package, error)

AddPackages adds packages to a dataset.

  • This call should typically be wrapped in a Transaction as it will run multiple queries.
  • Packages can be in different folders, but it is assumed that the folders already exist.

func (*Queries) CreateDataset added in v1.4.0

func (q *Queries) CreateDataset(ctx context.Context, p CreateDatasetParams) (*pgdb.Dataset, error)

func (*Queries) FindContributor added in v1.4.1

func (q *Queries) FindContributor(ctx context.Context, search NewContributor) (*pgdb.Contributor, error)

FindContributor will search for a contributor by several User Id, Email Address, and ORCID

func (*Queries) GetByCognitoId

func (q *Queries) GetByCognitoId(ctx context.Context, id string) (*pgdb.User, error)

GetByCognitoId returns a user from Postgress based on his/her cognito-id This function also returns the preferred org and whether the user is a super-admin. Returns (nil, sql.ErrNoRows) if no user with the given cognito id exists

func (*Queries) GetContributor added in v1.4.0

func (q *Queries) GetContributor(ctx context.Context, id int64) (*pgdb.Contributor, error)

GetContributor will get a Contributor by the Contributor Id (not the User Id).

func (*Queries) GetContributorByEmail added in v1.4.0

func (q *Queries) GetContributorByEmail(ctx context.Context, email string) (*pgdb.Contributor, error)

GetContributorByEmail will get a Contributor by Email Address.

func (*Queries) GetContributorByOrcid added in v1.4.0

func (q *Queries) GetContributorByOrcid(ctx context.Context, orcid string) (*pgdb.Contributor, error)

GetContributorByOrcid will get a Contributor by ORCID iD.

func (*Queries) GetContributorByUserId added in v1.4.0

func (q *Queries) GetContributorByUserId(ctx context.Context, userId int64) (*pgdb.Contributor, error)

GetContributorByUserId will get a Contributor by User Id.

func (*Queries) GetDatasetById added in v1.11.0

func (q *Queries) GetDatasetById(ctx context.Context, id int64) (*pgdb.Dataset, error)

GetDatasetById will query workspace datasets by name and return one if found.

func (*Queries) GetDatasetByName added in v1.4.0

func (q *Queries) GetDatasetByName(ctx context.Context, name string) (*pgdb.Dataset, error)

GetDatasetByName will query workspace datasets by name and return one if found.

func (*Queries) GetDatasetByNodeId added in v1.11.0

func (q *Queries) GetDatasetByNodeId(ctx context.Context, nodeId string) (*pgdb.Dataset, error)

GetDatasetByNodeId will query workspace datasets by name and return one if found.

func (*Queries) GetDatasetClaim

func (q *Queries) GetDatasetClaim(ctx context.Context, user *pgdb.User, datasetNodeId string, organizationId int64) (*dataset.Claim, error)

GetDatasetClaim returns the highest role that the user has for a given dataset. This method checks the roles of the dataset, the teams, and the specific user roles. returns (nil, sql.ErrNoRows) if no dataset with the given nodeId is found

func (*Queries) GetDatasetContributor added in v1.4.0

func (q *Queries) GetDatasetContributor(ctx context.Context, datasetId int64, contributorId int64) (*pgdb.DatasetContributor, error)

func (*Queries) GetDatasetRelease added in v1.9.0

func (q *Queries) GetDatasetRelease(ctx context.Context, datasetId int64, label string, marker string) (*pgdb.DatasetRelease, error)

func (*Queries) GetDatasetReleaseById added in v1.11.0

func (q *Queries) GetDatasetReleaseById(ctx context.Context, id int64) (*pgdb.DatasetRelease, error)

func (*Queries) GetDatasetStorageById

func (q *Queries) GetDatasetStorageById(ctx context.Context, datasetId int64) (int64, error)

func (*Queries) GetDatasetUser added in v1.4.0

func (q *Queries) GetDatasetUser(ctx context.Context, dataset *pgdb.Dataset, user *pgdb.User) (*pgdb.DatasetUser, error)

func (*Queries) GetDatasets

func (q *Queries) GetDatasets(ctx context.Context, organizationId int) ([]pgdb.Dataset, error)

GetDatasets returns all rows in the Upload Record Table

func (*Queries) GetDefaultDataUseAgreement added in v1.4.0

func (q *Queries) GetDefaultDataUseAgreement(ctx context.Context, organizationId int) (*pgdb.DataUseAgreement, error)

GetDefaultDataUseAgreement will return the default data use agreement for the organization. Returns (nil, sql.ErrNoRows) if no default data use agreement is found for the organization

func (*Queries) GetDefaultDatasetStatus added in v1.4.0

func (q *Queries) GetDefaultDatasetStatus(ctx context.Context, organizationId int) (*pgdb.DatasetStatus, error)

GetDefaultDatasetStatus will return the default dataset status for the organization. This is assumed to be the dataset status row with the lowest id number. Returns (nil, sql.ErrNoRows) if no dataset status is found for the organization

func (*Queries) GetEnabledFeatureFlags added in v1.12.1

func (q *Queries) GetEnabledFeatureFlags(ctx context.Context, organizationId int64) ([]pgdb.FeatureFlags, error)

func (*Queries) GetFeatureFlags

func (q *Queries) GetFeatureFlags(ctx context.Context, organizationId int64) ([]pgdb.FeatureFlags, error)

GetFeatureFlags returns all rows in the FeatureFlags Table

func (*Queries) GetOrganization

func (q *Queries) GetOrganization(ctx context.Context, id int64) (*pgdb.Organization, error)

GetOrganization returns a single organization

func (*Queries) GetOrganizationByName added in v1.4.10

func (q *Queries) GetOrganizationByName(ctx context.Context, name string) (*pgdb.Organization, error)

GetOrganizationByName returns a single organization

func (*Queries) GetOrganizationByNodeId added in v1.4.9

func (q *Queries) GetOrganizationByNodeId(ctx context.Context, nodeId string) (*pgdb.Organization, error)

GetOrganizationByNodeId returns a single organization

func (*Queries) GetOrganizationBySlug added in v1.4.10

func (q *Queries) GetOrganizationBySlug(ctx context.Context, slug string) (*pgdb.Organization, error)

GetOrganizationBySlug returns a single organization

func (*Queries) GetOrganizationClaim

func (q *Queries) GetOrganizationClaim(ctx context.Context, userId int64, organizationId int64) (*organization.Claim, error)

GetOrganizationClaim returns an organization claim for a specific user given a workspace id

func (*Queries) GetOrganizationClaimByNodeId added in v1.12.1

func (q *Queries) GetOrganizationClaimByNodeId(ctx context.Context, userId int64, organizationNodeId string) (*organization.Claim, error)

GetOrganizationClaimByNodeId returns an organization claim for a specific user given a workspace node id

func (*Queries) GetOrganizationStorageById

func (q *Queries) GetOrganizationStorageById(ctx context.Context, organizationId int64) (int64, error)

func (*Queries) GetOrganizationUser added in v1.4.0

func (q *Queries) GetOrganizationUser(ctx context.Context, orgId int64, userId int64) (*pgdb.OrganizationUser, error)

GetOrganizationUser returns the *pgdb.OrganizationUser with the give org and user ids. Returns (nil, OrganizationUserNotFoundError) if no such org user is found

func (*Queries) GetOrganizationUserById

func (q *Queries) GetOrganizationUserById(ctx context.Context, id int64) (*pgdb.OrganizationUser, error)

GetOrganizationUserById returns *pgdb.OrganizationUser with the given user id. If no such user exists, returns (nil, sql.ErrNoRows)

func (*Queries) GetPackageAncestorIds added in v1.4.7

func (q *Queries) GetPackageAncestorIds(ctx context.Context, packageId int64) ([]int64, error)

GetPackageAncestorIds returns an array of Package Ids corresponding with the ancestor Package Ids for the provided package.

  • resulting array includes requested package Id as first entry
  • resulting array includes first folder in dataset as last entry if package is in nested folder

func (*Queries) GetPackageByNodeId

func (q *Queries) GetPackageByNodeId(ctx context.Context, nodeId string) (*pgdb.Package, error)

func (*Queries) GetPackageChildren

func (q *Queries) GetPackageChildren(ctx context.Context, parent *pgdb.Package, datasetId int, onlyFolders bool) ([]pgdb.Package, error)

GetPackageChildren Get the children in a package

func (*Queries) GetPackageStorageById

func (q *Queries) GetPackageStorageById(ctx context.Context, packageId int64) (int64, error)

func (*Queries) GetTeamClaims added in v1.6.0

func (q *Queries) GetTeamClaims(ctx context.Context, userId int64) ([]teamUser.Claim, error)

func (*Queries) GetTeamMemberships added in v1.6.0

func (q *Queries) GetTeamMemberships(ctx context.Context, userId int64) ([]UserTeamMembership, error)

func (*Queries) GetTokenByCognitoId

func (q *Queries) GetTokenByCognitoId(ctx context.Context, id string) (*pgdb.Token, error)

GetTokenByCognitoId returns a user from Postgress based on his/her cognito-id This function also returns the preferred org and whether the user is a super-admin. Returns (nil, sql.ErrNoRows) if no user with the given cognito id exists.

func (*Queries) GetUserByCognitoId

func (q *Queries) GetUserByCognitoId(ctx context.Context, id string) (*pgdb.User, error)

GetUserByCognitoId returns a Pennsieve User based on the cognito id in the token pool. Returns (nil, sql.ErrNoRows) if no user with the given token exists

func (*Queries) GetUserById added in v1.4.0

func (q *Queries) GetUserById(ctx context.Context, id int64) (*pgdb.User, error)

GetUserById returns a user from Postgres based on the user's int id This function also returns the preferred org and whether the user is a super-admin. Returns (nil, sql.ErrNoRows) if no user with the given id exists.

func (*Queries) IncrementDatasetStorage

func (q *Queries) IncrementDatasetStorage(ctx context.Context, datasetId int64, size int64) error

IncrementDatasetStorage increases the storage associated with the provided dataset.

func (*Queries) IncrementOrganizationStorage

func (q *Queries) IncrementOrganizationStorage(ctx context.Context, organizationId int64, size int64) error

IncrementOrganizationStorage increases the storage associated with the provided organization.

func (*Queries) IncrementPackageStorage

func (q *Queries) IncrementPackageStorage(ctx context.Context, packageId int64, size int64) error

IncrementPackageStorage increases the storage associated with the provided package.

func (*Queries) IncrementPackageStorageAncestors

func (q *Queries) IncrementPackageStorageAncestors(ctx context.Context, parentId int64, size int64) error

IncrementPackageStorageAncestors increases the storage associated with the parents of the provided package.

func (*Queries) SetUpdatedAt added in v1.9.1

func (q *Queries) SetUpdatedAt(ctx context.Context, datasetId int64, t time.Time) error

func (*Queries) ShowSearchPath

func (q *Queries) ShowSearchPath(loc string)

func (*Queries) UpdateBucketForFile

func (q *Queries) UpdateBucketForFile(ctx context.Context, uploadId string, bucket string, s3Key string, organizationId int64) error

UpdateBucketForFile updates the storage bucket as part of upload process and sets Status

func (*Queries) UpdateDatasetRelease added in v1.11.0

func (q *Queries) UpdateDatasetRelease(ctx context.Context, release pgdb.DatasetRelease) (*pgdb.DatasetRelease, error)

func (*Queries) WithOrg

func (q *Queries) WithOrg(orgId int) (*Queries, error)

func (*Queries) WithTx

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

WithTx Returns a new Queries object wrapped by a transactions.

type SQLStore

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

SQLStore provides the Queries interface and a db instance.

func NewSQLStore

func NewSQLStore(db *sql.DB) *SQLStore

NewSQLStore returns a SQLStore object which implements the Queries

type UserTeamMembership added in v1.5.0

type UserTeamMembership struct {
	UserId            int64
	UserEmail         string
	UserNodeId        string
	OrgId             int64
	OrgName           string
	OrgNodeId         string
	OrgUserPermission pgdb.DbPermission
	TeamId            int64
	TeamName          string
	TeamNodeId        string
	TeamPermission    pgdb.DbPermission
	TeamType          sql.NullString
}

Jump to

Keyboard shortcuts

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