database

package
v0.0.0-...-c8d5bbb Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2020 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 BucketMeasurements

type BucketMeasurements struct {
	BucketId     int64          `json:"bucket_id"`
	Measurements []*Measurement `json:"measurements"`
}

type Column

type Column struct {
	Name  string `json:"name"`
	Type  string `json:"type"`
	IsKey bool   `json:"is_key"`
}

func (*Column) ToSQL

func (self *Column) ToSQL() string

type Database

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

func New

func New(connString string) *Database

func (*Database) CreateUser

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

func (*Database) CreateUserIfNotExists

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

func (*Database) Exec

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

func (*Database) GetUserByApikey

func (self *Database) GetUserByApikey(apikey string) (*User, error)

func (*Database) GetUserByEmail

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

func (*Database) GetUserByUsername

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

func (*Database) GetUsers

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

func (*Database) GetVersion

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

func (*Database) Insert

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

func (*Database) QueryRow

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

type Device

type Device struct {
	Id        string    `json:"id"`
	Name      string    `json:"name"`
	Type      string    `json:"type"`
	Username  string    `json:"username"`
	IsDeleted bool      `json:"is_deleted"`
	IsActive  bool      `json:"is_active"`
	CreatedAt time.Time `json:"created_at,string"`
	UpdatedAt time.Time `json:"updated_at,string"`
	Sensors   []*Sensor `json:"sensors"`
	// contains filtered or unexported fields
}

func (*Device) Activate

func (self *Device) Activate() error

Activate a device

func (*Device) CreateSensor

func (self *Device) CreateSensor(sname, stype string) error

func (*Device) Deactivate

func (self *Device) Deactivate() error

Deactivate a device

func (*Device) Delete

func (self *Device) Delete() error

Delete deletes user

func (*Device) GetSensorById

func (self *Device) GetSensorById(sensor_id string) (*Sensor, error)

func (*Device) GetSensorByName

func (self *Device) GetSensorByName(sensor_name string) (*Sensor, error)

func (*Device) GetSensorIds

func (self *Device) GetSensorIds() ([]string, error)

func (*Device) GetSensors

func (self *Device) GetSensors() ([]*Sensor, error)

func (*Device) GetUser

func (self *Device) GetUser() *User

func (*Device) Marshal

func (self *Device) Marshal() (string, error)

func (*Device) SetLocation

func (self *Device) SetLocation(location_id string, probability float64) error

func (*Device) SetName

func (self *Device) SetName(dname string) error

SetPassword sets password

func (*Device) SetType

func (self *Device) SetType(dtype string) error

func (*Device) Unmarshal

func (self *Device) Unmarshal(data string) error

func (*Device) Update

func (self *Device) Update() error

Update updates user data in database

type DeviceLocationStats

type DeviceLocationStats struct {
	DeviceId           string                 `json:"device_id"`
	DeviceName         string                 `json:"device_name"`
	FirstTimestamp     time.Time              `json:"first_timestamp,string"`
	LastestTimestamp   time.Time              `json:"latest_timestamp,string"`
	AverageProbability float64                `json:"average_probability"`
	Sensors            []*SensorLocationStats `json:"sensors"`
}

type DeviceLocations

type DeviceLocations struct {
	LocationId   string                 `json:"location_id"`
	LocationName string                 `json:"location_name"`
	Geometry     geojson.Geometry       `json:"geometry"`
	Devices      []*DeviceLocationStats `json:"devices"`
}

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(table string) (string, error)

type LocationMeasurements

type LocationMeasurements struct {
	LocationId         string                `json:"location_id"`
	SensorMeasurements []*SensorMeasurements `json:"sensors"`
}

type Measurement

type Measurement struct {
	Key   string  `json:"key"`
	Value float64 `json:"value"`
}

type MeasurementLocationStats

type MeasurementLocationStats struct {
	Key              string    `json:"key"`
	Sensors          int       `json:"sensors"`
	Count            int       `json:"count"`
	Min              float64   `json:"min"`
	Max              float64   `json:"max"`
	Stddev           float64   `json:"stddev"`
	Mean             float64   `json:"mean"`
	FirstTimestamp   time.Time `json:"first_timestamp,string"`
	LastestTimestamp time.Time `json:"latest_timestamp,string"`
}

type MeasurementLocations

type MeasurementLocations struct {
	LocationId   string                      `json:"location_id"`
	LocationName string                      `json:"location_name"`
	Geometry     geojson.Geometry            `json:"geometry"`
	Scanners     []*MeasurementLocationStats `json:"scanners"`
}

type Sensor

type Sensor struct {
	Id        string    `json:"id"`
	Name      string    `json:"name"`
	Type      string    `json:"type"`
	DeviceId  string    `json:"device_id"`
	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
}

func (*Sensor) Activate

func (self *Sensor) Activate() error

Activate a sensor

func (*Sensor) Deactivate

func (self *Sensor) Deactivate() error

Deactivate a sensor

func (*Sensor) Delete

func (self *Sensor) Delete() error

Delete deletes user

func (*Sensor) ImportMeasurement

func (self *Sensor) ImportMeasurement(key string, value float64) error

func (*Sensor) ImportMeasurementAtLocation

func (self *Sensor) ImportMeasurementAtLocation(location_id, key string, value float64) error

func (*Sensor) ImportMeasurements

func (self *Sensor) ImportMeasurements(data map[string]float64) error

func (*Sensor) ImportMeasurementsAtLocation

func (self *Sensor) ImportMeasurementsAtLocation(location_id string, data map[string]float64) error

func (*Sensor) SetName

func (self *Sensor) SetName(dname string) error

SetName

func (*Sensor) SetType

func (self *Sensor) SetType(dtype string) error

SetType

func (*Sensor) Update

func (self *Sensor) Update() error

Update updates user data in database

type SensorLocationStats

type SensorLocationStats struct {
	SensorId     string `json:"sensor_id"`
	SensorName   string `json:"sensor_name"`
	Measurements int    `json:"measurements"`
}

type SensorMeasurements

type SensorMeasurements struct {
	DeviceId           string                `json:"device_id"`
	SensorId           string                `json:"sensor_id"`
	BucketMeasurements []*BucketMeasurements `json:"buckets"`
}

type Table

type Table struct {
	Name    string   `json:"string"`
	Columns []Column `json:"columns"`
}

func (*Table) IsGeoSpatial

func (self *Table) IsGeoSpatial() bool

func (*Table) IsTimeSeries

func (self *Table) IsTimeSeries() bool

func (*Table) ToSQL

func (self *Table) ToSQL() string

type User

type User struct {
	Username    string    `json:"username"`
	Password    string    `json:"-"`
	Email       string    `json:"email"`
	Apikey      string    `json:"apikey,omitempty"`
	SecretToken string    `json:"secret_token,omitempty"`
	IsDeleted   bool      `json:"is_deleted"`
	IsActive    bool      `json:"is_active"`
	IsSuperuser bool      `json:"is_superuser"`
	CreatedAt   time.Time `json:"created_at,string"`
	UpdatedAt   time.Time `json:"updated_at,string"`
	// contains filtered or unexported fields
}

func (*User) Activate

func (self *User) Activate() error

Activate deletes user

func (*User) CreateDevice

func (self *User) CreateDevice(dname, dtype string) (*Device, error)

*

  • APP FUNCTIONS

func (*User) CreateLocation

func (self *User) CreateLocation(lname string, lng, lat float64) error

func (*User) CreateSocialAccountIfNotExists

func (self *User) CreateSocialAccountIfNotExists(user_id, username, account_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 deletes user

func (*User) Delete

func (self *User) Delete() error

Delete deletes user

func (*User) ExportDevicesByLocation

func (self *User) ExportDevicesByLocation() ([]*DeviceLocations, error)

func (*User) ExportMeasurementStatsByLocation

func (self *User) ExportMeasurementStatsByLocation() ([]*MeasurementLocations, error)

func (*User) ExportMeasurements

func (self *User) ExportMeasurements() ([]*LocationMeasurements, error)

func (*User) GetDeviceById

func (self *User) GetDeviceById(device_id string) (*Device, error)

func (*User) GetDeviceByName

func (self *User) GetDeviceByName(device_name string) (*Device, error)

func (*User) GetDevices

func (self *User) GetDevices() ([]*Device, error)

func (*User) GetLocations

func (self *User) GetLocations() (*geojson.FeatureCollection, error)

func (*User) IsPassword

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

IsPassword checks if provided password/hash matches database record

func (*User) Marshal

func (self *User) Marshal() (string, error)

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 password

func (*User) Unmarshal

func (self *User) Unmarshal(data string) error

func (*User) Update

func (self *User) Update() error

Update updates user data in database

Jump to

Keyboard shortcuts

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