db

package
v0.0.0-...-029bd64 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Queries = map[string]string{

	"productsQuery": `
		SELECT
			*
		FROM
			products
		LIMIT $1 OFFSET $2`,

	"detailsQuery": `
		SELECT
			p.id,
			p.name,
			p.slogan,
			p.description,
			p.category,
			p.default_price,
			(
				SELECT
					json_agg(f)
				FROM (
					SELECT
						feature,
						value
					FROM
						features
					WHERE
						product_id = $1
				) AS f
			) AS features
		FROM
			products p
		WHERE
			id = $1`,

	"relatedQuery": `
		SELECT
			related_product_id
		FROM
			related
		WHERE
			current_product_id = $1`,

	"stylesQuery": `SELECT
		(
			SELECT
				json_agg(style_agg)
			FROM
				(
					SELECT
						styles.id AS style_id,
						styles.name,
						styles.original_price,
						styles.sale_price,
						styles.default AS "default?",
						(
							SELECT
								json_agg(photo_agg)
							FROM
								(
									SELECT
										thumbnail_url,
										url
									FROM
										photos
									WHERE
										photos.style_id = styles.id
								) AS photo_agg
						) AS photos,
						(
							SELECT
								json_object_agg(
									skus.id,
									json_build_object(
										'quantity', skus.quantity,
										'size', skus.size
									)
								) AS skus
							FROM
								skus
							WHERE
								skus.style_id = styles.id
						) AS skus
					FROM
						styles
					WHERE
						product_id = $1
				) AS style_agg
		) AS results`,
}

Functions

func Init

func Init()

Types

type DB

type DB struct {
	*pgxpool.Pool
}

func ConnectDB

func ConnectDB(connString string) (DB, error)

func GetDB

func GetDB() DB

Jump to

Keyboard shortcuts

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