Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

store

> 编程语言
Open source

PostgreSQL shopping cart

275 stars0 likes4 views
WebsiteGitHub

About

PostgreSQL shopping cart

PostgreSQL shopping cart

All functionality is in PostgreSQL’s PL/pgSQL functions.

SELECT * FROM … result
items_get() show all items
cart_get(person_id) get cart (unpaid invoice)
lineitem_add(person_id, item_id, quantity) add item to cart
lineitem_delete(lineitems.id) delete lineitem in cart
lineitem_update(lineitems.id, quantity) change quantity (0=delete)
invoice_get(invoices.id) get order
invoice_update(invoices.id, country) update country
invoice_update(invoices.id, country, address) update address
invoice_delete(invoices.id) delete order
invoice_paid(invoices.id, payment info) mark order as paid
invoices_get() show all orders
invoices_get_unshipped() orders needing to be shipped
invoice_shipped(invoice_id, info) mark order as shipped
invoices_get_for(person_id) this person’s orders
items_get_for(person_id) items this person has paid for

Install

gem install pg
gem install json
sh init.sh
sh reset.sh
ruby test-db.rb
ruby test-api.rb

Every API function returns:

  1. “ok” = boolean success/fail
  2. “js” = JSON result (if !ok then {error: "explanation"})

Play around

…

Contents

  • api/ = public API functions (only use these)
  • functions/ = private functions used by API
  • getdb.rb = helper to call API
  • tables.sql = tables and indexes
  • test-api.rb = unit tests of API calls
  • test-db.rb = unit tests of private functions
  • test_data.sql = sample data for testing
  • tester.rb = helper for unit tests
  • triggers/ = triggers for data logic
  • views/ = re-usable views for JSON

Schema for functions

All functions, views, and triggers are in the "store" schema.

So any time you make a change, you can run … "drop schema store cascade; create schema store" … then re-load them all anytime. It won't lose your data.

Questions?

Email me at

Sorry I won’t be watching pull-requests or issues here. I’m posting this just as some example code.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言