From a6b49f89f4ba0b3c0922147585d66d23dc31d8d7 Mon Sep 17 00:00:00 2001 From: prathamesh0 Date: Tue, 3 May 2022 19:13:00 +0530 Subject: [PATCH] Updates to use v4 schema --- postgres/database.go | 12 +++++++++--- postgres/database_test.go | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/postgres/database.go b/postgres/database.go index a064961..47334bc 100644 --- a/postgres/database.go +++ b/postgres/database.go @@ -32,9 +32,15 @@ import ( var errNotSupported = errors.New("this operation is not supported") var ( - hasPgStr = "SELECT exists(select 1 from public.blocks WHERE key = $1)" - getPgStr = "SELECT data FROM public.blocks WHERE key = $1" - putPgStr = "INSERT INTO public.blocks (key, data) VALUES ($1, $2) ON CONFLICT (key) DO NOTHING" + hasPgStr = "SELECT exists(select 1 from public.blocks WHERE key = $1)" + + // TODO Fix the get query to accomodate block_number field + // Using LIMIT 1 for now + getPgStr = "SELECT data FROM public.blocks WHERE key = $1 LIMIT 1" + + // TODO Fix the put query to accomodate block_number field + // block_number has been put as 1 always for now. + putPgStr = "INSERT INTO public.blocks (key, data, block_number) VALUES ($1, $2, 1) ON CONFLICT DO NOTHING" deletePgStr = "DELETE FROM public.blocks WHERE key = $1" dbSizePgStr = "SELECT pg_database_size(current_database())" ) diff --git a/postgres/database_test.go b/postgres/database_test.go index 3ce5072..eab71a7 100644 --- a/postgres/database_test.go +++ b/postgres/database_test.go @@ -67,7 +67,7 @@ var _ = Describe("Database", func() { Expect(has).ToNot(BeTrue()) }) It("returns true if a key-pair exists in the db", func() { - _, err = db.Exec("INSERT into public.blocks (key, data) VALUES ($1, $2)", testMhKey, testValue) + _, err = db.Exec("INSERT into public.blocks (key, data, block_number) VALUES ($1, $2, 1)", testMhKey, testValue) Expect(err).ToNot(HaveOccurred()) has, err := database.Has(testEthKey) Expect(err).ToNot(HaveOccurred()) @@ -82,7 +82,7 @@ var _ = Describe("Database", func() { Expect(err.Error()).To(ContainSubstring("sql: no rows in result set")) }) It("returns the value associated with the key, if the pair exists", func() { - _, err = db.Exec("INSERT into public.blocks (key, data) VALUES ($1, $2)", testMhKey, testValue) + _, err = db.Exec("INSERT into public.blocks (key, data, block_number) VALUES ($1, $2, 1)", testMhKey, testValue) Expect(err).ToNot(HaveOccurred()) val, err := database.Get(testEthKey) Expect(err).ToNot(HaveOccurred())