mirror of
https://github.com/optim-enterprises-bv/databunker.git
synced 2025-11-01 18:38:06 +00:00
user []map insead of []bson
This commit is contained in:
@@ -717,7 +717,7 @@ func (dbobj MySQLDB) CleanupRecord(t Tbl, keyName string, keyValue string, bdel
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetExpiring get records that are expiring
|
// GetExpiring get records that are expiring
|
||||||
func (dbobj MySQLDB) GetExpiring(t Tbl, keyName string, keyValue string) ([]bson.M, error) {
|
func (dbobj MySQLDB) GetExpiring(t Tbl, keyName string, keyValue string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
now := int32(time.Now().Unix())
|
now := int32(time.Now().Unix())
|
||||||
q := fmt.Sprintf("select * from %s WHERE endtime>0 AND endtime<%d AND %s=?",
|
q := fmt.Sprintf("select * from %s WHERE endtime>0 AND endtime<%d AND %s=?",
|
||||||
@@ -729,7 +729,7 @@ func (dbobj MySQLDB) GetExpiring(t Tbl, keyName string, keyValue string) ([]bson
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUniqueList returns a unique list of values from specific column in database
|
// GetUniqueList returns a unique list of values from specific column in database
|
||||||
func (dbobj MySQLDB) GetUniqueList(t Tbl, keyName string) ([]bson.M, error) {
|
func (dbobj MySQLDB) GetUniqueList(t Tbl, keyName string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
keyName = dbobj.escapeName(keyName)
|
keyName = dbobj.escapeName(keyName)
|
||||||
q := "select distinct " + keyName + " from " + table + " ORDER BY " + keyName
|
q := "select distinct " + keyName + " from " + table + " ORDER BY " + keyName
|
||||||
@@ -739,7 +739,7 @@ func (dbobj MySQLDB) GetUniqueList(t Tbl, keyName string) ([]bson.M, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetList is used to return list of rows. It can be used to return values using pager.
|
// GetList is used to return list of rows. It can be used to return values using pager.
|
||||||
func (dbobj MySQLDB) GetList0(t Tbl, start int32, limit int32, orderField string) ([]bson.M, error) {
|
func (dbobj MySQLDB) GetList0(t Tbl, start int32, limit int32, orderField string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
if limit > 100 {
|
if limit > 100 {
|
||||||
limit = 100
|
limit = 100
|
||||||
@@ -761,7 +761,7 @@ func (dbobj MySQLDB) GetList0(t Tbl, start int32, limit int32, orderField string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetList is used to return list of rows. It can be used to return values using pager.
|
// GetList is used to return list of rows. It can be used to return values using pager.
|
||||||
func (dbobj MySQLDB) GetList(t Tbl, keyName string, keyValue string, start int32, limit int32, orderField string) ([]bson.M, error) {
|
func (dbobj MySQLDB) GetList(t Tbl, keyName string, keyValue string, start int32, limit int32, orderField string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
if limit > 100 {
|
if limit > 100 {
|
||||||
limit = 100
|
limit = 100
|
||||||
@@ -782,7 +782,7 @@ func (dbobj MySQLDB) GetList(t Tbl, keyName string, keyValue string, start int32
|
|||||||
return dbobj.getListDo(q, values)
|
return dbobj.getListDo(q, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dbobj MySQLDB) getListDo(q string, values []interface{}) ([]bson.M, error) {
|
func (dbobj MySQLDB) getListDo(q string, values []interface{}) ([]map[string]interface{}, error) {
|
||||||
tx, err := dbobj.db.Begin()
|
tx, err := dbobj.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -804,11 +804,11 @@ func (dbobj MySQLDB) getListDo(q string, values []interface{}) ([]bson.M, error)
|
|||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var results []bson.M
|
var results []map[string]interface{}
|
||||||
//pointers := make([]interface{}, len(columnNames))
|
//pointers := make([]interface{}, len(columnNames))
|
||||||
//rows.Next()
|
//rows.Next()
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
recBson := bson.M{}
|
recBson := make(map[string]interface{})
|
||||||
columnPointers := make([]interface{}, len(columnNames))
|
columnPointers := make([]interface{}, len(columnNames))
|
||||||
columns := make([]interface{}, len(columnNames))
|
columns := make([]interface{}, len(columnNames))
|
||||||
for idx := range columns {
|
for idx := range columns {
|
||||||
|
|||||||
@@ -715,7 +715,7 @@ func (dbobj PGSQLDB) CleanupRecord(t Tbl, keyName string, keyValue string, bdel
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetExpiring get records that are expiring
|
// GetExpiring get records that are expiring
|
||||||
func (dbobj PGSQLDB) GetExpiring(t Tbl, keyName string, keyValue string) ([]bson.M, error) {
|
func (dbobj PGSQLDB) GetExpiring(t Tbl, keyName string, keyValue string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
now := int32(time.Now().Unix())
|
now := int32(time.Now().Unix())
|
||||||
q := fmt.Sprintf("select * from %s WHERE endtime>0 AND endtime<%d AND %s=$1",
|
q := fmt.Sprintf("select * from %s WHERE endtime>0 AND endtime<%d AND %s=$1",
|
||||||
@@ -727,7 +727,7 @@ func (dbobj PGSQLDB) GetExpiring(t Tbl, keyName string, keyValue string) ([]bson
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUniqueList returns a unique list of values from specific column in database
|
// GetUniqueList returns a unique list of values from specific column in database
|
||||||
func (dbobj PGSQLDB) GetUniqueList(t Tbl, keyName string) ([]bson.M, error) {
|
func (dbobj PGSQLDB) GetUniqueList(t Tbl, keyName string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
keyName = dbobj.escapeName(keyName)
|
keyName = dbobj.escapeName(keyName)
|
||||||
q := "select distinct " + keyName + " from " + table + " ORDER BY " + keyName
|
q := "select distinct " + keyName + " from " + table + " ORDER BY " + keyName
|
||||||
@@ -737,7 +737,7 @@ func (dbobj PGSQLDB) GetUniqueList(t Tbl, keyName string) ([]bson.M, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetList is used to return list of rows. It can be used to return values using pager.
|
// GetList is used to return list of rows. It can be used to return values using pager.
|
||||||
func (dbobj PGSQLDB) GetList0(t Tbl, start int32, limit int32, orderField string) ([]bson.M, error) {
|
func (dbobj PGSQLDB) GetList0(t Tbl, start int32, limit int32, orderField string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
if limit > 100 {
|
if limit > 100 {
|
||||||
limit = 100
|
limit = 100
|
||||||
@@ -759,7 +759,7 @@ func (dbobj PGSQLDB) GetList0(t Tbl, start int32, limit int32, orderField string
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetList is used to return list of rows. It can be used to return values using pager.
|
// GetList is used to return list of rows. It can be used to return values using pager.
|
||||||
func (dbobj PGSQLDB) GetList(t Tbl, keyName string, keyValue string, start int32, limit int32, orderField string) ([]bson.M, error) {
|
func (dbobj PGSQLDB) GetList(t Tbl, keyName string, keyValue string, start int32, limit int32, orderField string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
if limit > 100 {
|
if limit > 100 {
|
||||||
limit = 100
|
limit = 100
|
||||||
@@ -780,7 +780,7 @@ func (dbobj PGSQLDB) GetList(t Tbl, keyName string, keyValue string, start int32
|
|||||||
return dbobj.getListDo(q, values)
|
return dbobj.getListDo(q, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dbobj PGSQLDB) getListDo(q string, values []interface{}) ([]bson.M, error) {
|
func (dbobj PGSQLDB) getListDo(q string, values []interface{}) ([]map[string]interface{}, error) {
|
||||||
tx, err := dbobj.db.Begin()
|
tx, err := dbobj.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -789,7 +789,7 @@ func (dbobj PGSQLDB) getListDo(q string, values []interface{}) ([]bson.M, error)
|
|||||||
return dbobj.getListDoRaw(tx, q, values)
|
return dbobj.getListDoRaw(tx, q, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dbobj PGSQLDB) getListDoRaw(tx *sql.Tx, q string, values []interface{}) ([]bson.M, error) {
|
func (dbobj PGSQLDB) getListDoRaw(tx *sql.Tx, q string, values []interface{}) ([]map[string]interface{}, error) {
|
||||||
rows, err := tx.Query(q, values...)
|
rows, err := tx.Query(q, values...)
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
fmt.Println("nothing found")
|
fmt.Println("nothing found")
|
||||||
@@ -807,11 +807,11 @@ func (dbobj PGSQLDB) getListDoRaw(tx *sql.Tx, q string, values []interface{}) ([
|
|||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var results []bson.M
|
var results []map[string]interface{}
|
||||||
//pointers := make([]interface{}, len(columnNames))
|
//pointers := make([]interface{}, len(columnNames))
|
||||||
//rows.Next()
|
//rows.Next()
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
recBson := bson.M{}
|
recBson := make(map[string]interface{})
|
||||||
columnPointers := make([]interface{}, len(columnNames))
|
columnPointers := make([]interface{}, len(columnNames))
|
||||||
columns := make([]interface{}, len(columnNames))
|
columns := make([]interface{}, len(columnNames))
|
||||||
for idx := range columns {
|
for idx := range columns {
|
||||||
|
|||||||
@@ -700,7 +700,7 @@ func (dbobj SQLiteDB) CleanupRecord(t Tbl, keyName string, keyValue string, bdel
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetExpiring get records that are expiring
|
// GetExpiring get records that are expiring
|
||||||
func (dbobj SQLiteDB) GetExpiring(t Tbl, keyName string, keyValue string) ([]bson.M, error) {
|
func (dbobj SQLiteDB) GetExpiring(t Tbl, keyName string, keyValue string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
now := int32(time.Now().Unix())
|
now := int32(time.Now().Unix())
|
||||||
q := fmt.Sprintf("select * from %s WHERE endtime>0 AND endtime<%d AND %s=$1",
|
q := fmt.Sprintf("select * from %s WHERE endtime>0 AND endtime<%d AND %s=$1",
|
||||||
@@ -712,7 +712,7 @@ func (dbobj SQLiteDB) GetExpiring(t Tbl, keyName string, keyValue string) ([]bso
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUniqueList returns a unique list of values from specific column in database
|
// GetUniqueList returns a unique list of values from specific column in database
|
||||||
func (dbobj SQLiteDB) GetUniqueList(t Tbl, keyName string) ([]bson.M, error) {
|
func (dbobj SQLiteDB) GetUniqueList(t Tbl, keyName string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
keyName = dbobj.escapeName(keyName)
|
keyName = dbobj.escapeName(keyName)
|
||||||
q := "select distinct " + keyName + " from " + table + " ORDER BY " + keyName
|
q := "select distinct " + keyName + " from " + table + " ORDER BY " + keyName
|
||||||
@@ -722,7 +722,7 @@ func (dbobj SQLiteDB) GetUniqueList(t Tbl, keyName string) ([]bson.M, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetList is used to return list of rows. It can be used to return values using pager.
|
// GetList is used to return list of rows. It can be used to return values using pager.
|
||||||
func (dbobj SQLiteDB) GetList0(t Tbl, start int32, limit int32, orderField string) ([]bson.M, error) {
|
func (dbobj SQLiteDB) GetList0(t Tbl, start int32, limit int32, orderField string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
if limit > 100 {
|
if limit > 100 {
|
||||||
limit = 100
|
limit = 100
|
||||||
@@ -744,7 +744,7 @@ func (dbobj SQLiteDB) GetList0(t Tbl, start int32, limit int32, orderField strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetList is used to return list of rows. It can be used to return values using pager.
|
// GetList is used to return list of rows. It can be used to return values using pager.
|
||||||
func (dbobj SQLiteDB) GetList(t Tbl, keyName string, keyValue string, start int32, limit int32, orderField string) ([]bson.M, error) {
|
func (dbobj SQLiteDB) GetList(t Tbl, keyName string, keyValue string, start int32, limit int32, orderField string) ([]map[string]interface{}, error) {
|
||||||
table := GetTable(t)
|
table := GetTable(t)
|
||||||
if limit > 100 {
|
if limit > 100 {
|
||||||
limit = 100
|
limit = 100
|
||||||
@@ -766,7 +766,7 @@ func (dbobj SQLiteDB) GetList(t Tbl, keyName string, keyValue string, start int3
|
|||||||
return dbobj.getListDo(q, values)
|
return dbobj.getListDo(q, values)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dbobj SQLiteDB) getListDo(q string, values []interface{}) ([]bson.M, error) {
|
func (dbobj SQLiteDB) getListDo(q string, values []interface{}) ([]map[string]interface{}, error) {
|
||||||
tx, err := dbobj.db.Begin()
|
tx, err := dbobj.db.Begin()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -789,11 +789,11 @@ func (dbobj SQLiteDB) getListDo(q string, values []interface{}) ([]bson.M, error
|
|||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
var results []bson.M
|
var results []map[string]interface{}
|
||||||
//pointers := make([]interface{}, len(columnNames))
|
//pointers := make([]interface{}, len(columnNames))
|
||||||
//rows.Next()
|
//rows.Next()
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
recBson := bson.M{}
|
recBson := make(map[string]interface{})
|
||||||
//fmt.Println("parsing result line")
|
//fmt.Println("parsing result line")
|
||||||
columnPointers := make([]interface{}, len(columnNames))
|
columnPointers := make([]interface{}, len(columnNames))
|
||||||
//for i, _ := range columnNames {
|
//for i, _ := range columnNames {
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tbl is used to store table id
|
// Tbl is used to store table id
|
||||||
@@ -95,10 +96,10 @@ type BackendDB interface {
|
|||||||
DeleteExpired0(Tbl, int32) (int64, error)
|
DeleteExpired0(Tbl, int32) (int64, error)
|
||||||
DeleteExpired(Tbl, string, string) (int64, error)
|
DeleteExpired(Tbl, string, string) (int64, error)
|
||||||
CleanupRecord(Tbl, string, string, []string) (int64, error)
|
CleanupRecord(Tbl, string, string, []string) (int64, error)
|
||||||
GetExpiring(Tbl, string, string) ([]bson.M, error)
|
GetExpiring(Tbl, string, string) ([]map[string]interface{}, error)
|
||||||
GetUniqueList(Tbl, string) ([]bson.M, error)
|
GetUniqueList(Tbl, string) ([]map[string]interface{}, error)
|
||||||
GetList0(Tbl, int32, int32, string) ([]bson.M, error)
|
GetList0(Tbl, int32, int32, string) ([]map[string]interface{}, error)
|
||||||
GetList(Tbl, string, string, int32, int32, string) ([]bson.M, error)
|
GetList(Tbl, string, string, int32, int32, string) ([]map[string]interface{}, error)
|
||||||
GetAllTables() ([]string, error)
|
GetAllTables() ([]string, error)
|
||||||
ValidateNewApp(appName string) bool
|
ValidateNewApp(appName string) bool
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user