mirror of
https://github.com/filebrowser/filebrowser.git
synced 2026-07-25 17:04:17 +00:00
DB Updates :)
This commit is contained in:
parent
174330929a
commit
a04ff87bf9
15 changed files with 337 additions and 297 deletions
17
bolt/config.go
Normal file
17
bolt/config.go
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package bolt
|
||||
|
||||
import (
|
||||
"github.com/asdine/storm"
|
||||
)
|
||||
|
||||
type ConfigStore struct {
|
||||
DB *storm.DB
|
||||
}
|
||||
|
||||
func (c ConfigStore) Get(name string, to interface{}) error {
|
||||
return c.DB.Get("config", name, to)
|
||||
}
|
||||
|
||||
func (c ConfigStore) Save(name string, from interface{}) error {
|
||||
return c.DB.Set("config", name, from)
|
||||
}
|
||||
36
bolt/share.go
Normal file
36
bolt/share.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package bolt
|
||||
|
||||
import (
|
||||
"github.com/asdine/storm"
|
||||
fm "github.com/hacdias/filemanager"
|
||||
)
|
||||
|
||||
type ShareStore struct {
|
||||
DB *storm.DB
|
||||
}
|
||||
|
||||
func (s ShareStore) Get(hash string) (*fm.ShareLink, error) {
|
||||
var v *fm.ShareLink
|
||||
err := s.DB.One("Hash", hash, &v)
|
||||
return v, err
|
||||
}
|
||||
|
||||
func (s ShareStore) GetByPath(hash string) ([]*fm.ShareLink, error) {
|
||||
var v []*fm.ShareLink
|
||||
err := s.DB.Find("Path", hash, &v)
|
||||
return v, err
|
||||
}
|
||||
|
||||
func (s ShareStore) Gets(hash string) ([]*fm.ShareLink, error) {
|
||||
var v []*fm.ShareLink
|
||||
err := s.DB.All(&v)
|
||||
return v, err
|
||||
}
|
||||
|
||||
func (s ShareStore) Save(l *fm.ShareLink) error {
|
||||
return s.DB.Save(l)
|
||||
}
|
||||
|
||||
func (s ShareStore) Delete(hash string) error {
|
||||
return s.DB.DeleteStruct(&fm.ShareLink{Hash: hash})
|
||||
}
|
||||
55
bolt/users.go
Normal file
55
bolt/users.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package bolt
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/asdine/storm"
|
||||
fm "github.com/hacdias/filemanager"
|
||||
)
|
||||
|
||||
type UsersStore struct {
|
||||
DB *storm.DB
|
||||
}
|
||||
|
||||
func (u UsersStore) Get(id int) (*fm.User, error) {
|
||||
var us *fm.User
|
||||
err := u.DB.One("ID", id, us)
|
||||
if err == storm.ErrNotFound {
|
||||
return nil, fm.ErrUserNotExist
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &fm.User{}, nil
|
||||
}
|
||||
|
||||
func (u UsersStore) Gets() ([]*fm.User, error) {
|
||||
var us []*fm.User
|
||||
err := u.DB.All(us)
|
||||
return us, err
|
||||
}
|
||||
|
||||
func (u UsersStore) Update(us *fm.User, fields ...string) error {
|
||||
if len(fields) == 0 {
|
||||
return u.Save(us)
|
||||
}
|
||||
|
||||
for _, field := range fields {
|
||||
val := reflect.ValueOf(us).Elem().FieldByName(field).Interface()
|
||||
if err := u.DB.UpdateField(us, field, val); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u UsersStore) Save(us *fm.User) error {
|
||||
return u.DB.Save(us)
|
||||
}
|
||||
|
||||
func (u UsersStore) Delete(id int) error {
|
||||
return u.DB.DeleteStruct(&fm.User{ID: id})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue