database

package
v0.0.0-...-2eaac80 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Apikey

type Apikey struct {
	UserId    string    `json:"user_id"`
	Name      string    `json:"name"`
	Apikey    string    `json:"apikey"`
	Secret    string    `json:"secret"`
	IsDeleted bool      `json:"is_deleted"`
	IsActive  bool      `json:"is_active"`
	CreatedAt time.Time `json:"created_at,string"`
	UpdatedAt time.Time `json:"updated_at,string"`
	// contains filtered or unexported fields
}

Apikey struct of apikey object

func (*Apikey) Activate

func (self *Apikey) Activate() error

Activate markers object as active

func (*Apikey) Deactivate

func (self *Apikey) Deactivate() error

Deactivate markers object as inactive

func (*Apikey) Delete

func (self *Apikey) Delete() error

Delete markers object as deleted

func (*Apikey) SetDatabase

func (self *Apikey) SetDatabase(db *Database)

SetDatabase set object database reference

func (*Apikey) Update

func (self *Apikey) Update() error

Update updates object data in database

type Database

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

Database struct

func New

func New(connString string) *Database

New creates new Database object

func (*Database) CreateUser

func (self *Database) CreateUser(email, username string) (*User, error)

CreateUser creates new user

func (*Database) CreateUserIfNotExists

func (self *Database) CreateUserIfNotExists(email, username string) (*User, error)

CreateUserIfNotExists creates new user if does not exist

func (*Database) Exec

func (self *Database) Exec(clbk func(*sql.DB) error) error

Exec passes sql.DB to callback

func (*Database) GetUserByEmail

func (self *Database) GetUserByEmail(email string) (*User, error)

GetUserByEmail get user by email

func (*Database) GetUserByUsername

func (self *Database) GetUserByUsername(username string) (*User, error)

GetUserByUsername get user by username

func (*Database) GetUsers

func (self *Database) GetUsers() ([]*User, error)

GetUsers get list of users

func (*Database) GetVersion

func (self *Database) GetVersion() (string, error)

GetVersion returns database version

func (*Database) Insert

func (self *Database) Insert(query string, args ...interface{}) error

Insert new record to database

func (*Database) QueryRow

func (self *Database) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow wrapper for sql.DB QueryRow

func (*Database) Select

func (self *Database) Select(model Model, query string, args ...interface{}) error

Select data from database

type Filter

type Filter struct {
	Logical    string            `json:"logical,omitempty"`
	Test       string            `json:"test,omitempty"`
	ColumnId   string            `json:"column_id,omitempty"`
	Value      string            `json:"value,omitempty"`
	Values     []string          `json:"values,omitempty"`
	Min        float64           `json:"min,omitempty"`
	Max        float64           `json:"max,omitempty"`
	Start      time.Time         `json:"start,omitempty"`
	End        time.Time         `json:"end,omitempty"`
	Check      bool              `json:"check,omitempty"`
	Geometry   *geojson.Geometry `json:"geometry,omitempty"`
	Conditions []*Filter         `json:"conditions,omitempty"`
}

func (*Filter) ToSQL

func (self *Filter) ToSQL() (string, error)

type Model

type Model interface {
	SetDatabase(*Database)
}

type User

type User struct {
	Id             string         `json:"id"`
	Username       string         `json:"username"`
	Password       string         `json:"-"`
	Email          string         `json:"email"`
	IsDeleted      bool           `json:"is_deleted"`
	IsActive       bool           `json:"is_active"`
	CreatedAt      time.Time      `json:"created_at,string"`
	UpdatedAt      time.Time      `json:"updated_at,string"`
	Apikeys        []Apikey       `json:"apikeys"`
	SocialAccounts *[]interface{} `json:"social_accounts"`
	// contains filtered or unexported fields
}

User struct of user object

func (*User) Activate

func (self *User) Activate() error

Activate markers object as active

func (*User) CreateApikey

func (self *User) CreateApikey(name string) (*Apikey, error)

CreateApikey creates new apikey for user

func (*User) CreateSocialAccountIfNotExists

func (self *User) CreateSocialAccountIfNotExists(social_id, social_name, social_type string) error

*

  • Social Accounts

CreateSocialAccountIfNotExists https://stackoverflow.com/questions/4069718/postgres-insert-if-does-not-exist-already ON CONFLICT DO NOTHING/UPDATE http://www.postgresqltutorial.com/postgresql-upsert/

func (*User) Deactivate

func (self *User) Deactivate() error

Deactivate markers object as inactive

func (*User) Delete

func (self *User) Delete() error

Delete markers object as deleted

func (*User) IsPassword

func (self *User) IsPassword(password string) (bool, error)

IsPassword checks if provided password/hash matches database record

func (*User) SetDatabase

func (self *User) SetDatabase(db *Database)

SetDatabase set object database reference

func (*User) SetEmail

func (self *User) SetEmail(email string) error

SetEmail sets user email

func (*User) SetPassword

func (self *User) SetPassword(password string) error

SetPassword sets user password

func (*User) Update

func (self *User) Update() error

Update updates object data in database

Jump to

Keyboard shortcuts

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