Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Apr 5, 2024
1 parent e22f174 commit 3bef75a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
16 changes: 8 additions & 8 deletions sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,17 @@ func (db *SQLiteDB) ReverseIterator(start, end []byte) (Iterator, error) {
stmt := "SELECT key, value FROM kv"
args := []interface{}{}

if start != nil {
stmt += " WHERE key <= ?"
args = append(args, start)
}
if end != nil {
if start != nil {
stmt += " AND key > ?"
stmt += " WHERE key < ?"
args = append(args, end)
}
if start != nil {
if end != nil {
stmt += " AND key >= ?"
} else {
stmt += " WHERE key > ?"
stmt += " WHERE key >= ?"
}
args = append(args, end)
args = append(args, start)
}
stmt += " ORDER BY key DESC"

Expand Down
53 changes: 53 additions & 0 deletions sqlite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package db

import (
"fmt"
"os"
"testing"

"github.com/stretchr/testify/require"
)

func TestSQLiteDBGetSetDelete(t *testing.T) {
name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()

Check failure on line 13 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007(related information): this call to os.TempDir returns the user's temporary directory, for example /tmp (staticcheck)

Check failure on line 13 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007(related information): this call to os.TempDir returns the user's temporary directory, for example /tmp (staticcheck)
db, err := NewSQLiteDB(name, dir)
require.NoError(t, err)
defer db.Close()
defer os.RemoveAll(dir)

Check failure on line 17 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007: this call to os.RemoveAll deletes the user's entire temporary directory, not a subdirectory therein (staticcheck)

Check failure on line 17 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007: this call to os.RemoveAll deletes the user's entire temporary directory, not a subdirectory therein (staticcheck)

testBackendGetSetDelete(t, SQLiteDBBackend)
}

func TestSQLiteDBIterator(t *testing.T) {
name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()

Check failure on line 24 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007(related information): this call to os.TempDir returns the user's temporary directory, for example /tmp (staticcheck)

Check failure on line 24 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007(related information): this call to os.TempDir returns the user's temporary directory, for example /tmp (staticcheck)
db, err := NewSQLiteDB(name, dir)
require.NoError(t, err)
defer db.Close()
defer os.RemoveAll(dir)

Check failure on line 28 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007: this call to os.RemoveAll deletes the user's entire temporary directory, not a subdirectory therein (staticcheck)

Check failure on line 28 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007: this call to os.RemoveAll deletes the user's entire temporary directory, not a subdirectory therein (staticcheck)

testDBIterator(t, SQLiteDBBackend)
}

func TestSQLiteDBBatch(t *testing.T) {
name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()

Check failure on line 35 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007(related information): this call to os.TempDir returns the user's temporary directory, for example /tmp (staticcheck)

Check failure on line 35 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007(related information): this call to os.TempDir returns the user's temporary directory, for example /tmp (staticcheck)
db, err := NewSQLiteDB(name, dir)
require.NoError(t, err)
defer db.Close()
defer os.RemoveAll(dir)

Check failure on line 39 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007: this call to os.RemoveAll deletes the user's entire temporary directory, not a subdirectory therein (staticcheck)

Check failure on line 39 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007: this call to os.RemoveAll deletes the user's entire temporary directory, not a subdirectory therein (staticcheck)

testDBBatch(t, SQLiteDBBackend)
}

func BenchmarkSQLiteDBRandomReadsWrites(b *testing.B) {
name := fmt.Sprintf("test_%x", randStr(12))
dir := os.TempDir()

Check failure on line 46 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007(related information): this call to os.TempDir returns the user's temporary directory, for example /tmp (staticcheck)

Check failure on line 46 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007(related information): this call to os.TempDir returns the user's temporary directory, for example /tmp (staticcheck)
db, err := NewSQLiteDB(name, dir)
require.NoError(b, err)
defer db.Close()
defer os.RemoveAll(dir)

Check failure on line 50 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007: this call to os.RemoveAll deletes the user's entire temporary directory, not a subdirectory therein (staticcheck)

Check failure on line 50 in sqlite_test.go

View workflow job for this annotation

GitHub Actions / lint

SA9007: this call to os.RemoveAll deletes the user's entire temporary directory, not a subdirectory therein (staticcheck)

benchmarkRandomReadsWrites(b, db)
}

0 comments on commit 3bef75a

Please sign in to comment.