2021-11-10 04:01:39 +00:00
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"go.mongodb.org/mongo-driver/mongo"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Table
|
|
|
|
var (
|
|
|
|
tableUser = "users"
|
|
|
|
tableRole = "roles"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
db *mongo.Database
|
|
|
|
prefix string
|
|
|
|
)
|
|
|
|
|
2021-11-10 04:52:07 +00:00
|
|
|
// Set ...
|
2021-11-10 04:01:39 +00:00
|
|
|
func Set(instance *mongo.Database, tablePrefix string) {
|
|
|
|
db = instance
|
|
|
|
prefix = tablePrefix
|
|
|
|
}
|
|
|
|
|
2021-11-10 04:42:23 +00:00
|
|
|
// GetUserCol ...
|
2021-11-10 04:01:39 +00:00
|
|
|
func GetUserCol() *mongo.Collection {
|
|
|
|
return db.Collection(fmt.Sprintf("%s-%s", prefix, tableUser))
|
|
|
|
}
|
|
|
|
|
2021-11-10 04:42:23 +00:00
|
|
|
// GetRoleCol ...
|
2021-11-10 04:01:39 +00:00
|
|
|
func GetRoleCol() *mongo.Collection {
|
|
|
|
return db.Collection(fmt.Sprintf("%s-%s", prefix, tableRole))
|
|
|
|
}
|