@@ -116,7 +116,7 @@ func TestPostgresDatabase_GetExactCount(t *testing.T) {
116116
117117 // Test case 1: Valid row returned
118118 rows := sqlmock .NewRows ([]string {"exact_count" }).AddRow (int64 (10 ))
119- mock .ExpectQuery ("SELECT id ::BIGINT AS exact_count FROM torrents ORDER BY id DESC LIMIT 1 ;" ).
119+ mock .ExpectQuery ("SELECT last_value ::BIGINT AS exact_count FROM seq_torrents_id ;" ).
120120 WillReturnRows (rows )
121121
122122 count , err := db .getExactCount ()
@@ -129,7 +129,7 @@ func TestPostgresDatabase_GetExactCount(t *testing.T) {
129129
130130 // Test case 2: No rows returned
131131 rows = sqlmock .NewRows ([]string {"exact_count" })
132- mock .ExpectQuery ("SELECT id ::BIGINT AS exact_count FROM torrents ORDER BY id DESC LIMIT 1 ;" ).
132+ mock .ExpectQuery ("SELECT last_value ::BIGINT AS exact_count FROM seq_torrents_id ;" ).
133133 WillReturnRows (rows )
134134
135135 count , err = db .getExactCount ()
@@ -142,7 +142,7 @@ func TestPostgresDatabase_GetExactCount(t *testing.T) {
142142
143143 // Test case 3: Null value returned
144144 rows = sqlmock .NewRows ([]string {"exact_count" }).AddRow (nil )
145- mock .ExpectQuery ("SELECT id ::BIGINT AS exact_count FROM torrents ORDER BY id DESC LIMIT 1 ;" ).
145+ mock .ExpectQuery ("SELECT last_value ::BIGINT AS exact_count FROM seq_torrents_id ;" ).
146146 WillReturnRows (rows )
147147
148148 count , err = db .getExactCount ()
@@ -226,7 +226,7 @@ func TestPostgresDatabase_GetNumberOfTorrents(t *testing.T) {
226226
227227 // Test case 1: getExactCount succeeds
228228 rows := sqlmock .NewRows ([]string {"exact_count" }).AddRow (int64 (10 ))
229- mock .ExpectQuery ("SELECT id ::BIGINT AS exact_count FROM torrents ORDER BY id DESC LIMIT 1 ;" ).
229+ mock .ExpectQuery ("SELECT last_value ::BIGINT AS exact_count FROM seq_torrents_id ;" ).
230230 WillReturnRows (rows )
231231
232232 count , err := db .GetNumberOfTorrents ()
@@ -238,7 +238,7 @@ func TestPostgresDatabase_GetNumberOfTorrents(t *testing.T) {
238238 }
239239
240240 // Test case 2: getExactCount fails, getFuzzyCount succeeds
241- mock .ExpectQuery ("SELECT id ::BIGINT AS exact_count FROM torrents ORDER BY id DESC LIMIT 1 ;" ).
241+ mock .ExpectQuery ("SELECT last_value ::BIGINT AS exact_count FROM seq_torrents_id ;" ).
242242 WillReturnError (fmt .Errorf ("exact count failed" ))
243243 rows = sqlmock .NewRows ([]string {"estimate_count" }).AddRow (int64 (20 ))
244244 mock .ExpectQuery ("SELECT reltuples::BIGINT AS estimate_count FROM pg_class WHERE relname='torrents';" ).
@@ -253,7 +253,7 @@ func TestPostgresDatabase_GetNumberOfTorrents(t *testing.T) {
253253 }
254254
255255 // Test case 3: both getExactCount and getFuzzyCount fail
256- mock .ExpectQuery ("SELECT id ::BIGINT AS exact_count FROM torrents ORDER BY id DESC LIMIT 1 ;" ).
256+ mock .ExpectQuery ("SELECT last_value ::BIGINT AS exact_count FROM seq_torrents_id ;" ).
257257 WillReturnError (fmt .Errorf ("exact count failed" ))
258258 mock .ExpectQuery ("SELECT reltuples::BIGINT AS estimate_count FROM pg_class WHERE relname='torrents';" ).
259259 WillReturnError (fmt .Errorf ("fuzzy count failed" ))
0 commit comments