From 830302fa394f6546aac32a80102d404d9cfe6bf3 Mon Sep 17 00:00:00 2001 From: Asdine El Hrychy Date: Sat, 28 Mar 2020 11:03:48 +0400 Subject: [PATCH 01/13] Update bbolt to 1.3.4 --- go.mod | 3 +-- go.sum | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 41f88f6..bfbafd5 100644 --- a/go.mod +++ b/go.mod @@ -10,9 +10,8 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/testify v1.2.2 github.com/vmihailenco/msgpack v4.0.4+incompatible - go.etcd.io/bbolt v1.3.3 + go.etcd.io/bbolt v1.3.4 golang.org/x/net v0.0.0-20191105084925-a882066a44e0 // indirect - golang.org/x/sys v0.0.0-20191105142833-ac3223d80179 // indirect google.golang.org/appengine v1.6.5 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect ) diff --git a/go.sum b/go.sum index 0cc3bb4..6f3ed54 100644 --- a/go.sum +++ b/go.sum @@ -23,6 +23,8 @@ github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaU github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= +go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20190603091049-60506f45cf65 h1:+rhAzEzT3f4JtomfC371qB+0Ola2caSKcY69NUBZrRQ= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= @@ -31,6 +33,8 @@ golang.org/x/net v0.0.0-20191105084925-a882066a44e0/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20191105142833-ac3223d80179 h1:IqVhUQp5B9ARnZUcfqXy6zP+A+YuPpP7IFo8gFeCOzU= golang.org/x/sys v0.0.0-20191105142833-ac3223d80179/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= +golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From 41b6175d11b5cc84c3ba9738ed3fb669f7aca9f7 Mon Sep 17 00:00:00 2001 From: Asdine El Hrychy Date: Sat, 28 Mar 2020 11:04:06 +0400 Subject: [PATCH 02/13] Test on Go 1.14 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 92e5ecd..08e22c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,9 +7,9 @@ env: GO111MODULE=on go: - - '1.11.x' - '1.12.x' - '1.13.x' + - '1.14.x' - tip matrix: From c7f9ee329cf86e1850b8582014e82f10919c0102 Mon Sep 17 00:00:00 2001 From: Paul van Santen Date: Fri, 15 May 2020 16:58:57 +0200 Subject: [PATCH 03/13] Add AES codec for database encryption --- codec/aes/aes.go | 68 +++++++++++++++++++++++++++++++++++++++++++ codec/aes/aes_test.go | 20 +++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 codec/aes/aes.go create mode 100644 codec/aes/aes_test.go diff --git a/codec/aes/aes.go b/codec/aes/aes.go new file mode 100644 index 0000000..60710d3 --- /dev/null +++ b/codec/aes/aes.go @@ -0,0 +1,68 @@ +package database + +import ( + "crypto/aes" + "crypto/cipher" + "crypto/rand" + "fmt" + "io" + + "github.com/asdine/storm/v3/codec" +) + +const name = "aes-" + +// AES is an Codec that encrypts the data and uses a sub marshaller to actually serialize the data +type AES struct { + subMarshaller codec.MarshalUnmarshaler + aesGCM cipher.AEAD +} + +// NewAES creates a new AES encryption marshaller. It takes a sub marshaller to actually serialize the data and a 16/24/32 bytes private key to +// encrypt all data using AES in GCM block mode. +func NewAES(subMarshaller codec.MarshalUnmarshaler, key []byte) (*AES, error) { + aesCipher, err := aes.NewCipher(key) + if err != nil { + return nil, fmt.Errorf("error creating AES cipher: %w", err) + } + + aesGCM, err := cipher.NewGCM(aesCipher) + if err != nil { + return nil, fmt.Errorf("error creating GCM block mode: %w", err) + } + + return &AES{ + subMarshaller: subMarshaller, + aesGCM: aesGCM, + }, nil +} + +func (c *AES) Name() string { + // Return a dynamic name, because the marshalling will also fail if the inner marshalling changes. + return name + c.subMarshaller.Name() +} + +func (c *AES) Marshal(v interface{}) ([]byte, error) { + data, err := c.subMarshaller.Marshal(v) + if err != nil { + return nil, err + } + + nonce := make([]byte, c.aesGCM.NonceSize()) + _, err = io.ReadFull(rand.Reader, nonce) + if err != nil { + return nil, fmt.Errorf("error reading random nonce: %w", err) + } + + return c.aesGCM.Seal(nonce, nonce, data, nil), nil +} + +func (c *AES) Unmarshal(data []byte, v interface{}) error { + nonceSize := c.aesGCM.NonceSize() + decrypted, err := c.aesGCM.Open(nil, data[:nonceSize], data[nonceSize:], nil) + if err != nil { + return fmt.Errorf("error decrypting data: %w", err) + } + + return c.subMarshaller.Unmarshal(decrypted, v) +} diff --git a/codec/aes/aes_test.go b/codec/aes/aes_test.go new file mode 100644 index 0000000..185f9d9 --- /dev/null +++ b/codec/aes/aes_test.go @@ -0,0 +1,20 @@ +package database + +import ( + "encoding/base64" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/asdine/storm/v3/codec/internal" + "github.com/asdine/storm/v3/codec/json" +) + +var testKey, _ = base64.StdEncoding.DecodeString("xkBTXc1wn0C/aL31u9SA7g==") + +func TestAES(t *testing.T) { + aes, err := NewAES(json.Codec, testKey) + require.NoError(t, err) + + internal.RoundtripTester(t, aes) +} From fb193f1315a598b471bbd5759575b0631f45e221 Mon Sep 17 00:00:00 2001 From: Paul van Santen Date: Fri, 15 May 2020 17:00:26 +0200 Subject: [PATCH 04/13] Fix comment --- codec/aes/aes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codec/aes/aes.go b/codec/aes/aes.go index 60710d3..ac772e7 100644 --- a/codec/aes/aes.go +++ b/codec/aes/aes.go @@ -18,7 +18,7 @@ type AES struct { aesGCM cipher.AEAD } -// NewAES creates a new AES encryption marshaller. It takes a sub marshaller to actually serialize the data and a 16/24/32 bytes private key to +// NewAES creates a new AES encryption marshaller. It takes a sub marshaller to actually serialize the data and a 16/32 bytes private key to // encrypt all data using AES in GCM block mode. func NewAES(subMarshaller codec.MarshalUnmarshaler, key []byte) (*AES, error) { aesCipher, err := aes.NewCipher(key) From 3d67b2134e295c23b9a9de2a98028298eb1d0aa6 Mon Sep 17 00:00:00 2001 From: Paul van Santen Date: Fri, 15 May 2020 17:03:49 +0200 Subject: [PATCH 05/13] Add explanatory comments --- codec/aes/aes.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/codec/aes/aes.go b/codec/aes/aes.go index ac772e7..fb09b24 100644 --- a/codec/aes/aes.go +++ b/codec/aes/aes.go @@ -37,11 +37,13 @@ func NewAES(subMarshaller codec.MarshalUnmarshaler, key []byte) (*AES, error) { }, nil } +// Name returns a compound of the inner marshaller prefixed by 'aes-' func (c *AES) Name() string { // Return a dynamic name, because the marshalling will also fail if the inner marshalling changes. return name + c.subMarshaller.Name() } +// Marshal marshals the given data object to an encrypted byte array func (c *AES) Marshal(v interface{}) ([]byte, error) { data, err := c.subMarshaller.Marshal(v) if err != nil { @@ -57,6 +59,7 @@ func (c *AES) Marshal(v interface{}) ([]byte, error) { return c.aesGCM.Seal(nonce, nonce, data, nil), nil } +// Unmarshal unmarshals the given encrypted byte array to the given type func (c *AES) Unmarshal(data []byte, v interface{}) error { nonceSize := c.aesGCM.NonceSize() decrypted, err := c.aesGCM.Open(nil, data[:nonceSize], data[nonceSize:], nil) From b468682ee093dd947abc0a807ecad67ab5d7d9ff Mon Sep 17 00:00:00 2001 From: Asdine El Hrychy Date: Sun, 17 May 2020 13:36:35 +0400 Subject: [PATCH 06/13] Drop support for Go 1.12 --- .travis.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 08e22c5..01a9bfd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,11 @@ language: go before_install: - go get github.com/stretchr/testify -env: - GO111MODULE=on +env: GO111MODULE=on go: - - '1.12.x' - - '1.13.x' - - '1.14.x' + - "1.13.x" + - "1.14.x" - tip matrix: From 50b28c7fa06a32700bf1f329f30cda2985908381 Mon Sep 17 00:00:00 2001 From: Paul van Santen Date: Sun, 17 May 2020 11:43:47 +0200 Subject: [PATCH 07/13] Rename the AES Codec package to aes --- codec/aes/aes.go | 2 +- codec/aes/aes_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codec/aes/aes.go b/codec/aes/aes.go index fb09b24..fe95d42 100644 --- a/codec/aes/aes.go +++ b/codec/aes/aes.go @@ -1,4 +1,4 @@ -package database +package aes import ( "crypto/aes" diff --git a/codec/aes/aes_test.go b/codec/aes/aes_test.go index 185f9d9..c8efc75 100644 --- a/codec/aes/aes_test.go +++ b/codec/aes/aes_test.go @@ -1,4 +1,4 @@ -package database +package aes import ( "encoding/base64" From 569aa937e62c9633ed751ad16a9c0f375a328352 Mon Sep 17 00:00:00 2001 From: makeworld <25111343+makeworld-the-better-one@users.noreply.github.com> Date: Tue, 26 May 2020 22:51:27 -0400 Subject: [PATCH 08/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f51ec19..d7a030c 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ _For extended queries and support for [Badger](https://github.com/dgraph-io/badg ## Getting Started ```bash -go get -u github.com/asdine/storm +GO111MODULE=on go get -u github.com/asdine/storm/v3 ``` ## Import Storm From 14d135a0eeb2fe4fc2c34f16474d87f62fbd2413 Mon Sep 17 00:00:00 2001 From: Paul van Santen Date: Mon, 15 Jun 2020 08:51:22 +0200 Subject: [PATCH 09/13] AES: Add guard for data length to prevent panicking --- codec/aes/aes.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/codec/aes/aes.go b/codec/aes/aes.go index fe95d42..f66348a 100644 --- a/codec/aes/aes.go +++ b/codec/aes/aes.go @@ -62,6 +62,10 @@ func (c *AES) Marshal(v interface{}) ([]byte, error) { // Unmarshal unmarshals the given encrypted byte array to the given type func (c *AES) Unmarshal(data []byte, v interface{}) error { nonceSize := c.aesGCM.NonceSize() + if len(data) < nonceSize { + return fmt.Errorf("not enough data for aes decryption (%d < %d)", len(data), nonceSize) + } + decrypted, err := c.aesGCM.Open(nil, data[:nonceSize], data[nonceSize:], nil) if err != nil { return fmt.Errorf("error decrypting data: %w", err) From 25ad146d2c78ff31c63d83e1659b8a2174d2f08c Mon Sep 17 00:00:00 2001 From: skaldesh Date: Wed, 9 Sep 2020 10:27:10 +0200 Subject: [PATCH 10/13] Update README for zero-value fields updates I just add two more comments to the Update section of the code examples, since it was not obvious to me that you can not Update() fields when you want to set them to their zero-value. You have to use UpdateField() for that --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d7a030c..f1b0cef 100644 --- a/README.md +++ b/README.md @@ -250,9 +250,11 @@ err := db.DeleteStruct(&user) ```go // Update multiple fields +// Only works for non zero-value fields (e.g. Name can not be "", Age can not be 0) err := db.Update(&User{ID: 10, Name: "Jack", Age: 45}) // Update a single field +// Also works for zero-value fields (0, false, "", ...) err := db.UpdateField(&User{ID: 10}, "Age", 0) ``` From 0399baa5df95d362949807d0fb442d17009f6085 Mon Sep 17 00:00:00 2001 From: Anderson Bargas Date: Sat, 6 Jan 2024 12:41:14 -0300 Subject: [PATCH 11/13] Syncing with storm. --- .github/workflows/main.yml | 32 +++ .travis.yml | 19 -- LICENSE | 1 + README.md | 165 ++++++----- bench_test.go | 10 +- bucket.go | 2 +- bucket_test.go | 2 +- codec/aes/aes.go | 2 +- codec/aes/aes_test.go | 4 +- codec/codec.go | 2 +- codec/example_test.go | 24 +- codec/gob/gob_test.go | 7 +- codec/internal/test_helpers.go | 2 +- codec/json/json_test.go | 7 +- codec/msgpack/msgpack_test.go | 7 +- codec/protobuf/protobuf.go | 2 +- codec/protobuf/protobuf_test.go | 24 +- codec/protobuf/simple_user.pb.go | 12 +- codec/sereal/sereal_test.go | 6 +- errors.go | 2 +- examples_test.go | 48 ++-- extract.go | 18 +- extract_test.go | 28 +- finder.go | 6 +- finder_test.go | 20 +- go.mod | 4 +- go.sum | 6 +- index/id.go | 128 +++++++++ index/id_test.go | 458 +++++++++++++++++++++++++++++++ index/list.go | 10 +- index/list_test.go | 54 ++-- index/unique.go | 12 +- index/unique_test.go | 20 +- kv.go | 2 +- kv_test.go | 10 +- metadata.go | 2 +- node.go | 28 +- node_test.go | 10 +- options.go | 12 +- q/examples_test.go | 20 +- q/tree_test.go | 67 +++++ query.go | 8 +- query_test.go | 12 +- scan.go | 2 +- scan_test.go | 2 +- sink.go | 10 +- sink_sorter_swap.go | 2 +- sink_sorter_swap_go1.8.go | 2 +- store.go | 10 +- store_test.go | 52 ++-- storm.go | 16 +- storm_test.go | 42 +-- structs_test.go | 70 ++--- transaction.go | 2 +- transaction_test.go | 2 +- version.go | 6 +- 56 files changed, 1132 insertions(+), 401 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml create mode 100644 index/id.go create mode 100644 index/id_test.go diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..c312a57 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,32 @@ +name: GoLang +on: + push: + paths-ignore: + - '*.md*' + - 'LICENSE' +jobs: + + build: + name: Build + runs-on: ubuntu-latest + steps: + + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Code coverage report + run: | + go test ./... -coverprofile=coverage.out + go tool cover -html=coverage.out -o coverage.html + + - name: Code coverage artifacts + uses: actions/upload-artifact@v1 + with: + name: Code coverage report + path: ./coverage.html diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 01a9bfd..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: go - -before_install: - - go get github.com/stretchr/testify - -env: GO111MODULE=on - -go: - - "1.13.x" - - "1.14.x" - - tip - -matrix: - allow_failures: - - go: tip - -script: - - go mod vendor - - go test -mod vendor -race -v ./... diff --git a/LICENSE b/LICENSE index bf86c69..024302d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) Copyright (c) [2017] [Asdine El Hrychy] +Copyright (c) [2020] [Anderson Bargas] Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index f1b0cef..7158500 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,17 @@ -# Storm +# Rainstorm -[![Build Status](https://travis-ci.org/asdine/storm.svg)](https://travis-ci.org/asdine/storm) -[![GoDoc](https://godoc.org/github.com/asdine/storm?status.svg)](https://godoc.org/github.com/asdine/storm) +[![GoDoc](https://godoc.org/github.com/AndersonBargas/rainstorm?status.svg)](https://pkg.go.dev/github.com/AndersonBargas/rainstorm/v4?tab=doc) [![Go Report Card](https://goreportcard.com/badge/github.com/AndersonBargas/rainstorm)](https://goreportcard.com/report/github.com/AndersonBargas/rainstorm) ![GoLang](https://github.com/AndersonBargas/rainstorm/workflows/GoLang/badge.svg) -Storm is a simple and powerful toolkit for [BoltDB](https://github.com/coreos/bbolt). Basically, Storm provides indexes, a wide range of methods to store and fetch data, an advanced query system, and much more. +Rainstorm is a simple and powerful toolkit for [BoltDB](https://github.com/coreos/bbolt), forked from the great [Storm](https://github.com/asdine/storm). +Basically, Rainstorm provides indexes, a wide range of methods to store and fetch data, an advanced query system, and much more. -In addition to the examples below, see also the [examples in the GoDoc](https://godoc.org/github.com/asdine/storm#pkg-examples). - -_For extended queries and support for [Badger](https://github.com/dgraph-io/badger), see also [Genji](https://github.com/asdine/genji)_ +In addition to the examples below, see also the [examples in the GoDoc](https://godoc.org/github.com/AndersonBargas/rainstorm#pkg-examples). ## Table of Contents - [Getting Started](#getting-started) -- [Import Storm](#import-storm) +- [Main differences from "storm"](#main-differences-from-"storm") +- [Import Rainstorm](#import-rainstorm) - [Open a database](#open-a-database) - [Simple CRUD system](#simple-crud-system) - [Declare your structures](#declare-your-structures) @@ -28,6 +27,7 @@ _For extended queries and support for [Badger](https://github.com/dgraph-io/badg - [Skip, Limit and Reverse](#skip-limit-and-reverse) - [Delete an object](#delete-an-object) - [Update an object](#update-an-object) + - [Count the objects](#count-the-objects) - [Initialize buckets and indexes before saving an object](#initialize-buckets-and-indexes-before-saving-an-object) - [Drop a bucket](#drop-a-bucket) - [Re-index a bucket](#re-index-a-bucket) @@ -49,13 +49,23 @@ _For extended queries and support for [Badger](https://github.com/dgraph-io/badg ## Getting Started ```bash -GO111MODULE=on go get -u github.com/asdine/storm/v3 +GO111MODULE=on go get -u github.com/AndersonBargas/rainstorm/v4 ``` -## Import Storm +## Main differences from "storm" + +The main differente for now is the primary key indexes. On storm, the PK index (aka ID) is, in fact, a unique index. +By nature, an ID is already unique, so there's no need to indexing the ID. +This way, rainstorm uses the Primary Keys as ID so almost every operations over ID index is executed as fast as possible. + +Rainstorm emerged from the fork of storm library at version 3.1.0. After renaming the package and their imports to the rainstorm, version 3.2.0 was generated. +This means that if you want to test the library with the same characteristics that it had at the time of the fork, just use version 3.2.0. +To take advantage of the performance changes made after the fork, just use version 4 and above. + +## Import Rainstorm ```go -import "github.com/asdine/storm/v3" +import "github.com/AndersonBargas/rainstorm/v4" ``` ## Open a database @@ -63,7 +73,7 @@ import "github.com/asdine/storm/v3" Quick way of opening a database ```go -db, err := storm.Open("my.db") +db, err := rainstorm.Open("my.db") defer db.Close() ``` @@ -77,37 +87,37 @@ defer db.Close() ```go type User struct { ID int // primary key - Group string `storm:"index"` // this field will be indexed - Email string `storm:"unique"` // this field will be indexed with a unique constraint + Group string `rainstorm:"index"` // this field will be indexed + Email string `rainstorm:"unique"` // this field will be indexed with a unique constraint Name string // this field will not be indexed - Age int `storm:"index"` + Age int `rainstorm:"index"` } ``` -The primary key can be of any type as long as it is not a zero value. Storm will search for the tag `id`, if not present Storm will search for a field named `ID`. +The primary key can be of any type as long as it is not a zero value. Rainstorm will search for the tag `id`, if not present Rainstorm will search for a field named `ID`. ```go type User struct { - ThePrimaryKey string `storm:"id"`// primary key - Group string `storm:"index"` // this field will be indexed - Email string `storm:"unique"` // this field will be indexed with a unique constraint + ThePrimaryKey string `rainstorm:"id"`// primary key + Group string `rainstorm:"index"` // this field will be indexed + Email string `rainstorm:"unique"` // this field will be indexed with a unique constraint Name string // this field will not be indexed } ``` -Storm handles tags in nested structures with the `inline` tag +Rainstorm handles tags in nested structures with the `inline` tag ```go type Base struct { - Ident bson.ObjectId `storm:"id"` + Ident bson.ObjectId `rainstorm:"id"` } type User struct { - Base `storm:"inline"` - Group string `storm:"index"` - Email string `storm:"unique"` + Base `rainstorm:"inline"` + Group string `rainstorm:"index"` + Email string `rainstorm:"unique"` Name string - CreatedAt time.Time `storm:"index"` + CreatedAt time.Time `rainstorm:"index"` } ``` @@ -128,7 +138,7 @@ err := db.Save(&user) user.ID++ err = db.Save(&user) -// err == storm.ErrAlreadyExists +// err == rainstorm.ErrAlreadyExists ``` That's it. @@ -137,16 +147,16 @@ That's it. #### Auto Increment -Storm can auto increment integer values so you don't have to worry about that when saving your objects. Also, the new value is automatically inserted in your field. +Rainstorm can auto increment integer values so you don't have to worry about that when saving your objects. Also, the new value is automatically inserted in your field. ```go type Product struct { - Pk int `storm:"id,increment"` // primary key with auto increment + Pk int `rainstorm:"id,increment"` // primary key with auto increment Name string - IntegerField uint64 `storm:"increment"` - IndexedIntegerField uint32 `storm:"index,increment"` - UniqueIntegerField int16 `storm:"unique,increment=100"` // the starting value can be set + IntegerField uint64 `rainstorm:"increment"` + IndexedIntegerField uint32 `rainstorm:"index,increment"` + UniqueIntegerField int16 `rainstorm:"unique,increment=100"` // the starting value can be set } p := Product{Name: "Vaccum Cleaner"} @@ -175,7 +185,7 @@ fmt.Println(p.UniqueIntegerField) ### Simple queries -Any object can be fetched, indexed or not. Storm uses indexes when available, otherwise it uses the [query system](#advanced-queries). +Any object can be fetched, indexed or not. Rainstorm uses indexes when available, otherwise it uses the [query system](#advanced-queries). #### Fetch one object @@ -188,7 +198,7 @@ err = db.One("Name", "John", &user) // err == nil err = db.One("Name", "Jack", &user) -// err == storm.ErrNotFound +// err == rainstorm.ErrNotFound ``` #### Fetch multiple objects @@ -230,20 +240,20 @@ err := db.Prefix("Name", "Jo", &users) ```go var users []User -err := db.Find("Group", "staff", &users, storm.Skip(10)) -err = db.Find("Group", "staff", &users, storm.Limit(10)) -err = db.Find("Group", "staff", &users, storm.Reverse()) -err = db.Find("Group", "staff", &users, storm.Limit(10), storm.Skip(10), storm.Reverse()) +err := db.Find("Group", "staff", &users, rainstorm.Skip(10)) +err = db.Find("Group", "staff", &users, rainstorm.Limit(10)) +err = db.Find("Group", "staff", &users, rainstorm.Reverse()) +err = db.Find("Group", "staff", &users, rainstorm.Limit(10), rainstorm.Skip(10), rainstorm.Reverse()) -err = db.All(&users, storm.Limit(10), storm.Skip(10), storm.Reverse()) -err = db.AllByIndex("CreatedAt", &users, storm.Limit(10), storm.Skip(10), storm.Reverse()) -err = db.Range("Age", 10, 21, &users, storm.Limit(10), storm.Skip(10), storm.Reverse()) +err = db.All(&users, rainstorm.Limit(10), rainstorm.Skip(10), rainstorm.Reverse()) +err = db.AllByIndex("CreatedAt", &users, rainstorm.Limit(10), rainstorm.Skip(10), rainstorm.Reverse()) +err = db.Range("Age", 10, 21, &users, rainstorm.Limit(10), rainstorm.Skip(10), rainstorm.Reverse()) ``` #### Delete an object ```go -err := db.DeleteStruct(&user) +err := db.DeleteStruct(&User{}) ``` #### Update an object @@ -258,6 +268,11 @@ err := db.Update(&User{ID: 10, Name: "Jack", Age: 45}) err := db.UpdateField(&User{ID: 10}, "Age", 0) ``` +#### Count the objects +```go +number, err := db.Count(&User{}) +``` + #### Initialize buckets and indexes before saving an object ```go @@ -291,7 +306,7 @@ Useful when the structure has changed ### Advanced queries For more complex queries, you can use the `Select` method. -`Select` takes any number of [`Matcher`](https://godoc.org/github.com/asdine/storm/q#Matcher) from the [`q`](https://godoc.org/github.com/asdine/storm/q) package. +`Select` takes any number of [`Matcher`](https://godoc.org/github.com/AndersonBargas/rainstorm/q#Matcher) from the [`q`](https://godoc.org/github.com/AndersonBargas/rainstorm/q) package. Here are some common Matchers: @@ -344,9 +359,9 @@ q.Or( ) ``` -You can find the complete list in the [documentation](https://godoc.org/github.com/asdine/storm/q#Matcher). +You can find the complete list in the [documentation](https://godoc.org/github.com/AndersonBargas/rainstorm/q#Matcher). -`Select` takes any number of matchers and wraps them into a `q.And()` so it's not necessary to specify it. It returns a [`Query`](https://godoc.org/github.com/asdine/storm#Query) type. +`Select` takes any number of matchers and wraps them into a `q.And()` so it's not necessary to specify it. It returns a [`Query`](https://godoc.org/github.com/AndersonBargas/rainstorm#Query) type. ```go query := db.Select(q.Gte("Age", 7), q.Lte("Age", 77)) @@ -409,14 +424,14 @@ err = query.Delete(new(User)) // Fetching records one by one (useful when the bucket contains a lot of records) query = db.Select(q.Gte("ID", 10),q.Lte("ID", 100)).OrderBy("Age", "Name") -err = query.Each(new(User), func(record interface{}) error) { +err = query.Each(new(User), func(record interface{}) error { u := record.(*User) ... return nil -} +}) ``` -See the [documentation](https://godoc.org/github.com/asdine/storm#Query) for a complete list of methods. +See the [documentation](https://godoc.org/github.com/AndersonBargas/rainstorm#Query) for a complete list of methods. ### Transactions @@ -445,57 +460,57 @@ return tx.Commit() ### Options -Storm options are functions that can be passed when constructing you Storm instance. You can pass it any number of options. +Rainstorm options are functions that can be passed when constructing you Rainstorm instance. You can pass it any number of options. #### BoltOptions -By default, Storm opens a database with the mode `0600` and a timeout of one second. +By default, Rainstorm opens a database with the mode `0600` and a timeout of one second. You can change this behavior by using `BoltOptions` ```go -db, err := storm.Open("my.db", storm.BoltOptions(0600, &bolt.Options{Timeout: 1 * time.Second})) +db, err := rainstorm.Open("my.db", rainstorm.BoltOptions(0600, &bolt.Options{Timeout: 1 * time.Second})) ``` #### MarshalUnmarshaler -To store the data in BoltDB, Storm marshals it in JSON by default. If you wish to change this behavior you can pass a codec that implements [`codec.MarshalUnmarshaler`](https://godoc.org/github.com/asdine/storm/codec#MarshalUnmarshaler) via the [`storm.Codec`](https://godoc.org/github.com/asdine/storm#Codec) option: +To store the data in BoltDB, Rainstorm marshals it in JSON by default. If you wish to change this behavior you can pass a codec that implements [`codec.MarshalUnmarshaler`](https://godoc.org/github.com/AndersonBargas/rainstorm/codec#MarshalUnmarshaler) via the [`rainstorm.Codec`](https://godoc.org/github.com/AndersonBargas/rainstorm#Codec) option: ```go -db := storm.Open("my.db", storm.Codec(myCodec)) +db := rainstorm.Open("my.db", rainstorm.Codec(myCodec)) ``` ##### Provided Codecs -You can easily implement your own `MarshalUnmarshaler`, but Storm comes with built-in support for [JSON](https://godoc.org/github.com/asdine/storm/codec/json) (default), [GOB](https://godoc.org/github.com/asdine/storm/codec/gob), [Sereal](https://godoc.org/github.com/asdine/storm/codec/sereal), [Protocol Buffers](https://godoc.org/github.com/asdine/storm/codec/protobuf) and [MessagePack](https://godoc.org/github.com/asdine/storm/codec/msgpack). +You can easily implement your own `MarshalUnmarshaler`, but Rainstorm comes with built-in support for [JSON](https://godoc.org/github.com/AndersonBargas/rainstorm/codec/json) (default), [GOB](https://godoc.org/github.com/AndersonBargas/rainstorm/codec/gob), [Sereal](https://godoc.org/github.com/AndersonBargas/rainstorm/codec/sereal), [Protocol Buffers](https://godoc.org/github.com/AndersonBargas/rainstorm/codec/protobuf) and [MessagePack](https://godoc.org/github.com/AndersonBargas/rainstorm/codec/msgpack). -These can be used by importing the relevant package and use that codec to configure Storm. The example below shows all variants (without proper error handling): +These can be used by importing the relevant package and use that codec to configure Rainstorm. The example below shows all variants (without proper error handling): ```go import ( - "github.com/asdine/storm/v3" - "github.com/asdine/storm/v3/codec/gob" - "github.com/asdine/storm/v3/codec/json" - "github.com/asdine/storm/v3/codec/sereal" - "github.com/asdine/storm/v3/codec/protobuf" - "github.com/asdine/storm/v3/codec/msgpack" + "github.com/AndersonBargas/rainstorm/v4" + "github.com/AndersonBargas/rainstorm/v4/codec/gob" + "github.com/AndersonBargas/rainstorm/v4/codec/json" + "github.com/AndersonBargas/rainstorm/v4/codec/sereal" + "github.com/AndersonBargas/rainstorm/v4/codec/protobuf" + "github.com/AndersonBargas/rainstorm/v4/codec/msgpack" ) -var gobDb, _ = storm.Open("gob.db", storm.Codec(gob.Codec)) -var jsonDb, _ = storm.Open("json.db", storm.Codec(json.Codec)) -var serealDb, _ = storm.Open("sereal.db", storm.Codec(sereal.Codec)) -var protobufDb, _ = storm.Open("protobuf.db", storm.Codec(protobuf.Codec)) -var msgpackDb, _ = storm.Open("msgpack.db", storm.Codec(msgpack.Codec)) +var gobDb, _ = rainstorm.Open("gob.db", rainstorm.Codec(gob.Codec)) +var jsonDb, _ = rainstorm.Open("json.db", rainstorm.Codec(json.Codec)) +var serealDb, _ = rainstorm.Open("sereal.db", rainstorm.Codec(sereal.Codec)) +var protobufDb, _ = rainstorm.Open("protobuf.db", rainstorm.Codec(protobuf.Codec)) +var msgpackDb, _ = rainstorm.Open("msgpack.db", rainstorm.Codec(msgpack.Codec)) ``` -**Tip**: Adding Storm tags to generated Protobuf files can be tricky. A good solution is to use [this tool](https://github.com/favadi/protoc-go-inject-tag) to inject the tags during the compilation. +**Tip**: Adding Rainstorm tags to generated Protobuf files can be tricky. A good solution is to use [this tool](https://github.com/favadi/protoc-go-inject-tag) to inject the tags during the compilation. #### Use existing Bolt connection -You can use an existing connection and pass it to Storm +You can use an existing connection and pass it to Rainstorm ```go bDB, _ := bolt.Open(filepath.Join(dir, "bolt.db"), 0600, &bolt.Options{Timeout: 10 * time.Second}) -db := storm.Open("my.db", storm.UseDB(bDB)) +db := rainstorm.Open("my.db", rainstorm.UseDB(bDB)) ``` #### Batch mode @@ -503,14 +518,14 @@ db := storm.Open("my.db", storm.UseDB(bDB)) Batch mode can be enabled to speed up concurrent writes (see [Batch read-write transactions](https://github.com/coreos/bbolt#batch-read-write-transactions)) ```go -db := storm.Open("my.db", storm.Batch()) +db := rainstorm.Open("my.db", rainstorm.Batch()) ``` ## Nodes and nested buckets -Storm takes advantage of BoltDB nested buckets feature by using `storm.Node`. -A `storm.Node` is the underlying object used by `storm.DB` to manipulate a bucket. -To create a nested bucket and use the same API as `storm.DB`, you can use the `DB.From` method. +Rainstorm takes advantage of BoltDB nested buckets feature by using `rainstorm.Node`. +A `rainstorm.Node` is the underlying object used by `rainstorm.DB` to manipulate a bucket. +To create a nested bucket and use the same API as `rainstorm.DB`, you can use the `DB.From` method. ```go repo := db.From("repo") @@ -575,7 +590,7 @@ n = n.WithCodec(gob.Codec) ## Simple Key/Value store -Storm can be used as a simple, robust, key/value store that can store anything. +Rainstorm can be used as a simple, robust, key/value store that can store anything. The key and the value can be of any type as long as the key is not a zero value. Saving data : @@ -608,7 +623,7 @@ db.Delete("sessions", someObjectId) db.Delete("weird storage", "754-3010") ``` -You can find other useful methods in the [documentation](https://godoc.org/github.com/asdine/storm#KeyValueStore). +You can find other useful methods in the [documentation](https://godoc.org/github.com/AndersonBargas/rainstorm#KeyValueStore). ## BoltDB @@ -623,7 +638,7 @@ db.Bolt.View(func(tx *bolt.Tx) error { }) ``` -A transaction can be also be passed to Storm +A transaction can be also be passed to Rainstorm ```go db.Bolt.Update(func(tx *bolt.Tx) error { diff --git a/bench_test.go b/bench_test.go index ce1ec09..7d4afa6 100644 --- a/bench_test.go +++ b/bench_test.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import ( "fmt" @@ -93,12 +93,12 @@ func BenchmarkOneByID(b *testing.B) { defer cleanup() type User struct { - ID int `storm:"increment"` - Name string `storm:"index"` + ID int `rainstorm:"increment"` + Name string `rainstorm:"index"` age int - DateOfBirth time.Time `storm:"index"` + DateOfBirth time.Time `rainstorm:"index"` Group string - Slug string `storm:"unique"` + Slug string `rainstorm:"unique"` } var u User diff --git a/bucket.go b/bucket.go index e2ef170..ecd61e4 100644 --- a/bucket.go +++ b/bucket.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import bolt "go.etcd.io/bbolt" diff --git a/bucket_test.go b/bucket_test.go index ec6902d..2e6cc62 100644 --- a/bucket_test.go +++ b/bucket_test.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import ( "testing" diff --git a/codec/aes/aes.go b/codec/aes/aes.go index f66348a..2b075c6 100644 --- a/codec/aes/aes.go +++ b/codec/aes/aes.go @@ -7,7 +7,7 @@ import ( "fmt" "io" - "github.com/asdine/storm/v3/codec" + "github.com/AndersonBargas/rainstorm/v4/codec" ) const name = "aes-" diff --git a/codec/aes/aes_test.go b/codec/aes/aes_test.go index c8efc75..e936b25 100644 --- a/codec/aes/aes_test.go +++ b/codec/aes/aes_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/asdine/storm/v3/codec/internal" - "github.com/asdine/storm/v3/codec/json" + "github.com/AndersonBargas/rainstorm/v4/codec/internal" + "github.com/AndersonBargas/rainstorm/v4/codec/json" ) var testKey, _ = base64.StdEncoding.DecodeString("xkBTXc1wn0C/aL31u9SA7g==") diff --git a/codec/codec.go b/codec/codec.go index b157379..e11cbb8 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -1,5 +1,5 @@ // Package codec contains sub-packages with different codecs that can be used -// to encode and decode entities in Storm. +// to encode and decode entities in Rainstorm. package codec // MarshalUnmarshaler represents a codec used to marshal and unmarshal entities. diff --git a/codec/example_test.go b/codec/example_test.go index 6965289..679058a 100644 --- a/codec/example_test.go +++ b/codec/example_test.go @@ -3,22 +3,22 @@ package codec_test import ( "fmt" - "github.com/asdine/storm/v3" - "github.com/asdine/storm/v3/codec/gob" - "github.com/asdine/storm/v3/codec/json" - "github.com/asdine/storm/v3/codec/msgpack" - "github.com/asdine/storm/v3/codec/protobuf" - "github.com/asdine/storm/v3/codec/sereal" + "github.com/AndersonBargas/rainstorm/v4" + "github.com/AndersonBargas/rainstorm/v4/codec/gob" + "github.com/AndersonBargas/rainstorm/v4/codec/json" + "github.com/AndersonBargas/rainstorm/v4/codec/msgpack" + "github.com/AndersonBargas/rainstorm/v4/codec/protobuf" + "github.com/AndersonBargas/rainstorm/v4/codec/sereal" ) func Example() { - // The examples below show how to set up all the codecs shipped with Storm. + // The examples below show how to set up all the codecs shipped with Rainstorm. // Proper error handling left out to make it simple. - var gobDb, _ = storm.Open("gob.db", storm.Codec(gob.Codec)) - var jsonDb, _ = storm.Open("json.db", storm.Codec(json.Codec)) - var msgpackDb, _ = storm.Open("msgpack.db", storm.Codec(msgpack.Codec)) - var serealDb, _ = storm.Open("sereal.db", storm.Codec(sereal.Codec)) - var protobufDb, _ = storm.Open("protobuf.db", storm.Codec(protobuf.Codec)) + var gobDb, _ = rainstorm.Open("gob.db", rainstorm.Codec(gob.Codec)) + var jsonDb, _ = rainstorm.Open("json.db", rainstorm.Codec(json.Codec)) + var msgpackDb, _ = rainstorm.Open("msgpack.db", rainstorm.Codec(msgpack.Codec)) + var serealDb, _ = rainstorm.Open("sereal.db", rainstorm.Codec(sereal.Codec)) + var protobufDb, _ = rainstorm.Open("protobuf.db", rainstorm.Codec(protobuf.Codec)) fmt.Printf("%T\n", gobDb.Codec()) fmt.Printf("%T\n", jsonDb.Codec()) diff --git a/codec/gob/gob_test.go b/codec/gob/gob_test.go index 0f21a27..9fe8c3b 100644 --- a/codec/gob/gob_test.go +++ b/codec/gob/gob_test.go @@ -3,9 +3,14 @@ package gob import ( "testing" - "github.com/asdine/storm/v3/codec/internal" + "github.com/AndersonBargas/rainstorm/v4/codec/internal" + "github.com/stretchr/testify/require" ) func TestGob(t *testing.T) { internal.RoundtripTester(t, Codec) } + +func TestCodecName(t *testing.T) { + require.EqualValues(t, Codec.Name(), "gob") +} diff --git a/codec/internal/test_helpers.go b/codec/internal/test_helpers.go index eda0382..00f8922 100644 --- a/codec/internal/test_helpers.go +++ b/codec/internal/test_helpers.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/asdine/storm/v3/codec" + "github.com/AndersonBargas/rainstorm/v4/codec" ) type testStruct struct { diff --git a/codec/json/json_test.go b/codec/json/json_test.go index 01f60b8..2f93b6e 100644 --- a/codec/json/json_test.go +++ b/codec/json/json_test.go @@ -3,9 +3,14 @@ package json import ( "testing" - "github.com/asdine/storm/v3/codec/internal" + "github.com/AndersonBargas/rainstorm/v4/codec/internal" + "github.com/stretchr/testify/require" ) func TestJSON(t *testing.T) { internal.RoundtripTester(t, Codec) } + +func TestCodecName(t *testing.T) { + require.EqualValues(t, Codec.Name(), "json") +} diff --git a/codec/msgpack/msgpack_test.go b/codec/msgpack/msgpack_test.go index 28e6d1b..a8710df 100644 --- a/codec/msgpack/msgpack_test.go +++ b/codec/msgpack/msgpack_test.go @@ -3,9 +3,14 @@ package msgpack import ( "testing" - "github.com/asdine/storm/v3/codec/internal" + "github.com/AndersonBargas/rainstorm/v4/codec/internal" + "github.com/stretchr/testify/require" ) func TestMsgpack(t *testing.T) { internal.RoundtripTester(t, Codec) } + +func TestCodecName(t *testing.T) { + require.EqualValues(t, Codec.Name(), "msgpack") +} diff --git a/codec/protobuf/protobuf.go b/codec/protobuf/protobuf.go index b8ea093..534cb62 100644 --- a/codec/protobuf/protobuf.go +++ b/codec/protobuf/protobuf.go @@ -4,7 +4,7 @@ package protobuf import ( "errors" - "github.com/asdine/storm/v3/codec/json" + "github.com/AndersonBargas/rainstorm/v4/codec/json" "github.com/golang/protobuf/proto" ) diff --git a/codec/protobuf/protobuf_test.go b/codec/protobuf/protobuf_test.go index 2201595..86b3801 100644 --- a/codec/protobuf/protobuf_test.go +++ b/codec/protobuf/protobuf_test.go @@ -6,35 +6,35 @@ import ( "path/filepath" "testing" - "github.com/asdine/storm/v3" - "github.com/asdine/storm/v3/codec/internal" + "github.com/AndersonBargas/rainstorm/v4" + "github.com/AndersonBargas/rainstorm/v4/codec/internal" "github.com/stretchr/testify/require" ) func TestProtobuf(t *testing.T) { - u1 := SimpleUser{Id: 1, Name: "John"} + u1 := SimpleUser{ID: 1, Name: "John"} u2 := SimpleUser{} internal.RoundtripTester(t, Codec, &u1, &u2) - require.True(t, u1.Id == u2.Id) + require.True(t, u1.ID == u2.ID) } func TestSave(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db"), storm.Codec(Codec)) - u1 := SimpleUser{Id: 1, Name: "John"} + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db"), rainstorm.Codec(Codec)) + u1 := SimpleUser{ID: 1, Name: "John"} err := db.Save(&u1) require.NoError(t, err) u2 := SimpleUser{} - err = db.One("Id", uint64(1), &u2) + err = db.One("ID", uint64(1), &u2) require.NoError(t, err) require.Equal(t, u2.Name, u1.Name) } func TestGetSet(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db"), storm.Codec(Codec)) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db"), rainstorm.Codec(Codec)) err := db.Set("bucket", "key", "value") require.NoError(t, err) var s string @@ -42,3 +42,7 @@ func TestGetSet(t *testing.T) { require.NoError(t, err) require.Equal(t, "value", s) } + +func TestCodecName(t *testing.T) { + require.EqualValues(t, Codec.Name(), "protobuf") +} diff --git a/codec/protobuf/simple_user.pb.go b/codec/protobuf/simple_user.pb.go index 5c73a0b..5afc5bd 100644 --- a/codec/protobuf/simple_user.pb.go +++ b/codec/protobuf/simple_user.pb.go @@ -13,9 +13,13 @@ It has these top-level messages: */ package protobuf -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" +import ( + fmt "fmt" + + proto "github.com/golang/protobuf/proto" + + math "math" +) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal @@ -27,7 +31,7 @@ var _ = math.Inf const _ = proto.ProtoPackageIsVersion1 type SimpleUser struct { - Id uint64 `protobuf:"varint,1,opt,name=id" json:"id,omitempty" storm:"id"` + ID uint64 `protobuf:"varint,1,opt,name=id" json:"id,omitempty" rainstorm:"id"` Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"` Age int32 `protobuf:"varint,3,opt,name=age" json:"age,omitempty"` } diff --git a/codec/sereal/sereal_test.go b/codec/sereal/sereal_test.go index fae2514..87fb6b7 100644 --- a/codec/sereal/sereal_test.go +++ b/codec/sereal/sereal_test.go @@ -3,7 +3,7 @@ package sereal import ( "testing" - "github.com/asdine/storm/v3/codec/internal" + "github.com/AndersonBargas/rainstorm/v4/codec/internal" "github.com/stretchr/testify/require" ) @@ -19,3 +19,7 @@ func TestSereal(t *testing.T) { internal.RoundtripTester(t, Codec, &u1, &u2) require.True(t, u2 == u2.Self) } + +func TestCodecName(t *testing.T) { + require.EqualValues(t, Codec.Name(), "sereal") +} diff --git a/errors.go b/errors.go index ef52656..ad446db 100644 --- a/errors.go +++ b/errors.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import "errors" diff --git a/examples_test.go b/examples_test.go index 780f8fb..8cde906 100644 --- a/examples_test.go +++ b/examples_test.go @@ -1,4 +1,4 @@ -package storm_test +package rainstorm_test import ( "fmt" @@ -9,26 +9,26 @@ import ( "strings" "time" - "github.com/asdine/storm/v3" - "github.com/asdine/storm/v3/codec/gob" + "github.com/AndersonBargas/rainstorm/v4" + "github.com/AndersonBargas/rainstorm/v4/codec/gob" bolt "go.etcd.io/bbolt" ) func ExampleDB_Save() { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) type User struct { - ID int `storm:"id,increment"` // the increment tag will auto-increment integer IDs without existing values. - Group string `storm:"index"` - Email string `storm:"unique"` + ID int `rainstorm:"id,increment"` // the increment tag will auto-increment integer IDs without existing values. + Group string `rainstorm:"index"` + Email string `rainstorm:"unique"` Name string - Age int `storm:"index"` - CreatedAt time.Time `storm:"index"` + Age int `rainstorm:"index"` + CreatedAt time.Time `rainstorm:"index"` } // Open takes an optional list of options as the last argument. - db, _ := storm.Open(filepath.Join(dir, "storm.db"), storm.Codec(gob.Codec)) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db"), rainstorm.Codec(gob.Codec)) defer db.Close() user := User{ @@ -164,7 +164,7 @@ func ExampleLimit() { defer db.Close() var users []User - err := db.All(&users, storm.Limit(2)) + err := db.All(&users, rainstorm.Limit(2)) if err != nil { log.Fatal(err) @@ -182,7 +182,7 @@ func ExampleSkip() { defer db.Close() var users []User - err := db.All(&users, storm.Skip(1)) + err := db.All(&users, rainstorm.Skip(1)) if err != nil { log.Fatal(err) @@ -195,7 +195,7 @@ func ExampleSkip() { } func ExampleUseDB() { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) bDB, err := bolt.Open(filepath.Join(dir, "bolt.db"), 0600, &bolt.Options{Timeout: 10 * time.Second}) @@ -203,7 +203,7 @@ func ExampleUseDB() { log.Fatal(err) } - db, _ := storm.Open("", storm.UseDB(bDB)) + db, _ := rainstorm.Open("", rainstorm.UseDB(bDB)) defer db.Close() err = db.Save(&User{ID: 10}) @@ -497,27 +497,27 @@ func ExampleNode_RangeScan() { } type User struct { - ID int `storm:"id,increment"` - Group string `storm:"index"` - Email string `storm:"unique"` + ID int `rainstorm:"id,increment"` + Group string `rainstorm:"index"` + Email string `rainstorm:"unique"` Name string - Age int `storm:"index"` - CreatedAt time.Time `storm:"index"` + Age int `rainstorm:"index"` + CreatedAt time.Time `rainstorm:"index"` } type Account struct { - ID int `storm:"id,increment"` + ID int `rainstorm:"id,increment"` Amount int64 // amount in cents } type Note struct { - ID string `storm:"id"` + ID string `rainstorm:"id"` Text string } -func prepareDB() (string, *storm.DB) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") - db, _ := storm.Open(filepath.Join(dir, "storm.db")) +func prepareDB() (string, *rainstorm.DB) { + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) for i, name := range []string{"John", "Eric", "Dilbert"} { email := strings.ToLower(name + "@provider.com") diff --git a/extract.go b/extract.go index f601050..b465327 100644 --- a/extract.go +++ b/extract.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import ( "fmt" @@ -6,18 +6,18 @@ import ( "strconv" "strings" - "github.com/asdine/storm/v3/index" + "github.com/AndersonBargas/rainstorm/v4/index" bolt "go.etcd.io/bbolt" ) -// Storm tags +// Rainstorm tags const ( tagID = "id" tagIdx = "index" tagUniqueIdx = "unique" tagInline = "inline" tagIncrement = "increment" - indexPrefix = "__storm_index_" + indexPrefix = "__rainstorm_index_" ) type fieldConfig struct { @@ -99,7 +99,7 @@ func extractField(value *reflect.Value, field *reflect.StructField, m *structCon var f *fieldConfig var err error - tag := field.Tag.Get("storm") + tag := field.Tag.Get("rainstorm") if tag != "" { f = &fieldConfig{ Name: field.Name, @@ -113,9 +113,9 @@ func extractField(value *reflect.Value, field *reflect.StructField, m *structCon for _, tag := range tags { switch tag { - case "id": + case tagID: f.IsID = true - f.Index = tagUniqueIdx + fallthrough case tagUniqueIdx, tagIdx: f.Index = tag case tagInline: @@ -164,7 +164,7 @@ func extractField(value *reflect.Value, field *reflect.StructField, m *structCon if m.ID == nil && field.Name == "ID" { if f == nil { f = &fieldConfig{ - Index: tagUniqueIdx, + Index: tagID, Name: field.Name, IsZero: isZero(value), IsInteger: isInteger(value), @@ -203,6 +203,8 @@ func getIndex(bucket *bolt.Bucket, idxKind string, fieldName string) (index.Inde var err error switch idxKind { + case tagID: + idx, err = index.NewIDIndex(bucket, []byte(indexPrefix+fieldName)) case tagUniqueIdx: idx, err = index.NewUniqueIndex(bucket, []byte(indexPrefix+fieldName)) case tagIdx: diff --git a/extract_test.go b/extract_test.go index 1f6dcb0..1ce1f49 100644 --- a/extract_test.go +++ b/extract_test.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import ( "reflect" @@ -44,8 +44,9 @@ func TestExtractUniqueTags(t *testing.T) { require.NotNil(t, infos.ID) require.False(t, infos.ID.IsZero) require.Equal(t, "ClassicUnique", infos.Name) + require.Len(t, allByType(infos, "id"), 1) require.Len(t, allByType(infos, "index"), 0) - require.Len(t, allByType(infos, "unique"), 5) + require.Len(t, allByType(infos, "unique"), 4) } func TestExtractIndexTags(t *testing.T) { @@ -58,7 +59,8 @@ func TestExtractIndexTags(t *testing.T) { require.False(t, infos.ID.IsZero) require.Equal(t, "ClassicIndex", infos.Name) require.Len(t, allByType(infos, "index"), 5) - require.Len(t, allByType(infos, "unique"), 1) + require.Len(t, allByType(infos, "unique"), 0) + require.Len(t, allByType(infos, "id"), 1) } func TestExtractInlineWithIndex(t *testing.T) { @@ -70,16 +72,17 @@ func TestExtractInlineWithIndex(t *testing.T) { require.NotNil(t, infos.ID) require.Equal(t, "ClassicInline", infos.Name) require.Len(t, allByType(infos, "index"), 3) - require.Len(t, allByType(infos, "unique"), 3) + require.Len(t, allByType(infos, "unique"), 2) + require.Len(t, allByType(infos, "id"), 1) } func TestExtractMultipleTags(t *testing.T) { type User struct { - ID uint64 `storm:"id,increment"` - Age uint16 `storm:"index,increment"` - unexportedField int32 `storm:"index,increment"` - X uint32 `storm:"unique,increment=100"` - Y int8 `storm:"index,increment=-100"` + ID uint64 `rainstorm:"id,increment"` + Age uint16 `rainstorm:"index,increment"` + unexportedField int32 `rainstorm:"index,increment"` + X uint32 `rainstorm:"unique,increment=100"` + Y int8 `rainstorm:"index,increment=-100"` } s := User{} @@ -90,7 +93,8 @@ func TestExtractMultipleTags(t *testing.T) { require.NotNil(t, infos.ID) require.Equal(t, "User", infos.Name) require.Len(t, allByType(infos, "index"), 2) - require.Len(t, allByType(infos, "unique"), 2) + require.Len(t, allByType(infos, "unique"), 1) + require.Len(t, allByType(infos, "id"), 1) require.True(t, infos.Fields["Age"].Increment) require.Equal(t, int64(1), infos.Fields["Age"].IncrementStart) @@ -117,7 +121,7 @@ func TestExtractMultipleTags(t *testing.T) { require.NotNil(t, infos.Fields["Y"].Value) type NoInt struct { - ID uint64 `storm:"id,increment=hello"` + ID uint64 `rainstorm:"id,increment=hello"` } var n NoInt @@ -126,7 +130,7 @@ func TestExtractMultipleTags(t *testing.T) { require.Error(t, err) type BadSuffix struct { - ID uint64 `storm:"id,incrementag=100"` + ID uint64 `rainstorm:"id,incrementag=100"` } var b BadSuffix diff --git a/finder.go b/finder.go index 8162862..e7dfb4c 100644 --- a/finder.go +++ b/finder.go @@ -1,11 +1,11 @@ -package storm +package rainstorm import ( "fmt" "reflect" - "github.com/asdine/storm/v3/index" - "github.com/asdine/storm/v3/q" + "github.com/AndersonBargas/rainstorm/v4/index" + "github.com/AndersonBargas/rainstorm/v4/q" bolt "go.etcd.io/bbolt" ) diff --git a/finder_test.go b/finder_test.go index 1fd2e37..d7656e0 100644 --- a/finder_test.go +++ b/finder_test.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import ( "fmt" @@ -8,8 +8,8 @@ import ( "testing" "time" - bolt "go.etcd.io/bbolt" "github.com/stretchr/testify/require" + bolt "go.etcd.io/bbolt" ) func TestFind(t *testing.T) { @@ -114,9 +114,9 @@ func TestFindNil(t *testing.T) { defer cleanup() type User struct { - ID int `storm:"increment"` - CreatedAt *time.Time `storm:"index"` - DeletedAt *time.Time `storm:"unique"` + ID int `rainstorm:"increment"` + CreatedAt *time.Time `rainstorm:"index"` + DeletedAt *time.Time `rainstorm:"unique"` } t1 := time.Now() @@ -154,8 +154,8 @@ func TestFindIntIndex(t *testing.T) { defer cleanup() type Score struct { - ID int `storm:"increment"` - Score uint64 `storm:"index"` + ID int `rainstorm:"increment"` + Score uint64 `rainstorm:"index"` } for i := 0; i < 10; i++ { @@ -491,16 +491,16 @@ func TestOne(t *testing.T) { } func TestOneNotWritable(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := Open(filepath.Join(dir, "storm.db")) + db, _ := Open(filepath.Join(dir, "rainstorm.db")) err := db.Save(&User{ID: 10, Name: "John"}) require.NoError(t, err) db.Close() - db, _ = Open(filepath.Join(dir, "storm.db"), BoltOptions(0660, &bolt.Options{ + db, _ = Open(filepath.Join(dir, "rainstorm.db"), BoltOptions(0660, &bolt.Options{ ReadOnly: true, })) defer db.Close() diff --git a/go.mod b/go.mod index bfbafd5..ce81777 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,8 @@ -module github.com/asdine/storm/v3 +module github.com/AndersonBargas/rainstorm/v4 require ( github.com/DataDog/zstd v1.4.1 // indirect - github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863 + github.com/Sereal/Sereal v0.0.0-20200820125258-a016b7cda3f3 github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.3.2 github.com/golang/snappy v0.0.1 // indirect diff --git a/go.sum b/go.sum index 6f3ed54..b657197 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM= github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863 h1:BRrxwOZBolJN4gIwvZMJY1tzqBvQgpaZiQRuIDD40jM= github.com/Sereal/Sereal v0.0.0-20190618215532-0b8ac451a863/go.mod h1:D0JMgToj/WdxCgd30Kc1UcA9E+WdZoJqeVOuYW7iTBM= +github.com/Sereal/Sereal v0.0.0-20200820125258-a016b7cda3f3 h1:XgiXcABXIRyuLNyKHIk6gICrVXcGooDUxR+XMRr2QDM= +github.com/Sereal/Sereal v0.0.0-20200820125258-a016b7cda3f3/go.mod h1:D0JMgToj/WdxCgd30Kc1UcA9E+WdZoJqeVOuYW7iTBM= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= @@ -21,8 +23,6 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= -go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk= -go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg= go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -31,8 +31,6 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20191105084925-a882066a44e0 h1:QPlSTtPE2k6PZPasQUbzuK3p9JbS+vMXYVto8g/yrsg= golang.org/x/net v0.0.0-20191105084925-a882066a44e0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20191105142833-ac3223d80179 h1:IqVhUQp5B9ARnZUcfqXy6zP+A+YuPpP7IFo8gFeCOzU= -golang.org/x/sys v0.0.0-20191105142833-ac3223d80179/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0= golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/index/id.go b/index/id.go new file mode 100644 index 0000000..3689361 --- /dev/null +++ b/index/id.go @@ -0,0 +1,128 @@ +package index + +import ( + "bytes" + + "github.com/AndersonBargas/rainstorm/v4/internal" + bolt "go.etcd.io/bbolt" +) + +// NewIDIndex loads a IDIndex +func NewIDIndex(parent *bolt.Bucket, indexName []byte) (*IDIndex, error) { + return &IDIndex{ + IndexBucket: parent, + }, nil +} + +// IDIndex is an index that references unique values and the corresponding ID. +type IDIndex struct { + IndexBucket *bolt.Bucket +} + +// Add a value to the unique index +func (idx *IDIndex) Add(value []byte, targetID []byte) error { + if value == nil || len(value) == 0 { + return ErrNilParam + } + if targetID == nil || len(targetID) == 0 { + return ErrNilParam + } + + return nil +} + +// Remove a value from the unique index +// This method is never called for PK index, since the there is no really an indice to be removed +func (idx *IDIndex) Remove(value []byte) error { + return nil +} + +// RemoveID removes an ID from the unique index +func (idx *IDIndex) RemoveID(id []byte) error { + return nil +} + +// Get the id corresponding to the given value +// This method is never called for PK index, since the finder goes direct on the bucket to get one register +func (idx *IDIndex) Get(value []byte) []byte { + return idx.IndexBucket.Get(value) +} + +// All returns all the ids corresponding to the given value +func (idx *IDIndex) All(value []byte, opts *Options) ([][]byte, error) { + id := idx.IndexBucket.Get(value) + if id != nil { + return [][]byte{id}, nil + } + + return nil, nil +} + +// AllRecords returns all the IDs of this index +// This method is never called for PK index, since the All method is the preferred one +func (idx *IDIndex) AllRecords(opts *Options) ([][]byte, error) { + var list [][]byte + return list, nil +} + +// Range returns the ids corresponding to the given range of values +func (idx *IDIndex) Range(min []byte, max []byte, opts *Options) ([][]byte, error) { + var list [][]byte + + c := internal.RangeCursor{ + C: idx.IndexBucket.Cursor(), + Reverse: opts != nil && opts.Reverse, + Min: min, + Max: max, + CompareFn: func(val, limit []byte) int { + return bytes.Compare(val, limit) + }, + } + + for ident, _ := c.First(); ident != nil && c.Continue(ident); ident, _ = c.Next() { + if opts != nil && opts.Skip > 0 { + opts.Skip-- + continue + } + + if opts != nil && opts.Limit == 0 { + break + } + + if opts != nil && opts.Limit > 0 { + opts.Limit-- + } + + list = append(list, ident) + } + return list, nil +} + +// Prefix returns the ids whose values have the given prefix. +func (idx *IDIndex) Prefix(prefix []byte, opts *Options) ([][]byte, error) { + var list [][]byte + + c := internal.PrefixCursor{ + C: idx.IndexBucket.Cursor(), + Reverse: opts != nil && opts.Reverse, + Prefix: prefix, + } + + for ident, _ := c.First(); ident != nil && c.Continue(ident); ident, _ = c.Next() { + if opts != nil && opts.Skip > 0 { + opts.Skip-- + continue + } + + if opts != nil && opts.Limit == 0 { + break + } + + if opts != nil && opts.Limit > 0 { + opts.Limit-- + } + + list = append(list, ident) + } + return list, nil +} diff --git a/index/id_test.go b/index/id_test.go new file mode 100644 index 0000000..54db1e5 --- /dev/null +++ b/index/id_test.go @@ -0,0 +1,458 @@ +package index_test + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + + "github.com/AndersonBargas/rainstorm/v4" + "github.com/AndersonBargas/rainstorm/v4/index" + "github.com/AndersonBargas/rainstorm/v4/q" + "github.com/stretchr/testify/require" + bolt "go.etcd.io/bbolt" +) + +// SimpleLogin represents a simple login model +type SimpleLogin struct { + Email string `rainstorm:"id"` + Password string +} + +// SimpleProduct represents a simple product model +type SimpleProduct struct { + Barcode int `rainstorm:"id,increment"` + Description string +} + +func TestIDIndex(t *testing.T) { + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") + defer os.RemoveAll(dir) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) + defer db.Close() + + err := db.Init(&SimpleLogin{}) + require.NoError(t, err) + + simpleLogin := &SimpleLogin{ + Email: "unique@example.org", + Password: "OoopsRAWpassword!", + } + + err = db.Save(simpleLogin) + require.NoError(t, err) + + var simpleLogins []SimpleLogin + + err = db.AllByIndex("Email", &simpleLogins) + require.NoError(t, err) + require.Len(t, simpleLogins, 1) + + err = db.Prefix("Email", "uni", &simpleLogins) + require.NoError(t, err) + + err = db.Select(q.Eq("Email", "unique@example.org")).First(&SimpleLogin{}) + require.NoError(t, err) + + err = db.Set("loggedInUsers", 1, &simpleLogin) + require.NoError(t, err) + + err = db.Delete("loggedInUsers", 1) + require.NoError(t, err) +} + +func TestIDIndexPrefix(t *testing.T) { + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") + defer os.RemoveAll(dir) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) + defer db.Close() + + err := db.Init(&SimpleLogin{}) + require.NoError(t, err) + + simpleLogin := &SimpleLogin{ + Email: "unique@example.org", + Password: "OoopsRAWpassword!", + } + + err = db.Save(simpleLogin) + require.NoError(t, err) + + simpleLogin = &SimpleLogin{ + Email: "unique123@example.org", + Password: "OoopsRAWpasswordAgain!", + } + + err = db.Save(simpleLogin) + require.NoError(t, err) + + var simpleLogins []SimpleLogin + + err = db.Prefix("Email", "uni", &simpleLogins) + require.NoError(t, err) + + setSkip := func(opt *index.Options) { + opt.Skip = 1 + } + err = db.Prefix("Email", "uni", &simpleLogins, setSkip) + require.NoError(t, err) + + setZeroedLimit := func(opt *index.Options) { + opt.Limit = 0 + } + err = db.Prefix("Email", "uni", &simpleLogins, setZeroedLimit) + require.Error(t, err) + require.True(t, rainstorm.ErrNotFound == err) + + setLimit := func(opt *index.Options) { + opt.Limit = 1 + } + err = db.Prefix("Email", "uni", &simpleLogins, setLimit) + require.NoError(t, err) +} + +func TestIDIndexRange(t *testing.T) { + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") + defer os.RemoveAll(dir) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) + defer db.Close() + + err := db.Init(&SimpleProduct{}) + require.NoError(t, err) + + for i := 1; i <= 50; i++ { + simpleProduct := &SimpleProduct{ + Barcode: i, + Description: "Must have product!", + } + + err = db.Save(simpleProduct) + require.NoError(t, err) + } + + var simpleProducts []SimpleProduct + + err = db.Range("Barcode", 5, 8, &simpleProducts) + require.NoError(t, err) + + setSkip := func(opt *index.Options) { + opt.Skip = 2 + } + err = db.Range("Barcode", 5, 8, &simpleProducts, setSkip) + require.NoError(t, err) + + setZeroedLimit := func(opt *index.Options) { + opt.Limit = 0 + } + + err = db.Range("Barcode", 5, 8, &simpleProducts, setZeroedLimit) + require.Error(t, err) + require.True(t, rainstorm.ErrNotFound == err) + + setLimit := func(opt *index.Options) { + opt.Limit = 1 + } + + err = db.Range("Barcode", 5, 8, &simpleProducts, setLimit) + require.NoError(t, err) + +} + +func TestIDIndexParams(t *testing.T) { + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") + defer os.RemoveAll(dir) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) + defer db.Close() + + err := db.Bolt.Update(func(tx *bolt.Tx) error { + b, err := tx.CreateBucket([]byte("test")) + require.NoError(t, err) + + idx, err := index.NewIDIndex(b, []byte("pkindex1")) + require.NoError(t, err) + + // empty value param + err = idx.Add([]byte(""), []byte("id")) + require.Equal(t, index.ErrNilParam, err) + + // nil value param + err = idx.Add(nil, []byte("id")) + require.Equal(t, index.ErrNilParam, err) + + // empty id param + err = idx.Add([]byte("value"), []byte("")) + require.Equal(t, index.ErrNilParam, err) + + // nil id param + err = idx.Add([]byte("value"), nil) + require.Equal(t, index.ErrNilParam, err) + + // passing value and id params + err = idx.Add([]byte("value"), []byte("id")) + require.NoError(t, err) + + return nil + }) + + require.NoError(t, err) +} + +/*func TestIDIndex(t *testing.T) { + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") + defer os.RemoveAll(dir) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) + defer db.Close() + + err := db.Bolt.Update(func(tx *bolt.Tx) error { + b, err := tx.CreateBucket([]byte("test")) + require.NoError(t, err) + + idx, err := index.NewIDIndex(b, []byte("pkindex1")) + require.NoError(t, err) + + err = idx.Add([]byte("hello"), []byte("id1")) + require.NoError(t, err) + + err = idx.Add([]byte("hello"), []byte("id1")) + require.NoError(t, err) + + err = idx.Add([]byte("hello"), []byte("id2")) + require.Error(t, err) + require.Equal(t, index.ErrAlreadyExists, err) + + err = idx.Add(nil, []byte("id2")) + require.Error(t, err) + require.Equal(t, index.ErrNilParam, err) + + err = idx.Add([]byte("hi"), nil) + require.Error(t, err) + require.Equal(t, index.ErrNilParam, err) + + id := idx.Get([]byte("hello")) + require.Equal(t, []byte("id1"), id) + + id = idx.Get([]byte("goodbye")) + require.Nil(t, id) + + err = idx.Remove([]byte("hello")) + require.NoError(t, err) + + err = idx.Remove(nil) + require.NoError(t, err) + + id = idx.Get([]byte("hello")) + require.Nil(t, id) + + err = idx.Add([]byte("hello"), []byte("id1")) + require.NoError(t, err) + + err = idx.Add([]byte("hi"), []byte("id2")) + require.NoError(t, err) + + err = idx.Add([]byte("yo"), []byte("id3")) + require.NoError(t, err) + + list, err := idx.AllRecords(nil) + require.NoError(t, err) + require.Len(t, list, 3) + + opts := index.NewOptions() + opts.Limit = 2 + list, err = idx.AllRecords(opts) + require.NoError(t, err) + require.Len(t, list, 2) + + opts = index.NewOptions() + opts.Skip = 2 + list, err = idx.AllRecords(opts) + require.NoError(t, err) + require.Len(t, list, 1) + require.Equal(t, []byte("id3"), list[0]) + + opts = index.NewOptions() + opts.Skip = 2 + opts.Limit = 1 + opts.Reverse = true + list, err = idx.AllRecords(opts) + require.NoError(t, err) + require.Len(t, list, 1) + require.Equal(t, []byte("id1"), list[0]) + + err = idx.RemoveID([]byte("id2")) + require.NoError(t, err) + + id = idx.Get([]byte("hello")) + require.Equal(t, []byte("id1"), id) + id = idx.Get([]byte("hi")) + require.Nil(t, id) + id = idx.Get([]byte("yo")) + require.Equal(t, []byte("id3"), id) + ids, err := idx.All([]byte("yo"), nil) + require.NoError(t, err) + require.Len(t, ids, 1) + require.Equal(t, []byte("id3"), ids[0]) + + err = idx.RemoveID([]byte("id2")) + require.NoError(t, err) + err = idx.RemoveID([]byte("id4")) + require.NoError(t, err) + return nil + }) + + require.NoError(t, err) +} + +func TestIDIndexRange(t *testing.T) { + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") + defer os.RemoveAll(dir) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) + defer db.Close() + + db.Bolt.Update(func(tx *bolt.Tx) error { + b, err := tx.CreateBucket([]byte("test")) + require.NoError(t, err) + + idx, err := index.NewIDIndex(b, []byte("pkindex1")) + require.NoError(t, err) + + for i := 0; i < 10; i++ { + val, _ := gob.Codec.Marshal(i) + err = idx.Add(val, val) + require.NoError(t, err) + } + + min, _ := gob.Codec.Marshal(3) + max, _ := gob.Codec.Marshal(5) + list, err := idx.Range(min, max, nil) + require.Len(t, list, 3) + require.NoError(t, err) + assertEncodedIntListEqual(t, []int{3, 4, 5}, list) + + min, _ = gob.Codec.Marshal(11) + max, _ = gob.Codec.Marshal(20) + list, err = idx.Range(min, max, nil) + require.Len(t, list, 0) + require.NoError(t, err) + + min, _ = gob.Codec.Marshal(7) + max, _ = gob.Codec.Marshal(2) + list, err = idx.Range(min, max, nil) + require.Len(t, list, 0) + require.NoError(t, err) + + min, _ = gob.Codec.Marshal(-5) + max, _ = gob.Codec.Marshal(2) + list, err = idx.Range(min, max, nil) + require.Len(t, list, 0) + require.NoError(t, err) + + min, _ = gob.Codec.Marshal(3) + max, _ = gob.Codec.Marshal(7) + opts := index.NewOptions() + opts.Skip = 2 + list, err = idx.Range(min, max, opts) + require.Len(t, list, 3) + require.NoError(t, err) + assertEncodedIntListEqual(t, []int{5, 6, 7}, list) + + opts = index.NewOptions() + opts.Limit = 2 + list, err = idx.Range(min, max, opts) + require.Len(t, list, 2) + require.NoError(t, err) + assertEncodedIntListEqual(t, []int{3, 4}, list) + + opts = index.NewOptions() + opts.Reverse = true + opts.Skip = 2 + opts.Limit = 2 + list, err = idx.Range(min, max, opts) + require.Len(t, list, 2) + require.NoError(t, err) + assertEncodedIntListEqual(t, []int{5, 4}, list) + return nil + }) +} + +func TestIDIndexPrefix(t *testing.T) { + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") + defer os.RemoveAll(dir) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) + defer db.Close() + + db.Bolt.Update(func(tx *bolt.Tx) error { + b, err := tx.CreateBucket([]byte("test")) + require.NoError(t, err) + + idx, err := index.NewIDIndex(b, []byte("pkindex1")) + require.NoError(t, err) + + for i := 0; i < 10; i++ { + val := []byte(fmt.Sprintf("a%d", i)) + err = idx.Add(val, val) + require.NoError(t, err) + } + + for i := 0; i < 10; i++ { + val := []byte(fmt.Sprintf("b%d", i)) + err = idx.Add(val, val) + require.NoError(t, err) + } + + list, err := idx.Prefix([]byte("a"), nil) + require.Len(t, list, 10) + require.NoError(t, err) + + list, err = idx.Prefix([]byte("b"), nil) + require.Len(t, list, 10) + require.NoError(t, err) + require.Equal(t, []byte("b0"), list[0]) + require.Equal(t, []byte("b9"), list[9]) + + opts := index.NewOptions() + opts.Reverse = true + list, err = idx.Prefix([]byte("a"), opts) + require.Len(t, list, 10) + require.NoError(t, err) + require.Equal(t, []byte("a9"), list[0]) + require.Equal(t, []byte("a0"), list[9]) + + opts = index.NewOptions() + opts.Reverse = true + list, err = idx.Prefix([]byte("b"), opts) + require.Len(t, list, 10) + require.NoError(t, err) + require.Equal(t, []byte("b9"), list[0]) + require.Equal(t, []byte("b0"), list[9]) + + opts = index.NewOptions() + opts.Skip = 9 + opts.Limit = 5 + list, err = idx.Prefix([]byte("a"), opts) + require.Len(t, list, 1) + require.NoError(t, err) + require.Equal(t, []byte("a9"), list[0]) + + opts = index.NewOptions() + opts.Reverse = true + opts.Skip = 9 + opts.Limit = 5 + list, err = idx.Prefix([]byte("a"), opts) + require.Len(t, list, 1) + require.NoError(t, err) + require.Equal(t, []byte("a0"), list[0]) + return nil + }) +} + +func assertEncodedIntListEqual(t *testing.T, expected []int, actual [][]byte) { + ints := make([]int, len(actual)) + + for i, e := range actual { + err := gob.Codec.Unmarshal(e, &ints[i]) + require.NoError(t, err) + } + + require.Equal(t, expected, ints) +} +*/ diff --git a/index/list.go b/index/list.go index 27ce410..e0278ed 100644 --- a/index/list.go +++ b/index/list.go @@ -3,7 +3,7 @@ package index import ( "bytes" - "github.com/asdine/storm/v3/internal" + "github.com/AndersonBargas/rainstorm/v4/internal" bolt "go.etcd.io/bbolt" ) @@ -21,7 +21,7 @@ func NewListIndex(parent *bolt.Bucket, indexName []byte) (*ListIndex, error) { } } - ids, err := NewUniqueIndex(b, []byte("storm__ids")) + ids, err := NewUniqueIndex(b, []byte("rainstorm__ids")) if err != nil { return nil, err } @@ -176,7 +176,7 @@ func (idx *ListIndex) AllRecords(opts *Options) ([][]byte, error) { c := internal.Cursor{C: idx.IndexBucket.Cursor(), Reverse: opts != nil && opts.Reverse} for k, id := c.First(); k != nil; k, id = c.Next() { - if id == nil || bytes.Equal(k, []byte("storm__ids")) { + if id == nil || bytes.Equal(k, []byte("rainstorm__ids")) { continue } @@ -215,7 +215,7 @@ func (idx *ListIndex) Range(min []byte, max []byte, opts *Options) ([][]byte, er } for k, id := c.First(); c.Continue(k); k, id = c.Next() { - if id == nil || bytes.Equal(k, []byte("storm__ids")) { + if id == nil || bytes.Equal(k, []byte("rainstorm__ids")) { continue } @@ -249,7 +249,7 @@ func (idx *ListIndex) Prefix(prefix []byte, opts *Options) ([][]byte, error) { } for k, id := c.First(); k != nil && c.Continue(k); k, id = c.Next() { - if id == nil || bytes.Equal(k, []byte("storm__ids")) { + if id == nil || bytes.Equal(k, []byte("rainstorm__ids")) { continue } diff --git a/index/list_test.go b/index/list_test.go index 4940d83..1f7877c 100644 --- a/index/list_test.go +++ b/index/list_test.go @@ -8,17 +8,17 @@ import ( "path/filepath" "testing" - "github.com/asdine/storm/v3" - "github.com/asdine/storm/v3/codec/gob" - "github.com/asdine/storm/v3/index" - bolt "go.etcd.io/bbolt" + "github.com/AndersonBargas/rainstorm/v4" + "github.com/AndersonBargas/rainstorm/v4/codec/gob" + "github.com/AndersonBargas/rainstorm/v4/index" "github.com/stretchr/testify/require" + bolt "go.etcd.io/bbolt" ) func TestListIndex(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db")) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) defer db.Close() err := db.Bolt.Update(func(tx *bolt.Tx) error { @@ -54,16 +54,19 @@ func TestListIndex(t *testing.T) { require.Equal(t, []byte("id1"), ids[0]) ids, err = idx.All([]byte("goodbye"), nil) + require.NoError(t, err) require.Len(t, ids, 1) require.Equal(t, []byte("id2"), ids[0]) ids, err = idx.All([]byte("yo"), nil) + require.NoError(t, err) require.Nil(t, ids) err = idx.RemoveID([]byte("id2")) require.NoError(t, err) ids, err = idx.All([]byte("goodbye"), nil) + require.NoError(t, err) require.Len(t, ids, 0) err = idx.RemoveID(nil) @@ -93,11 +96,14 @@ func TestListIndex(t *testing.T) { require.NoError(t, err) ids, err = idx.All([]byte("hello"), nil) + require.NoError(t, err) require.Len(t, ids, 1) require.Equal(t, []byte("id1"), ids[0]) ids, err = idx.All([]byte("hi"), nil) + require.NoError(t, err) require.Len(t, ids, 0) ids, err = idx.All([]byte("yo"), nil) + require.NoError(t, err) require.Len(t, ids, 1) require.Equal(t, []byte("id3"), ids[0]) @@ -107,20 +113,28 @@ func TestListIndex(t *testing.T) { require.NoError(t, err) err = idx.Add([]byte("hey"), []byte("id1")) + require.NoError(t, err) err = idx.Add([]byte("hey"), []byte("id2")) + require.NoError(t, err) err = idx.Add([]byte("hey"), []byte("id3")) + require.NoError(t, err) err = idx.Add([]byte("hey"), []byte("id4")) + require.NoError(t, err) + ids, err = idx.All([]byte("hey"), nil) + require.NoError(t, err) require.Len(t, ids, 4) opts := index.NewOptions() opts.Limit = 1 ids, err = idx.All([]byte("hey"), opts) + require.NoError(t, err) require.Len(t, ids, 1) opts = index.NewOptions() opts.Skip = 2 ids, err = idx.All([]byte("hey"), opts) + require.NoError(t, err) require.Len(t, ids, 2) opts = index.NewOptions() @@ -128,6 +142,7 @@ func TestListIndex(t *testing.T) { opts.Limit = 3 opts.Reverse = true ids, err = idx.All([]byte("hey"), opts) + require.NoError(t, err) require.Len(t, ids, 2) require.Equal(t, []byte("id2"), ids[0]) @@ -150,9 +165,9 @@ func TestListIndex(t *testing.T) { } func TestListIndexReverse(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db")) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) defer db.Close() err := db.Bolt.Update(func(tx *bolt.Tx) error { @@ -167,12 +182,14 @@ func TestListIndexReverse(t *testing.T) { opts := index.NewOptions() ids, err := idx.All([]byte("hello"), opts) + require.NoError(t, err) require.Len(t, ids, 1) require.Equal(t, []byte("id1"), ids[0]) opts = index.NewOptions() opts.Reverse = true ids, err = idx.All([]byte("hello"), opts) + require.NoError(t, err) require.Len(t, ids, 1) require.Equal(t, []byte("id1"), ids[0]) @@ -182,6 +199,7 @@ func TestListIndexReverse(t *testing.T) { opts = index.NewOptions() opts.Reverse = true ids, err = idx.All([]byte("hello"), opts) + require.NoError(t, err) require.Len(t, ids, 2) require.Equal(t, []byte("id2"), ids[0]) require.Equal(t, []byte("id1"), ids[1]) @@ -192,9 +210,9 @@ func TestListIndexReverse(t *testing.T) { } func TestListIndexAddRemoveID(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db")) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) defer db.Close() db.Bolt.Update(func(tx *bolt.Tx) error { @@ -236,9 +254,9 @@ func TestListIndexAddRemoveID(t *testing.T) { } func TestListIndexAllRecords(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db")) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) defer db.Close() db.Bolt.Update(func(tx *bolt.Tx) error { @@ -292,11 +310,13 @@ func TestListIndexAllRecords(t *testing.T) { opts := index.NewOptions() opts.Limit = 1 ids, err = idx.AllRecords(opts) + require.NoError(t, err) require.Len(t, ids, 1) opts = index.NewOptions() opts.Skip = 2 ids, err = idx.AllRecords(opts) + require.NoError(t, err) require.Len(t, ids, 2) opts = index.NewOptions() @@ -313,9 +333,9 @@ func TestListIndexAllRecords(t *testing.T) { } func TestListIndexRange(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db")) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) defer db.Close() db.Bolt.Update(func(tx *bolt.Tx) error { @@ -409,9 +429,9 @@ func TestListIndexRange(t *testing.T) { } func TestListIndexPrefix(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db")) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) defer db.Close() db.Bolt.Update(func(tx *bolt.Tx) error { @@ -487,7 +507,7 @@ func countItems(t *testing.T, bucket *bolt.Bucket) int { c := bucket.Cursor() count := 0 for k, id := c.First(); k != nil; k, id = c.Next() { - if id == nil || bytes.Equal(k, []byte("storm__ids")) { + if id == nil || bytes.Equal(k, []byte("rainstorm__ids")) { continue } count++ diff --git a/index/unique.go b/index/unique.go index ec5989d..79ffbc7 100644 --- a/index/unique.go +++ b/index/unique.go @@ -3,7 +3,7 @@ package index import ( "bytes" - "github.com/asdine/storm/v3/internal" + "github.com/AndersonBargas/rainstorm/v4/internal" bolt "go.etcd.io/bbolt" ) @@ -171,13 +171,3 @@ func (idx *UniqueIndex) Prefix(prefix []byte, opts *Options) ([][]byte, error) { } return list, nil } - -// first returns the first ID of this index -func (idx *UniqueIndex) first() []byte { - c := idx.IndexBucket.Cursor() - - for val, ident := c.First(); val != nil; val, ident = c.Next() { - return ident - } - return nil -} diff --git a/index/unique_test.go b/index/unique_test.go index 6c54f89..d264ee1 100644 --- a/index/unique_test.go +++ b/index/unique_test.go @@ -7,17 +7,17 @@ import ( "path/filepath" "testing" - "github.com/asdine/storm/v3" - "github.com/asdine/storm/v3/codec/gob" - "github.com/asdine/storm/v3/index" - bolt "go.etcd.io/bbolt" + "github.com/AndersonBargas/rainstorm/v4" + "github.com/AndersonBargas/rainstorm/v4/codec/gob" + "github.com/AndersonBargas/rainstorm/v4/index" "github.com/stretchr/testify/require" + bolt "go.etcd.io/bbolt" ) func TestUniqueIndex(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db")) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) defer db.Close() err := db.Bolt.Update(func(tx *bolt.Tx) error { @@ -120,9 +120,9 @@ func TestUniqueIndex(t *testing.T) { } func TestUniqueIndexRange(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db")) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) defer db.Close() db.Bolt.Update(func(tx *bolt.Tx) error { @@ -192,9 +192,9 @@ func TestUniqueIndexRange(t *testing.T) { } func TestUniqueIndexPrefix(t *testing.T) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") defer os.RemoveAll(dir) - db, _ := storm.Open(filepath.Join(dir, "storm.db")) + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) defer db.Close() db.Bolt.Update(func(tx *bolt.Tx) error { diff --git a/kv.go b/kv.go index 7e2fb0a..ad040ca 100644 --- a/kv.go +++ b/kv.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import ( "reflect" diff --git a/kv_test.go b/kv_test.go index 7543bd2..8c503e7 100644 --- a/kv_test.go +++ b/kv_test.go @@ -1,14 +1,14 @@ -package storm +package rainstorm import ( "net/mail" "testing" "time" - "github.com/asdine/storm/v3/codec/gob" - "github.com/asdine/storm/v3/codec/json" - bolt "go.etcd.io/bbolt" + "github.com/AndersonBargas/rainstorm/v4/codec/gob" + "github.com/AndersonBargas/rainstorm/v4/codec/json" "github.com/stretchr/testify/require" + bolt "go.etcd.io/bbolt" ) func TestGet(t *testing.T) { @@ -168,7 +168,9 @@ func TestKeyExists(t *testing.T) { exists, err = db.KeyExists("i don't exist", "myfile.csv") require.Equal(t, ErrNotFound, err) + require.False(t, exists) exists, err = db.KeyExists("", nil) require.Equal(t, ErrNotFound, err) + require.False(t, exists) } diff --git a/metadata.go b/metadata.go index 21f3bba..3521edb 100644 --- a/metadata.go +++ b/metadata.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import ( "reflect" diff --git a/node.go b/node.go index 75fbb88..68852f7 100644 --- a/node.go +++ b/node.go @@ -1,18 +1,18 @@ -package storm +package rainstorm import ( - "github.com/asdine/storm/v3/codec" + "github.com/AndersonBargas/rainstorm/v4/codec" bolt "go.etcd.io/bbolt" ) -// A Node in Storm represents the API to a BoltDB bucket. +// A Node in Rainstorm represents the API to a BoltDB bucket. type Node interface { Tx TypeStore KeyValueStore BucketScanner - // From returns a new Storm node with a new bucket root below the current. + // From returns a new Rainstorm node with a new bucket root below the current. // All DB operations on the new node will be executed relative to this bucket. From(addend ...string) Node @@ -27,23 +27,23 @@ type Node interface { // already exist. CreateBucketIfNotExists(tx *bolt.Tx, bucket string) (*bolt.Bucket, error) - // WithTransaction returns a New Storm node that will use the given transaction. + // WithTransaction returns a New Rainstorm node that will use the given transaction. WithTransaction(tx *bolt.Tx) Node // Begin starts a new transaction. Begin(writable bool) (Node, error) - // Codec used by this instance of Storm + // Codec used by this instance of Rainstorm Codec() codec.MarshalUnmarshaler - // WithCodec returns a New Storm Node that will use the given Codec. + // WithCodec returns a New Rainstorm Node that will use the given Codec. WithCodec(codec codec.MarshalUnmarshaler) Node - // WithBatch returns a new Storm Node with the batch mode enabled. + // WithBatch returns a new Rainstorm Node with the batch mode enabled. WithBatch(enabled bool) Node } -// A Node in Storm represents the API to a BoltDB bucket. +// A Node in Rainstorm represents the API to a BoltDB bucket. type node struct { s *DB @@ -60,26 +60,26 @@ type node struct { batchMode bool } -// From returns a new Storm Node with a new bucket root below the current. +// From returns a new Rainstorm Node with a new bucket root below the current. // All DB operations on the new node will be executed relative to this bucket. func (n node) From(addend ...string) Node { n.rootBucket = append(n.rootBucket, addend...) return &n } -// WithTransaction returns a new Storm Node that will use the given transaction. +// WithTransaction returns a new Rainstorm Node that will use the given transaction. func (n node) WithTransaction(tx *bolt.Tx) Node { n.tx = tx return &n } -// WithCodec returns a new Storm Node that will use the given Codec. +// WithCodec returns a new Rainstorm Node that will use the given Codec. func (n node) WithCodec(codec codec.MarshalUnmarshaler) Node { n.codec = codec return &n } -// WithBatch returns a new Storm Node with the batch mode enabled. +// WithBatch returns a new Rainstorm Node with the batch mode enabled. func (n node) WithBatch(enabled bool) Node { n.batchMode = enabled return &n @@ -91,7 +91,7 @@ func (n *node) Bucket() []string { return n.rootBucket } -// Codec returns the EncodeDecoder used by this instance of Storm +// Codec returns the EncodeDecoder used by this instance of Rainstorm func (n *node) Codec() codec.MarshalUnmarshaler { return n.codec } diff --git a/node_test.go b/node_test.go index 945e996..98a637a 100644 --- a/node_test.go +++ b/node_test.go @@ -1,12 +1,12 @@ -package storm +package rainstorm import ( "testing" - "github.com/asdine/storm/v3/codec/gob" - "github.com/asdine/storm/v3/codec/json" - bolt "go.etcd.io/bbolt" + "github.com/AndersonBargas/rainstorm/v4/codec/gob" + "github.com/AndersonBargas/rainstorm/v4/codec/json" "github.com/stretchr/testify/require" + bolt "go.etcd.io/bbolt" ) func TestNode(t *testing.T) { @@ -68,7 +68,7 @@ func TestNodeWithCodec(t *testing.T) { type User struct { ID int - Name string `storm:"index"` + Name string `rainstorm:"index"` } requireBytesEqual := func(raw []byte, expected interface{}) { diff --git a/options.go b/options.go index ff89984..0c44970 100644 --- a/options.go +++ b/options.go @@ -1,10 +1,10 @@ -package storm +package rainstorm import ( "os" - "github.com/asdine/storm/v3/codec" - "github.com/asdine/storm/v3/index" + "github.com/AndersonBargas/rainstorm/v4/codec" + "github.com/AndersonBargas/rainstorm/v4/index" bolt "go.etcd.io/bbolt" ) @@ -41,8 +41,8 @@ func Root(root ...string) func(*Options) error { } } -// UseDB allows Storm to use an existing open Bolt.DB. -// Warning: storm.DB.Close() will close the bolt.DB instance. +// UseDB allows Rainstorm to use an existing open Bolt.DB. +// Warning: rainstorm.DB.Close() will close the bolt.DB instance. func UseDB(b *bolt.DB) func(*Options) error { return func(opts *Options) error { opts.path = b.Path() @@ -72,7 +72,7 @@ func Reverse() func(*index.Options) { } } -// Options are used to customize the way Storm opens a database. +// Options are used to customize the way Rainstorm opens a database. type Options struct { // Handles encoding and decoding of objects codec codec.MarshalUnmarshaler diff --git a/q/examples_test.go b/q/examples_test.go index c55d260..4a0602e 100644 --- a/q/examples_test.go +++ b/q/examples_test.go @@ -12,8 +12,8 @@ import ( "path/filepath" "strings" - "github.com/asdine/storm/v3" - "github.com/asdine/storm/v3/q" + "github.com/AndersonBargas/rainstorm/v4" + "github.com/AndersonBargas/rainstorm/v4/q" ) func ExampleRe() { @@ -37,17 +37,17 @@ func ExampleRe() { } type User struct { - ID int `storm:"id,increment"` - Group string `storm:"index"` - Email string `storm:"unique"` + ID int `rainstorm:"id,increment"` + Group string `rainstorm:"index"` + Email string `rainstorm:"unique"` Name string - Age int `storm:"index"` - CreatedAt time.Time `storm:"index"` + Age int `rainstorm:"index"` + CreatedAt time.Time `rainstorm:"index"` } -func prepareDB() (string, *storm.DB) { - dir, _ := ioutil.TempDir(os.TempDir(), "storm") - db, _ := storm.Open(filepath.Join(dir, "storm.db")) +func prepareDB() (string, *rainstorm.DB) { + dir, _ := ioutil.TempDir(os.TempDir(), "rainstorm") + db, _ := rainstorm.Open(filepath.Join(dir, "rainstorm.db")) for i, name := range []string{"John", "Norm", "Donald", "Eric", "Dilbert"} { email := strings.ToLower(name + "@provider.com") diff --git a/q/tree_test.go b/q/tree_test.go index cde130b..eea31a1 100644 --- a/q/tree_test.go +++ b/q/tree_test.go @@ -93,6 +93,65 @@ func TestCmp(t *testing.T) { require.NoError(t, err) require.True(t, ok) + q = GtF("Age", "Age") + ok, err = q.Match(&a) + require.NoError(t, err) + require.False(t, ok) + ok, err = q.Match(&b) + require.NoError(t, err) + require.False(t, ok) + + q = GteF("Age", "Age") + ok, err = q.Match(&a) + require.NoError(t, err) + require.True(t, ok) + ok, err = q.Match(&b) + require.NoError(t, err) + require.True(t, ok) + + q = Lt("Age", 15) + ok, err = q.Match(&a) + require.NoError(t, err) + require.True(t, ok) + ok, err = q.Match(&b) + require.NoError(t, err) + require.False(t, ok) + ok, err = q.Match(&b) + require.NoError(t, err) + require.False(t, ok) + + q = LtF("Age", "Age") + ok, err = q.Match(&a) + require.NoError(t, err) + require.False(t, ok) + ok, err = q.Match(&b) + require.NoError(t, err) + require.False(t, ok) + + q = LteF("Age", "Age") + ok, err = q.Match(&a) + require.NoError(t, err) + require.True(t, ok) + ok, err = q.Match(&b) + require.NoError(t, err) + require.True(t, ok) + + q = Gte("Age", 15) + ok, err = q.Match(&a) + require.NoError(t, err) + require.False(t, ok) + ok, err = q.Match(&b) + require.NoError(t, err) + require.True(t, ok) + + q = Lte("Age", 15) + ok, err = q.Match(&a) + require.NoError(t, err) + require.True(t, ok) + ok, err = q.Match(&b) + require.NoError(t, err) + require.False(t, ok) + // Unknown field q = Gt("Unknown", 15) ok, err = q.Match(&a) @@ -108,6 +167,14 @@ func TestCmp(t *testing.T) { require.True(t, ok) } +func TestTrueMatcher(t *testing.T) { + trueMatcher := True() + + ok, err := trueMatcher.Match("") + require.NoError(t, err) + require.True(t, ok) +} + func TestStrictEq(t *testing.T) { a := A{ Age: 10, diff --git a/query.go b/query.go index 5f57583..1019c5c 100644 --- a/query.go +++ b/query.go @@ -1,8 +1,8 @@ -package storm +package rainstorm import ( - "github.com/asdine/storm/v3/internal" - "github.com/asdine/storm/v3/q" + "github.com/AndersonBargas/rainstorm/v4/internal" + "github.com/AndersonBargas/rainstorm/v4/q" bolt "go.etcd.io/bbolt" ) @@ -12,7 +12,7 @@ func (n *node) Select(matchers ...q.Matcher) Query { return newQuery(n, tree) } -// Query is the low level query engine used by Storm. It allows to operate searches through an entire bucket. +// Query is the low level query engine used by Rainstorm. It allows to operate searches through an entire bucket. type Query interface { // Skip matching records by the given number Skip(int) Query diff --git a/query_test.go b/query_test.go index 88e3b8b..c782f37 100644 --- a/query_test.go +++ b/query_test.go @@ -1,16 +1,16 @@ -package storm +package rainstorm import ( "fmt" "testing" - "github.com/asdine/storm/v3/codec/json" - "github.com/asdine/storm/v3/q" + "github.com/AndersonBargas/rainstorm/v4/codec/json" + "github.com/AndersonBargas/rainstorm/v4/q" "github.com/stretchr/testify/require" ) type Score struct { - ID int `storm:"increment"` + ID int `rainstorm:"increment"` Value int } @@ -206,7 +206,7 @@ func TestSelectFindOrderBy(t *testing.T) { defer cleanup() type T struct { - ID int `storm:"increment"` + ID int `rainstorm:"increment"` Str string Int int Rnd int @@ -357,7 +357,7 @@ func TestSelectFirstOrderBy(t *testing.T) { defer cleanup() type T struct { - ID int `storm:"increment"` + ID int `rainstorm:"increment"` Str string Int int } diff --git a/scan.go b/scan.go index f2596e6..d491bb3 100644 --- a/scan.go +++ b/scan.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import ( "bytes" diff --git a/scan_test.go b/scan_test.go index c08e77e..a0f5850 100644 --- a/scan_test.go +++ b/scan_test.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import ( "fmt" diff --git a/sink.go b/sink.go index 117119e..5d9542b 100644 --- a/sink.go +++ b/sink.go @@ -1,11 +1,12 @@ -package storm +package rainstorm import ( "reflect" "sort" "time" - "github.com/asdine/storm/v3/index" - "github.com/asdine/storm/v3/q" + + "github.com/AndersonBargas/rainstorm/v4/index" + "github.com/AndersonBargas/rainstorm/v4/q" bolt "go.etcd.io/bbolt" ) @@ -147,9 +148,8 @@ func (s *sorter) compareValue(left reflect.Value, right reflect.Value) int { if lok && rok { if lt.Before(rt) { return -1 - } else { - return 1 } + return 1 } } } diff --git a/sink_sorter_swap.go b/sink_sorter_swap.go index 43af7cd..1a9bcb6 100644 --- a/sink_sorter_swap.go +++ b/sink_sorter_swap.go @@ -1,6 +1,6 @@ // +build !go1.8 -package storm +package rainstorm import "reflect" diff --git a/sink_sorter_swap_go1.8.go b/sink_sorter_swap_go1.8.go index 21bf7ae..0ec07e8 100644 --- a/sink_sorter_swap_go1.8.go +++ b/sink_sorter_swap_go1.8.go @@ -1,6 +1,6 @@ // +build go1.8 -package storm +package rainstorm import "reflect" diff --git a/store.go b/store.go index f22651f..29fab52 100644 --- a/store.go +++ b/store.go @@ -1,11 +1,11 @@ -package storm +package rainstorm import ( "bytes" "reflect" - "github.com/asdine/storm/v3/index" - "github.com/asdine/storm/v3/q" + "github.com/AndersonBargas/rainstorm/v4/index" + "github.com/AndersonBargas/rainstorm/v4/q" bolt "go.etcd.io/bbolt" ) @@ -64,6 +64,8 @@ func (n *node) init(tx *bolt.Tx, cfg *structConfig) error { continue } switch fieldCfg.Index { + case tagID: + _, err = index.NewIDIndex(bucket, []byte(indexPrefix+fieldName)) case tagUniqueIdx: _, err = index.NewUniqueIndex(bucket, []byte(indexPrefix+fieldName)) case tagIdx: @@ -222,7 +224,7 @@ func (n *node) save(tx *bolt.Tx, cfg *structConfig, data interface{}, update boo return err } for _, idSaved := range idsSaved { - if bytes.Compare(idSaved, id) == 0 { + if bytes.Equal(idSaved, id) { found = true break } diff --git a/store_test.go b/store_test.go index edd12af..83beaa5 100644 --- a/store_test.go +++ b/store_test.go @@ -1,4 +1,4 @@ -package storm +package rainstorm import ( "fmt" @@ -6,9 +6,9 @@ import ( "testing" "time" - "github.com/asdine/storm/v3/codec/gob" - "github.com/asdine/storm/v3/codec/json" - "github.com/asdine/storm/v3/q" + "github.com/AndersonBargas/rainstorm/v4/codec/gob" + "github.com/AndersonBargas/rainstorm/v4/codec/json" + "github.com/AndersonBargas/rainstorm/v4/q" "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" ) @@ -63,8 +63,8 @@ func TestReIndex(t *testing.T) { for i := 1; i < 10; i++ { type User struct { ID int - Age int `storm:"index"` - Name string `storm:"unique"` + Age int `rainstorm:"index"` + Name string `rainstorm:"unique"` } u := User{ @@ -88,8 +88,8 @@ func TestReIndex(t *testing.T) { type User struct { ID int Age int - Name string `storm:"index"` - Group string `storm:"unique"` + Name string `rainstorm:"index"` + Group string `rainstorm:"unique"` } require.NoError(t, db.ReIndex(new(User))) @@ -317,9 +317,9 @@ func TestSaveIncrement(t *testing.T) { defer cleanup() type User struct { - Identifier int `storm:"id,increment"` - Name string `storm:"index,increment"` - Age int `storm:"unique,increment=18"` + Identifier int `rainstorm:"id,increment"` + Name string `rainstorm:"index,increment"` + Age int `rainstorm:"unique,increment=18"` } for i := 1; i < 10; i++ { @@ -380,16 +380,16 @@ func TestSaveEmbedded(t *testing.T) { defer cleanup() type Base struct { - ID int `storm:"id,increment"` + ID int `rainstorm:"id,increment"` } type User struct { - Base `storm:"inline"` - Group string `storm:"index"` - Email string `storm:"unique"` + Base `rainstorm:"inline"` + Group string `rainstorm:"index"` + Email string `rainstorm:"unique"` Name string Age int - CreatedAt time.Time `storm:"index"` + CreatedAt time.Time `rainstorm:"index"` } user := User{ @@ -450,12 +450,12 @@ func TestUpdate(t *testing.T) { defer cleanup() type User struct { - ID int `storm:"id,increment"` - Name string `storm:"index"` - Age uint64 `storm:"index,increment"` - DateOfBirth time.Time `storm:"index"` + ID int `rainstorm:"id,increment"` + Name string `rainstorm:"index"` + Age uint64 `rainstorm:"index,increment"` + DateOfBirth time.Time `rainstorm:"index"` Group string - Slug string `storm:"unique"` + Slug string `rainstorm:"unique"` } var u User @@ -503,12 +503,12 @@ func TestUpdateField(t *testing.T) { defer cleanup() type User struct { - ID int `storm:"id,increment"` - Name string `storm:"index"` - Age uint64 `storm:"index,increment"` - DateOfBirth time.Time `storm:"index"` + ID int `rainstorm:"id,increment"` + Name string `rainstorm:"index"` + Age uint64 `rainstorm:"index,increment"` + DateOfBirth time.Time `rainstorm:"index"` Group string - Slug string `storm:"unique"` + Slug string `rainstorm:"unique"` } var u User diff --git a/storm.go b/storm.go index 88f16ea..e26676e 100644 --- a/storm.go +++ b/storm.go @@ -1,29 +1,29 @@ -package storm +package rainstorm import ( "bytes" "encoding/binary" "time" - "github.com/asdine/storm/v3/codec" - "github.com/asdine/storm/v3/codec/json" + "github.com/AndersonBargas/rainstorm/v4/codec" + "github.com/AndersonBargas/rainstorm/v4/codec/json" bolt "go.etcd.io/bbolt" ) const ( - dbinfo = "__storm_db" - metadataBucket = "__storm_metadata" + dbinfo = "__rainstorm_db" + metadataBucket = "__rainstorm_metadata" ) // Defaults to json var defaultCodec = json.Codec -// Open opens a database at the given path with optional Storm options. -func Open(path string, stormOptions ...func(*Options) error) (*DB, error) { +// Open opens a database at the given path with optional Rainstorm options. +func Open(path string, rainstormOptions ...func(*Options) error) (*DB, error) { var err error var opts Options - for _, option := range stormOptions { + for _, option := range rainstormOptions { if err = option(&opts); err != nil { return nil, err } diff --git a/storm_test.go b/storm_test.go index fc7bee1..9f2c6b5 100644 --- a/storm_test.go +++ b/storm_test.go @@ -1,32 +1,36 @@ -package storm +package rainstorm import ( "bytes" "encoding/binary" "io/ioutil" "math" + "math/bits" "os" "path/filepath" "reflect" "testing" "time" - "github.com/asdine/storm/v3/codec/json" - bolt "go.etcd.io/bbolt" + "github.com/AndersonBargas/rainstorm/v4/codec/json" "github.com/stretchr/testify/require" + bolt "go.etcd.io/bbolt" ) +const maxInt = 1<<(bits.UintSize-1) - 1 +const maxUint = 1< Date: Sat, 6 Jan 2024 12:51:59 -0300 Subject: [PATCH 12/13] Updating build env to use go 1.21 --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c312a57..bc2d12a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,10 +11,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.13 + - name: Set up Go 1.21 uses: actions/setup-go@v1 with: - go-version: 1.13 + go-version: '1.21' id: go - name: Check out code into the Go module directory From 3e11372977e69a2cbaae19d4f62dd0983b49714d Mon Sep 17 00:00:00 2001 From: Anderson Bargas Date: Sat, 6 Jan 2024 12:56:45 -0300 Subject: [PATCH 13/13] Bumping the version to 5.0.0 --- README.md | 18 +++++++++--------- codec/aes/aes.go | 2 +- codec/aes/aes_test.go | 4 ++-- codec/example_test.go | 12 ++++++------ codec/gob/gob_test.go | 2 +- codec/internal/test_helpers.go | 2 +- codec/json/json_test.go | 2 +- codec/msgpack/msgpack_test.go | 2 +- codec/protobuf/protobuf.go | 2 +- codec/protobuf/protobuf_test.go | 4 ++-- codec/sereal/sereal_test.go | 2 +- examples_test.go | 4 ++-- extract.go | 2 +- finder.go | 4 ++-- go.mod | 2 +- index/id.go | 2 +- index/id_test.go | 6 +++--- index/list.go | 2 +- index/list_test.go | 6 +++--- index/unique.go | 2 +- index/unique_test.go | 6 +++--- kv_test.go | 4 ++-- node.go | 2 +- node_test.go | 4 ++-- options.go | 4 ++-- q/examples_test.go | 4 ++-- query.go | 4 ++-- query_test.go | 4 ++-- sink.go | 4 ++-- store.go | 4 ++-- store_test.go | 6 +++--- storm.go | 4 ++-- storm_test.go | 2 +- version.go | 2 +- 34 files changed, 68 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 7158500..2314b5f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Rainstorm -[![GoDoc](https://godoc.org/github.com/AndersonBargas/rainstorm?status.svg)](https://pkg.go.dev/github.com/AndersonBargas/rainstorm/v4?tab=doc) [![Go Report Card](https://goreportcard.com/badge/github.com/AndersonBargas/rainstorm)](https://goreportcard.com/report/github.com/AndersonBargas/rainstorm) ![GoLang](https://github.com/AndersonBargas/rainstorm/workflows/GoLang/badge.svg) +[![GoDoc](https://godoc.org/github.com/AndersonBargas/rainstorm?status.svg)](https://pkg.go.dev/github.com/AndersonBargas/rainstorm/v5?tab=doc) [![Go Report Card](https://goreportcard.com/badge/github.com/AndersonBargas/rainstorm)](https://goreportcard.com/report/github.com/AndersonBargas/rainstorm) ![GoLang](https://github.com/AndersonBargas/rainstorm/workflows/GoLang/badge.svg) Rainstorm is a simple and powerful toolkit for [BoltDB](https://github.com/coreos/bbolt), forked from the great [Storm](https://github.com/asdine/storm). Basically, Rainstorm provides indexes, a wide range of methods to store and fetch data, an advanced query system, and much more. @@ -49,7 +49,7 @@ In addition to the examples below, see also the [examples in the GoDoc](https:// ## Getting Started ```bash -GO111MODULE=on go get -u github.com/AndersonBargas/rainstorm/v4 +GO111MODULE=on go get -u github.com/AndersonBargas/rainstorm/v5 ``` ## Main differences from "storm" @@ -65,7 +65,7 @@ To take advantage of the performance changes made after the fork, just use versi ## Import Rainstorm ```go -import "github.com/AndersonBargas/rainstorm/v4" +import "github.com/AndersonBargas/rainstorm/v5" ``` ## Open a database @@ -487,12 +487,12 @@ These can be used by importing the relevant package and use that codec to config ```go import ( - "github.com/AndersonBargas/rainstorm/v4" - "github.com/AndersonBargas/rainstorm/v4/codec/gob" - "github.com/AndersonBargas/rainstorm/v4/codec/json" - "github.com/AndersonBargas/rainstorm/v4/codec/sereal" - "github.com/AndersonBargas/rainstorm/v4/codec/protobuf" - "github.com/AndersonBargas/rainstorm/v4/codec/msgpack" + "github.com/AndersonBargas/rainstorm/v5" + "github.com/AndersonBargas/rainstorm/v5/codec/gob" + "github.com/AndersonBargas/rainstorm/v5/codec/json" + "github.com/AndersonBargas/rainstorm/v5/codec/sereal" + "github.com/AndersonBargas/rainstorm/v5/codec/protobuf" + "github.com/AndersonBargas/rainstorm/v5/codec/msgpack" ) var gobDb, _ = rainstorm.Open("gob.db", rainstorm.Codec(gob.Codec)) diff --git a/codec/aes/aes.go b/codec/aes/aes.go index 2b075c6..252a881 100644 --- a/codec/aes/aes.go +++ b/codec/aes/aes.go @@ -7,7 +7,7 @@ import ( "fmt" "io" - "github.com/AndersonBargas/rainstorm/v4/codec" + "github.com/AndersonBargas/rainstorm/v5/codec" ) const name = "aes-" diff --git a/codec/aes/aes_test.go b/codec/aes/aes_test.go index e936b25..89cd0ad 100644 --- a/codec/aes/aes_test.go +++ b/codec/aes/aes_test.go @@ -6,8 +6,8 @@ import ( "github.com/stretchr/testify/require" - "github.com/AndersonBargas/rainstorm/v4/codec/internal" - "github.com/AndersonBargas/rainstorm/v4/codec/json" + "github.com/AndersonBargas/rainstorm/v5/codec/internal" + "github.com/AndersonBargas/rainstorm/v5/codec/json" ) var testKey, _ = base64.StdEncoding.DecodeString("xkBTXc1wn0C/aL31u9SA7g==") diff --git a/codec/example_test.go b/codec/example_test.go index 679058a..d55a688 100644 --- a/codec/example_test.go +++ b/codec/example_test.go @@ -3,12 +3,12 @@ package codec_test import ( "fmt" - "github.com/AndersonBargas/rainstorm/v4" - "github.com/AndersonBargas/rainstorm/v4/codec/gob" - "github.com/AndersonBargas/rainstorm/v4/codec/json" - "github.com/AndersonBargas/rainstorm/v4/codec/msgpack" - "github.com/AndersonBargas/rainstorm/v4/codec/protobuf" - "github.com/AndersonBargas/rainstorm/v4/codec/sereal" + "github.com/AndersonBargas/rainstorm/v5" + "github.com/AndersonBargas/rainstorm/v5/codec/gob" + "github.com/AndersonBargas/rainstorm/v5/codec/json" + "github.com/AndersonBargas/rainstorm/v5/codec/msgpack" + "github.com/AndersonBargas/rainstorm/v5/codec/protobuf" + "github.com/AndersonBargas/rainstorm/v5/codec/sereal" ) func Example() { diff --git a/codec/gob/gob_test.go b/codec/gob/gob_test.go index 9fe8c3b..9c26954 100644 --- a/codec/gob/gob_test.go +++ b/codec/gob/gob_test.go @@ -3,7 +3,7 @@ package gob import ( "testing" - "github.com/AndersonBargas/rainstorm/v4/codec/internal" + "github.com/AndersonBargas/rainstorm/v5/codec/internal" "github.com/stretchr/testify/require" ) diff --git a/codec/internal/test_helpers.go b/codec/internal/test_helpers.go index 00f8922..2c42a08 100644 --- a/codec/internal/test_helpers.go +++ b/codec/internal/test_helpers.go @@ -5,7 +5,7 @@ import ( "reflect" "testing" - "github.com/AndersonBargas/rainstorm/v4/codec" + "github.com/AndersonBargas/rainstorm/v5/codec" ) type testStruct struct { diff --git a/codec/json/json_test.go b/codec/json/json_test.go index 2f93b6e..cb5e232 100644 --- a/codec/json/json_test.go +++ b/codec/json/json_test.go @@ -3,7 +3,7 @@ package json import ( "testing" - "github.com/AndersonBargas/rainstorm/v4/codec/internal" + "github.com/AndersonBargas/rainstorm/v5/codec/internal" "github.com/stretchr/testify/require" ) diff --git a/codec/msgpack/msgpack_test.go b/codec/msgpack/msgpack_test.go index a8710df..98a3f81 100644 --- a/codec/msgpack/msgpack_test.go +++ b/codec/msgpack/msgpack_test.go @@ -3,7 +3,7 @@ package msgpack import ( "testing" - "github.com/AndersonBargas/rainstorm/v4/codec/internal" + "github.com/AndersonBargas/rainstorm/v5/codec/internal" "github.com/stretchr/testify/require" ) diff --git a/codec/protobuf/protobuf.go b/codec/protobuf/protobuf.go index 534cb62..0dda121 100644 --- a/codec/protobuf/protobuf.go +++ b/codec/protobuf/protobuf.go @@ -4,7 +4,7 @@ package protobuf import ( "errors" - "github.com/AndersonBargas/rainstorm/v4/codec/json" + "github.com/AndersonBargas/rainstorm/v5/codec/json" "github.com/golang/protobuf/proto" ) diff --git a/codec/protobuf/protobuf_test.go b/codec/protobuf/protobuf_test.go index 86b3801..249e619 100644 --- a/codec/protobuf/protobuf_test.go +++ b/codec/protobuf/protobuf_test.go @@ -6,8 +6,8 @@ import ( "path/filepath" "testing" - "github.com/AndersonBargas/rainstorm/v4" - "github.com/AndersonBargas/rainstorm/v4/codec/internal" + "github.com/AndersonBargas/rainstorm/v5" + "github.com/AndersonBargas/rainstorm/v5/codec/internal" "github.com/stretchr/testify/require" ) diff --git a/codec/sereal/sereal_test.go b/codec/sereal/sereal_test.go index 87fb6b7..c7c850b 100644 --- a/codec/sereal/sereal_test.go +++ b/codec/sereal/sereal_test.go @@ -3,7 +3,7 @@ package sereal import ( "testing" - "github.com/AndersonBargas/rainstorm/v4/codec/internal" + "github.com/AndersonBargas/rainstorm/v5/codec/internal" "github.com/stretchr/testify/require" ) diff --git a/examples_test.go b/examples_test.go index 8cde906..4e98217 100644 --- a/examples_test.go +++ b/examples_test.go @@ -9,8 +9,8 @@ import ( "strings" "time" - "github.com/AndersonBargas/rainstorm/v4" - "github.com/AndersonBargas/rainstorm/v4/codec/gob" + "github.com/AndersonBargas/rainstorm/v5" + "github.com/AndersonBargas/rainstorm/v5/codec/gob" bolt "go.etcd.io/bbolt" ) diff --git a/extract.go b/extract.go index b465327..c348cc1 100644 --- a/extract.go +++ b/extract.go @@ -6,7 +6,7 @@ import ( "strconv" "strings" - "github.com/AndersonBargas/rainstorm/v4/index" + "github.com/AndersonBargas/rainstorm/v5/index" bolt "go.etcd.io/bbolt" ) diff --git a/finder.go b/finder.go index e7dfb4c..0486e77 100644 --- a/finder.go +++ b/finder.go @@ -4,8 +4,8 @@ import ( "fmt" "reflect" - "github.com/AndersonBargas/rainstorm/v4/index" - "github.com/AndersonBargas/rainstorm/v4/q" + "github.com/AndersonBargas/rainstorm/v5/index" + "github.com/AndersonBargas/rainstorm/v5/q" bolt "go.etcd.io/bbolt" ) diff --git a/go.mod b/go.mod index ce81777..453b439 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/AndersonBargas/rainstorm/v4 +module github.com/AndersonBargas/rainstorm/v5 require ( github.com/DataDog/zstd v1.4.1 // indirect diff --git a/index/id.go b/index/id.go index 3689361..0ee7e97 100644 --- a/index/id.go +++ b/index/id.go @@ -3,7 +3,7 @@ package index import ( "bytes" - "github.com/AndersonBargas/rainstorm/v4/internal" + "github.com/AndersonBargas/rainstorm/v5/internal" bolt "go.etcd.io/bbolt" ) diff --git a/index/id_test.go b/index/id_test.go index 54db1e5..a8ca70c 100644 --- a/index/id_test.go +++ b/index/id_test.go @@ -6,9 +6,9 @@ import ( "path/filepath" "testing" - "github.com/AndersonBargas/rainstorm/v4" - "github.com/AndersonBargas/rainstorm/v4/index" - "github.com/AndersonBargas/rainstorm/v4/q" + "github.com/AndersonBargas/rainstorm/v5" + "github.com/AndersonBargas/rainstorm/v5/index" + "github.com/AndersonBargas/rainstorm/v5/q" "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" ) diff --git a/index/list.go b/index/list.go index e0278ed..0e720b3 100644 --- a/index/list.go +++ b/index/list.go @@ -3,7 +3,7 @@ package index import ( "bytes" - "github.com/AndersonBargas/rainstorm/v4/internal" + "github.com/AndersonBargas/rainstorm/v5/internal" bolt "go.etcd.io/bbolt" ) diff --git a/index/list_test.go b/index/list_test.go index 1f7877c..260bd1f 100644 --- a/index/list_test.go +++ b/index/list_test.go @@ -8,9 +8,9 @@ import ( "path/filepath" "testing" - "github.com/AndersonBargas/rainstorm/v4" - "github.com/AndersonBargas/rainstorm/v4/codec/gob" - "github.com/AndersonBargas/rainstorm/v4/index" + "github.com/AndersonBargas/rainstorm/v5" + "github.com/AndersonBargas/rainstorm/v5/codec/gob" + "github.com/AndersonBargas/rainstorm/v5/index" "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" ) diff --git a/index/unique.go b/index/unique.go index 79ffbc7..2a907c4 100644 --- a/index/unique.go +++ b/index/unique.go @@ -3,7 +3,7 @@ package index import ( "bytes" - "github.com/AndersonBargas/rainstorm/v4/internal" + "github.com/AndersonBargas/rainstorm/v5/internal" bolt "go.etcd.io/bbolt" ) diff --git a/index/unique_test.go b/index/unique_test.go index d264ee1..a824932 100644 --- a/index/unique_test.go +++ b/index/unique_test.go @@ -7,9 +7,9 @@ import ( "path/filepath" "testing" - "github.com/AndersonBargas/rainstorm/v4" - "github.com/AndersonBargas/rainstorm/v4/codec/gob" - "github.com/AndersonBargas/rainstorm/v4/index" + "github.com/AndersonBargas/rainstorm/v5" + "github.com/AndersonBargas/rainstorm/v5/codec/gob" + "github.com/AndersonBargas/rainstorm/v5/index" "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" ) diff --git a/kv_test.go b/kv_test.go index 8c503e7..2f31bb7 100644 --- a/kv_test.go +++ b/kv_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/AndersonBargas/rainstorm/v4/codec/gob" - "github.com/AndersonBargas/rainstorm/v4/codec/json" + "github.com/AndersonBargas/rainstorm/v5/codec/gob" + "github.com/AndersonBargas/rainstorm/v5/codec/json" "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" ) diff --git a/node.go b/node.go index 68852f7..e3ac4a6 100644 --- a/node.go +++ b/node.go @@ -1,7 +1,7 @@ package rainstorm import ( - "github.com/AndersonBargas/rainstorm/v4/codec" + "github.com/AndersonBargas/rainstorm/v5/codec" bolt "go.etcd.io/bbolt" ) diff --git a/node_test.go b/node_test.go index 98a637a..47d80ab 100644 --- a/node_test.go +++ b/node_test.go @@ -3,8 +3,8 @@ package rainstorm import ( "testing" - "github.com/AndersonBargas/rainstorm/v4/codec/gob" - "github.com/AndersonBargas/rainstorm/v4/codec/json" + "github.com/AndersonBargas/rainstorm/v5/codec/gob" + "github.com/AndersonBargas/rainstorm/v5/codec/json" "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" ) diff --git a/options.go b/options.go index 0c44970..c6341ca 100644 --- a/options.go +++ b/options.go @@ -3,8 +3,8 @@ package rainstorm import ( "os" - "github.com/AndersonBargas/rainstorm/v4/codec" - "github.com/AndersonBargas/rainstorm/v4/index" + "github.com/AndersonBargas/rainstorm/v5/codec" + "github.com/AndersonBargas/rainstorm/v5/index" bolt "go.etcd.io/bbolt" ) diff --git a/q/examples_test.go b/q/examples_test.go index 4a0602e..b21a334 100644 --- a/q/examples_test.go +++ b/q/examples_test.go @@ -12,8 +12,8 @@ import ( "path/filepath" "strings" - "github.com/AndersonBargas/rainstorm/v4" - "github.com/AndersonBargas/rainstorm/v4/q" + "github.com/AndersonBargas/rainstorm/v5" + "github.com/AndersonBargas/rainstorm/v5/q" ) func ExampleRe() { diff --git a/query.go b/query.go index 1019c5c..7446689 100644 --- a/query.go +++ b/query.go @@ -1,8 +1,8 @@ package rainstorm import ( - "github.com/AndersonBargas/rainstorm/v4/internal" - "github.com/AndersonBargas/rainstorm/v4/q" + "github.com/AndersonBargas/rainstorm/v5/internal" + "github.com/AndersonBargas/rainstorm/v5/q" bolt "go.etcd.io/bbolt" ) diff --git a/query_test.go b/query_test.go index c782f37..212872e 100644 --- a/query_test.go +++ b/query_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/AndersonBargas/rainstorm/v4/codec/json" - "github.com/AndersonBargas/rainstorm/v4/q" + "github.com/AndersonBargas/rainstorm/v5/codec/json" + "github.com/AndersonBargas/rainstorm/v5/q" "github.com/stretchr/testify/require" ) diff --git a/sink.go b/sink.go index 5d9542b..185eed1 100644 --- a/sink.go +++ b/sink.go @@ -5,8 +5,8 @@ import ( "sort" "time" - "github.com/AndersonBargas/rainstorm/v4/index" - "github.com/AndersonBargas/rainstorm/v4/q" + "github.com/AndersonBargas/rainstorm/v5/index" + "github.com/AndersonBargas/rainstorm/v5/q" bolt "go.etcd.io/bbolt" ) diff --git a/store.go b/store.go index 29fab52..dd28881 100644 --- a/store.go +++ b/store.go @@ -4,8 +4,8 @@ import ( "bytes" "reflect" - "github.com/AndersonBargas/rainstorm/v4/index" - "github.com/AndersonBargas/rainstorm/v4/q" + "github.com/AndersonBargas/rainstorm/v5/index" + "github.com/AndersonBargas/rainstorm/v5/q" bolt "go.etcd.io/bbolt" ) diff --git a/store_test.go b/store_test.go index 83beaa5..d844d15 100644 --- a/store_test.go +++ b/store_test.go @@ -6,9 +6,9 @@ import ( "testing" "time" - "github.com/AndersonBargas/rainstorm/v4/codec/gob" - "github.com/AndersonBargas/rainstorm/v4/codec/json" - "github.com/AndersonBargas/rainstorm/v4/q" + "github.com/AndersonBargas/rainstorm/v5/codec/gob" + "github.com/AndersonBargas/rainstorm/v5/codec/json" + "github.com/AndersonBargas/rainstorm/v5/q" "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" ) diff --git a/storm.go b/storm.go index e26676e..8de63a6 100644 --- a/storm.go +++ b/storm.go @@ -5,8 +5,8 @@ import ( "encoding/binary" "time" - "github.com/AndersonBargas/rainstorm/v4/codec" - "github.com/AndersonBargas/rainstorm/v4/codec/json" + "github.com/AndersonBargas/rainstorm/v5/codec" + "github.com/AndersonBargas/rainstorm/v5/codec/json" bolt "go.etcd.io/bbolt" ) diff --git a/storm_test.go b/storm_test.go index 9f2c6b5..cae8978 100644 --- a/storm_test.go +++ b/storm_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - "github.com/AndersonBargas/rainstorm/v4/codec/json" + "github.com/AndersonBargas/rainstorm/v5/codec/json" "github.com/stretchr/testify/require" bolt "go.etcd.io/bbolt" ) diff --git a/version.go b/version.go index c29d60a..2197416 100644 --- a/version.go +++ b/version.go @@ -1,4 +1,4 @@ package rainstorm // Version of Rainstorm -const Version = "4.1.0" +const Version = "5.0.0"