Skip to content

Commit

Permalink
update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan Yin Loo committed Nov 24, 2024
1 parent 7093825 commit 531c797
Show file tree
Hide file tree
Showing 31 changed files with 2,860 additions and 108 deletions.
24 changes: 0 additions & 24 deletions coredb/txengine/tx_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"fmt"

"github.com/olachat/gola/v2/coredb"
"github.com/olachat/gola/v2/golalib/testdata/blogs"
"github.com/olachat/gola/v2/golalib/testdata/users"
)

type TypedTx[T any] sql.Tx
Expand Down Expand Up @@ -50,28 +48,6 @@ func StartTx(ctx context.Context, tx *sql.Tx, fn func(ctx context.Context, sqlTx
return err
}

func Example() {
ctxOuter := context.Background()
tx, _ := coredb.BeginTx(ctxOuter, "test_db", &coredb.DefaultTxOpts)
var count int
_ = StartTx(ctxOuter, tx, func(ctx context.Context, sqlTx *sql.Tx) error {
userRec, err := WithTypedTx[users.User](sqlTx).FindOne(ctx, users.TableName, coredb.NewWhere("where uid=?", 1))
if err != nil {
return fmt.Errorf("findOne user uid:%d failed: %w", 1, err)
}
if userRec == nil {
return fmt.Errorf("user:%d not found", 1)
}
ct, err := WithTx(sqlTx).QueryInt(ctx, blogs.DBName, "select count(*) from blogs")
if err != nil {
return fmt.Errorf("QueryInt error: %w", err)
}
count = ct
return nil
})
fmt.Println(count)
}

// FindOne returns a row from given table type with where query.
// If no rows found, *T will be nil. No error will be returned.
func (o *TypedTx[T]) FindOne(ctx context.Context, tableName string, where coredb.WhereQuery) (*T, error) {
Expand Down
43 changes: 24 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,33 @@ replace github.com/jordan-bonecutter/goption v1.0.1 => github.com/yinloo-ola/gop

require (
github.com/blastrain/vitess-sqlparser v0.0.0-20201030050434-a139afbb1aba
github.com/go-sql-driver/mysql v1.7.0
github.com/go-sql-driver/mysql v1.7.2-0.20231213112541-0004702b931d
github.com/jordan-bonecutter/goption v1.0.1
github.com/mitchellh/cli v1.1.4
github.com/pkg/errors v0.9.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.1
golang.org/x/text v0.7.0
github.com/stretchr/testify v1.8.2
golang.org/x/text v0.13.0
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Masterminds/goutils v1.1.0 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.0 // indirect
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dolthub/vitess v0.0.0-20220603212614-514e62ec66cd // indirect
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 // indirect
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e // indirect
github.com/dolthub/jsonpath v0.0.2-0.20240227200619-19675ab05c71 // indirect
github.com/dolthub/vitess v0.0.0-20230823204737-4a21a94e90c3 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-kit/kit v0.10.0 // indirect
github.com/gocraft/dbr/v2 v2.7.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/flatbuffers v2.0.6+incompatible // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
Expand All @@ -48,37 +52,38 @@ require (
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/posener/complete v1.1.1 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/src-d/go-oniguruma v1.1.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/tools v0.5.0 // indirect
github.com/tetratelabs/wazero v1.1.0 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
go.opentelemetry.io/otel v1.7.0 // indirect
go.opentelemetry.io/otel/trace v1.7.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230131230820-1c016267d619 // indirect
google.golang.org/grpc v1.52.3 // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/src-d/go-errors.v1 v1.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/dolthub/go-mysql-server v0.12.0 // test
github.com/dolthub/go-mysql-server v0.17.0 // test
github.com/google/go-cmp v0.5.9 // test
)
Loading

0 comments on commit 531c797

Please sign in to comment.