@@ -100,13 +100,13 @@ proc addOption*(r: RethinkClient, k: string, v: MutableDatum) =
100100 # # Set a global option
101101 r.options.add ((k, v))
102102
103- proc use * (r: RethinkClient , s: string ) =
103+ proc use * (r: RethinkClient , s: string ): RethinkClient {. discardable .} =
104104 # # Change the default database on this connection.
105- var term: RqlQuery
106- new (term)
105+ var term = new (RqlQuery )
107106 term.tt = DB
108107 term.args = @ [newDatum (s)]
109108 r.addOption (" db" , term.toDatum)
109+ result = r
110110
111111proc newRethinkClient * (address = " 127.0.0.1" , port = Port (28015 ), db: string = " " ): RethinkClient =
112112 # # Init new client instance
@@ -123,6 +123,11 @@ proc newRethinkClient*(address = "127.0.0.1", port = Port(28015), db: string = "
123123
124124 if db != " " :
125125 result .use (db)
126+
127+ template R * (address = " 127.0.0.1" , port = Port (28015 ), db: string = " " ): RethinkClient =
128+ # # Alias for `newRethinkClient`
129+ newRethinkClient (address, port, db)
130+
126131when not compileOption (" threads" ):
127132 proc handshake (r: RethinkClient ) {.async .} =
128133 when defined (debug):
@@ -275,7 +280,7 @@ when not compileOption("threads"):
275280
276281 result = newResponse (buf, token)
277282
278- proc connect * (r: RethinkClient , username = " admin" , password: string = " " ): Future [void ] {.async .} =
283+ proc connect * (r: RethinkClient , username = " admin" , password: string = " " ): Future [RethinkClient ] {.discardable , async .} =
279284 # # Create a new connection to the database server
280285 if not r.isConnected:
281286 if r.username != username:
@@ -287,6 +292,7 @@ when not compileOption("threads"):
287292 await r.sock.connect (r.address, r.port)
288293 r.sockConnected = true
289294 await r.handshake ()
295+ result = r
290296
291297 proc reconnect * (r: RethinkClient ) {.async .} =
292298 # # Close and reopen a connection
@@ -348,7 +354,7 @@ else:
348354 echo " <<< " , buf
349355 newResponse (buf, token)
350356
351- proc connect * (r: RethinkClient , username = " admin" , password: string = " " ) =
357+ proc connect * (r: RethinkClient , username = " admin" , password: string = " " ): RethinkClient {. discardable .} =
352358 # # Create a new connection to the database server
353359 if not r.isConnected:
354360 if r.username != username:
@@ -360,6 +366,7 @@ else:
360366 r.sock.connect (r.address, r.port)
361367 r.sockConnected = true
362368 r.handshake ()
369+ result = r
363370
364371 proc reconnect * (r: RethinkClient ) =
365372 # # Close and reopen a connection
0 commit comments