postgres

package
v0.0.0-...-b70f3cf Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Postgres

type Postgres interface {
	Close() // Add any other methods you want to define
	NewID(prefix string) string
	GetConnectionPool() *pgxpool.Pool

	//users
	InsertNewUser(ctx context.Context, user models.Users) (*models.Users, error)
	GetUserByEmail(ctx context.Context, email string) (*models.Users, error)
	GetUserByID(ctx context.Context, id string) (*models.Users, error)
	UpdateUserSeenAtByID(ctx context.Context, userID string) error
	GetPasswordHashByEmail(ctx context.Context, email string) (string, error)

	//organizations
	InsertNewOrganization(ctx context.Context, organization models.Organizations) error
	GetOrganizationsByCreatorID(creatorID string) ([]models.Organizations, error)
	GetOrganizationByID(ctx context.Context, id string) (*models.Organizations, error)

	//userorganizations
	InsertNewUserOrganization(ctx context.Context, userOrganization models.UserOrganizations) error
	GetLastUserOrganizationByUserID(ctx context.Context, userID string) (*models.UserOrganizations, error)
	UpdateUserOrganizationUpdatedAt(ctx context.Context, id string) error
	GetUserOrganizationByOrgIDAndUserID(ctx context.Context, orgID, userID string) (*models.UserOrganizations, error)

	//urlstore
	InsertNewURLStore(ctx context.Context, urlStore models.URLStore) (*models.URLStore, error)
	GetURLStoreByURL(ctx context.Context, url string) (*models.URLStore, error)
	GetURLStoreByID(ctx context.Context, id string) (*models.URLStore, error)
	UpdateURLStoreByURL(ctx context.Context, url string, urlData models.URLStore) (*models.URLStore, error)
	UpdateURLStoreByID(ctx context.Context, id string, urlData models.URLStore) (*models.URLStore, error)
	GetURLStoreByIDs(ctx context.Context, ids []string) ([]models.URLStore, error)
	GetURLsByIDs(ctx context.Context, ids []string) ([]models.URLStore, error)

	//jobqueue
	InsertJobQueues(ctx context.Context, org_id, job_id string, job_data []string) error
	UpdateJobQueueStatus(ctx context.Context, job_id, url_id, status string) error
	GetJobQueueStatusCount(ctx context.Context, org_id string) (map[string]int, error)
	InsertJobQueue(ctx context.Context, org_id, job_data string) error
	GetJobQueuePendingOlderThan1Hour(ctx context.Context, org_id string) ([]models.JobQueue, error)

	//urlorganizations
	InsertNewURLOrganization(ctx context.Context, urlOrganization models.URLOrganizations) (*models.URLOrganizations, error)
	GetURLsForOrganization(ctx context.Context, organizationID string, lastID string, pageSize int) ([]*models.URLResponses, error)
	GetURLOrganizationByID(ctx context.Context, id string) (*models.URLOrganizations, error)
	GetURLCountForOrganization(ctx context.Context, organizationID string) (int, error)
	GetURLOrganizationsByURLIDOrgID(ctx context.Context, urlID string, organizationID string) (*models.URLOrganizations, error)
	UpdateURLStatusByID(ctx context.Context, id string, status string) error
	DeleteURLByID(ctx context.Context, id string) error
	DeleteURLsByIDs(ctx context.Context, ids []string, orgID string) error
	GetNewURLsForOrganization(ctx context.Context, organizationID string, firstId string, pageSize int) ([]models.URLOrganizations, error)

	//urlstore and urlorganizations
	GetAllURLsForORG(ctx context.Context, orgID string) (*[]models.URLStore, *[]models.URLOrganizations, error)
	SearchURLs(ctx context.Context, orgID, query, domain string) ([]*models.URLResponses, error)
	GetURLStoreByURLOrgIDOrgID(ctx context.Context, urlOrgID, orgID string) (*models.URLStore, error)
	GetSingleURLForOrganization(ctx context.Context, organizationID string, urlOrgID string) (*models.URLResponses, error)
	GetSingleURLForOrganizationURL(ctx context.Context, organizationID string, url string) (*models.URLResponses, error)

	//secrets
	InsertNewSecret(ctx context.Context, secret models.DbSecret) error
	GetSecretByOrgAndValue(ctx context.Context, organizationID, secretType, secretValue string) (*models.DbSecret, error)
	GetSecretByID(ctx context.Context, id string) (*models.DbSecret, error)
	GetSecretsByOrganizationID(ctx context.Context, organizationID, secretType string) ([]*models.DbSecret, error)
	DeactivateSecret(ctx context.Context, id, organizationID string) error
	GetSecretByValue(ctx context.Context, secretValue string) (*models.DbSecret, error)

	//subscriptions
	InsertSubscription(ctx context.Context, subscription models.Subscription) (*models.Subscription, error)
	GetSubscriptionByUserID(ctx context.Context, userID string) (*models.Subscription, error)
	IsAllowedToUse(ctx context.Context, userID string) (bool, error)
	UpdateSubscriptionStatus(ctx context.Context, subID, orderID string) error

	//orders
	InsertOrder(ctx context.Context, order models.Orders) (*models.Orders, error)
	UpdateOrder(ctx context.Context, order_id, order_object string) (*models.Orders, error)

	GetActiveOrgSchedules(ctx context.Context, org_id string) (*[]models.Schedule, error)
	InsertSchedule(ctx context.Context, schedule *models.Schedule) error
	GetAllSchedulesForORG(ctx context.Context, orgID string) (*[]models.Schedule, error)
	GetScheduleByID(ctx context.Context, schedule_id string) (*models.Schedule, error)
	UpdateScheduleStatus(ctx context.Context, schedule_id, org_id, status string) error
	DeleteScheduleByIDs(ctx context.Context, schedule_ids []string, org_id string) error
	GetActiveSchedulesWithInterval(ctx context.Context, interval int) (*[]models.Schedule, error)
	GetSchedulesByIDsAndOrgIDs(ctx context.Context, schedule_ids []string, org_id string) (*[]models.Schedule, error)
}

Postgres interface defines the methods for the PostgreSQL implementation

func ConfigurePostgres

func ConfigurePostgres(ctx context.Context, connString string) (Postgres, error)

ConfigurePostgres initializes the PostgreSQL connection pool

type PostgresImplementation

type PostgresImplementation struct {
	Pool *pgxpool.Pool
}

PostgresImplementation holds the connection pool

func (*PostgresImplementation) Close

func (p *PostgresImplementation) Close()

Close closes the database connection pool

func (*PostgresImplementation) DeactivateSecret

func (p *PostgresImplementation) DeactivateSecret(ctx context.Context, id, organizationID string) error

deactivate a secret given id and organization id

func (*PostgresImplementation) DeleteScheduleByIDs

func (p *PostgresImplementation) DeleteScheduleByIDs(ctx context.Context, schedule_ids []string, org_id string) error

Delete a schedule given schedule id and org id

func (*PostgresImplementation) DeleteURLByID

func (p *PostgresImplementation) DeleteURLByID(ctx context.Context, id string) error

DeleteURLByID

func (*PostgresImplementation) DeleteURLsByIDs

func (p *PostgresImplementation) DeleteURLsByIDs(ctx context.Context, ids []string, orgID string) error

delete urls by ids

func (*PostgresImplementation) GetActiveOrgSchedules

func (p *PostgresImplementation) GetActiveOrgSchedules(ctx context.Context, org_id string) (*[]models.Schedule, error)

Get Active Schedules for org

func (*PostgresImplementation) GetActiveSchedulesWithInterval

func (p *PostgresImplementation) GetActiveSchedulesWithInterval(ctx context.Context, interval int) (*[]models.Schedule, error)

Get all schedules that are active and given an interval

func (*PostgresImplementation) GetAllSchedulesForORG

func (p *PostgresImplementation) GetAllSchedulesForORG(ctx context.Context, orgID string) (*[]models.Schedule, error)

Get all schedules for an organization

func (*PostgresImplementation) GetAllURLsForORG

func (p *PostgresImplementation) GetAllURLsForORG(ctx context.Context, orgID string) (*[]models.URLStore, *[]models.URLOrganizations, error)

func (*PostgresImplementation) GetConnectionPool

func (p *PostgresImplementation) GetConnectionPool() *pgxpool.Pool

GetConnectionPool returns the connection pool

func (*PostgresImplementation) GetJobQueueByOrgIDJobData

func (p *PostgresImplementation) GetJobQueueByOrgIDJobData(ctx context.Context, org_id, job_data string) (*models.JobQueue, error)

get jobqueue models.JobQueue by orgid and job data, should return only one

func (*PostgresImplementation) GetJobQueuePendingOlderThan1Hour

func (p *PostgresImplementation) GetJobQueuePendingOlderThan1Hour(ctx context.Context, org_id string) ([]models.JobQueue, error)

given orgid get job_data with status pending or queued older than 1 hour

func (*PostgresImplementation) GetJobQueueStatusCount

func (p *PostgresImplementation) GetJobQueueStatusCount(ctx context.Context, org_id string) (map[string]int, error)

GetJobQueueStatusCount(org_id string)

func (*PostgresImplementation) GetLastUserOrganizationByUserID

func (p *PostgresImplementation) GetLastUserOrganizationByUserID(ctx context.Context, userID string) (*models.UserOrganizations, error)

func (*PostgresImplementation) GetNewURLsForOrganization

func (p *PostgresImplementation) GetNewURLsForOrganization(ctx context.Context, organizationID string, firstId string, pageSize int) ([]models.URLOrganizations, error)

GetNewURLsForOrganization(organizationID string, firstId string, pageSize int) ([]models.URLOrganizations, error)

func (*PostgresImplementation) GetOrganizationByID

func (p *PostgresImplementation) GetOrganizationByID(ctx context.Context, id string) (*models.Organizations, error)

get organization by id

func (*PostgresImplementation) GetOrganizationsByCreatorID

func (p *PostgresImplementation) GetOrganizationsByCreatorID(creatorID string) ([]models.Organizations, error)

func (*PostgresImplementation) GetPasswordHashByEmail

func (p *PostgresImplementation) GetPasswordHashByEmail(ctx context.Context, email string) (string, error)

get password has by email id

func (*PostgresImplementation) GetScheduleByID

func (p *PostgresImplementation) GetScheduleByID(ctx context.Context, schedule_id string) (*models.Schedule, error)

get schedules for a particular schedule id from schedules table

func (*PostgresImplementation) GetSchedulesByIDsAndOrgIDs

func (p *PostgresImplementation) GetSchedulesByIDsAndOrgIDs(ctx context.Context, schedule_ids []string, org_id string) (*[]models.Schedule, error)

get schedules for given schedule ids []string and org id

func (*PostgresImplementation) GetSecretByID

func (p *PostgresImplementation) GetSecretByID(ctx context.Context, id string) (*models.DbSecret, error)

get by id

func (*PostgresImplementation) GetSecretByOrgAndValue

func (p *PostgresImplementation) GetSecretByOrgAndValue(ctx context.Context, organizationID, secretType, secretValue string) (*models.DbSecret, error)

Get a secret by Organization ID and Secret Type and Secret Value and status ACTIVE

func (*PostgresImplementation) GetSecretByValue

func (p *PostgresImplementation) GetSecretByValue(ctx context.Context, secretValue string) (*models.DbSecret, error)

get secret by secret value

func (*PostgresImplementation) GetSecretsByOrganizationID

func (p *PostgresImplementation) GetSecretsByOrganizationID(ctx context.Context, organizationID, secretType string) ([]*models.DbSecret, error)

return active secrets for an organization

func (*PostgresImplementation) GetSingleURLForOrganization

func (p *PostgresImplementation) GetSingleURLForOrganization(ctx context.Context, organizationID string, urlOrgID string) (*models.URLResponses, error)

func (*PostgresImplementation) GetSingleURLForOrganizationURL

func (p *PostgresImplementation) GetSingleURLForOrganizationURL(ctx context.Context, organizationID string, url string) (*models.URLResponses, error)

func (*PostgresImplementation) GetSubscriptionByUserID

func (p *PostgresImplementation) GetSubscriptionByUserID(ctx context.Context, userID string) (*models.Subscription, error)

GetSubscriptionByUserID

func (*PostgresImplementation) GetURLCountForOrganization

func (p *PostgresImplementation) GetURLCountForOrganization(ctx context.Context, organizationID string) (int, error)

GetURLCountForOrganization

func (*PostgresImplementation) GetURLOrganizationByID

func (p *PostgresImplementation) GetURLOrganizationByID(ctx context.Context, id string) (*models.URLOrganizations, error)

func (*PostgresImplementation) GetURLOrganizationsByURLIDOrgID

func (p *PostgresImplementation) GetURLOrganizationsByURLIDOrgID(ctx context.Context, urlID string, organizationID string) (*models.URLOrganizations, error)

GetURLOrganizationsByURLIDOrgID

func (*PostgresImplementation) GetURLStoreByID

func (p *PostgresImplementation) GetURLStoreByID(ctx context.Context, id string) (*models.URLStore, error)

func (*PostgresImplementation) GetURLStoreByIDs

func (p *PostgresImplementation) GetURLStoreByIDs(ctx context.Context, ids []string) ([]models.URLStore, error)

func (*PostgresImplementation) GetURLStoreByURL

func (p *PostgresImplementation) GetURLStoreByURL(ctx context.Context, url string) (*models.URLStore, error)

func (*PostgresImplementation) GetURLStoreByURLOrgIDOrgID

func (p *PostgresImplementation) GetURLStoreByURLOrgIDOrgID(ctx context.Context, urlOrgID, orgID string) (*models.URLStore, error)

GetURLStoreByURLOrgIDOrgID

func (*PostgresImplementation) GetURLsByIDs

func (p *PostgresImplementation) GetURLsByIDs(ctx context.Context, ids []string) ([]models.URLStore, error)

func (*PostgresImplementation) GetURLsForOrganization

func (p *PostgresImplementation) GetURLsForOrganization(ctx context.Context, organizationID string, lastID string, pageSize int) ([]*models.URLResponses, error)

func (*PostgresImplementation) GetUserByEmail

func (p *PostgresImplementation) GetUserByEmail(ctx context.Context, email string) (*models.Users, error)

GetUserByEmail retrieves a user by their email from theusers table

func (*PostgresImplementation) GetUserByID

func (p *PostgresImplementation) GetUserByID(ctx context.Context, id string) (*models.Users, error)

GetUserByID ...

func (*PostgresImplementation) GetUserOrganizationByOrgIDAndUserID

func (p *PostgresImplementation) GetUserOrganizationByOrgIDAndUserID(ctx context.Context, orgID, userID string) (*models.UserOrganizations, error)

giver org id and user id, return user organization

func (*PostgresImplementation) InsertJobQueue

func (p *PostgresImplementation) InsertJobQueue(ctx context.Context, org_id, job_data string) error

insert one on unique key constraint violation update status to pending

func (*PostgresImplementation) InsertJobQueues

func (p *PostgresImplementation) InsertJobQueues(ctx context.Context, org_id, job_id string, job_data []string) error

func (*PostgresImplementation) InsertNewOrganization

func (p *PostgresImplementation) InsertNewOrganization(ctx context.Context, organization models.Organizations) error

func (*PostgresImplementation) InsertNewSecret

func (p *PostgresImplementation) InsertNewSecret(ctx context.Context, secret models.DbSecret) error

Insert a new secret

func (*PostgresImplementation) InsertNewURLOrganization

func (p *PostgresImplementation) InsertNewURLOrganization(ctx context.Context, urlOrganization models.URLOrganizations) (*models.URLOrganizations, error)

func (*PostgresImplementation) InsertNewURLStore

func (p *PostgresImplementation) InsertNewURLStore(ctx context.Context, urlStore models.URLStore) (*models.URLStore, error)

func (*PostgresImplementation) InsertNewUser

func (p *PostgresImplementation) InsertNewUser(ctx context.Context, user models.Users) (*models.Users, error)

InsertNewUser inserts a new user into theusers table

func (*PostgresImplementation) InsertNewUserOrganization

func (p *PostgresImplementation) InsertNewUserOrganization(ctx context.Context, userOrganization models.UserOrganizations) error

func (*PostgresImplementation) InsertOrder

func (p *PostgresImplementation) InsertOrder(ctx context.Context, order models.Orders) (*models.Orders, error)

create order

func (*PostgresImplementation) InsertSchedule

func (p *PostgresImplementation) InsertSchedule(ctx context.Context, schedule *models.Schedule) error

insert a new schedule

func (*PostgresImplementation) InsertSubscription

func (p *PostgresImplementation) InsertSubscription(ctx context.Context, subscription models.Subscription) (*models.Subscription, error)

insert into Subscription

func (*PostgresImplementation) IsAllowedToUse

func (p *PostgresImplementation) IsAllowedToUse(ctx context.Context, userID string) (bool, error)

is allowed to use if current_state == PAID or if created_at < 14 days, return true

func (*PostgresImplementation) NewID

func (p *PostgresImplementation) NewID(prefix string) string

func (*PostgresImplementation) SearchURLs

func (p *PostgresImplementation) SearchURLs(ctx context.Context, orgID, query, domain string) ([]*models.URLResponses, error)

func (*PostgresImplementation) UpdateJobQueueStatus

func (p *PostgresImplementation) UpdateJobQueueStatus(ctx context.Context, org_id, job_data, status string) error

func (*PostgresImplementation) UpdateOrder

func (p *PostgresImplementation) UpdateOrder(ctx context.Context, order_id, order_object string) (*models.Orders, error)

Update order to PAID along with order object

func (*PostgresImplementation) UpdateScheduleStatus

func (p *PostgresImplementation) UpdateScheduleStatus(ctx context.Context, schedule_id, org_id, status string) error

Update status of a schedule given schedule id and org id

func (*PostgresImplementation) UpdateSubscriptionStatus

func (p *PostgresImplementation) UpdateSubscriptionStatus(ctx context.Context, subID, orderID string) error

update subscription status to active given user_id, order_id

func (*PostgresImplementation) UpdateURLStatusByID

func (p *PostgresImplementation) UpdateURLStatusByID(ctx context.Context, id string, status string) error

UpdateURLStatusByID

func (*PostgresImplementation) UpdateURLStoreByID

func (p *PostgresImplementation) UpdateURLStoreByID(ctx context.Context, id string, urlData models.URLStore) (*models.URLStore, error)

func (*PostgresImplementation) UpdateURLStoreByURL

func (p *PostgresImplementation) UpdateURLStoreByURL(ctx context.Context, url string, urlData models.URLStore) (*models.URLStore, error)

func (*PostgresImplementation) UpdateUserOrganizationUpdatedAt

func (p *PostgresImplementation) UpdateUserOrganizationUpdatedAt(ctx context.Context, id string) error

func (*PostgresImplementation) UpdateUserSeenAtByID

func (p *PostgresImplementation) UpdateUserSeenAtByID(ctx context.Context, userID string) error

UpdateUserSeenAtByID

Jump to

Keyboard shortcuts

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