database

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

CreateSchema SQL script for creating the schema

View Source
var DropSchema = `` /* 292-byte string literal not displayed */

DropSchema SQL script for dropping the schema

Functions

func NewUserObject added in v0.1.15

func NewUserObject(userService UserService, email string) (*UserObject, *DBError)

func PrintQuery added in v0.2.1

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

func PrintResult added in v0.2.1

func PrintResult(i interface{})

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 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 IDE

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

IDE ide

func (*IDE) Meta added in v0.2.0

func (ur *IDE) Meta() MappingConfig

Meta provides mapping config specific to user

func (*IDE) PrimaryKey added in v0.2.0

func (ur *IDE) PrimaryKey() int64

PrimaryKey returns primary key

func (*IDE) SetPrimaryKey added in v0.2.0

func (ur *IDE) SetPrimaryKey(id int64)

SetPrimaryKey updates the primary key value after insert

type IDERepo

type IDERepo struct {
	ID        int64  `db:"id"`
	UserIDEID int64  `db:"user_ide_id"`
	URI       string `db:"uri"`
}

IDERepo ide repo

func (*IDERepo) Meta added in v0.2.0

func (ur *IDERepo) Meta() MappingConfig

Meta provides mapping config specific to ide repo

func (*IDERepo) PrimaryKey added in v0.2.0

func (ur *IDERepo) PrimaryKey() int64

PrimaryKey returns primary key

func (*IDERepo) SetPrimaryKey added in v0.2.0

func (ur *IDERepo) SetPrimaryKey(id int64)

SetPrimaryKey updates the primary key value after insert

type IDERuntimeInstall

type IDERuntimeInstall struct {
	ID               int64 `db:"id"`
	UserIDEID        int64 `db:"user_ide_id"`
	RuntimeInstallID int64 `db:"runtime_install_id"`
}

IDERuntimeInstall ide runtime install

func (*IDERuntimeInstall) Meta added in v0.2.0

func (ur *IDERuntimeInstall) Meta() MappingConfig

Meta provides mapping config specific to ide runtime install

func (*IDERuntimeInstall) PrimaryKey added in v0.2.0

func (ur *IDERuntimeInstall) PrimaryKey() int64

PrimaryKey returns primary key

func (*IDERuntimeInstall) SetPrimaryKey added in v0.2.0

func (ur *IDERuntimeInstall) SetPrimaryKey(id int64)

SetPrimaryKey updates the primary key value after insert

func (IDERuntimeInstall) String added in v0.2.1

func (u IDERuntimeInstall) String() string

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

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 (ur *RuntimeInstall) Meta() MappingConfig

Meta provides mapping config specific to runtime install

func (*RuntimeInstall) PrimaryKey added in v0.2.0

func (ur *RuntimeInstall) PrimaryKey() int64

PrimaryKey returns primary key

func (*RuntimeInstall) SetPrimaryKey added in v0.2.0

func (ur *RuntimeInstall) SetPrimaryKey(id int64)

SetPrimaryKey updates the primary key value after insert

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"`
	DockerTag        string
	IDEs             []IDE
	RuntimeInstalls  []string
	Repos            []string
	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

type UserIDE

type UserIDE struct {
	ID     int64 `db:"id"`
	UserID int64 `db:"user_id"`
	IDEID  int64 `db:"ide_id"`
}

UserIDE user ide

func (*UserIDE) Meta added in v0.2.0

func (ur *UserIDE) Meta() MappingConfig

Meta provides mapping config specific to user ide

func (*UserIDE) PrimaryKey added in v0.2.0

func (ur *UserIDE) PrimaryKey() int64

PrimaryKey returns primary key

func (*UserIDE) SetPrimaryKey added in v0.2.0

func (ur *UserIDE) SetPrimaryKey(id int64)

SetPrimaryKey updates the primary key value after insert

func (UserIDE) String added in v0.2.1

func (u UserIDE) String() string

type UserObject added in v0.1.15

type UserObject struct {
	User
	UserService UserService
}

func (*UserObject) DoesUserHaveIDE added in v0.1.15

func (uo *UserObject) DoesUserHaveIDE(ideName string) (bool, *DBError)

func (*UserObject) DoesUserHaveRuntimeInstallFor added in v0.1.15

func (uo *UserObject) DoesUserHaveRuntimeInstallFor(ide IDE, runtimeInstallName string) (bool, *DBError)

func (*UserObject) GetIDE added in v0.1.15

func (uo *UserObject) GetIDE(ideName string) (*IDE, *DBError)

func (*UserObject) IDEs added in v0.1.15

func (uo *UserObject) IDEs() ([]IDE, *DBError)

func (*UserObject) RuntimeInstallsFor added in v0.1.15

func (uo *UserObject) RuntimeInstallsFor(ide IDE) ([]RuntimeInstall, *DBError)

func (*UserObject) UserIDE added in v0.1.15

func (uo *UserObject) UserIDE(ide IDE) (UserIDE, *DBError)

type UserRepo

type UserRepo struct {
	ID     int64  `db:"id"`
	URI    string `db:"uri"`
	UserID int64  `db:"user_id"`
}

UserRepo user repo

func NewUserRepo added in v0.2.0

func NewUserRepo(uri string, userID int64) *UserRepo

NewUserRepo returns new instance of user repo

func (*UserRepo) Meta added in v0.2.0

func (ur *UserRepo) Meta() MappingConfig

Meta provides mapping config specific to user

func (*UserRepo) PrimaryKey added in v0.2.0

func (ur *UserRepo) PrimaryKey() int64

PrimaryKey returns primary key

func (*UserRepo) SetPrimaryKey added in v0.2.0

func (ur *UserRepo) SetPrimaryKey(id int64)

SetPrimaryKey updates the primary key value after insert

type UserService

type UserService struct {
	*DBService
}

UserService manages user data

func NewUserService

func NewUserService(db *sqlx.DB) UserService

NewUserService instantiates new user service

func (UserService) DeleteALLIDEReposForUser

func (u UserService) DeleteALLIDEReposForUser(userID int64) *DBError

DeleteALLIDEReposForUser deletes all ide repos for given user

func (UserService) DeleteALLIDERuntimeInstallsForUser

func (u UserService) DeleteALLIDERuntimeInstallsForUser(userID int64) *DBError

DeleteALLIDERuntimeInstallsForUser deletes all ide runtime installs for given user

func (UserService) DeleteALLUserIDEsForUser

func (u UserService) DeleteALLUserIDEsForUser(userID int64) *DBError

DeleteALLUserIDEsForUser deletes all user ides for given user

func (UserService) DeleteALLUserReposForUser

func (u UserService) DeleteALLUserReposForUser(userID int64) *DBError

DeleteALLUserReposForUser deletes all user repos for given user

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) FindUserIDERepoURIsByUserAndIDE added in v0.2.0

func (u UserService) FindUserIDERepoURIsByUserAndIDE(username string, ide string) (*[]string, *DBError)

FindUserIDERepoURIsByUserAndIDE finds user ide repos by user and ide

func (UserService) FindUserIDERuntimeInstallsByUsernameAndIDE added in v0.2.0

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

FindUserIDERuntimeInstallsByUsernameAndIDE finds user installs by user and ide

func (UserService) FindUserIDEsByUserID

func (u UserService) FindUserIDEsByUserID(userID int64) (*[]string, *DBError)

FindUserIDEsByUserID find user ides by user 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