diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 33abc62..4f81ae7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,14 +9,14 @@ on: branches: - '**' schedule: - - cron: '27 0 * * *' + - cron: '28 0 * * *' jobs: test: runs-on: ${{ matrix.os }} strategy: matrix: - go-version: ["1.21", "1.22"] + go-version: ["1.22", "1.23"] edgedb-version: [stable, nightly] os: [ubuntu-latest, macos-latest] steps: @@ -33,6 +33,11 @@ jobs: run: | go install make lint && make gendocs-lint + make gen + if [[ "$(git status --porcelain)" != "" ]]; then + echo "Generated code is out of sync. Run make gen." + exit 1 + fi - name: Build run: | diff --git a/.golangci.yml b/.golangci.yml index bd0f2c7..760248e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,16 +32,6 @@ run: # vendor$, third_party$, testdata$, examples$, Godeps$, builtin$ skip-dirs-use-default: true - # which files to skip: they will be analyzed, but issues from them - # won't be reported. Default value is empty list, but there is - # no need to include all autogenerated files, we confidently recognize - # autogenerated files. If it's not please let us know. - # "/" will be replaced by current OS file path separator to properly work - # on Windows. - skip-files: - - doc_test.go - - cmd/edgeql-go/doc.go - # by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules": # If invoked with -mod=readonly, the go command is disallowed from the implicit # automatic updating of go.mod described above. Instead, it fails when any changes @@ -59,9 +49,6 @@ run: # output configuration options output: - # colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number" - format: colored-line-number - # print lines of code with issue, default is true print-issued-lines: true @@ -92,11 +79,6 @@ linters-settings: # default is false: such cases aren't reported by default. check-blank: false - # [deprecated] comma-separated list of pairs of the form pkg:regex - # the regex is used to ignore names within pkg. (default "fmt:.*"). - # see https://github.com/kisielk/errcheck#the-deprecated-method for details - ignore: fmt:.*,io/ioutil:^Read.* - # path to a file containing a list of functions to exclude from checking # see https://github.com/kisielk/errcheck#excluding-functions for details # exclude: /path/to/file.txt @@ -110,11 +92,6 @@ linters-settings: funlen: lines: 60 statements: 40 - gci: - # put imports beginning with prefix after 3rd-party packages; - # only support one prefix - # if not set, use goimports.local-prefixes - local-prefixes: github.com/org/project gocognit: # minimal code complexity to report, 30 by default (but we recommend 10-20) min-complexity: 10 @@ -183,11 +160,9 @@ linters-settings: # minimal confidence for issues, default is 0.8 min-confidence: 0.8 gomnd: - settings: - mnd: - # the list of enabled checks, - # see https://github.com/tommy-muehle/go-mnd/#checks for description. - checks: argument,case,condition,operation,return,assign + # the list of enabled checks, + # see https://github.com/tommy-muehle/go-mnd/#checks for description. + checks: argument,case,condition,operation,return,assign gomodguard: allowed: # List of allowed modules @@ -216,9 +191,6 @@ linters-settings: # # Reason why the version constraint exists. (Optional) # reason: "testing if blocked version constraint works." govet: - # report about shadowed variables - check-shadowing: true - # settings per analyzer settings: printf: # analyzer name, run `go tool vet help` to see all analyzers @@ -364,6 +336,7 @@ linters-settings: linters: enable: - errcheck + - gci - gocritic - gofmt - goheader @@ -372,10 +345,10 @@ linters: - govet - ineffassign - lll - - revive - prealloc + - revive - staticcheck - - typecheck + # - typecheck - unconvert - unused - whitespace @@ -458,6 +431,10 @@ issues: # Show only new issues created in git patch with set file path. # new-from-patch: path/to/patch/file + + exclude-files: + - doc_test.go + - cmd/edgeql-go/doc.go severity: # Default value is empty string. diff --git a/Makefile b/Makefile index 0144f08..b5463d2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ +CHANGES:=$(shell git status --porcelain) + quality: lint test bench lint: - go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.1 run --sort-results + go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 run --sort-results test: go test -v -count=1 -race -bench=$$^ -timeout=20m ./... @@ -24,6 +26,9 @@ errors: go run internal/cmd/generrexport/main.go > errors_gen.go make format +gen: + go generate ./... + gendocs: go run internal/cmd/gendocs/*.go diff --git a/cmd/edgeql-go/main.go b/cmd/edgeql-go/main.go index 7eca640..d85fc9c 100644 --- a/cmd/edgeql-go/main.go +++ b/cmd/edgeql-go/main.go @@ -49,7 +49,7 @@ var ( ) func usage() { - fmt.Fprintf(flag.CommandLine.Output(), ""+ + _, _ = fmt.Fprintf(flag.CommandLine.Output(), ""+ "Generate go functions from edgeql files.\n"+ "\n"+ "USAGE:\n"+ diff --git a/doc.go b/doc.go index 5d248d9..881b451 100644 --- a/doc.go +++ b/doc.go @@ -15,8 +15,8 @@ // limitations under the License. // Package edgedb is the official Go driver for [EdgeDB]. Additionally, -// [github.com/edgedb/edgedb-go/cmd/edgeql-go] is a code generator that generates go functions from edgeql -// files. +// [github.com/edgedb/edgedb-go/cmd/edgeql-go] is a code generator that +// generates go functions from edgeql files. // // Typical client usage looks like this: // diff --git a/doc_test.go b/doc_test.go index c3db99c..76a001a 100644 --- a/doc_test.go +++ b/doc_test.go @@ -22,7 +22,7 @@ import ( "log" "time" - "github.com/edgedb/edgedb-go" + edgedb "github.com/edgedb/edgedb-go" ) type User struct { diff --git a/export.go b/export.go index b33cba9..553cef8 100644 --- a/export.go +++ b/export.go @@ -71,7 +71,7 @@ type ( // ErrorTag is the argument type to Error.HasTag(). ErrorTag = edgedb.ErrorTag - // Executor is a common interface between Client and Tx, + // Executor is a common interface between *Client and *Tx, // that can run queries on an EdgeDB database. Executor = edgedb.Executor @@ -238,7 +238,7 @@ type ( // before making the next attempt when retrying a transaction. RetryBackoff = edgedb.RetryBackoff - // RetryCondition represents scenarios that can caused a transaction + // RetryCondition represents scenarios that can cause a transaction // run in Tx() methods to be retried. RetryCondition = edgedb.RetryCondition @@ -428,7 +428,7 @@ var ( // NewRelativeDuration returns a new RelativeDuration NewRelativeDuration = edgedbtypes.NewRelativeDuration - // NewRetryOptions returns the default RetryOptions value. + // NewRetryOptions returns the default retry options. NewRetryOptions = edgedb.NewRetryOptions // NewRetryRule returns the default RetryRule value. diff --git a/internal/buff/read_test.go b/internal/buff/read_test.go index 713523d..8646de4 100644 --- a/internal/buff/read_test.go +++ b/internal/buff/read_test.go @@ -19,11 +19,10 @@ package buff import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - types "github.com/edgedb/edgedb-go/internal/edgedbtypes" "github.com/edgedb/edgedb-go/internal/soc" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNext(t *testing.T) { diff --git a/internal/client/aspect.go b/internal/client/aspect.go index 88bd83f..04d4744 100644 --- a/internal/client/aspect.go +++ b/internal/client/aspect.go @@ -16,7 +16,7 @@ package edgedb -//go:generate stringer -type Aspect +//go:generate go run golang.org/x/tools/cmd/stringer@v0.25.0 -type Aspect // Aspect is the description aspect from protocol version 0.X type Aspect uint8 diff --git a/internal/client/cardinality.go b/internal/client/cardinality.go index 8955877..34c9167 100644 --- a/internal/client/cardinality.go +++ b/internal/client/cardinality.go @@ -16,7 +16,7 @@ package edgedb -//go:generate stringer -type Cardinality +//go:generate go run golang.org/x/tools/cmd/stringer@v0.25.0 -type Cardinality // Cardinality is the result cardinality for a command. type Cardinality uint8 diff --git a/internal/client/format.go b/internal/client/format.go index 96edd1c..faf99e9 100644 --- a/internal/client/format.go +++ b/internal/client/format.go @@ -16,7 +16,7 @@ package edgedb -//go:generate stringer -type Format +//go:generate go run golang.org/x/tools/cmd/stringer@v0.25.0 -type Format // Format is the query response format. type Format uint8 diff --git a/internal/client/message.go b/internal/client/message.go index b80f678..d225bac 100644 --- a/internal/client/message.go +++ b/internal/client/message.go @@ -16,7 +16,7 @@ package edgedb -//go:generate stringer -type Cardinality +//go:generate go run golang.org/x/tools/cmd/stringer@v0.25.0 -type Message // Message is a protocol message type. type Message uint8 diff --git a/internal/client/message_string.go b/internal/client/message_string.go new file mode 100644 index 0000000..1afdb7e --- /dev/null +++ b/internal/client/message_string.go @@ -0,0 +1,79 @@ +// Code generated by "stringer -type Message"; DO NOT EDIT. + +package edgedb + +import "strconv" + +func _() { + // An "invalid array index" compiler error signifies that the constant values have changed. + // Re-run the stringer command to generate them again. + var x [1]struct{} + _ = x[Authentication-82] + _ = x[CommandComplete-67] + _ = x[CommandDataDescription-84] + _ = x[Data-68] + _ = x[DumpBlock-61] + _ = x[DumpHeader-64] + _ = x[ErrorResponse-69] + _ = x[LogMessage-76] + _ = x[ParameterStatus-83] + _ = x[ParseComplete-49] + _ = x[ReadyForCommand-90] + _ = x[RestoreReady-43] + _ = x[ServerHandshake-118] + _ = x[ServerKeyData-75] + _ = x[StateDataDescription-115] + _ = x[AuthenticationSASLInitialResponse-112] + _ = x[AuthenticationSASLResponse-114] + _ = x[ClientHandshake-86] + _ = x[DescribeStatement-68] + _ = x[Dump-62] + _ = x[Execute0pX-69] + _ = x[ExecuteScript-81] + _ = x[Flush-72] + _ = x[Execute-79] + _ = x[Parse-80] + _ = x[Restore-60] + _ = x[RestoreBlock-61] + _ = x[RestoreEOF-46] + _ = x[Sync-83] + _ = x[Terminate-88] +} + +const _Message_name = "RestoreReadyRestoreEOFParseCompleteRestoreDumpBlockDumpDumpHeaderCommandCompleteDataErrorResponseFlushServerKeyDataLogMessageExecuteParseExecuteScriptAuthenticationParameterStatusCommandDataDescriptionClientHandshakeTerminateReadyForCommandAuthenticationSASLInitialResponseAuthenticationSASLResponseStateDataDescriptionServerHandshake" + +var _Message_map = map[Message]string{ + 43: _Message_name[0:12], + 46: _Message_name[12:22], + 49: _Message_name[22:35], + 60: _Message_name[35:42], + 61: _Message_name[42:51], + 62: _Message_name[51:55], + 64: _Message_name[55:65], + 67: _Message_name[65:80], + 68: _Message_name[80:84], + 69: _Message_name[84:97], + 72: _Message_name[97:102], + 75: _Message_name[102:115], + 76: _Message_name[115:125], + 79: _Message_name[125:132], + 80: _Message_name[132:137], + 81: _Message_name[137:150], + 82: _Message_name[150:164], + 83: _Message_name[164:179], + 84: _Message_name[179:201], + 86: _Message_name[201:216], + 88: _Message_name[216:225], + 90: _Message_name[225:240], + 112: _Message_name[240:273], + 114: _Message_name[273:299], + 115: _Message_name[299:319], + 118: _Message_name[319:334], +} + +func (i Message) String() string { + if str, ok := _Message_map[i]; ok { + return str + } + return "Message(" + strconv.FormatInt(int64(i), 10) + ")" +} diff --git a/internal/cmd/export/names.txt b/internal/cmd/export/names.txt index 94c9052..b9b50ad 100644 --- a/internal/cmd/export/names.txt +++ b/internal/cmd/export/names.txt @@ -3,9 +3,11 @@ CreateClient CreateClientDSN DateDuration Duration +DurationFromNanoseconds Error ErrorCategory ErrorTag +Executor IsolationLevel LocalDate LocalDateTime @@ -50,6 +52,7 @@ NewRangeInt64 NewRangeLocalDate NewRangeLocalDateTime NewRelativeDuration +NewRetryOptions NewRetryRule NewTxOptions Optional diff --git a/internal/codecs/codecs.go b/internal/codecs/codecs.go index 3f17908..989b60f 100644 --- a/internal/codecs/codecs.go +++ b/internal/codecs/codecs.go @@ -520,7 +520,7 @@ func buildScalarDecoder( expectedType = "edgedb.Duration or edgedb.OptionalDuration" } case JSONID: - ptr := reflect.PtrTo(typ) + ptr := reflect.PointerTo(typ) switch { case typ == bytesType: @@ -751,7 +751,7 @@ func buildScalarDecoderV2( expectedType = "edgedb.Duration or edgedb.OptionalDuration" } case JSONID: - ptr := reflect.PtrTo(typ) + ptr := reflect.PointerTo(typ) switch { case typ == bytesType: diff --git a/internal/codecs/namedtuple.go b/internal/codecs/namedtuple.go index 2f44d1d..df7f99a 100644 --- a/internal/codecs/namedtuple.go +++ b/internal/codecs/namedtuple.go @@ -144,7 +144,7 @@ func buildNamedTupleDecoder( decoder := namedTupleDecoder{desc.ID, fields} - if reflect.PtrTo(typ).Implements(optionalUnmarshalerType) { + if reflect.PointerTo(typ).Implements(optionalUnmarshalerType) { return &optionalNamedTupleDecoder{decoder, typ}, nil } @@ -191,7 +191,7 @@ func buildNamedTupleDecoderV2( decoder := namedTupleDecoder{desc.ID, fields} - if reflect.PtrTo(typ).Implements(optionalUnmarshalerType) { + if reflect.PointerTo(typ).Implements(optionalUnmarshalerType) { return &optionalNamedTupleDecoder{decoder, typ}, nil } diff --git a/internal/codecs/object.go b/internal/codecs/object.go index 34d1331..2b422b4 100644 --- a/internal/codecs/object.go +++ b/internal/codecs/object.go @@ -101,7 +101,7 @@ func buildObjectDecoder( decoder := objectDecoder{desc.ID, fields} - if reflect.PtrTo(typ).Implements(optionalUnmarshalerType) { + if reflect.PointerTo(typ).Implements(optionalUnmarshalerType) { return &optionalObjectDecoder{decoder, typ}, nil } @@ -159,7 +159,7 @@ func buildObjectDecoderV2( decoder := objectDecoder{desc.ID, fields} - if reflect.PtrTo(typ).Implements(optionalUnmarshalerType) { + if reflect.PointerTo(typ).Implements(optionalUnmarshalerType) { return &optionalObjectDecoder{decoder, typ}, nil } diff --git a/internal/codecs/tuple.go b/internal/codecs/tuple.go index 43b7b53..2b12f89 100644 --- a/internal/codecs/tuple.go +++ b/internal/codecs/tuple.go @@ -131,7 +131,7 @@ func buildTupleDecoder( decoder := tupleDecoder{desc.ID, fields} - if reflect.PtrTo(typ).Implements(optionalUnmarshalerType) { + if reflect.PointerTo(typ).Implements(optionalUnmarshalerType) { return &optionalTupleDecoder{decoder, typ}, nil } @@ -179,7 +179,7 @@ func buildTupleDecoderV2( decoder := tupleDecoder{desc.ID, fields} - if reflect.PtrTo(typ).Implements(optionalUnmarshalerType) { + if reflect.PointerTo(typ).Implements(optionalUnmarshalerType) { return &optionalTupleDecoder{decoder, typ}, nil } diff --git a/internal/codecs/unmarshaler.go b/internal/codecs/unmarshaler.go index 694cf64..1033c4f 100644 --- a/internal/codecs/unmarshaler.go +++ b/internal/codecs/unmarshaler.go @@ -137,7 +137,7 @@ func buildUnmarshaler( return nil, false, nil } - ptr := reflect.PtrTo(typ) + ptr := reflect.PointerTo(typ) if !ptr.Implements(iface.typ) { return nil, false, nil } @@ -171,7 +171,7 @@ func buildUnmarshalerV2( return nil, false, nil } - ptr := reflect.PtrTo(typ) + ptr := reflect.PointerTo(typ) if !ptr.Implements(iface.typ) { return nil, false, nil } diff --git a/internal/descriptor/descriptor.go b/internal/descriptor/descriptor.go index 6e506d2..3b03444 100644 --- a/internal/descriptor/descriptor.go +++ b/internal/descriptor/descriptor.go @@ -30,7 +30,7 @@ import ( // https://www.edgedb.com/docs/internals/protocol/typedesc#type-descriptors var IDZero = edgedbtypes.UUID{} -//go:generate stringer -type Type +//go:generate go run golang.org/x/tools/cmd/stringer@v0.25.0 -type Type // Type represents a descriptor type. type Type uint8 @@ -147,7 +147,8 @@ func Pop( Desc: descriptors[r.PopUint16()], }}} default: - if 0x80 <= typ && typ <= 0xff { + + if 0x80 <= typ { // ignore unknown type annotations r.PopBytes() break diff --git a/internal/descriptor/descriptor_v2.go b/internal/descriptor/descriptor_v2.go index 4157568..8af0342 100644 --- a/internal/descriptor/descriptor_v2.go +++ b/internal/descriptor/descriptor_v2.go @@ -154,7 +154,7 @@ func PopV2( }} desc = V2{MultiRange, id, name, true, ancestors, fields} default: - if 0x80 <= typ && typ <= 0xff { + if 0x80 <= typ { // ignore unknown type annotations r.PopBytes() break diff --git a/internal/descriptor/type_string.go b/internal/descriptor/type_string.go index e423eff..af96815 100644 --- a/internal/descriptor/type_string.go +++ b/internal/descriptor/type_string.go @@ -20,11 +20,12 @@ func _() { _ = x[Range-9] _ = x[ObjectShape-10] _ = x[Compound-11] + _ = x[MultiRange-12] } -const _Type_name = "SetObjectBaseScalarScalarTupleNamedTupleArrayEnumInputShapeRangeObjectShapeCompound" +const _Type_name = "SetObjectBaseScalarScalarTupleNamedTupleArrayEnumInputShapeRangeObjectShapeCompoundMultiRange" -var _Type_index = [...]uint8{0, 3, 9, 19, 25, 30, 40, 45, 49, 59, 64, 75, 83} +var _Type_index = [...]uint8{0, 3, 9, 19, 25, 30, 40, 45, 49, 59, 64, 75, 83, 93} func (i Type) String() string { if i >= Type(len(_Type_index)-1) { diff --git a/rstdocs/api.rst b/rstdocs/api.rst index 0368c58..91f71b9 100644 --- a/rstdocs/api.rst +++ b/rstdocs/api.rst @@ -50,7 +50,7 @@ ErrorTag is the argument type to Error.HasTag(). *type* Executor --------------- -Executor is a common interface between Client and Tx, +Executor is a common interface between \*Client and \*Tx, that can run queries on an EdgeDB database. @@ -108,7 +108,7 @@ before making the next attempt when retrying a transaction. *type* RetryCondition --------------------- -RetryCondition represents scenarios that can caused a transaction +RetryCondition represents scenarios that can cause a transaction run in Tx() methods to be retried. diff --git a/rstdocs/index.rst b/rstdocs/index.rst index f17b12d..89c77ec 100644 --- a/rstdocs/index.rst +++ b/rstdocs/index.rst @@ -16,8 +16,8 @@ EdgeDB Go Driver Package edgedb is the official Go driver for `EdgeDB `_. Additionally, -`edgeql-go `_ is a code generator that generates go functions from edgeql -files. +`edgeql-go `_ is a code generator that +generates go functions from edgeql files. Typical client usage looks like this: @@ -212,7 +212,7 @@ Usage Example "log" "time" - "github.com/edgedb/edgedb-go" + edgedb "github.com/edgedb/edgedb-go" ) type User struct { diff --git a/tools.go b/tools.go deleted file mode 100644 index 9c703b6..0000000 --- a/tools.go +++ /dev/null @@ -1,6 +0,0 @@ -//go:build tools - -package edgedb - -//nolint:typecheck -import _ "golang.org/x/tools/cmd/stringer" diff --git a/tx_test.go b/tx_test.go index e8d3b4c..10c7ceb 100644 --- a/tx_test.go +++ b/tx_test.go @@ -1,3 +1,19 @@ +// This source file is part of the EdgeDB open source project. +// +// Copyright EdgeDB Inc. and the EdgeDB authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package edgedb_test import ( @@ -17,11 +33,13 @@ import ( func ExampleTx() { ctx := context.Background() client, err := edgedb.CreateClient(ctx, edgedb.Options{}) + if err != nil { + log.Println(err) + } err = client.Tx(ctx, func(ctx context.Context, tx *edgedb.Tx) error { return tx.Execute(ctx, "INSERT User { name := 'Don' }") }) - if err != nil { log.Println(err) }