dal

package
v2.1.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 1, 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 user rows.

func (*AccessToken) Create

func (t *AccessToken) Create(tx *sqlx.Tx, userId 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) 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"`
	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) 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 Host

type Host struct {
	Base
}

func NewHost

func NewHost(db *sqlx.DB) *Host

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) AllHostsByAccessTokenId

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

AllHostsByAccessTokenId returns all user rows.

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"`
	AccessTokenID int64               `db:"access_token_id"`
	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 ResourcedPayload

type ResourcedPayload struct {
	Data     map[string]interface{}
	GoStruct string
	Host     struct {
		Name string
		Tags []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) AllByAccessTokenID

func (sq *SavedQuery) AllByAccessTokenID(tx *sqlx.Tx, accessTokenID int64) ([]*SavedQueryRow, error)

AllByAccessTokenID 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 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) CreateAccessTokenRow

func (u *User) CreateAccessTokenRow(tx *sqlx.Tx, userId int64, level string) (*AccessTokenRow, error)

CreateAccessTokenRow create a new token for a user.

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