mirror of
https://github.com/outbackdingo/databunker.git
synced 2026-01-27 10:18:45 +00:00
Add CountRecords0 function
This commit is contained in:
@@ -114,9 +114,12 @@ func (dbobj dbcon) getAuditEvents(userTOKEN string, offset int32, limit int32) (
|
||||
}
|
||||
|
||||
func (dbobj dbcon) getAdminAuditEvents(offset int32, limit int32) ([]byte, int64, error) {
|
||||
count := int64(1000)
|
||||
count, err := dbobj.store.CountRecords0(storage.TblName.Audit)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if count == 0 {
|
||||
return []byte("[]"), 0, nil
|
||||
return []byte("[]"), 0, err
|
||||
}
|
||||
var results []bson.M
|
||||
records, err := dbobj.store.GetList0(storage.TblName.Audit, offset, limit, "when")
|
||||
|
||||
@@ -361,10 +361,10 @@ func (dbobj DBStorage) CreateRecord(t Tbl, data interface{}) (int, error) {
|
||||
return dbobj.CreateRecordInTable(tbl, data)
|
||||
}
|
||||
|
||||
// CountRecords returns number of records that match filter
|
||||
func (dbobj DBStorage) CountRecords(t Tbl, keyName string, keyValue string) (int64, error) {
|
||||
// CountRecords returns number of records in table
|
||||
func (dbobj DBStorage) CountRecords0(t Tbl) (int64, error) {
|
||||
tbl := getTable(t)
|
||||
q := "select count(*) from " + tbl + " WHERE " + escapeName(keyName) + "=$1"
|
||||
q := "select count(*) from " + tbl
|
||||
fmt.Printf("q: %s\n", q)
|
||||
|
||||
tx, err := dbobj.db.Begin()
|
||||
@@ -372,7 +372,7 @@ func (dbobj DBStorage) CountRecords(t Tbl, keyName string, keyValue string) (int
|
||||
return 0, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
row := tx.QueryRow(q, keyValue)
|
||||
row := tx.QueryRow(q)
|
||||
// Columns
|
||||
var count int
|
||||
err = row.Scan(&count)
|
||||
@@ -385,6 +385,30 @@ func (dbobj DBStorage) CountRecords(t Tbl, keyName string, keyValue string) (int
|
||||
return int64(count), nil
|
||||
}
|
||||
|
||||
// CountRecords returns number of records that match filter
|
||||
func (dbobj DBStorage) CountRecords(t Tbl, keyName string, keyValue string) (int64, error) {
|
||||
tbl := getTable(t)
|
||||
q := "select count(*) from " + tbl + " WHERE " + escapeName(keyName) + "=$1"
|
||||
fmt.Printf("q: %s\n", q)
|
||||
|
||||
tx, err := dbobj.db.Begin()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
row := tx.QueryRow(q, keyValue)
|
||||
// Columns
|
||||
var count int
|
||||
err = row.Scan(&count)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int64(count), nil
|
||||
}
|
||||
|
||||
// UpdateRecord updates database record
|
||||
func (dbobj DBStorage) UpdateRecord(t Tbl, keyName string, keyValue string, bdoc *bson.M) (int64, error) {
|
||||
table := getTable(t)
|
||||
|
||||
Reference in New Issue
Block a user