barcodes

package
v0.0.0-...-bf2171b Latest Latest
Warning

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

Go to latest
Published: May 31, 2015 License: MIT Imports: 3 Imported by: 3

Documentation

Index

Constants

View Source
const (

	// Create/Update/Delete
	ACCOUNT_INSERT = "insert into account (id, email, verify_code) values (unhex(?), ?, ?)"
	ACCOUNT_UPDATE = "update account set email = ?, verified = ?, enabled = ?, date_verified=NOW() where id = unhex(?)"
	ACCOUNT_DELETE = "delete from account where id = unhex(?)"

	// Lookup
	ACCOUNT_LOOKUP_BY_EMAIL = "select hex(id), verify_code, verified, enabled from account where email = ?"
	ACCOUNT_LOOKUP_BY_ID    = "select email, verify_code, verified, enabled from account where id = unhex(?)"
)
View Source
const (

	// Amazon
	ASIN_LOOKUP = "select asin, product, is_upc, is_ean, is_isbn, locale from amazon where barcode = ?"
	ASIN_INSERT = "insert into amazon (id, barcode, asin, product, is_upc, is_ean, is_isbn, locale) values (unhex(?), ?, ?, ?, ?, ?, ?, ?)"
)
View Source
const (
	// Barcode Types
	UPC  = "UPC"
	EAN  = "EAN"
	ISBN = "ISBN"
)
View Source
const (
	// Prepared Queries (POD)
	GTIN_LOOKUP       = "select gtin_nm, bsin from gtin where gtin_cd = ?"
	BRAND_LOOKUP      = "select brand_nm, brand_link from brand where bsin = ?"
	BRAND_NAME_LOOKUP = "select bsin, brand_nm, brand_link from brand where brand_nm like ?"

	// User contributions
	BARCODE_LOOKUP           = "select hex(id), product_name, product_desc, is_edit, hex(account_id) from barcode where barcode = ?"
	BARCODE_INSERT           = "insert into barcode (id, barcode, product_name, product_desc, is_edit, account_id) values (unhex(?), ?, ?, ?, ?, unhex(?))"
	BARCODE_BRAND_INSERT     = "insert into barcode_brand (id, bsin, barcode_id) values (unhex(?), ?, unhex(?))"
	CONTRIBUTED_BRAND_LOOKUP = "select hex(id), brand_name, brand_url, hex(account_id) from contributed_brand where brand_name like ?"
	CONTRIBUTED_BRAND_INSERT = "insert into contributed_brand (id, brand_name, brand_url, account_id) values (unhex(?), ?, ?, unhex(?))"
)

Variables

View Source
var (
	// Formatting function: take the 16 random bytes and return them as a string
	// of 8-4-4-4-12 tuples, separated by dashes
	DashedUUID = func(b []byte) string {
		return fmt.Sprintf("%x-%x-%x-%x-%x", b[0:4], b[4:6], b[6:8], b[8:10], b[10:])
	}

	// An alternative formatting function: take the 16 random bytes and return
	// them as a single string, with no dashes
	UndashedUUID = func(b []byte) string {
		return fmt.Sprintf("%x", b)
	}
)

Functions

func ContributeBarcode

func ContributeBarcode(stmt *sql.Stmt, rec BARCODE, acc *ACCOUNT) (string, error)

func ContributeBarcodeBrand

func ContributeBarcodeBrand(stmt *sql.Stmt, rec BARCODE, brand *BRAND) error

func ContributeBrand

func ContributeBrand(stmt *sql.Stmt, rec *CONTRIBUTED_BRAND, acc *ACCOUNT) error

func GenerateUUID

func GenerateUUID(fn func([]byte) string) string

Generate a universally unique identifier (UUID) using the computer's /dev/urandom output as a randomizer, returning a string specified by the given formatting function

func InsertAsin

func InsertAsin(stmt *sql.Stmt, rec AMAZON) error

InsertAsin takes a prepared statement corresponding to an insert, an AMAZON data struct, and inserts the data from the struct as a new record in the database

Types

type ACCOUNT

type ACCOUNT struct {
	Id       string `json:"pk"`
	Email    string `json:"email"`
	APICode  string `json:"code"`
	Verified bool   `json:"verified,omitempty"`
	Enabled  bool   `json:"enabled,omitempty"`
}

func LookupAccount

func LookupAccount(stmt *sql.Stmt, param string, usingId bool) (*ACCOUNT, error)

LookupAccount searches for the Account using either the id (uuid) or email address string parameter, depending on which prepared statement and boolean flag is passed

func (*ACCOUNT) Add

func (a *ACCOUNT) Add(stmt *sql.Stmt) (string, error)

func (*ACCOUNT) Delete

func (a *ACCOUNT) Delete(stmt *sql.Stmt) error

func (*ACCOUNT) Update

func (a *ACCOUNT) Update(stmt *sql.Stmt) error

type AMAZON

type AMAZON struct {
	Asin        string `json:"asin"`
	Barcode     string `json:"barcode"`
	ProductName string `json:"product,omitempty"`
	ProductType string `json:"type,omitempty"`
	Locale      string `json:"locale"`
}

func LookupAsin

func LookupAsin(stmt *sql.Stmt, barcode string) ([]*AMAZON, error)

LookupAsin takes a prepared statment (using the ASIN_LOOKUP string), a barcode string, and looks it up in the Amazon table (sourced from querying the Amazon Product API), returning a list of matching AMAZON structs

type BARCODE

type BARCODE struct {
	Uuid        string `json:"id"`
	Barcode     string `json:"barcode"`
	ProductName string `json:"product,omitempty"`
	ProductDesc string `json:"desc,omitempty"`
	GtinEdit    bool   `json:"gtinCorrection,omitempty"`
	AccountID   string `json:"account"`
}

func LookupContributedBarcode

func LookupContributedBarcode(stmt *sql.Stmt, code string) ([]*BARCODE, error)

type BRAND

type BRAND struct {
	Id   string `json:"bsin"`
	Name string `json:"brand,omitempty"`
	URL  string `json:"url,omitempty"`
}

func LookupBrand

func LookupBrand(stmt *sql.Stmt, bsin string) ([]*BRAND, error)

LookupBrand takes a prepared statment (using the BRAND_LOOKUP string), a bsin (brand id) string, and looks it up in POD, returning a list of matching BRAND structs

func LookupBrandByName

func LookupBrandByName(stmt *sql.Stmt, brandName string) ([]*BRAND, error)

type CONTRIBUTED_BRAND

type CONTRIBUTED_BRAND struct {
	Uuid      string `json:"id"`
	Name      string `json:"brand,omitempty"`
	URL       string `json:"url,omitempty"`
	AccountID string `json:"account"`
}

func LookupContributedBrand

func LookupContributedBrand(stmt *sql.Stmt, brandName string) ([]*CONTRIBUTED_BRAND, error)

type GTIN

type GTIN struct {
	Id          string `json:"barcode"`
	ProductName string `json:"product,omitempty"`
	BrandId     string `json:"bsin,omitempty"`
}

func LookupGtin

func LookupGtin(stmt *sql.Stmt, barcode string) ([]*GTIN, error)

LookupGtin takes a prepared statment (using the GTIN_LOOKUP string), a barcode string, and looks it up in POD, returning a list of matching GTIN structs

Jump to

Keyboard shortcuts

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