summaryrefslogtreecommitdiff
path: root/system/db
diff options
context:
space:
mode:
Diffstat (limited to 'system/db')
-rw-r--r--system/db/config.go4
-rw-r--r--system/db/content.go20
-rw-r--r--system/db/init.go8
-rw-r--r--system/db/user.go14
4 files changed, 23 insertions, 23 deletions
diff --git a/system/db/config.go b/system/db/config.go
index 6855081..ab1c720 100644
--- a/system/db/config.go
+++ b/system/db/config.go
@@ -24,7 +24,7 @@ func init() {
// SetConfig sets key:value pairs in the db for configuration settings
func SetConfig(data url.Values) error {
err := store.Update(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_config"))
+ b := tx.Bucket([]byte("__config"))
// check for any multi-value fields (ex. checkbox fields)
// and correctly format for db storage. Essentially, we need
@@ -108,7 +108,7 @@ func Config(key string) ([]byte, error) {
func ConfigAll() ([]byte, error) {
val := &bytes.Buffer{}
err := store.View(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_config"))
+ b := tx.Bucket([]byte("__config"))
val.Write(b.Get([]byte("settings")))
return nil
diff --git a/system/db/content.go b/system/db/content.go
index ef74091..74a77ec 100644
--- a/system/db/content.go
+++ b/system/db/content.go
@@ -39,11 +39,11 @@ func SetContent(target string, data url.Values) (int, error) {
}
func update(ns, id string, data url.Values) (int, error) {
- var specifier string // i.e. _pending, _sorted, etc.
- if strings.Contains(ns, "_") {
- spec := strings.Split(ns, "_")
+ var specifier string // i.e. __pending, __sorted, etc.
+ if strings.Contains(ns, "__") {
+ spec := strings.Split(ns, "__")
ns = spec[0]
- specifier = "_" + spec[1]
+ specifier = "__" + spec[1]
}
cid, err := strconv.Atoi(id)
@@ -82,11 +82,11 @@ func update(ns, id string, data url.Values) (int, error) {
func insert(ns string, data url.Values) (int, error) {
var effectedID int
- var specifier string // i.e. _pending, _sorted, etc.
- if strings.Contains(ns, "_") {
- spec := strings.Split(ns, "_")
+ var specifier string // i.e. __pending, __sorted, etc.
+ if strings.Contains(ns, "__") {
+ spec := strings.Split(ns, "__")
ns = spec[0]
- specifier = "_" + spec[1]
+ specifier = "__" + spec[1]
}
err := store.Update(func(tx *bolt.Tx) error {
@@ -328,7 +328,7 @@ func Query(namespace string, opts QueryOptions) (int, [][]byte) {
// Should be called from a goroutine after SetContent is successful
func SortContent(namespace string) {
// only sort main content types i.e. Post
- if strings.Contains(namespace, "_") {
+ if strings.Contains(namespace, "__") {
return
}
@@ -354,7 +354,7 @@ func SortContent(namespace string) {
// store in <namespace>_sorted bucket, first delete existing
err := store.Update(func(tx *bolt.Tx) error {
- bname := []byte(namespace + "_sorted")
+ bname := []byte(namespace + "__sorted")
err := tx.DeleteBucket(bname)
if err != nil {
return err
diff --git a/system/db/init.go b/system/db/init.go
index 63804e1..967eed1 100644
--- a/system/db/init.go
+++ b/system/db/init.go
@@ -38,14 +38,14 @@ func Init() {
return err
}
- _, err = tx.CreateBucketIfNotExists([]byte(t + "_sorted"))
+ _, err = tx.CreateBucketIfNotExists([]byte(t + "__sorted"))
if err != nil {
return err
}
}
// init db with other buckets as needed
- buckets := []string{"_config", "_users"}
+ buckets := []string{"__config", "__users"}
for _, name := range buckets {
_, err := tx.CreateBucketIfNotExists([]byte(name))
if err != nil {
@@ -54,7 +54,7 @@ func Init() {
}
// seed db with configs structure if not present
- b := tx.Bucket([]byte("_config"))
+ b := tx.Bucket([]byte("__config"))
if b.Get([]byte("settings")) == nil {
j, err := json.Marshal(&config.Config{})
if err != nil {
@@ -93,7 +93,7 @@ func SystemInitComplete() bool {
complete := false
err := store.View(func(tx *bolt.Tx) error {
- users := tx.Bucket([]byte("_users"))
+ users := tx.Bucket([]byte("__users"))
err := users.ForEach(func(k, v []byte) error {
complete = true
diff --git a/system/db/user.go b/system/db/user.go
index a133890..b92a62a 100644
--- a/system/db/user.go
+++ b/system/db/user.go
@@ -24,7 +24,7 @@ var ErrNoUserExists = errors.New("Error. No user exists.")
func SetUser(usr *user.User) (int, error) {
err := store.Update(func(tx *bolt.Tx) error {
email := []byte(usr.Email)
- users := tx.Bucket([]byte("_users"))
+ users := tx.Bucket([]byte("__users"))
// check if user is found by email, fail if nil
exists := users.Get(email)
@@ -67,7 +67,7 @@ func UpdateUser(usr, updatedUsr *user.User) error {
}
err := store.Update(func(tx *bolt.Tx) error {
- users := tx.Bucket([]byte("_users"))
+ users := tx.Bucket([]byte("__users"))
// check if user is found by email, fail if nil
exists := users.Get([]byte(usr.Email))
@@ -108,7 +108,7 @@ func UpdateUser(usr, updatedUsr *user.User) error {
// DeleteUser deletes a user from the db by email
func DeleteUser(email string) error {
err := store.Update(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_users"))
+ b := tx.Bucket([]byte("__users"))
err := b.Delete([]byte(email))
if err != nil {
return err
@@ -127,7 +127,7 @@ func DeleteUser(email string) error {
func User(email string) ([]byte, error) {
val := &bytes.Buffer{}
err := store.View(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_users"))
+ b := tx.Bucket([]byte("__users"))
usr := b.Get([]byte(email))
_, err := val.Write(usr)
@@ -152,7 +152,7 @@ func User(email string) ([]byte, error) {
func UserAll() ([][]byte, error) {
var users [][]byte
err := store.View(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_users"))
+ b := tx.Bucket([]byte("__users"))
err := b.ForEach(func(k, v []byte) error {
users = append(users, v)
return nil
@@ -201,7 +201,7 @@ func SetRecoveryKey(email string) (string, error) {
key := fmt.Sprintf("%d", rand.Int63())
err := store.Update(func(tx *bolt.Tx) error {
- b, err := tx.CreateBucketIfNotExists([]byte("_recoveryKeys"))
+ b, err := tx.CreateBucketIfNotExists([]byte("__recoveryKeys"))
if err != nil {
return err
}
@@ -226,7 +226,7 @@ func RecoveryKey(email string) (string, error) {
key := &bytes.Buffer{}
err := store.View(func(tx *bolt.Tx) error {
- b := tx.Bucket([]byte("_recoveryKeys"))
+ b := tx.Bucket([]byte("__recoveryKeys"))
if b == nil {
return errors.New("No database found for checking keys.")
}