Skip to content

Commit

Permalink
Change migration / insert into sheet table
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalObi committed Jan 21, 2021
1 parent 9237929 commit ad37de8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
25 changes: 16 additions & 9 deletions BE/cmd/api/models/sheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,33 @@ import (
"github.com/simplesheet/pkg/application"
)

type Position struct {
Field string
Value string
}

type Sheet struct {
ID int `json:"id"`
Field string `json:"field"`
Value string `json:"value"`
ID int `json:"id"`
HasMetals bool `json:"has_metals"`
HasCrypto bool `json:"has_crypto"`
MetalsFields []Position `json:"metals_fields"`
CryptoFields []Position `json:"crypto_fields"`
}

func (s *Sheet) Create(ctx context.Context, app *application.Application) error {
stmt := `
INSERT INTO sheets (
field,
value
has_metals,
has_crypto
)
VALUES ($1, $2)
RETURNING id
`
err := app.DB.Client.QueryRowContext(
ctx,
stmt,
s.Field,
s.Value,
s.HasMetals,
s.HasCrypto,
).Scan(&s.ID)

if err != nil {
Expand All @@ -46,8 +53,8 @@ func (s *Sheet) GetByID(ctx context.Context, app *application.Application) error
s.ID,
).Scan(
&s.ID,
s.Field,
s.Value,
s.HasMetals,
s.HasCrypto,
)

if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
CREATE TABLE IF NOT EXISTS public.sheets
(
id SERIAL PRIMARY KEY,
group_name VARCHAR(100) NOT NULL,
has_positions BOOLEAN NOT NULL
has_metals BOOLEAN NOT NULL,
has_crypto BOOLEAN NOT NULL
);

CREATE TABLE IF NOT EXISTS public.metals
Expand Down

0 comments on commit ad37de8

Please sign in to comment.