database

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CreateSchema = `` /* 2093-byte string literal not displayed */

CreateSchema SQL script for creating the schema

View Source
var DropSchema = `
DROP TABLE IF EXISTS runtime_install CASCADE;

DROP TABLE IF EXISTS users CASCADE;
`

DropSchema SQL script for dropping the schema

Functions

func PrintQuery added in v0.2.1

func PrintQuery(query string, args ...interface{})

PrintQuery prints query

func PrintResult added in v0.2.1

func PrintResult(i interface{})

PrintResult prints result

Types

type DBError

type DBError struct {
	Query string `json:"query"`
	Err   error  `json:"error"`
}

DBError database error

func (*DBError) Error

func (e *DBError) Error() string

The error interface implementation, which formats to a JSON object string.

func (*DBError) Log

func (e *DBError) Log(tx string)

Log logs the database transaction with query and error

func (*DBError) Unwrap

func (e *DBError) Unwrap() error

type DBOption added in v0.2.10

type DBOption func(*DBService)

DBOption db option

func DBOptionDebug added in v0.2.10

func DBOptionDebug(debug bool) DBOption

DBOptionDebug db option debug

type DBResult

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

DBResult for capturing result information for inserts

func (DBResult) LastInsertId

func (dbr DBResult) LastInsertId() (int64, error)

LastInsertId last inserted id

func (DBResult) RowsAffected

func (dbr DBResult) RowsAffected() (int64, error)

RowsAffected number of rows affected

type DBService

type DBService struct {
	*sqlx.DB
	Debug bool
}

DBService db service

func NewDBService

func NewDBService(db *sqlx.DB) DBService

NewDBService instantiates new db service

func (DBService) Del added in v0.2.0

func (u DBService) Del(i interface{}) *DBError

Del deletes given data

func (DBService) Delete

func (u DBService) Delete(sql string, id int64) *DBError

Delete convenience function for delete statement

func (DBService) FindByID added in v0.2.0

func (u DBService) FindByID(tableName string, id int64, i interface{}) (interface{}, *DBError)

FindByID finds by id

func (DBService) FindByName added in v0.2.0

func (u DBService) FindByName(tableName string, name string, i interface{}) (interface{}, *DBError)

FindByName finds by name

func (DBService) Insert added in v0.2.0

func (u DBService) Insert(tableName string, i interface{}) (sql.Result, *DBError)

Insert convenience function for insert statement

func (DBService) List added in v0.2.0

func (u DBService) List(tableName string, dest interface{}) *DBError

List all rows of given entity

func (DBService) ListBy added in v0.2.0

func (u DBService) ListBy(tableName string, dest interface{}, where string, args ...interface{}) *DBError

ListBy lists all rows of given entity with where clause

func (DBService) MustExec

func (u DBService) MustExec(sql string, args ...interface{}) *DBError

MustExec wrapper for sqlx.MustExec

func (DBService) NamedExec

func (u DBService) NamedExec(sql string, obj interface{}) (sql.Result, *DBError)

NamedExec wrapper for sqls.NamedExec.

func (DBService) PrepareNamed

func (u DBService) PrepareNamed(sql string, arg interface{}) (sql.Result, *DBError)

PrepareNamed wrapper for sqlx.PrepareNamed. However, it handles retrieval of new id

func (DBService) Save added in v0.2.0

func (u DBService) Save(i interface{}) *DBError

Save adds new data

func (DBService) Select added in v0.2.0

func (u DBService) Select(dest interface{}, query string, args ...interface{}) (interface{}, *DBError)

Select executes sqlx.Select

type Mappable added in v0.2.0

type Mappable interface {
	Meta() MappingConfig
	PrimaryKey() int64
	SetPrimaryKey(int64)
}

Mappable structs returns sql specific meta data

type MappingConfig added in v0.2.0

type MappingConfig struct {
	TableName string
}

MappingConfig provides addtional hints to DBService

func GetMappingConfigFromSlicePointer added in v0.2.0

func GetMappingConfigFromSlicePointer(dest interface{}) *MappingConfig

GetMappingConfigFromSlicePointer gets mapping config from slice pointer

type RuntimeInstall

type RuntimeInstall struct {
	ID         int64  `db:"id"`
	Name       string `db:"name"`
	ScriptBody string `db:"script_body"`
}

RuntimeInstall runtime install

func (RuntimeInstall) Meta added in v0.2.0

func (ri RuntimeInstall) Meta() MappingConfig

Meta provides mapping config specific to runtime install

func (RuntimeInstall) PrimaryKey added in v0.2.0

func (ri RuntimeInstall) PrimaryKey() int64

PrimaryKey returns primary key

func (RuntimeInstall) SetPrimaryKey added in v0.2.0

func (ri RuntimeInstall) SetPrimaryKey(id int64)

SetPrimaryKey updates the primary key value after insert

func (RuntimeInstall) String added in v0.3.0

func (ri RuntimeInstall) String() string

type User

type User struct {
	ID               int64  `db:"id"`
	GoogleID         string `db:"google_id"`
	Username         string `db:"username"`
	Password         string `db:"password"`
	Email            string `db:"email"`
	HashedEmail      string `db:"hashed_email"`
	IsActive         bool   `db:"is_active"`
	PrivateKey       string `db:"private_key"`
	PublicKey        string `db:"public_key"`
	PublicKeyID      int64  `db:"public_key_id"`
	GitRepoURI       string `db:"git_repo_uri"`
	IDE              string `db:"ide"`
	RuntimeInstalls  string `db:"runtime_installs"`
	DockerTag        string
	Installed        []RuntimeInstall
	PostgresUsername string
	PGHost           string
	PGDBName         string
}

User user

func (*User) Meta added in v0.2.0

func (u *User) Meta() MappingConfig

Meta provides mapping config specific to user

func (*User) PrimaryKey added in v0.2.0

func (u *User) PrimaryKey() int64

PrimaryKey returns primary key

func (*User) SetPrimaryKey added in v0.2.0

func (u *User) SetPrimaryKey(id int64)

SetPrimaryKey updates the primary key value after insert

func (User) String added in v0.1.7

func (u User) String() string

String string representation of user

type UserService

type UserService struct {
	*DBService
}

UserService manages user data

func NewUserService

func NewUserService(db *sqlx.DB) UserService

NewUserService instantiates new user service

func NewUserServiceWithOptions added in v0.2.10

func NewUserServiceWithOptions(db *sqlx.DB, options ...DBOption) UserService

NewUserServiceWithOptions returns new user service with options

func (UserService) FindAllRuntimeInstallsForUser added in v0.3.0

func (u UserService) FindAllRuntimeInstallsForUser(dest interface{}, username string) *DBError

FindUserIDERuntimeInstallsByUsernameAndIDE finds user installs by user and ide

func (UserService) FindBy added in v0.2.0

func (u UserService) FindBy(i interface{}, where string, args ...interface{}) *DBError

FindBy finds ide by given where clause

func (UserService) FindUserByGoogleID

func (u UserService) FindUserByGoogleID(googleIDHashed string) (User, *DBError)

FindUserByGoogleID finds user by google id

func (UserService) UpdateGoogleID

func (u UserService) UpdateGoogleID(user User) (sql.Result, *DBError)

UpdateGoogleID updates user google id

func (UserService) UpdateProfile

func (u UserService) UpdateProfile(user User) (sql.Result, *DBError)

UpdateProfile updates user profile

Jump to

Keyboard shortcuts

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