pgdb

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: Apache-2.0 Imports: 23 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

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.

Types

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 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) 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) 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) 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.

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.

func (*Queries) GetDatasetStorageById

func (q *Queries) GetDatasetStorageById(ctx context.Context, datasetId int64) (int64, 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) 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) GetOrganizationClaim

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

GetOrganizationClaim returns an organization claim for a specific user.

func (*Queries) GetOrganizationStorageById

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

func (*Queries) GetOrganizationUserById

func (q *Queries) GetOrganizationUserById(ctx context.Context, id int64) (*pgdb.OrganizationUser, 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) 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.

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.

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) 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) 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

Jump to

Keyboard shortcuts

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