Documentation
¶
Index ¶
- Constants
- Variables
- func CurrentURI() string
- func IDFilter(id string) bson.M
- type Collection
- type Field
- type FieldType
- type Instance
- func (m *Instance) AddItem(item Item) error
- func (m *Instance) DeleteItem(item Item) error
- func (m *Instance) DeleteItemByID(col Collection, id string) error
- func (m *Instance) DeleteOne(database, collection string, filter interface{}) (*mongo.DeleteResult, error)
- func (m *Instance) DropCollection(database, collection string) error
- func (m *Instance) GetItems(col Collection, filter interface{}) ([]Item, error)
- func (m *Instance) GetUser(name string) (User, error)
- func (m *Instance) HasCollection(database, collection string) (bool, error)
- func (m *Instance) InsertOne(database, collection string, v interface{}) error
- func (m *Instance) ReplaceItem(item Item) error
- func (m *Instance) ReplaceOne(database, collection string, filter, v interface{}) (*mongo.UpdateResult, error)
- func (m *Instance) UnmarshallCollection(database, collection string, filter interface{}, v interface{}) error
- func (m *Instance) UpdateItem(item Item) error
- func (m *Instance) UpdateOne(database, collection string, filter, update interface{}) (*mongo.UpdateResult, error)
- func (m *Instance) UserAddCollection(user *User, col Collection) error
- func (m *Instance) UserDeleteCollection(user *User, col Collection) error
- func (m *Instance) UserUpdate(userID string, update interface{}) (*mongo.UpdateResult, error)
- func (m *Instance) UserUpdateCollection(user *User, col Collection) error
- type Item
- type ItemData
- type User
Constants ¶
const ( // SettingsDB database with settings SettingsDB = "datel" // SettingsUsersCol collection with user settings SettingsUsersCol = "users" )
const (
// LabelTypeName Name of the key for the "label", i.e. gets priority for display
LabelTypeName = "_label"
)
Variables ¶
var ( //ErrCollectionNotFound collection not found error ErrCollectionNotFound = errors.New("collection not found") //ErrFieldNotFound field not found error ErrFieldNotFound = errors.New("field not found") )
var ( // CtxTimeout default timeout for database connection CtxTimeout = 10 * time.Second )
var ( // ErrItemNotFound item not found error ErrItemNotFound = errors.New("item not found") )
var ( // ErrUserNotFound user not found error ErrUserNotFound = errors.New("user not found") )
Functions ¶
Types ¶
type Collection ¶
type Collection struct {
Name string `json:"name" bson:"name"`
Label string `json:"label" bson:"label"`
Database string `json:"database" bson:"database"`
Fields []Field `json:"fields" bson:"fields"`
}
Collection collection in database and its fields
func (*Collection) FieldIndex ¶
func (c *Collection) FieldIndex(key string) int
FieldIndex find field index by key
type Field ¶
type Field struct {
Key string `json:"key" bson:"key"`
Label string `json:"label" bson:"label"`
Type FieldType `json:"type" bson:"type"`
}
Field fields of collection
type FieldType ¶
type FieldType struct {
Name string `json:"name" bson:"name"`
Properties map[string]interface{} `json:"properties,omitempty" bson:"properties,omitempty"`
}
FieldType type of field
type Instance ¶
Instance database connection instance
func GetInstance ¶
GetInstance gets the current instance so that it doesn't have to reconnect.
func (*Instance) AddItem ¶
AddItem adds an entry to the database, if ID is "", database will created it
func (*Instance) DeleteItem ¶
DeleteItem deletes item which gets filtered by the item.ID
func (*Instance) DeleteItemByID ¶
func (m *Instance) DeleteItemByID(col Collection, id string) error
DeleteItemByID deletes item by ID
func (*Instance) DeleteOne ¶
func (m *Instance) DeleteOne(database, collection string, filter interface{}) (*mongo.DeleteResult, error)
DeleteOne deletes one document
func (*Instance) DropCollection ¶
DropCollection drops / deletes specified collection
func (*Instance) GetItems ¶
func (m *Instance) GetItems(col Collection, filter interface{}) ([]Item, error)
GetItems gets items from the database
func (*Instance) HasCollection ¶
HasCollection finds out if the database contains the given collection
func (*Instance) ReplaceItem ¶
ReplaceItem replaces the item which is filtered by ID
func (*Instance) ReplaceOne ¶
func (m *Instance) ReplaceOne(database, collection string, filter, v interface{}) (*mongo.UpdateResult, error)
ReplaceOne replaces one document
func (*Instance) UnmarshallCollection ¶
func (m *Instance) UnmarshallCollection(database, collection string, filter interface{}, v interface{}) error
UnmarshallCollection retrieves data from the collection using a filter. Similar to JSON Unmarshall
func (*Instance) UpdateItem ¶
UpdateItem updates item in the collection. Existing fields are kept.
func (*Instance) UpdateOne ¶
func (m *Instance) UpdateOne(database, collection string, filter, update interface{}) (*mongo.UpdateResult, error)
UpdateOne updates one document
func (*Instance) UserAddCollection ¶
func (m *Instance) UserAddCollection(user *User, col Collection) error
UserAddCollection adds collection to the user
func (*Instance) UserDeleteCollection ¶
func (m *Instance) UserDeleteCollection(user *User, col Collection) error
UserDeleteCollection deletes collection from user settings
func (*Instance) UserUpdate ¶
func (m *Instance) UserUpdate(userID string, update interface{}) (*mongo.UpdateResult, error)
UserUpdate update user settings
func (*Instance) UserUpdateCollection ¶
func (m *Instance) UserUpdateCollection(user *User, col Collection) error
UserUpdateCollection updates collections of the user
type Item ¶
type Item struct {
ID string `json:"_id" bson:"_id"`
Collection *Collection `json:"-" bson:"-"`
Label string `json:"-" bson:"-"`
Data []ItemData `json:"data" bson:"data"`
}
Item item (mongo document) in collection
func EmptyItem ¶
func EmptyItem(col Collection) Item
EmptyItem creates an empty item based on the collection fields
func ItemFromMultipart ¶
func ItemFromMultipart(col Collection, multipart *multipart.Form) Item
ItemFromMultipart converts a multipart request to an item
type ItemData ¶
type ItemData struct {
Field Field `json:"field" bson:"field"`
Value interface{} `json:"value" bson:"value"`
}
ItemData items of the document
type User ¶
type User struct {
ID string `json:"_id" bson:"_id"`
Username string `json:"username" bson:"username"`
DefaultDatabase string `json:"default_database" bson:"default_database"`
Collections []Collection `json:"collections" bson:"collections"`
}
User user settings
func (*User) CollectionByName ¶
func (u *User) CollectionByName(name string) (Collection, error)
CollectionByName find collection by name
func (*User) CollectionIndex ¶
CollectionIndex find collection index by name