From 7db4ca2aeccc76504713b3a1b756275a4d52b769 Mon Sep 17 00:00:00 2001 From: Vinayaks439 <vinayaks439@gmail.com> Date: Sun, 3 Dec 2023 21:41:19 +0530 Subject: [PATCH] Remove update and delete in entry --- db/query/entries.sql | 13 +------------ db/sqlc/entries.sql.go | 36 ------------------------------------ db/sqlc/entries.sql_test.go | 28 ---------------------------- db/sqlc/querier.go | 2 -- 4 files changed, 1 insertion(+), 78 deletions(-) diff --git a/db/query/entries.sql b/db/query/entries.sql index 045267f..0c4f7af 100644 --- a/db/query/entries.sql +++ b/db/query/entries.sql @@ -16,15 +16,4 @@ INSERT INTO entries ( amount ) VALUES ( $1,$2 -) RETURNING *; - --- name: UpdateEntry :one -UPDATE entries SET - account_id = $1, - amount = $2 -WHERE id = $3 -RETURNING *; - --- name: DeleteEntry :exec -DELETE FROM entries -WHERE id = $1; \ No newline at end of file +) RETURNING *; \ No newline at end of file diff --git a/db/sqlc/entries.sql.go b/db/sqlc/entries.sql.go index 10ba10f..958eb72 100644 --- a/db/sqlc/entries.sql.go +++ b/db/sqlc/entries.sql.go @@ -35,16 +35,6 @@ func (q *Queries) CreateEntries(ctx context.Context, arg CreateEntriesParams) (E return i, err } -const deleteEntry = `-- name: DeleteEntry :exec -DELETE FROM entries -WHERE id = $1 -` - -func (q *Queries) DeleteEntry(ctx context.Context, id int64) error { - _, err := q.db.Exec(ctx, deleteEntry, id) - return err -} - const getEntry = `-- name: GetEntry :one SELECT id, account_id, amount, created_at FROM entries WHERE id = $1 @@ -101,29 +91,3 @@ func (q *Queries) ListEntries(ctx context.Context, arg ListEntriesParams) ([]Ent } return items, nil } - -const updateEntry = `-- name: UpdateEntry :one -UPDATE entries SET - account_id = $1, - amount = $2 -WHERE id = $3 -RETURNING id, account_id, amount, created_at -` - -type UpdateEntryParams struct { - AccountID int64 `json:"account_id"` - Amount int64 `json:"amount"` - ID int64 `json:"id"` -} - -func (q *Queries) UpdateEntry(ctx context.Context, arg UpdateEntryParams) (Entry, error) { - row := q.db.QueryRow(ctx, updateEntry, arg.AccountID, arg.Amount, arg.ID) - var i Entry - err := row.Scan( - &i.ID, - &i.AccountID, - &i.Amount, - &i.CreatedAt, - ) - return i, err -} diff --git a/db/sqlc/entries.sql_test.go b/db/sqlc/entries.sql_test.go index c37ce95..4598ede 100644 --- a/db/sqlc/entries.sql_test.go +++ b/db/sqlc/entries.sql_test.go @@ -47,31 +47,3 @@ func TestListEntries(t *testing.T) { require.NotZero(t, entry.CreatedAt) } } - -func TestUpdateEntry(t *testing.T) { - args := UpdateEntryParams{ - ID: 1, - Amount: 200, - } - entry, err := testQueries.UpdateEntry(context.Background(), args) - require.NoError(t, err) - require.NotEmpty(t, entry) - require.Equal(t, args.ID, entry.ID) - require.Equal(t, args.Amount, entry.Amount) - require.NotZero(t, entry.ID) - require.NotZero(t, entry.CreatedAt) - -} -func TestDeleteEntry(t *testing.T) { - entry, err := testQueries.CreateEntries(context.Background(), CreateEntriesParams{ - Amount: 100, - AccountID: int64(2), - }) - getEntry, err := testQueries.GetEntry(context.Background(), entry.ID) - err = testQueries.DeleteEntry(context.Background(), 1) - require.NoError(t, err) - require.NotEmpty(t, getEntry) - require.Equal(t, entry.ID, getEntry.ID) - require.Equal(t, entry.AccountID, getEntry.AccountID) - require.Equal(t, entry.Amount, getEntry.Amount) -} diff --git a/db/sqlc/querier.go b/db/sqlc/querier.go index da05ee2..4b7642c 100644 --- a/db/sqlc/querier.go +++ b/db/sqlc/querier.go @@ -12,13 +12,11 @@ type Querier interface { CreateAccount(ctx context.Context, arg CreateAccountParams) (Account, error) CreateEntries(ctx context.Context, arg CreateEntriesParams) (Entry, error) DeleteAccount(ctx context.Context, id int64) error - DeleteEntry(ctx context.Context, id int64) error GetAccount(ctx context.Context, id int64) (Account, error) GetEntry(ctx context.Context, id int64) (Entry, error) ListAccounts(ctx context.Context, arg ListAccountsParams) ([]Account, error) ListEntries(ctx context.Context, arg ListEntriesParams) ([]Entry, error) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (Account, error) - UpdateEntry(ctx context.Context, arg UpdateEntryParams) (Entry, error) } var _ Querier = (*Queries)(nil)