Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoor committed Nov 3, 2022
1 parent 966eabe commit 7315ffd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
21 changes: 19 additions & 2 deletions internal/client/doc.go → doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package edgedb is the official Go EdgeDB driver. https://www.edgedb.com
// Package edgedb is the official Go driver for [EdgeDB].
//
// Typical usage looks like this:
//
Expand Down Expand Up @@ -48,7 +48,10 @@
// ...
// }
//
// You can also connect to a database using a DSN:
// We recommend using environment variables for connection parameters. See the
// [client connection docs] for more information.
//
// You may also connect to a database using a DSN:
//
// url := "edgedb://edgedb@localhost/edgedb"
// client, err := edgedb.CreateClientDSN(ctx, url, opts)
Expand Down Expand Up @@ -135,8 +138,22 @@
// fmt.Println(result.Missing())
// // Output: false
//
// Not all types listed above are valid query parameters. To pass a slice of
// scalar values use array in your query. EdgeDB doesn't currently support
// using sets as parameters.
//
// query := `select User filter .id in array_unpack(<array<uuid>>$1)`
// client.QuerySingle(ctx, query, $user, []edgedb.UUID{...})
//
// Nested structures are also not directly allowed but you can use [json]
// instead.
//
// # Custom Marshalers
//
// Interfaces for user defined marshaler/unmarshalers are documented in the
// internal/marshal package.
//
// [EdgeDB]: https://www.edgedb.com
// [json]: https://www.edgedb.com/docs/edgeql/insert#bulk-inserts
// [client connection docs]: https://www.edgedb.com/docs/clients/connection
package edgedb
File renamed without changes.
18 changes: 0 additions & 18 deletions internal/client/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"errors"
"fmt"
"log"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -157,20 +156,3 @@ func TestTxKinds(t *testing.T) {
})
}
}

// Transactions can be executed using the Tx() method. Note that queries are
// executed on the Tx object. Queries executed on the client in a transaction
// callback will not run in the transaction and will be applied immediately. In
// edgedb-go the callback may be re-run if any of the queries fail in a way
// that might succeed on subsequent attempts. Transaction behavior can be
// configured with TxOptions and the retrying behavior can be configured with
// RetryOptions.
func ExampleTx() {
ctx := context.Background()
err := client.Tx(ctx, func(ctx context.Context, tx *Tx) error {
return tx.Execute(ctx, "INSERT User { name := 'Don' }")
})
if err != nil {
log.Println(err)
}
}
28 changes: 28 additions & 0 deletions tx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package edgedb_test

import (
"context"
"log"

edgedb "github.com/edgedb/edgedb-go/internal/client"
)

// Transactions can be executed using the Tx() method. Note that queries are
// executed on the Tx object. Queries executed on the client in a transaction
// callback will not run in the transaction and will be applied immediately. In
// edgedb-go the callback may be re-run if any of the queries fail in a way
// that might succeed on subsequent attempts. Transaction behavior can be
// configured with TxOptions and the retrying behavior can be configured with
// RetryOptions.
func ExampleTx() {
ctx := context.Background()
client, err := edgedb.CreateClient(ctx, edgedb.Options{})

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)
}
}

0 comments on commit 7315ffd

Please sign in to comment.