@@ -224,15 +224,15 @@ fn res_to_rows(res voidptr) []Row {
224224}
225225
226226// close frees the underlying resource allocated by the database connection
227- pub fn (db DB) close () {
227+ pub fn (db & DB) close () {
228228 C.PQfinish (db.conn)
229229}
230230
231231// q_int submit a command to the database server and
232232// returns an the first field in the first tuple
233233// converted to an int. If no row is found or on
234234// command failure, an error is returned
235- pub fn (db DB) q_int (query string ) ! int {
235+ pub fn (db & DB) q_int (query string ) ! int {
236236 rows := db.exec (query)!
237237 if rows.len == 0 {
238238 return error ('q_int "${query} " not found' )
@@ -249,7 +249,7 @@ pub fn (db DB) q_int(query string) !int {
249249// returns an the first field in the first tuple
250250// as a string. If no row is found or on
251251// command failure, an error is returned
252- pub fn (db DB) q_string (query string ) ! string {
252+ pub fn (db & DB) q_string (query string ) ! string {
253253 rows := db.exec (query)!
254254 if rows.len == 0 {
255255 return error ('q_string "${query} " not found' )
@@ -264,12 +264,12 @@ pub fn (db DB) q_string(query string) !string {
264264
265265// q_strings submit a command to the database server and
266266// returns the resulting row set. Alias of `exec`
267- pub fn (db DB) q_strings (query string ) ! []Row {
267+ pub fn (db & DB) q_strings (query string ) ! []Row {
268268 return db.exec (query)
269269}
270270
271271// exec submits a command to the database server and wait for the result, returning an error on failure and a row set on success
272- pub fn (db DB) exec (query string ) ! []Row {
272+ pub fn (db & DB) exec (query string ) ! []Row {
273273 res := C.PQexec (db.conn, & char (query.str))
274274 return db.handle_error_or_result (res, 'exec' )
275275}
@@ -282,7 +282,7 @@ fn rows_first_or_empty(rows []Row) !Row {
282282}
283283
284284// exec_one executes a query and returns its first row as a result, or an error on failure
285- pub fn (db DB) exec_one (query string ) ! Row {
285+ pub fn (db & DB) exec_one (query string ) ! Row {
286286 res := C.PQexec (db.conn, & char (query.str))
287287 e := unsafe { C.PQerrorMessage (db.conn).vstring () }
288288 if e != '' {
@@ -293,7 +293,7 @@ pub fn (db DB) exec_one(query string) !Row {
293293}
294294
295295// exec_param_many executes a query with the parameters provided as ($1), ($2), ($n)
296- pub fn (db DB) exec_param_many (query string , params []string ) ! []Row {
296+ pub fn (db & DB) exec_param_many (query string , params []string ) ! []Row {
297297 unsafe {
298298 mut param_vals := []& char{len: params.len}
299299 for i in 0 .. params.len {
@@ -307,24 +307,24 @@ pub fn (db DB) exec_param_many(query string, params []string) ![]Row {
307307}
308308
309309// exec_param executes a query with 1 parameter ($1), and returns either an error on failure, or the full result set on success
310- pub fn (db DB) exec_param (query string , param string ) ! []Row {
310+ pub fn (db & DB) exec_param (query string , param string ) ! []Row {
311311 return db.exec_param_many (query, [param])
312312}
313313
314314// exec_param2 executes a query with 2 parameters ($1) and ($2), and returns either an error on failure, or the full result set on success
315- pub fn (db DB) exec_param2 (query string , param string , param2 string ) ! []Row {
315+ pub fn (db & DB) exec_param2 (query string , param string , param2 string ) ! []Row {
316316 return db.exec_param_many (query, [param, param2 ])
317317}
318318
319319// prepare submits a request to create a prepared statement with the given parameters, and waits for completion. You must provide the number of parameters (`$1, $2, $3 ...`) used in the statement
320- pub fn (db DB) prepare (name string , query string , num_params int ) ! {
320+ pub fn (db & DB) prepare (name string , query string , num_params int ) ! {
321321 res := C.PQprepare (db.conn, & char (name.str), & char (query.str), num_params, 0 ) // defining param types is optional
322322
323323 return db.handle_error (res, 'prepare' )
324324}
325325
326326// exec_prepared sends a request to execute a prepared statement with given parameters, and waits for the result. The number of parameters must match with the parameters declared in the prepared statement.
327- pub fn (db DB) exec_prepared (name string , params []string ) ! []Row {
327+ pub fn (db & DB) exec_prepared (name string , params []string ) ! []Row {
328328 unsafe {
329329 mut param_vals := []& char{len: params.len}
330330 for i in 0 .. params.len {
@@ -337,7 +337,7 @@ pub fn (db DB) exec_prepared(name string, params []string) ![]Row {
337337 }
338338}
339339
340- fn (db DB) handle_error_or_result (res voidptr , elabel string ) ! []Row {
340+ fn (db & DB) handle_error_or_result (res voidptr , elabel string ) ! []Row {
341341 e := unsafe { C.PQerrorMessage (db.conn).vstring () }
342342 if e != '' {
343343 C.PQclear (res)
@@ -349,7 +349,7 @@ fn (db DB) handle_error_or_result(res voidptr, elabel string) ![]Row {
349349 return res_to_rows (res)
350350}
351351
352- fn (db DB) handle_error (res voidptr , elabel string ) ! {
352+ fn (db & DB) handle_error (res voidptr , elabel string ) ! {
353353 e := unsafe { C.PQerrorMessage (db.conn).vstring () }
354354 if e != '' {
355355 C.PQclear (res)
@@ -362,7 +362,7 @@ fn (db DB) handle_error(res voidptr, elabel string) ! {
362362
363363// copy_expert executes COPY command
364364// https://www.postgresql.org/docs/9.5/libpq-copy.html
365- pub fn (db DB) copy_expert (query string , mut file io.ReaderWriter) ! int {
365+ pub fn (db & DB) copy_expert (query string , mut file io.ReaderWriter) ! int {
366366 mut res := C.PQexec (db.conn, & char (query.str))
367367 status := unsafe { ExecStatusType (C.PQresultStatus (res)) }
368368 defer {
@@ -423,7 +423,7 @@ pub fn (db DB) copy_expert(query string, mut file io.ReaderWriter) !int {
423423 return 0
424424}
425425
426- fn pg_stmt_worker (db DB, query string , data orm.QueryData, where orm.QueryData) ! []Row {
426+ fn pg_stmt_worker (db & DB, query string , data orm.QueryData, where orm.QueryData) ! []Row {
427427 mut param_types := []u32 {}
428428 mut param_vals := []& char{}
429429 mut param_lens := []int {}
@@ -452,7 +452,7 @@ pub struct PQTransactionParam {
452452}
453453
454454// begin begins a new transaction.
455- pub fn (db DB) begin (param PQTransactionParam) ! {
455+ pub fn (db & DB) begin (param PQTransactionParam) ! {
456456 mut sql_stmt := 'BEGIN TRANSACTION ISOLATION LEVEL '
457457 match param.transaction_level {
458458 .read_uncommitted { sql_stmt + = 'READ UNCOMMITTED' }
@@ -468,7 +468,7 @@ pub fn (db DB) begin(param PQTransactionParam) ! {
468468}
469469
470470// commit commits the current transaction.
471- pub fn (db DB) commit () ! {
471+ pub fn (db & DB) commit () ! {
472472 _ := C.PQexec (db.conn, c 'COMMIT;' )
473473 e := unsafe { C.PQerrorMessage (db.conn).vstring () }
474474 if e != '' {
@@ -477,7 +477,7 @@ pub fn (db DB) commit() ! {
477477}
478478
479479// rollback rollbacks the current transaction.
480- pub fn (db DB) rollback () ! {
480+ pub fn (db & DB) rollback () ! {
481481 _ := C.PQexec (db.conn, c 'ROLLBACK;' )
482482 e := unsafe { C.PQerrorMessage (db.conn).vstring () }
483483 if e != '' {
@@ -486,7 +486,7 @@ pub fn (db DB) rollback() ! {
486486}
487487
488488// rollback_to rollbacks to a specified savepoint.
489- pub fn (db DB) rollback_to (savepoint string ) ! {
489+ pub fn (db & DB) rollback_to (savepoint string ) ! {
490490 if ! savepoint.is_identifier () {
491491 return error ('savepoint should be a identifier string' )
492492 }
@@ -499,7 +499,7 @@ pub fn (db DB) rollback_to(savepoint string) ! {
499499}
500500
501501// savepoint create a new savepoint.
502- pub fn (db DB) savepoint (savepoint string ) ! {
502+ pub fn (db & DB) savepoint (savepoint string ) ! {
503503 if ! savepoint.is_identifier () {
504504 return error ('savepoint should be a identifier string' )
505505 }
0 commit comments