-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_query_builder.go
More file actions
37 lines (28 loc) · 877 Bytes
/
db_query_builder.go
File metadata and controls
37 lines (28 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package repository_testing
import "database/sql"
// Declaring variable
var dbQueryBuilder DbQueryBuilderContract
// Initiate dbQueryBuilder instance
func init() {
dbQueryBuilder = new(DbQueryBuilder)
}
// DbQueryBuilder contract
type DbQueryBuilderContract interface {
QueryRow(query string, args ...interface{})
Scan(dest ...interface{}) error
}
// DbQueryBuilder struct
type DbQueryBuilder struct {
row *sql.Row
}
// QueryRow executes a query that is expected to return at most one row
func (self *DbQueryBuilder) QueryRow(query string, args ...interface{}) {
dbConnection := new(DbConnection).GetConnection()
defer dbConnection.Close()
self.row = dbConnection.QueryRow(query, args...)
}
// Scan copies the columns from the matched row into the values
func (self *DbQueryBuilder) Scan(dest ...interface{}) error {
err := self.row.Scan(dest...)
return err
}