database

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2022 License: Apache-2.0 Imports: 23 Imported by: 0

README

Database

The database is structured as follows:

There are 4 entities in total:

  • groups - groups are an entity that holds timeseries and apps, as well as scopes. A group's scopes only go up to the owning user's scopes. That is, even if a group has the user:create scope, it will not be able to create new users unless the user owning the group also has this scope
  • users - A user is a group with an additional password, and that can log into the frontend. The owner of the user is itself. A user's scopes encompass the entire database. That is, if a user has the user:create scope, it will be permitted to create users.
  • apps - A app represents something that has connected to the database programmatically. Apps can represent external programs, such as apps, services and devices, in which case the app will have an API key associated with it, or it can represent a user's instance of a plugin, in which case the app will not have an API key. A app has its own scopes, which work in the same way as group scope, meaning that even if a app has a scope, it will only be permitted to do up to its users' permissions.

The heedy user

When a database is created, the heedy user is created automatically. The user has no password, and nobody can log in as it. The heedy user represents heedy, and its plugins.

The heedy user is off-limits, meaning that no matter what your scopes, you cannot add/remove groups or apps from the user

Scopes

Scopes are used in groups

  • user:create - Allows creating new users.
  • user:read - Allows reading the owner.
  • user:modify - Allows modifying the user's information
  • users:read - Allows reading all users (all users that the owner can read), ignoring the group
  • users:modify - Modify users' information
  • group:create - Allows creating a group for the user
  • `group:

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound        = errors.New("not_found: The selected resource was not found")
	ErrNoUpdate        = errors.New("nop: Nothing to update")
	ErrNoPasswordGiven = errors.New("bad_request: A user cannot have an empty password")
	ErrUserNotFound    = errors.New("not_found: User was not found")
	ErrInvalidUserName = errors.New("bad_request: Invalid Username")
	ErrInvalidName     = errors.New("bad_request: Invalid name")
	ErrInvalidQuery    = errors.New("invalid_query: Invalid query")
)
View Source
var ErrSAccessDenied = errors.New("access_denied: You don't have necessary permissions for the given query")
View Source
var ErrUnimplemented = errors.New("The given functionality is currently unimplemented")

Functions

func AddCreateHook

func AddCreateHook(f func(*AdminDB) error)

AddCreateHook executes code when a database is created

func CanSubscribe

func CanSubscribe(db DB, e *events.Event) error

Check if the given DB can perform the given subscription

func CheckPassword

func CheckPassword(password, hashed string) error

CheckPassword checks if the password is valid

func Create

func Create(a *assets.Assets) error

Create sets up a new heedy instance

func ErrAccessDenied

func ErrAccessDenied(err string, args ...interface{}) error

func ErrBadQuery

func ErrBadQuery(err string, args ...interface{}) error

func FillEvent

func FillEvent(db *AdminDB, e *events.Event) error

FillEvent fills in the event's targeting data

func GenerateKey

func GenerateKey(length int) (string, error)

GenerateKey creates a random API key

func GetExecError

func GetExecError(result sql.Result, err error) error

Performs a set of tests on the result and error of a call to see what kind of error we should return.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword generates a bcrypt hash for the given password

func QQ

func QQ(size int) string

Insert the right amount of question marks for the given query

func ValidGroupScopes

func ValidGroupScopes(s *ScopeArray) error

Checks whether the given group access level is OK

func ValidIcon

func ValidIcon(icon string) error

Ensures that the icon is in a valid format

func ValidUserName

func ValidUserName(name string) error

Types

type AdminDB

type AdminDB struct {
	SqlxCache
	// contains filtered or unexported fields
}

AdminDB holds the main database, with admin access

func Open

func Open(a *assets.Assets) (*AdminDB, error)

Open opens the database given assets.

func (*AdminDB) AdminDB

func (db *AdminDB) AdminDB() *AdminDB

AdminDB returns the admin database

func (*AdminDB) As

func (db *AdminDB) As(identifier string) (DB, error)

As allows performing a query with the given permissions level

func (*AdminDB) Assets

func (db *AdminDB) Assets() *assets.Assets

Assets returns the assets being used for the database

func (*AdminDB) AuthUser

func (db *AdminDB) AuthUser(username string, password string) (string, string, error)

AuthUser returns the username corresponding to the username and password, or an authentication error

func (*AdminDB) CanCreateObject

func (db *AdminDB) CanCreateObject(s *Object) error

CanCreateObject returns whether the given object can be

func (*AdminDB) Close

func (db *AdminDB) Close() error

Close closes the backend database

func (*AdminDB) CreateApp

func (db *AdminDB) CreateApp(c *App) (string, string, error)

CreateApp creates a new app. Nuff said.

func (*AdminDB) CreateObject

func (db *AdminDB) CreateObject(s *Object) (string, error)

CreateObject creates the object

func (*AdminDB) CreateUser

func (db *AdminDB) CreateUser(u *User) error

CreateUser is the administrator version of create

func (*AdminDB) CreateUserSession

func (db *AdminDB) CreateUserSession(username string, description string) (token string, sessionid string, err error)

CreateUserSession creates a new session for the given user

func (*AdminDB) DelApp

func (db *AdminDB) DelApp(id string) error

DelApp deletes the given app.

func (*AdminDB) DelObject

func (db *AdminDB) DelObject(id string) error

DelObject deletes the given object

func (*AdminDB) DelUser

func (db *AdminDB) DelUser(name string) error

DelUser deletes the given user

func (*AdminDB) DelUserSession

func (db *AdminDB) DelUserSession(username, sessionid string) error

func (*AdminDB) DelUserSessionByToken

func (db *AdminDB) DelUserSessionByToken(token string) error

DelUserSessionByToken deletes the given token from the database

func (*AdminDB) GetAppByAccessToken

func (db *AdminDB) GetAppByAccessToken(accessToken string) (*App, error)

GetAppByAccessToken reads the app corresponding to the given access token, and sets the last access date if not today

func (*AdminDB) GetObjectShares

func (db *AdminDB) GetObjectShares(objectid string) (m map[string]*ScopeArray, err error)

GetObjectShares returns the shares of the object

func (*AdminDB) GetUserSessionByToken

func (db *AdminDB) GetUserSessionByToken(token string) (string, string, error)

GetUserSessionByToken gets an active login token's username/session ID, and sets the last access date if not today

func (*AdminDB) ID

func (db *AdminDB) ID() string

func (*AdminDB) ListApps

func (db *AdminDB) ListApps(o *ListAppOptions) ([]*App, error)

ListApps lists apps

func (*AdminDB) ListObjects

func (db *AdminDB) ListObjects(o *ListObjectsOptions) ([]*Object, error)

ListObjects lists the given objects

func (*AdminDB) ListUserSessions

func (db *AdminDB) ListUserSessions(username string) (u []UserSession, err error)

func (*AdminDB) ListUsers

func (db *AdminDB) ListUsers(o *ListUsersOptions) (u []*User, err error)

func (*AdminDB) ReadApp

func (db *AdminDB) ReadApp(aid string, o *ReadAppOptions) (*App, error)

ReadApp gets the app associated with the given API key

func (*AdminDB) ReadObject

func (db *AdminDB) ReadObject(id string, o *ReadObjectOptions) (s *Object, err error)

ReadObject gets the object by ID

func (*AdminDB) ReadPluginDatabaseVersion

func (db *AdminDB) ReadPluginDatabaseVersion(plugin string) (int, error)

func (*AdminDB) ReadUser

func (db *AdminDB) ReadUser(name string, o *ReadUserOptions) (*User, error)

ReadUser reads a user

func (*AdminDB) ReadUserPluginSettings

func (db *AdminDB) ReadUserPluginSettings(username string, plugin string) (v map[string]interface{}, err error)

func (*AdminDB) ReadUserSettings

func (db *AdminDB) ReadUserSettings(username string) (map[string]map[string]interface{}, error)

ReadUserSettings gets the given user's preferences. Returns default preferences if the user does not exist.

func (*AdminDB) ShareObject

func (db *AdminDB) ShareObject(objectid, userid string, sa *ScopeArray) error

ShareObject shares the given object with the given user, allowing the given set of scope

func (*AdminDB) Type

func (db *AdminDB) Type() DBType

func (*AdminDB) UnshareObject

func (db *AdminDB) UnshareObject(objectid string) error

UnshareObject deletes ALL the shares fro mthe object

func (*AdminDB) UnshareObjectFromUser

func (db *AdminDB) UnshareObjectFromUser(objectid, userid string) error

UnshareObjectFromUser Removes the given share from the object

func (*AdminDB) UpdateApp

func (db *AdminDB) UpdateApp(c *App) (err error)

UpdateApp updates the given app (by ID). Note that the inserted values will be written directly to the object.

func (*AdminDB) UpdateObject

func (db *AdminDB) UpdateObject(s *Object) error

UpdateObject updates the given object by ID

func (*AdminDB) UpdateUser

func (db *AdminDB) UpdateUser(u *User) error

UpdateUser updates the given portions of a user

func (*AdminDB) UpdateUserPluginSettings

func (db *AdminDB) UpdateUserPluginSettings(username string, plugin string, preferences map[string]interface{}) (err error)

func (*AdminDB) User

func (db *AdminDB) User() (*User, error)

User returns the user that is logged in

func (*AdminDB) WritePluginDatabaseVersion

func (db *AdminDB) WritePluginDatabaseVersion(plugin string, version int) error

type App

type App struct {
	Details
	Owner  *string `json:"owner" db:"owner"`
	Plugin *string `json:"plugin,omitempty" db:"plugin"`

	Enabled *bool `json:"enabled,omitempty" db:"enabled"`

	AccessToken    *string      `json:"access_token,omitempty" db:"access_token"`
	CreatedDate    dbutil.Date  `json:"created_date,omitempty" db:"created_date"`
	LastAccessDate *dbutil.Date `json:"last_access_date" db:"last_access_date"`

	Scope *AppScopeArray `json:"scope" db:"scope"`

	Settings       *dbutil.JSONObject `json:"settings" db:"settings"`
	SettingsSchema *dbutil.JSONObject `json:"settings_schema" db:"settings_schema"`
}

func (*App) String

func (a *App) String() string

type AppDB

type AppDB struct {
	// contains filtered or unexported fields
}

func NewAppDB

func NewAppDB(adb *AdminDB, c *App) *AppDB

func (*AppDB) AdminDB

func (db *AppDB) AdminDB() *AdminDB

func (*AppDB) CanCreateObject

func (db *AppDB) CanCreateObject(s *Object) error

CanCreateObject returns whether the given object can be

func (*AppDB) CreateApp

func (db *AppDB) CreateApp(c *App) (string, string, error)

func (*AppDB) CreateObject

func (db *AppDB) CreateObject(s *Object) (string, error)

CreateObject creates the object.

func (*AppDB) CreateUser

func (db *AppDB) CreateUser(u *User) error

func (*AppDB) DelApp

func (db *AppDB) DelApp(cid string) error

func (*AppDB) DelObject

func (db *AppDB) DelObject(id string) error

Can only delete objects that belong to *us*

func (*AppDB) DelUser

func (db *AppDB) DelUser(name string) error

func (*AppDB) DelUserSession

func (db *AppDB) DelUserSession(name, id string) error

func (*AppDB) GetObjectAccess

func (c *AppDB) GetObjectAccess(s *Object) (sa ScopeArray)

GetObjectAccess returns a ScopeArray that merges the current access

func (*AppDB) GetObjectShares

func (db *AppDB) GetObjectShares(objectid string) (m map[string]*ScopeArray, err error)

func (*AppDB) ID

func (db *AppDB) ID() string

func (*AppDB) ListApps

func (db *AppDB) ListApps(o *ListAppOptions) ([]*App, error)

func (*AppDB) ListObjects

func (db *AppDB) ListObjects(o *ListObjectsOptions) ([]*Object, error)

ListObjects lists the given objects

func (*AppDB) ListUserSessions

func (db *AppDB) ListUserSessions(name string) ([]UserSession, error)

func (*AppDB) ListUsers

func (db *AppDB) ListUsers(o *ListUsersOptions) ([]*User, error)

func (*AppDB) ReadApp

func (db *AppDB) ReadApp(cid string, o *ReadAppOptions) (*App, error)

func (*AppDB) ReadObject

func (db *AppDB) ReadObject(id string, o *ReadObjectOptions) (*Object, error)

ReadObject reads the given object if the user has sufficient permissions

func (*AppDB) ReadUser

func (db *AppDB) ReadUser(name string, o *ReadUserOptions) (*User, error)

func (*AppDB) ReadUserPluginSettings

func (db *AppDB) ReadUserPluginSettings(username string, plugin string) (map[string]interface{}, error)

func (*AppDB) ReadUserSettings

func (db *AppDB) ReadUserSettings(username string) (map[string]map[string]interface{}, error)

func (*AppDB) ShareObject

func (db *AppDB) ShareObject(objectid, userid string, sa *ScopeArray) error

func (*AppDB) Type

func (db *AppDB) Type() DBType

func (*AppDB) UnshareObject

func (db *AppDB) UnshareObject(objectid string) error

func (*AppDB) UnshareObjectFromUser

func (db *AppDB) UnshareObjectFromUser(objectid, userid string) error

func (*AppDB) UpdateApp

func (db *AppDB) UpdateApp(c *App) error

func (*AppDB) UpdateObject

func (db *AppDB) UpdateObject(s *Object) error

UpdateObject allows editing a object

func (*AppDB) UpdateUser

func (db *AppDB) UpdateUser(u *User) error

UpdateUser updates the given portions of a user

func (*AppDB) UpdateUserPluginSettings

func (db *AppDB) UpdateUserPluginSettings(username string, plugin string, preferences map[string]interface{}) error

func (*AppDB) User

func (db *AppDB) User() (*User, error)

type AppScopeArray

type AppScopeArray struct {
	ScopeArray
}

AppScopeArray works with app scope, which have different details than object scope

func (*AppScopeArray) HasScope

func (s *AppScopeArray) HasScope(sv string) (ok bool)

HasScope checks if the given scope is present

func (*AppScopeArray) Update

func (s *AppScopeArray) Update()

Update cleans out the scope to remove repeated items

type DB

type DB interface {
	AdminDB() *AdminDB // Returns the underlying administrative database
	ID() string        // This is an identifier for the database
	Type() DBType      // Returns the database type

	CreateUser(u *User) error
	ReadUser(name string, o *ReadUserOptions) (*User, error)
	UpdateUser(u *User) error
	DelUser(name string) error
	ListUsers(o *ListUsersOptions) ([]*User, error)

	ListUserSessions(name string) ([]UserSession, error)
	DelUserSession(name, id string) error

	CreateApp(c *App) (string, string, error)
	ReadApp(cid string, o *ReadAppOptions) (*App, error)
	UpdateApp(c *App) error
	DelApp(cid string) error
	ListApps(o *ListAppOptions) ([]*App, error)

	CanCreateObject(s *Object) error
	CreateObject(s *Object) (string, error)
	ReadObject(id string, o *ReadObjectOptions) (*Object, error)
	UpdateObject(s *Object) error
	DelObject(id string) error

	ShareObject(objectid, userid string, sa *ScopeArray) error
	UnshareObjectFromUser(objectid, userid string) error
	UnshareObject(objectid string) error
	GetObjectShares(objectid string) (m map[string]*ScopeArray, err error)

	ListObjects(o *ListObjectsOptions) ([]*Object, error)

	ReadUserSettings(username string) (map[string]map[string]interface{}, error)
	UpdateUserPluginSettings(username string, plugin string, preferences map[string]interface{}) error
	ReadUserPluginSettings(username string, plugin string) (map[string]interface{}, error)
}

DB represents the database. This interface is implemented in many ways:

once for admin
once for users
once for apps
once for public

type DBType

type DBType int
const (
	PublicType DBType = iota
	AppType
	UserType
	AdminType
)

type Details

type Details struct {
	// The ID is used as a handle for all modification, and as such is also present in users
	ID          string  `json:"id,omitempty" db:"id"`
	Name        *string `json:"name,omitempty" db:"name"`
	Description *string `json:"description,omitempty" db:"description"`
	Icon        *string `json:"icon,omitempty" db:"icon"`
}

Details is used in groups, users, apps and objects to hold info

type FilledHandler

type FilledHandler struct {
	events.Handler
	DB *AdminDB
}

func NewFilledHandler

func NewFilledHandler(db *AdminDB, h events.Handler) FilledHandler

func (FilledHandler) Fire

func (fh FilledHandler) Fire(e *events.Event)

type ListAppOptions

type ListAppOptions struct {
	ReadAppOptions

	// Limit the results either to enabled or disabled apps
	Enabled *bool `json:"enabled,omitempty" schema:"enabled"`
	// Limit results to the given user's apps
	Owner *string `json:"owner,omitempty" schema:"owner"`
	// Find the apps with the given plugin key
	Plugin *string `json:"plugin,omitempty" schema:"plugin"`
}

ListAppOptions holds the options associated with listing apps

type ListObjectsOptions

type ListObjectsOptions struct {
	ReadObjectOptions

	// Limit results to the given user's objects.
	Owner *string `json:"owner,omitempty" schema:"owner"`
	// Limit the results to the given app's objects
	App *string `json:"app,omitempty" schema:"app"`
	// Get by plugin key
	Key *string `json:"key,omitempty" schema:"key"`
	// Get objects with the given tags
	Tags *string `json:"tags,omitempty" schema:"tags"`
	// Limit results to objects of the given type
	Type *string `json:"type,omitempty" schema:"type"`
	// Maximum number of results to return
	Limit *int `json:"limit,omitempty" schema:"limit"`

	// Whether to include shared objects (not belonging to the user)
	// This is only allowed for user==current user
	Shared bool
}

ListObjectsOptions shows the options for listing objects

type ListUsersOptions

type ListUsersOptions struct {
	ReadUserOptions
}

type Object

type Object struct {
	Details

	Owner *string `json:"owner,omitempty" db:"owner"`
	App   *string `json:"app" db:"app"`

	Tags *dbutil.StringArray `json:"tags,omitempty" db:"tags"`

	Key *string `json:"key,omitempty" db:"key"`

	Type *string            `json:"type,omitempty" db:"type"`
	Meta *dbutil.JSONObject `json:"meta,omitempty" db:"meta"`

	CreatedDate  *dbutil.Date `json:"created_date,omitempty" db:"created_date"`
	ModifiedDate *dbutil.Date `json:"modified_date" db:"modified_date"`

	// The scope the owner has to the object. This allows apps to control objects belonging to them.
	OwnerScope *ScopeArray `json:"owner_scope,omitempty" db:"owner_scope"`

	// The access array, giving the permissions the currently logged in thing has
	// It is generated manually for each read query, it does not exist in the database.
	Access ScopeArray `json:"access,omitempty" db:"access"`
}

func (*Object) String

func (s *Object) String() string

type PublicDB

type PublicDB struct {
	// contains filtered or unexported fields
}

func NewPublicDB

func NewPublicDB(db *AdminDB) *PublicDB

func (*PublicDB) AdminDB

func (db *PublicDB) AdminDB() *AdminDB

AdminDB returns the admin database

func (*PublicDB) CanCreateObject

func (db *PublicDB) CanCreateObject(s *Object) error

CanCreateObject returns whether the given object can be

func (*PublicDB) CreateApp

func (db *PublicDB) CreateApp(c *App) (string, string, error)

func (*PublicDB) CreateObject

func (db *PublicDB) CreateObject(s *Object) (string, error)

func (*PublicDB) CreateUser

func (db *PublicDB) CreateUser(u *User) error

func (*PublicDB) DelApp

func (db *PublicDB) DelApp(cid string) error

func (*PublicDB) DelObject

func (db *PublicDB) DelObject(id string) error

func (*PublicDB) DelUser

func (db *PublicDB) DelUser(name string) error

func (*PublicDB) DelUserSession

func (db *PublicDB) DelUserSession(name, id string) error

func (*PublicDB) GetObjectShares

func (db *PublicDB) GetObjectShares(objectid string) (m map[string]*ScopeArray, err error)

func (*PublicDB) ID

func (db *PublicDB) ID() string

func (*PublicDB) ListApps

func (db *PublicDB) ListApps(o *ListAppOptions) ([]*App, error)

func (*PublicDB) ListObjects

func (db *PublicDB) ListObjects(o *ListObjectsOptions) ([]*Object, error)

ListObjects lists the given objects

func (*PublicDB) ListUserSessions

func (db *PublicDB) ListUserSessions(name string) ([]UserSession, error)

func (*PublicDB) ListUsers

func (db *PublicDB) ListUsers(o *ListUsersOptions) ([]*User, error)

func (*PublicDB) ReadApp

func (db *PublicDB) ReadApp(cid string, o *ReadAppOptions) (*App, error)

func (*PublicDB) ReadObject

func (db *PublicDB) ReadObject(id string, o *ReadObjectOptions) (*Object, error)

ReadObject reads the given object if it is shared

func (*PublicDB) ReadUser

func (db *PublicDB) ReadUser(name string, o *ReadUserOptions) (*User, error)

func (*PublicDB) ReadUserPluginSettings

func (db *PublicDB) ReadUserPluginSettings(username string, plugin string) (map[string]interface{}, error)

func (*PublicDB) ReadUserSettings

func (db *PublicDB) ReadUserSettings(username string) (map[string]map[string]interface{}, error)

func (*PublicDB) ShareObject

func (db *PublicDB) ShareObject(objectid, userid string, sa *ScopeArray) error

func (*PublicDB) Type

func (db *PublicDB) Type() DBType

func (*PublicDB) UnshareObject

func (db *PublicDB) UnshareObject(objectid string) error

func (*PublicDB) UnshareObjectFromUser

func (db *PublicDB) UnshareObjectFromUser(objectid, userid string) error

func (*PublicDB) UpdateApp

func (db *PublicDB) UpdateApp(c *App) error

func (*PublicDB) UpdateObject

func (db *PublicDB) UpdateObject(s *Object) error

UpdateObject allows editing a object

func (*PublicDB) UpdateUser

func (db *PublicDB) UpdateUser(u *User) error

func (*PublicDB) UpdateUserPluginSettings

func (db *PublicDB) UpdateUserPluginSettings(username string, plugin string, preferences map[string]interface{}) error

func (*PublicDB) User

func (db *PublicDB) User() (*User, error)

User returns the user that is logged in

type ReadAppOptions

type ReadAppOptions struct {
	Icon        bool `json:"icon,omitempty" schema:"icon"`
	AccessToken bool `json:"token,omitempty" schema:"token"` // using "token" instead of access_token, since the API uses access_token param
}

ReadAppOptions gives options for reading

type ReadObjectOptions

type ReadObjectOptions struct {
	Icon bool `json:"icon,omitempty" schema:"icon"`
}

ReadObjectOptions gives options for reading

type ReadUserOptions

type ReadUserOptions struct {
	Icon bool `json:"icon,omitempty" schema:"icon"`
}

ReadUserOptions gives options for reading a user

type ScopeArray

type ScopeArray struct {
	Scope []string
	// contains filtered or unexported fields
}

ScopeArray represents a json column in a table. To handle it correctly, we need to manually scan it and output a value.

func (*ScopeArray) HasScope

func (s *ScopeArray) HasScope(sv string) (ok bool)

HasScope checks if the given scope is present

func (*ScopeArray) Load

func (s *ScopeArray) Load(total string)

func (*ScopeArray) MarshalJSON

func (s *ScopeArray) MarshalJSON() ([]byte, error)

func (*ScopeArray) Scan

func (s *ScopeArray) Scan(val interface{}) error

func (*ScopeArray) String

func (s *ScopeArray) String() string

func (*ScopeArray) UnmarshalJSON

func (s *ScopeArray) UnmarshalJSON(b []byte) error

func (*ScopeArray) Update

func (s *ScopeArray) Update()

Update cleans out the scope to remove repeated items

func (*ScopeArray) Value

func (s *ScopeArray) Value() (driver.Value, error)

type SqlxCache

type SqlxCache struct {
	DB      *sqlx.DB
	Verbose bool
	// contains filtered or unexported fields
}

func (*SqlxCache) BeginImmediatex added in v0.5.1

func (db *SqlxCache) BeginImmediatex() (*TxWrapper, error)

func (*SqlxCache) Beginx

func (db *SqlxCache) Beginx() (*TxWrapper, error)

func (*SqlxCache) Exec

func (db *SqlxCache) Exec(query string, args ...interface{}) (sql.Result, error)

* This is a wrapper for the Exec done in sqlx, it does auto conversion to stored procedures executes them, and does conversion to the given query style for the given database. *

func (*SqlxCache) ExecUncached

func (db *SqlxCache) ExecUncached(query string, args ...interface{}) (sql.Result, error)

func (*SqlxCache) Get

func (db *SqlxCache) Get(dest interface{}, query string, args ...interface{}) error

* This is a wrapper for the Get done in sqlx, it does auto conversion to stored procedures executes them, and does conversion to the given query style for the given database.

Gets a single item from the DB, remember to add LIMIT 1 if the DB doesn't know about the query being for a unique item. *

func (*SqlxCache) GetOrPrepare

func (db *SqlxCache) GetOrPrepare(query string) (*sqlx.Stmt, error)

This function returns a prepared statement, or prepares one for the given query stores it and returns it

func (*SqlxCache) GetOrPrepareNamed

func (db *SqlxCache) GetOrPrepareNamed(query string) (*sqlx.NamedStmt, error)

This function returns a prepared statement, or prepares one for the given query stores it and returns it

func (*SqlxCache) InitCache

func (c *SqlxCache) InitCache(sqldb *sqlx.DB)

Initializes a sqlx mixin

func (*SqlxCache) NamedExec

func (db *SqlxCache) NamedExec(query string, arg interface{}) (sql.Result, error)

func (*SqlxCache) Queryx

func (db *SqlxCache) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

func (*SqlxCache) Select

func (db *SqlxCache) Select(dest interface{}, query string, args ...interface{}) error

* This is a wrapper for the Select done in sqlx, it does auto conversion to stored procedures executes them, and does conversion to the given query style for the given database. *

type TxWrapper

type TxWrapper struct {
	*sqlx.Tx
	Verbose bool
	// contains filtered or unexported fields
}

func (*TxWrapper) Commit

func (tx *TxWrapper) Commit() error

func (*TxWrapper) Exec

func (tx *TxWrapper) Exec(query string, args ...interface{}) (sql.Result, error)

func (*TxWrapper) Get

func (tx *TxWrapper) Get(dest interface{}, query string, args ...interface{}) error

func (*TxWrapper) Queryx

func (tx *TxWrapper) Queryx(query string, args ...interface{}) (*sqlx.Rows, error)

func (*TxWrapper) Rollback

func (tx *TxWrapper) Rollback() error

func (*TxWrapper) Select

func (tx *TxWrapper) Select(dest interface{}, query string, args ...interface{}) error

type User

type User struct {
	Details

	UserName *string `json:"username" db:"username"`

	PublicRead *bool `json:"public_read" db:"public_read"`
	UsersRead  *bool `json:"users_read" db:"users_read"`

	Password *string `json:"password,omitempty" db:"password"`
}

User holds a user's data

type UserDB

type UserDB struct {
	// contains filtered or unexported fields
}

func NewUserDB

func NewUserDB(adb *AdminDB, user string) *UserDB

func (*UserDB) AdminDB

func (db *UserDB) AdminDB() *AdminDB

AdminDB returns the admin database

func (*UserDB) CanCreateObject

func (db *UserDB) CanCreateObject(s *Object) error

CanCreateObject returns whether the given object can be

func (*UserDB) CreateApp

func (db *UserDB) CreateApp(c *App) (string, string, error)

func (*UserDB) CreateObject

func (db *UserDB) CreateObject(s *Object) (string, error)

CreateObject creates the object.

func (*UserDB) CreateUser

func (db *UserDB) CreateUser(u *User) error

func (*UserDB) DelApp

func (db *UserDB) DelApp(cid string) error

func (*UserDB) DelObject

func (db *UserDB) DelObject(id string) error

Can only delete objects that belong to *us*

func (*UserDB) DelUser

func (db *UserDB) DelUser(name string) error

func (*UserDB) DelUserSession

func (db *UserDB) DelUserSession(username, id string) error

func (*UserDB) GetObjectShares

func (db *UserDB) GetObjectShares(objectid string) (m map[string]*ScopeArray, err error)

func (*UserDB) ID

func (db *UserDB) ID() string

func (*UserDB) ListApps

func (db *UserDB) ListApps(o *ListAppOptions) ([]*App, error)

func (*UserDB) ListObjects

func (db *UserDB) ListObjects(o *ListObjectsOptions) ([]*Object, error)

ListObjects lists the given objects

func (*UserDB) ListUserSessions

func (db *UserDB) ListUserSessions(username string) ([]UserSession, error)

func (*UserDB) ListUsers

func (db *UserDB) ListUsers(o *ListUsersOptions) ([]*User, error)

func (*UserDB) ReadApp

func (db *UserDB) ReadApp(cid string, o *ReadAppOptions) (*App, error)

func (*UserDB) ReadObject

func (db *UserDB) ReadObject(id string, o *ReadObjectOptions) (*Object, error)

ReadObject reads the given object if the user has sufficient permissions

func (*UserDB) ReadUser

func (db *UserDB) ReadUser(name string, o *ReadUserOptions) (*User, error)

func (*UserDB) ReadUserPluginSettings

func (db *UserDB) ReadUserPluginSettings(username string, plugin string) (map[string]interface{}, error)

func (*UserDB) ReadUserSettings

func (db *UserDB) ReadUserSettings(username string) (map[string]map[string]interface{}, error)

func (*UserDB) ShareObject

func (db *UserDB) ShareObject(objectid, userid string, sa *ScopeArray) error

func (*UserDB) Type

func (db *UserDB) Type() DBType

func (*UserDB) UnshareObject

func (db *UserDB) UnshareObject(objectid string) error

func (*UserDB) UnshareObjectFromUser

func (db *UserDB) UnshareObjectFromUser(objectid, userid string) error

func (*UserDB) UpdateApp

func (db *UserDB) UpdateApp(c *App) error

func (*UserDB) UpdateObject

func (db *UserDB) UpdateObject(s *Object) error

UpdateObject allows editing a object

func (*UserDB) UpdateUser

func (db *UserDB) UpdateUser(u *User) error

UpdateUser updates the given portions of a user

func (*UserDB) UpdateUserPluginSettings

func (db *UserDB) UpdateUserPluginSettings(username string, plugin string, preferences map[string]interface{}) error

func (*UserDB) User

func (db *UserDB) User() (*User, error)

User returns the user that is logged in

type UserSession

type UserSession struct {
	SessionID      string      `db:"sessionid" json:"sessionid"`
	Description    string      `db:"description" json:"description"`
	LastAccessDate dbutil.Date `db:"last_access_date" json:"last_access_date"`
	CreatedDate    dbutil.Date `db:"created_date" json:"created_date"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL