Remove order_id, add created_at column
This commit is contained in:
parent
de42a7435b
commit
3092a3f89d
9
init.sql
9
init.sql
|
@ -40,12 +40,17 @@ CREATE TABLE invoices(
|
|||
CREATE TYPE order_side AS ENUM ('BUY', 'SELL');
|
||||
CREATE TABLE orders(
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
share_id UUID NOT NULL REFERENCES shares(id),
|
||||
pubkey TEXT NOT NULL REFERENCES users(pubkey),
|
||||
side ORDER_SIDE NOT NULL,
|
||||
quantity BIGINT NOT NULL,
|
||||
price BIGINT NOT NULL,
|
||||
invoice_id UUID NOT NULL REFERENCES invoices(id),
|
||||
order_id UUID REFERENCES orders(id)
|
||||
invoice_id UUID NOT NULL REFERENCES invoices(id)
|
||||
);
|
||||
ALTER TABLE orders ADD CONSTRAINT order_price CHECK(price > 0 AND price < 100);
|
||||
CREATE TABLE matches(
|
||||
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
|
||||
oid1 UUID NOT NULL REFERENCES orders(id),
|
||||
oid2 UUID NOT NULL REFERENCES orders(id)
|
||||
);
|
||||
|
|
|
@ -77,7 +77,7 @@ type FetchOrdersWhere struct {
|
|||
|
||||
func (db *DB) FetchOrders(where *FetchOrdersWhere, orders *[]Order) error {
|
||||
query := "" +
|
||||
"SELECT o.id, share_id, o.pubkey, o.side, o.quantity, o.price, o.invoice_id, s.description, s.market_id, i.confirmed_at, o.order_id " +
|
||||
"SELECT o.id, share_id, o.pubkey, o.side, o.quantity, o.price, o.invoice_id, o.created_at, s.description, s.market_id, i.confirmed_at " +
|
||||
"FROM orders o " +
|
||||
"JOIN invoices i ON o.invoice_id = i.id " +
|
||||
"JOIN shares s ON o.share_id = s.id " +
|
||||
|
@ -102,7 +102,7 @@ func (db *DB) FetchOrders(where *FetchOrdersWhere, orders *[]Order) error {
|
|||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var order Order
|
||||
rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.InvoiceId, &order.Share.Description, &order.Share.MarketId, &order.Invoice.ConfirmedAt, &order.OrderId)
|
||||
rows.Scan(&order.Id, &order.ShareId, &order.Pubkey, &order.Side, &order.Quantity, &order.Price, &order.InvoiceId, &order.CreatedAt, &order.Share.Description, &order.Share.MarketId, &order.Invoice.ConfirmedAt)
|
||||
*orders = append(*orders, order)
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -34,8 +34,8 @@ type Order struct {
|
|||
Side string `form:"side"`
|
||||
Price int `form:"price"`
|
||||
Quantity int `form:"quantity"`
|
||||
OrderId string
|
||||
InvoiceId string
|
||||
CreatedAt time.Time
|
||||
}
|
||||
|
||||
type Invoice struct {
|
||||
|
|
Loading…
Reference in New Issue