product.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package db
  2. import (
  3. "github.com/gshopify/service-wrapper/model"
  4. "gshopper.com/gshopify/products/cache"
  5. "time"
  6. )
  7. const defaultCurrency = "USD"
  8. var (
  9. productKey = func(clause string, args ...any) *cache.SqlKey {
  10. return cache.NewSQLKey(
  11. "product",
  12. time.Minute,
  13. clause, args...)
  14. }
  15. productSelection = func(ln model.LanguageCode) []string {
  16. return append([]string{
  17. "id", "handle", "type", "scope", "tags", "vendor",
  18. "collections", "images", "options",
  19. "created_at", "updated_at", "published_at", "deleted_at",
  20. },
  21. ln.SqlFieldSelection("title", ""),
  22. ln.SqlFieldSelection("description", ""),
  23. )
  24. }
  25. productCollectionSelection = func(ln model.LanguageCode) []string {
  26. return append([]string{
  27. "id", "handle", "scope", "sort_order", "image", "template_suffix",
  28. "created_at", "updated_at", "published_at", "deleted_at",
  29. },
  30. ln.SqlFieldSelection("title", ""),
  31. ln.SqlFieldSelection("description", ""),
  32. )
  33. }
  34. productCollectionKey = func(clause string, args ...any) *cache.SqlKey {
  35. return cache.NewSQLKey(
  36. "product_collection",
  37. 3*time.Minute,
  38. clause,
  39. args...,
  40. )
  41. }
  42. productOptionSelection = func(ln model.LanguageCode) []string {
  43. return append([]string{"id", "position", "created_at", "updated_at", "published_at", "deleted_at"},
  44. ln.SqlFieldSelection("name", ""),
  45. ln.SqlArraySelection("values"),
  46. )
  47. }
  48. productOptionKey = func(clause string, args ...any) *cache.SqlKey {
  49. return cache.NewSQLKey(
  50. "product_option",
  51. time.Minute,
  52. clause, args...)
  53. }
  54. productVariantKey = func(clause string, args ...any) *cache.SqlKey {
  55. return cache.NewSQLKey(
  56. "product_variant",
  57. time.Minute,
  58. clause, args...)
  59. }
  60. )