2017-11-12 05:25:04 +00:00
package qgen
2018-03-31 05:25:27 +00:00
import (
2022-02-21 03:32:53 +00:00
"database/sql"
"strings"
2021-04-27 10:35:10 +00:00
2022-02-21 03:32:53 +00:00
//"fmt"
"strconv"
2018-03-31 05:25:27 +00:00
)
2017-11-12 05:25:04 +00:00
type accDeleteBuilder struct {
2022-02-21 03:32:53 +00:00
table string
where string
dateCutoff * dateCutoff // We might want to do this in a slightly less hacky way
2017-11-12 05:25:04 +00:00
2022-02-21 03:32:53 +00:00
build * Accumulator
2017-11-12 05:25:04 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * accDeleteBuilder ) Where ( w string ) * accDeleteBuilder {
2022-02-21 03:32:53 +00:00
if b . where != "" {
b . where += " AND "
}
b . where += w
return b
2017-11-12 05:25:04 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * accDeleteBuilder ) DateCutoff ( col string , quantity int , unit string ) * accDeleteBuilder {
2022-02-21 03:32:53 +00:00
b . dateCutoff = & dateCutoff { col , quantity , unit , 0 }
return b
2019-06-05 04:57:10 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * accDeleteBuilder ) DateOlderThan ( col string , quantity int , unit string ) * accDeleteBuilder {
2022-02-21 03:32:53 +00:00
b . dateCutoff = & dateCutoff { col , quantity , unit , 1 }
return b
2018-07-28 12:52:23 +00:00
}
2021-04-07 14:23:11 +00:00
func ( b * accDeleteBuilder ) DateOlderThanQ ( col , unit string ) * accDeleteBuilder {
2022-02-21 03:32:53 +00:00
b . dateCutoff = & dateCutoff { col , 0 , unit , 11 }
return b
2021-04-07 14:23:11 +00:00
}
2019-06-05 04:57:10 +00:00
/ * func ( b * accDeleteBuilder ) Prepare ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
return b . build . SimpleDelete ( b . table , b . where )
2019-06-05 04:57:10 +00:00
} * /
// TODO: Fix this nasty hack
func ( b * accDeleteBuilder ) Prepare ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
// TODO: Phase out the procedural API and use the adapter's OO API? The OO API might need a bit more work before we do that and it needs to be rolled out to MSSQL.
if b . dateCutoff != nil {
dBuilder := b . build . GetAdapter ( ) . Builder ( ) . Delete ( ) . FromAcc ( b )
return b . build . prepare ( b . build . GetAdapter ( ) . ComplexDelete ( dBuilder ) )
}
return b . build . SimpleDelete ( b . table , b . where )
2019-06-05 04:57:10 +00:00
}
2021-04-27 10:35:10 +00:00
func ( b * accDeleteBuilder ) Exec ( args ... interface { } ) ( res sql . Result , e error ) {
2022-02-21 03:32:53 +00:00
stmt := b . Prepare ( )
if stmt == nil {
return res , b . build . FirstError ( )
}
return stmt . Exec ( args ... )
2021-04-27 10:35:10 +00:00
}
func ( b * accDeleteBuilder ) Run ( args ... interface { } ) ( int , error ) {
2022-02-21 03:32:53 +00:00
res , e := b . Exec ( args ... )
if e != nil {
return 0 , e
}
lastID , e := res . LastInsertId ( )
return int ( lastID ) , e
2017-11-12 05:25:04 +00:00
}
type accUpdateBuilder struct {
2022-02-21 03:32:53 +00:00
up * updatePrebuilder
build * Accumulator
2017-11-12 05:25:04 +00:00
}
2019-05-08 09:50:10 +00:00
func ( u * accUpdateBuilder ) Set ( set string ) * accUpdateBuilder {
2022-02-21 03:32:53 +00:00
u . up . set = set
return u
2017-11-12 05:25:04 +00:00
}
2019-05-08 09:50:10 +00:00
func ( u * accUpdateBuilder ) Where ( where string ) * accUpdateBuilder {
2022-02-21 03:32:53 +00:00
if u . up . where != "" {
u . up . where += " AND "
}
u . up . where += where
return u
2018-12-27 05:42:41 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * accUpdateBuilder ) DateCutoff ( col string , quantity int , unit string ) * accUpdateBuilder {
2022-02-21 03:32:53 +00:00
b . up . dateCutoff = & dateCutoff { col , quantity , unit , 0 }
return b
2017-11-12 05:25:04 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * accUpdateBuilder ) DateOlderThan ( col string , quantity int , unit string ) * accUpdateBuilder {
2022-02-21 03:32:53 +00:00
b . up . dateCutoff = & dateCutoff { col , quantity , unit , 1 }
return b
2019-05-08 09:50:10 +00:00
}
2021-04-07 14:23:11 +00:00
func ( b * accUpdateBuilder ) DateOlderThanQ ( col , unit string ) * accUpdateBuilder {
2022-02-21 03:32:53 +00:00
b . up . dateCutoff = & dateCutoff { col , 0 , unit , 11 }
return b
2021-04-07 14:23:11 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * accUpdateBuilder ) WhereQ ( sel * selectPrebuilder ) * accUpdateBuilder {
2022-02-21 03:32:53 +00:00
b . up . whereSubQuery = sel
return b
2019-05-08 09:50:10 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * accUpdateBuilder ) Prepare ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
if b . up . whereSubQuery != nil {
return b . build . prepare ( b . build . adapter . SimpleUpdateSelect ( b . up ) )
}
return b . build . prepare ( b . build . adapter . SimpleUpdate ( b . up ) )
2018-12-27 05:42:41 +00:00
}
2021-04-07 14:23:11 +00:00
func ( b * accUpdateBuilder ) Stmt ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
if b . up . whereSubQuery != nil {
return b . build . prepare ( b . build . adapter . SimpleUpdateSelect ( b . up ) )
}
return b . build . prepare ( b . build . adapter . SimpleUpdate ( b . up ) )
2021-04-07 14:23:11 +00:00
}
2018-12-27 05:42:41 +00:00
2019-08-28 06:47:54 +00:00
func ( b * accUpdateBuilder ) Exec ( args ... interface { } ) ( res sql . Result , err error ) {
2022-02-21 03:32:53 +00:00
q , e := b . build . adapter . SimpleUpdate ( b . up )
if err != nil {
return res , e
}
//fmt.Println("q:", q)
return b . build . exec ( q , args ... )
2021-04-07 14:23:11 +00:00
}
type AccBuilder interface {
2022-02-21 03:32:53 +00:00
Prepare ( ) * sql . Stmt
2017-11-12 05:25:04 +00:00
}
2021-04-27 10:35:10 +00:00
type AccExec interface {
2022-02-21 03:32:53 +00:00
Exec ( args ... interface { } ) ( res sql . Result , err error )
2021-04-27 10:35:10 +00:00
}
2018-04-22 12:33:56 +00:00
type AccSelectBuilder struct {
2022-02-21 03:32:53 +00:00
table string
columns string
where string
orderby string
limit string
dateCutoff * dateCutoff // We might want to do this in a slightly less hacky way
inChain * AccSelectBuilder
inColumn string
2017-11-12 05:25:04 +00:00
2022-02-21 03:32:53 +00:00
build * Accumulator
2017-11-12 05:25:04 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * AccSelectBuilder ) Columns ( cols string ) * AccSelectBuilder {
2022-02-21 03:32:53 +00:00
b . columns = cols
return b
2017-11-12 05:25:04 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * AccSelectBuilder ) Cols ( cols string ) * AccSelectBuilder {
2022-02-21 03:32:53 +00:00
b . columns = cols
return b
2018-12-27 05:42:41 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * AccSelectBuilder ) Where ( where string ) * AccSelectBuilder {
2022-02-21 03:32:53 +00:00
if b . where != "" {
b . where += " AND "
}
b . where += where
return b
2018-03-31 05:25:27 +00:00
}
// TODO: Don't implement the SQL at the accumulator level but the adapter level
2020-02-24 11:15:17 +00:00
func ( b * AccSelectBuilder ) In ( col string , inList [ ] int ) * AccSelectBuilder {
2022-02-21 03:32:53 +00:00
if len ( inList ) == 0 {
return b
}
var wsb strings . Builder
wsb . Grow ( len ( col ) + 5 + 1 + len ( b . where ) + ( len ( inList ) * 2 ) )
wsb . WriteString ( col )
wsb . WriteString ( " IN(" )
for i , it := range inList {
if i != 0 {
wsb . WriteRune ( ',' )
}
wsb . WriteString ( strconv . Itoa ( it ) )
}
if b . where != "" {
wsb . WriteString ( ") AND " )
wsb . WriteString ( b . where )
} else {
wsb . WriteRune ( ')' )
}
b . where = wsb . String ( )
return b
2017-11-12 05:25:04 +00:00
}
2019-08-28 06:47:54 +00:00
// TODO: Don't implement the SQL at the accumulator level but the adapter level
2020-02-24 11:15:17 +00:00
func ( b * AccSelectBuilder ) InPQuery ( col string , inList [ ] int ) ( * sql . Rows , error ) {
2022-02-21 03:32:53 +00:00
if len ( inList ) == 0 {
return nil , sql . ErrNoRows
}
// TODO: Optimise this
where := col + " IN("
2019-08-28 06:47:54 +00:00
2022-02-21 03:32:53 +00:00
idList := make ( [ ] interface { } , len ( inList ) )
for i , id := range inList {
idList [ i ] = strconv . Itoa ( id )
where += "?,"
}
where = where [ 0 : len ( where ) - 1 ] + ")"
2019-08-28 06:47:54 +00:00
2022-02-21 03:32:53 +00:00
if b . where != "" {
where += " AND " + b . where
}
2019-08-28 06:47:54 +00:00
2022-02-21 03:32:53 +00:00
b . where = where
return b . Query ( idList ... )
2019-08-28 06:47:54 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * AccSelectBuilder ) InQ ( col string , sb * AccSelectBuilder ) * AccSelectBuilder {
2022-02-21 03:32:53 +00:00
b . inChain = sb
b . inColumn = col
return b
2020-02-24 11:15:17 +00:00
}
func ( b * AccSelectBuilder ) DateCutoff ( col string , quantity int , unit string ) * AccSelectBuilder {
2022-02-21 03:32:53 +00:00
b . dateCutoff = & dateCutoff { col , quantity , unit , 0 }
return b
2018-01-21 11:17:43 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * AccSelectBuilder ) DateOlderThanQ ( col , unit string ) * AccSelectBuilder {
2022-02-21 03:32:53 +00:00
b . dateCutoff = & dateCutoff { col , 0 , unit , 11 }
return b
2018-01-03 07:46:18 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * AccSelectBuilder ) Orderby ( orderby string ) * AccSelectBuilder {
2022-02-21 03:32:53 +00:00
b . orderby = orderby
return b
2017-11-12 05:25:04 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * AccSelectBuilder ) Limit ( limit string ) * AccSelectBuilder {
2022-02-21 03:32:53 +00:00
b . limit = limit
return b
2017-11-12 05:25:04 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * AccSelectBuilder ) Prepare ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
// TODO: Phase out the procedural API and use the adapter's OO API? The OO API might need a bit more work before we do that and it needs to be rolled out to MSSQL.
if b . dateCutoff != nil || b . inChain != nil {
selectBuilder := b . build . GetAdapter ( ) . Builder ( ) . Select ( ) . FromAcc ( b )
return b . build . prepare ( b . build . GetAdapter ( ) . ComplexSelect ( selectBuilder ) )
}
return b . build . SimpleSelect ( b . table , b . columns , b . where , b . orderby , b . limit )
2021-04-07 14:23:11 +00:00
}
func ( b * AccSelectBuilder ) Stmt ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
// TODO: Phase out the procedural API and use the adapter's OO API? The OO API might need a bit more work before we do that and it needs to be rolled out to MSSQL.
if b . dateCutoff != nil || b . inChain != nil {
selectBuilder := b . build . GetAdapter ( ) . Builder ( ) . Select ( ) . FromAcc ( b )
return b . build . prepare ( b . build . GetAdapter ( ) . ComplexSelect ( selectBuilder ) )
}
return b . build . SimpleSelect ( b . table , b . columns , b . where , b . orderby , b . limit )
2017-11-12 05:25:04 +00:00
}
2020-12-18 00:53:12 +00:00
func ( b * AccSelectBuilder ) ComplexPrepare ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
selectBuilder := b . build . GetAdapter ( ) . Builder ( ) . Select ( ) . FromAcc ( b )
return b . build . prepare ( b . build . GetAdapter ( ) . ComplexSelect ( selectBuilder ) )
2020-12-18 00:53:12 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * AccSelectBuilder ) query ( ) ( string , error ) {
2022-02-21 03:32:53 +00:00
// TODO: Phase out the procedural API and use the adapter's OO API? The OO API might need a bit more work before we do that and it needs to be rolled out to MSSQL.
if b . dateCutoff != nil || b . inChain != nil {
selectBuilder := b . build . GetAdapter ( ) . Builder ( ) . Select ( ) . FromAcc ( b )
return b . build . GetAdapter ( ) . ComplexSelect ( selectBuilder )
}
return b . build . adapter . SimpleSelect ( "" , b . table , b . columns , b . where , b . orderby , b . limit )
2018-07-29 10:54:12 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * AccSelectBuilder ) Query ( args ... interface { } ) ( * sql . Rows , error ) {
2022-02-21 03:32:53 +00:00
stmt := b . Prepare ( )
if stmt != nil {
return stmt . Query ( args ... )
}
return nil , b . build . FirstError ( )
2017-11-12 05:25:04 +00:00
}
2018-05-14 08:56:56 +00:00
type AccRowWrap struct {
2022-02-21 03:32:53 +00:00
row * sql . Row
err error
2018-05-14 08:56:56 +00:00
}
2021-02-27 06:13:03 +00:00
func ( w * AccRowWrap ) Scan ( dest ... interface { } ) error {
2022-02-21 03:32:53 +00:00
if w . err != nil {
return w . err
}
return w . row . Scan ( dest ... )
2018-05-14 08:56:56 +00:00
}
// TODO: Test to make sure the errors are passed up properly
2019-06-05 04:57:10 +00:00
func ( b * AccSelectBuilder ) QueryRow ( args ... interface { } ) * AccRowWrap {
2022-02-21 03:32:53 +00:00
stmt := b . Prepare ( )
if stmt != nil {
return & AccRowWrap { stmt . QueryRow ( args ... ) , nil }
}
return & AccRowWrap { nil , b . build . FirstError ( ) }
2018-05-14 08:56:56 +00:00
}
2018-04-22 12:33:56 +00:00
// Experimental, reduces lines
2020-02-24 11:15:17 +00:00
func ( b * AccSelectBuilder ) Each ( h func ( * sql . Rows ) error ) error {
2022-02-21 03:32:53 +00:00
query , e := b . query ( )
if e != nil {
return e
}
rows , e := b . build . query ( query )
if e != nil {
return e
}
defer rows . Close ( )
for rows . Next ( ) {
if e = h ( rows ) ; e != nil {
return e
}
}
return rows . Err ( )
2021-02-27 06:13:03 +00:00
}
func ( b * AccSelectBuilder ) EachP ( h func ( * sql . Rows ) error , p ... interface { } ) error {
2022-02-21 03:32:53 +00:00
query , e := b . query ( )
if e != nil {
return e
}
rows , e := b . build . query ( query , p )
if e != nil {
return e
}
defer rows . Close ( )
for rows . Next ( ) {
if e = h ( rows ) ; e != nil {
return e
}
}
return rows . Err ( )
2018-04-22 12:33:56 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * AccSelectBuilder ) EachInt ( h func ( int ) error ) error {
2022-02-21 03:32:53 +00:00
query , e := b . query ( )
if e != nil {
return e
}
rows , e := b . build . query ( query )
if e != nil {
return e
}
defer rows . Close ( )
for rows . Next ( ) {
var theInt int
if e = rows . Scan ( & theInt ) ; e != nil {
return e
}
if e = h ( theInt ) ; e != nil {
return e
}
}
return rows . Err ( )
2018-07-28 12:52:23 +00:00
}
2018-04-22 12:33:56 +00:00
2017-11-12 05:25:04 +00:00
type accInsertBuilder struct {
2022-02-21 03:32:53 +00:00
table string
columns string
fields string
2017-11-12 05:25:04 +00:00
2022-02-21 03:32:53 +00:00
build * Accumulator
2017-11-12 05:25:04 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * accInsertBuilder ) Columns ( cols string ) * accInsertBuilder {
2022-02-21 03:32:53 +00:00
b . columns = cols
return b
2017-11-12 05:25:04 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * accInsertBuilder ) Fields ( fields string ) * accInsertBuilder {
2022-02-21 03:32:53 +00:00
b . fields = fields
return b
2017-11-12 05:25:04 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * accInsertBuilder ) Prepare ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
return b . build . SimpleInsert ( b . table , b . columns , b . fields )
2017-11-12 05:25:04 +00:00
}
2021-04-27 10:35:10 +00:00
func ( b * accInsertBuilder ) Exec ( args ... interface { } ) ( res sql . Result , e error ) {
2022-02-21 03:32:53 +00:00
q , e := b . build . adapter . SimpleInsert ( "" , b . table , b . columns , b . fields )
if e != nil {
return res , e
}
return b . build . exec ( q , args ... )
2018-02-03 05:47:14 +00:00
}
2019-06-05 04:57:10 +00:00
func ( b * accInsertBuilder ) Run ( args ... interface { } ) ( int , error ) {
2022-02-21 03:32:53 +00:00
res , e := b . Exec ( args ... )
if e != nil {
return 0 , e
}
lastID , e := res . LastInsertId ( )
return int ( lastID ) , e
2020-02-24 11:15:17 +00:00
}
type accBulkInsertBuilder struct {
2022-02-21 03:32:53 +00:00
table string
columns string
fieldSet [ ] string
2020-02-24 11:15:17 +00:00
2022-02-21 03:32:53 +00:00
build * Accumulator
2020-02-24 11:15:17 +00:00
}
func ( b * accBulkInsertBuilder ) Columns ( cols string ) * accBulkInsertBuilder {
2022-02-21 03:32:53 +00:00
b . columns = cols
return b
2020-02-24 11:15:17 +00:00
}
func ( b * accBulkInsertBuilder ) Fields ( fieldSet ... string ) * accBulkInsertBuilder {
2022-02-21 03:32:53 +00:00
b . fieldSet = fieldSet
return b
2020-02-24 11:15:17 +00:00
}
func ( b * accBulkInsertBuilder ) Prepare ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
return b . build . SimpleBulkInsert ( b . table , b . columns , b . fieldSet )
2020-02-24 11:15:17 +00:00
}
func ( b * accBulkInsertBuilder ) Exec ( args ... interface { } ) ( res sql . Result , err error ) {
2022-02-21 03:32:53 +00:00
q , e := b . build . adapter . SimpleBulkInsert ( "" , b . table , b . columns , b . fieldSet )
if e != nil {
return res , e
}
return b . build . exec ( q , args ... )
2020-02-24 11:15:17 +00:00
}
2018-07-28 12:52:23 +00:00
2020-02-24 11:15:17 +00:00
func ( b * accBulkInsertBuilder ) Run ( args ... interface { } ) ( int , error ) {
2022-02-21 03:32:53 +00:00
res , e := b . Exec ( args ... )
if e != nil {
return 0 , e
}
lastID , e := res . LastInsertId ( )
return int ( lastID ) , e
2018-07-28 12:52:23 +00:00
}
2017-11-12 05:25:04 +00:00
type accCountBuilder struct {
2022-02-21 03:32:53 +00:00
table string
where string
limit string
dateCutoff * dateCutoff // We might want to do this in a slightly less hacky way
inChain * AccSelectBuilder
inColumn string
2017-11-12 05:25:04 +00:00
2022-02-21 03:32:53 +00:00
build * Accumulator
2017-11-12 05:25:04 +00:00
}
2020-02-24 11:15:17 +00:00
func ( b * accCountBuilder ) Where ( w string ) * accCountBuilder {
2022-02-21 03:32:53 +00:00
if b . where != "" {
b . where += " AND "
}
b . where += w
return b
2019-03-12 09:13:57 +00:00
}
func ( b * accCountBuilder ) Limit ( limit string ) * accCountBuilder {
2022-02-21 03:32:53 +00:00
b . limit = limit
return b
2017-11-12 05:25:04 +00:00
}
2021-04-27 10:35:10 +00:00
func ( b * accCountBuilder ) DateCutoff ( col string , quantity int , unit string ) * accCountBuilder {
2022-02-21 03:32:53 +00:00
b . dateCutoff = & dateCutoff { col , quantity , unit , 0 }
return b
2021-04-27 10:35:10 +00:00
}
func ( b * accCountBuilder ) DateOlderThanQ ( col , unit string ) * accCountBuilder {
2022-02-21 03:32:53 +00:00
b . dateCutoff = & dateCutoff { col , 0 , unit , 11 }
return b
2017-11-12 05:25:04 +00:00
}
2019-03-12 09:13:57 +00:00
// TODO: Fix this nasty hack
func ( b * accCountBuilder ) Prepare ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
// TODO: Phase out the procedural API and use the adapter's OO API? The OO API might need a bit more work before we do that and it needs to be rolled out to MSSQL.
if b . dateCutoff != nil || b . inChain != nil {
selBuilder := b . build . GetAdapter ( ) . Builder ( ) . Count ( ) . FromCountAcc ( b )
selBuilder . columns = "COUNT(*)"
return b . build . prepare ( b . build . GetAdapter ( ) . ComplexSelect ( selBuilder ) )
}
return b . build . SimpleCount ( b . table , b . where , b . limit )
2017-11-12 05:25:04 +00:00
}
2021-04-27 10:35:10 +00:00
// TODO: Fix this nasty hack
func ( b * accCountBuilder ) Stmt ( ) * sql . Stmt {
2022-02-21 03:32:53 +00:00
// TODO: Phase out the procedural API and use the adapter's OO API? The OO API might need a bit more work before we do that and it needs to be rolled out to MSSQL.
if b . dateCutoff != nil || b . inChain != nil {
selBuilder := b . build . GetAdapter ( ) . Builder ( ) . Count ( ) . FromCountAcc ( b )
selBuilder . columns = "COUNT(*)"
return b . build . prepare ( b . build . GetAdapter ( ) . ComplexSelect ( selBuilder ) )
}
return b . build . SimpleCount ( b . table , b . where , b . limit )
2021-04-27 10:35:10 +00:00
}
2017-12-30 05:47:46 +00:00
2021-04-27 10:35:10 +00:00
func ( b * accCountBuilder ) Total ( ) ( total int , e error ) {
2022-02-21 03:32:53 +00:00
stmt := b . Prepare ( )
if stmt == nil {
return 0 , b . build . FirstError ( )
}
e = stmt . QueryRow ( ) . Scan ( & total )
return total , e
2018-12-27 05:42:41 +00:00
}
2021-04-27 10:35:10 +00:00
func ( b * accCountBuilder ) TotalP ( params ... interface { } ) ( total int , e error ) {
2022-02-21 03:32:53 +00:00
stmt := b . Prepare ( )
if stmt == nil {
return 0 , b . build . FirstError ( )
}
e = stmt . QueryRow ( params ) . Scan ( & total )
return total , e
2021-02-27 06:13:03 +00:00
}
2017-12-30 05:47:46 +00:00
// TODO: Add a Sum builder for summing viewchunks up into one number for the dashboard?