dal

package
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2015 License: MIT Imports: 12 Imported by: 0

README

Data Access Layer

(Definition from Wikipedia)

A data access layer (DAL) in computer software, is a layer of a computer program which provides simplified access to data stored in persistent storage of some kind, such as an entity-relational database. This acronym is prevalently used in Microsoft ASP.NET environments.

For example, the DAL might return a reference to an object (in terms of object-oriented programming) complete with its attributes instead of a row of fields from a database table. This allows the client (or user) modules to be created with a higher level of abstraction. This kind of model could be implemented by creating a class of data access methods that directly reference a corresponding set of database stored procedures. Another implementation could potentially retrieve or write records to or from a file system. The DAL hides this complexity of the underlying data store from the external world.

This directory is the equivalent of "models" directory in other web framework. Put all of you database logic here.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Base
}

func NewAccessToken

func NewAccessToken(db *sqlx.DB) *AccessToken

func (*AccessToken) AllAccessTokens

func (t *AccessToken) AllAccessTokens(tx *sqlx.Tx) ([]*AccessTokenRow, error)

AllAccessTokens returns all access tokens.

func (*AccessToken) AllAccessTokensByClusterID

func (t *AccessToken) AllAccessTokensByClusterID(tx *sqlx.Tx, clusterID int64) ([]*AccessTokenRow, error)

AllAccessTokens returns all access tokens by cluster id.

func (*AccessToken) Create

func (t *AccessToken) Create(tx *sqlx.Tx, userID, clusterID int64, level string) (*AccessTokenRow, error)

func (*AccessToken) GetByAccessToken

func (t *AccessToken) GetByAccessToken(tx *sqlx.Tx, token string) (*AccessTokenRow, error)

GetByAccessToken returns one record by token.

func (*AccessToken) GetByClusterID

func (t *AccessToken) GetByClusterID(tx *sqlx.Tx, clusterID int64) (*AccessTokenRow, error)

GetByClusterID returns one record by cluster_id.

func (*AccessToken) GetByID

func (t *AccessToken) GetByID(tx *sqlx.Tx, id int64) (*AccessTokenRow, error)

GetByID returns one record by id.

func (*AccessToken) GetByUserId

func (t *AccessToken) GetByUserId(tx *sqlx.Tx, userID int64) (*AccessTokenRow, error)

GetByUserId returns one record by user_id.

type AccessTokenRow

type AccessTokenRow struct {
	ID        int64  `db:"id"`
	UserID    int64  `db:"user_id"`
	ClusterID int64  `db:"cluster_id"`
	Token     string `db:"token"`
	Level     string `db:"level"` // read, write, execute
	Enabled   bool   `db:"enabled"`
}

type Base

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

func (*Base) DeleteById

func (b *Base) DeleteById(tx *sqlx.Tx, id int64) (sql.Result, error)

func (*Base) DeleteFromTable

func (b *Base) DeleteFromTable(tx *sqlx.Tx, where string) (sql.Result, error)

func (*Base) InsertIntoTable

func (b *Base) InsertIntoTable(tx *sqlx.Tx, data map[string]interface{}) (sql.Result, error)

func (*Base) UpdateByAccessTokenAndSavedQuery

func (b *Base) UpdateByAccessTokenAndSavedQuery(tx *sqlx.Tx, data map[string]interface{}, accessTokenRow *AccessTokenRow, savedQuery string) (sql.Result, error)

func (*Base) UpdateByID

func (b *Base) UpdateByID(tx *sqlx.Tx, data map[string]interface{}, id int64) (sql.Result, error)

func (*Base) UpdateById

func (b *Base) UpdateById(tx *sqlx.Tx, data map[string]interface{}, id int64) (sql.Result, error)

func (*Base) UpdateByKeyValueString

func (b *Base) UpdateByKeyValueString(tx *sqlx.Tx, data map[string]interface{}, key, value string) (sql.Result, error)

func (*Base) UpdateFromTable

func (b *Base) UpdateFromTable(tx *sqlx.Tx, data map[string]interface{}, where string) (sql.Result, error)

type Cluster

type Cluster struct {
	Base
}

func NewCluster

func NewCluster(db *sqlx.DB) *Cluster

func (*Cluster) AllClustersByUserID

func (a *Cluster) AllClustersByUserID(tx *sqlx.Tx, userId int64) ([]*ClusterRow, error)

AllClustersByUserID returns all clusters rows.

func (*Cluster) Create

func (a *Cluster) Create(tx *sqlx.Tx, userId int64, name string) (*ClusterRow, error)

func (*Cluster) GetById

func (a *Cluster) GetById(tx *sqlx.Tx, id int64) (*ClusterRow, error)

GetById returns one record by id.

type ClusterRow

type ClusterRow struct {
	ID   int64  `db:"id"`
	Name string `db:"name"`
}

type Executor

type Executor struct {
	Base
}

func NewExecutor

func NewExecutor(db *sqlx.DB) *Executor

func (*Executor) AllByClusterID

func (e *Executor) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*ExecutorRow, error)

AllByClusterID returns all executor rows by cluster id.

func (*Executor) CreateOrUpdate

func (e *Executor) CreateOrUpdate(tx *sqlx.Tx, clusterID int64, hostname string, data []byte) (*ExecutorRow, error)

CreateOrUpdate performs insert/update for one executor data.

func (*Executor) GetByClusterIDAndHostname

func (e *Executor) GetByClusterIDAndHostname(tx *sqlx.Tx, clusterID int64, hostname string) (*ExecutorRow, error)

GetByClusterIDAndHostname returns record by cluster_id and hostname.

func (*Executor) UpdateByClusterIDAndHostname

func (e *Executor) UpdateByClusterIDAndHostname(tx *sqlx.Tx, clusterID int64, hostname string, data []byte) (*ExecutorRow, error)

UpdateByClusterIDAndHostname updates record by cluster_id.

type ExecutorRow

type ExecutorRow struct {
	ClusterID int64               `db:"cluster_id" json:"-"`
	Hostname  string              `db:"hostname"`
	Data      sqlx_types.JsonText `db:"data"`
}

func (*ExecutorRow) DataString

func (executorRow *ExecutorRow) DataString() string

type Host

type Host struct {
	Base
}

func NewHost

func NewHost(db *sqlx.DB) *Host

func (*Host) AllByAccessTokenId

func (h *Host) AllByAccessTokenId(tx *sqlx.Tx, accessTokenId int64) ([]*HostRow, error)

AllByAccessTokenId returns all user rows.

func (*Host) AllByAccessTokenIdAndQuery

func (h *Host) AllByAccessTokenIdAndQuery(tx *sqlx.Tx, accessTokenId int64, resourcedQuery string) ([]*HostRow, error)

AllByAccessTokenIdAndQuery returns all user rows by resourced query.

func (*Host) CreateOrUpdate

func (h *Host) CreateOrUpdate(tx *sqlx.Tx, accessTokenId int64, jsonData []byte) (*HostRow, error)

CreateOrUpdate performs insert/update for one host data.

func (*Host) GetByID

func (h *Host) GetByID(tx *sqlx.Tx, id int64) (*HostRow, error)

GetByID returns record by id.

func (*Host) GetByName

func (h *Host) GetByName(tx *sqlx.Tx, name string) (*HostRow, error)

GetByName returns record by name.

type HostRow

type HostRow struct {
	ID            int64               `db:"id" json:"-"`
	AccessTokenID int64               `db:"access_token_id" json:"-"`
	Name          string              `db:"name"`
	Updated       time.Time           `db:"updated"`
	Tags          sqlx_types.JsonText `db:"tags"`
	Data          sqlx_types.JsonText `db:"data"`
}

func (*HostRow) DataAsFlatKeyValue

func (h *HostRow) DataAsFlatKeyValue() map[string]map[string]interface{}

func (*HostRow) StringTags

func (h *HostRow) StringTags() []string

type InsertResult

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

func (*InsertResult) LastInsertId

func (ir *InsertResult) LastInsertId() (int64, error)

func (*InsertResult) RowsAffected

func (ir *InsertResult) RowsAffected() (int64, error)

type Metadata

type Metadata struct {
	Base
}

func NewMetadata

func NewMetadata(db *sqlx.DB) *Metadata

func (*Metadata) AllByClusterID

func (metadata *Metadata) AllByClusterID(tx *sqlx.Tx, clusterID int64) ([]*MetadataRow, error)

AllByClusterID returns all user rows.

func (*Metadata) CreateOrUpdate

func (metadata *Metadata) CreateOrUpdate(tx *sqlx.Tx, clusterID int64, key string, data []byte) (*MetadataRow, error)

CreateOrUpdate performs insert/update for one metadata data.

func (*Metadata) GetByClusterIDAndKey

func (metadata *Metadata) GetByClusterIDAndKey(tx *sqlx.Tx, clusterID int64, key string) (*MetadataRow, error)

GetByClusterIDAndKey returns record by cluster_id and key.

func (*Metadata) UpdateByClusterIDAndKey

func (metadata *Metadata) UpdateByClusterIDAndKey(tx *sqlx.Tx, clusterID int64, key string, data []byte) (*MetadataRow, error)

UpdateByClusterIDAndKey updates record by cluster_id and key.

type MetadataRow

type MetadataRow struct {
	ClusterID int64               `db:"cluster_id" json:"-"`
	Key       string              `db:"key"`
	Data      sqlx_types.JsonText `db:"data"`
}

func (*MetadataRow) DataString

func (metadataRow *MetadataRow) DataString() string

type ResourcedPayload

type ResourcedPayload struct {
	Data     map[string]interface{}
	GoStruct string
	Host     struct {
		Name string
		Tags map[string]string
	}
	Interval string
	Path     string
	UnixNano float64
}

type SavedQuery

type SavedQuery struct {
	Base
}

func NewSavedQuery

func NewSavedQuery(db *sqlx.DB) *SavedQuery

func (*SavedQuery) AllByAccessToken

func (sq *SavedQuery) AllByAccessToken(tx *sqlx.Tx, accessTokenRow *AccessTokenRow) ([]*SavedQueryRow, error)

AllByAccessToken returns all saved_query rows.

func (*SavedQuery) CreateOrUpdate

func (sq *SavedQuery) CreateOrUpdate(tx *sqlx.Tx, accessTokenID int64, savedQuery string) (*SavedQueryRow, error)

CreateOrUpdate performs insert/update for one savedQuery data.

func (*SavedQuery) DeleteByID

func (sq *SavedQuery) DeleteByID(tx *sqlx.Tx, id int64) error

DeleteByID deletes record by id.

func (*SavedQuery) GetByAccessTokenAndQuery

func (sq *SavedQuery) GetByAccessTokenAndQuery(tx *sqlx.Tx, accessTokenRow *AccessTokenRow, savedQuery string) (*SavedQueryRow, error)

GetByAccessTokenAndQuery returns record by savedQuery.

func (*SavedQuery) GetByID

func (sq *SavedQuery) GetByID(tx *sqlx.Tx, id int64) (*SavedQueryRow, error)

GetByID returns record by id.

type SavedQueryRow

type SavedQueryRow struct {
	ID     int64  `db:"id"`
	UserID int64  `db:"user_id"`
	Query  string `db:"query"`
}

type Task

type Task struct {
	Base
}

func NewTask

func NewTask(db *sqlx.DB) *Task

func (*Task) AllByAccessToken

func (task *Task) AllByAccessToken(tx *sqlx.Tx, accessTokenRow *AccessTokenRow) ([]*TaskRow, error)

AllByAccessToken returns all tasks_cron rows.

func (*Task) Create

func (task *Task) Create(tx *sqlx.Tx, accessTokenID int64, savedQuery, cron string) (*TaskRow, error)

Create performs insert for one task data.

func (*Task) DeleteByID

func (task *Task) DeleteByID(tx *sqlx.Tx, id int64) error

DeleteByID deletes record by id.

func (*Task) GetByAccessTokenQueryAndCron

func (task *Task) GetByAccessTokenQueryAndCron(tx *sqlx.Tx, accessTokenRow *AccessTokenRow, savedQuery, cron string) (*TaskRow, error)

GetByAccessTokenQueryAndCron returns record by token, query and cron.

func (*Task) GetByID

func (task *Task) GetByID(tx *sqlx.Tx, id int64) (*TaskRow, error)

GetByID returns record by id.

type TaskRow

type TaskRow struct {
	ID     int64  `db:"id"`
	UserID int64  `db:"user_id"`
	Query  string `db:"query"`
	Cron   string `db:"cron"`
}

type User

type User struct {
	Base
}

func NewUser

func NewUser(db *sqlx.DB) *User

func (*User) AllUsers

func (u *User) AllUsers(tx *sqlx.Tx) ([]*UserRow, error)

AllUsers returns all user rows.

func (*User) GetByEmail

func (u *User) GetByEmail(tx *sqlx.Tx, email string) (*UserRow, error)

GetByEmail returns record by email.

func (*User) GetByID

func (u *User) GetByID(tx *sqlx.Tx, id int64) (*UserRow, error)

GetByID returns record by id.

func (*User) GetUserByEmailAndPassword

func (u *User) GetUserByEmailAndPassword(tx *sqlx.Tx, email, password string) (*UserRow, error)

GetByEmail returns record by email but checks password first.

func (*User) Signup

func (u *User) Signup(tx *sqlx.Tx, email, password, passwordAgain string) (*UserRow, error)

Signup create a new record of user.

func (*User) UpdateEmailAndPasswordById

func (u *User) UpdateEmailAndPasswordById(tx *sqlx.Tx, userId int64, email, password, passwordAgain string) (*UserRow, error)

UpdateEmailAndPasswordById updates user email and password.

type UserRow

type UserRow struct {
	ID       int64  `db:"id"`
	Email    string `db:"email"`
	Password string `db:"password"`
}

Jump to

Keyboard shortcuts

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