@@ -20,17 +20,26 @@ import (
2020 "context"
2121
2222 "github.com/geldata/gel-go/gelcfg"
23+ "github.com/geldata/gel-go/gelerr"
2324 "github.com/geldata/gel-go/geltypes"
2425 gel "github.com/geldata/gel-go/internal/client"
2526)
2627
2728// CreateClient returns a new client. The client connects lazily. Call
28- // Client.EnsureConnected() to force a connection.
29+ // [Client.EnsureConnected] to force a connection.
30+ //
31+ // Instead of providing connection details directly, we recommend connecting
32+ // using projects locally, and environment variables for remote instances,
33+ // providing an empty [gelcfg.Options] struct here.
34+ // [Read more] about the recommended ways to configure client connections.
35+ //
36+ // [Read more]: https://docs.geldata.com/reference/clients/connection
2937func CreateClient (opts gelcfg.Options ) (* Client , error ) { // nolint:gocritic,lll
3038 return CreateClientDSN ("" , opts )
3139}
3240
33- // CreateClientDSN returns a new client. See also CreateClient.
41+ // CreateClientDSN returns a new Client. We recommend using [CreateClient] for
42+ // most use cases.
3443//
3544// dsn is either an instance name or a [DSN].
3645//
@@ -51,7 +60,11 @@ type Client struct {
5160 pool * gel.Pool
5261}
5362
54- // EnsureConnected forces the client to connect if it hasn't already.
63+ // EnsureConnected forces the client to connect if it hasn't already. This can
64+ // be used to ensure that your program will fail early in the case that the
65+ // [configured connection parameters] are not correct.
66+ //
67+ // [configured connection parameters]: https://docs.geldata.com/reference/clients/connection
5568func (c * Client ) EnsureConnected (ctx context.Context ) error {
5669 return c .pool .EnsureConnected (ctx )
5770}
@@ -62,11 +75,7 @@ func (c *Client) EnsureConnected(ctx context.Context) error {
6275func (c * Client ) Close () error { return c .pool .Close () }
6376
6477// Execute an EdgeQL command (or commands).
65- func (c * Client ) Execute (
66- ctx context.Context ,
67- cmd string ,
68- args ... interface {},
69- ) error {
78+ func (c * Client ) Execute (ctx context.Context , cmd string , args ... interface {}) error { //nolint:lll
7079 conn , err := c .pool .Acquire (ctx )
7180 if err != nil {
7281 return err
@@ -91,12 +100,7 @@ func (c *Client) Execute(
91100}
92101
93102// Query runs a query and returns the results.
94- func (c * Client ) Query (
95- ctx context.Context ,
96- cmd string ,
97- out interface {},
98- args ... interface {},
99- ) error {
103+ func (c * Client ) Query (ctx context.Context , cmd string , out interface {}, args ... interface {}) error { //nolint:lll
100104 conn , err := c .pool .Acquire (ctx )
101105 if err != nil {
102106 return err
@@ -115,16 +119,15 @@ func (c *Client) Query(
115119 return gel .FirstError (err , c .pool .Release (conn , err ))
116120}
117121
118- // QuerySingle runs a singleton-returning query and returns its element.
119- // If the query executes successfully but doesn't return a result
120- // a NoDataError is returned. If the out argument is an optional type the out
121- // argument will be set to missing instead of returning a NoDataError.
122- func (c * Client ) QuerySingle (
123- ctx context.Context ,
124- cmd string ,
125- out interface {},
126- args ... interface {},
127- ) error {
122+ // needed for dock link [gelerr.NoDataError]
123+ var _ = gelerr .NoDataError
124+
125+ // QuerySingle runs a singleton-returning query and returns its element. If
126+ // the query executes successfully but doesn't return a result a
127+ // [gelerr.NoDataError] is returned. If the out
128+ // argument is an optional type the out argument will be set to missing instead
129+ // of returning a NoDataError.
130+ func (c * Client ) QuerySingle (ctx context.Context , cmd string , out interface {}, args ... interface {}) error { //nolint:lll
128131 conn , err := c .pool .Acquire (ctx )
129132 if err != nil {
130133 return err
@@ -143,13 +146,8 @@ func (c *Client) QuerySingle(
143146 return gel .FirstError (err , c .pool .Release (conn , err ))
144147}
145148
146- // QueryJSON runs a query and return the results as JSON.
147- func (c * Client ) QueryJSON (
148- ctx context.Context ,
149- cmd string ,
150- out * []byte ,
151- args ... interface {},
152- ) error {
149+ // QueryJSON runs a query and returns the results as JSON.
150+ func (c * Client ) QueryJSON (ctx context.Context , cmd string , out * []byte , args ... interface {}) error { //nolint:lll
153151 conn , err := c .pool .Acquire (ctx )
154152 if err != nil {
155153 return err
@@ -170,13 +168,8 @@ func (c *Client) QueryJSON(
170168
171169// QuerySingleJSON runs a singleton-returning query.
172170// If the query executes successfully but doesn't have a result
173- // a NoDataError is returned.
174- func (c * Client ) QuerySingleJSON (
175- ctx context.Context ,
176- cmd string ,
177- out interface {},
178- args ... interface {},
179- ) error {
171+ // a [gelerr.NoDataError] is returned.
172+ func (c * Client ) QuerySingleJSON (ctx context.Context , cmd string , out interface {}, args ... interface {}) error { //nolint:lll
180173 conn , err := c .pool .Acquire (ctx )
181174 if err != nil {
182175 return err
@@ -196,12 +189,7 @@ func (c *Client) QuerySingleJSON(
196189}
197190
198191// QuerySQL runs a SQL query and returns the results.
199- func (c * Client ) QuerySQL (
200- ctx context.Context ,
201- cmd string ,
202- out interface {},
203- args ... interface {},
204- ) error {
192+ func (c * Client ) QuerySQL (ctx context.Context , cmd string , out interface {}, args ... interface {}) error { //nolint:lll
205193 conn , err := c .pool .Acquire (ctx )
206194 if err != nil {
207195 return err
@@ -221,11 +209,7 @@ func (c *Client) QuerySQL(
221209}
222210
223211// ExecuteSQL executes a SQL command (or commands).
224- func (c * Client ) ExecuteSQL (
225- ctx context.Context ,
226- cmd string ,
227- args ... interface {},
228- ) error {
212+ func (c * Client ) ExecuteSQL (ctx context.Context , cmd string , args ... interface {}) error { //nolint:lll
229213 conn , err := c .pool .Acquire (ctx )
230214 if err != nil {
231215 return err
@@ -249,11 +233,16 @@ func (c *Client) ExecuteSQL(
249233 return gel .FirstError (err , c .pool .Release (conn , err ))
250234}
251235
252- // Tx runs action in a transaction retrying failed attempts.
236+ // Tx runs action in a transaction retrying failed attempts. Queries must be
237+ // executed on the [geltypes.Tx] that is passed to action. Queries executed on
238+ // the client in a geltypes.TxBlock will not run in the transaction and will be
239+ // applied immediately.
253240//
254- // Retries are governed by [gelcfg.RetryOptions] and [gelcfg.RetryRule].
255- // retry options can be set using [Client.WithRetryOptions].
256- // See [gelcfg.RetryRule] for more details on how they work.
241+ // The geltypes.TxBlock may be re-run if any of the queries fail in a way that
242+ // might succeed on subsequent attempts. Retries are governed by
243+ // [gelcfg.RetryOptions] and [gelcfg.RetryRule]. Retry options can be set
244+ // using [Client.WithRetryOptions]. See [gelcfg.RetryRule] for more details on
245+ // how they work.
257246func (c * Client ) Tx (ctx context.Context , action geltypes.TxBlock ) error {
258247 conn , err := c .pool .Acquire (ctx )
259248 if err != nil {
0 commit comments