fitbit_pgdb

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

README

Fitbit PostgreSQL storage

This package contains an implementation of the fitbit.Storage interface for the Fitbit Web API - Go client package.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthorizedUser

type AuthorizedUser struct {
	types.AuthorizedUser
	ID        int64     `igor:"primary_key"`
	CreatedAt time.Time `sql:"default:now()"`
}

AuthorizedUser wraps fitbit types.AuthorizedUser and adds: - The igor-required method TableName() - The primary key - The created at field

func (AuthorizedUser) TableName

func (AuthorizedUser) TableName() string

type AuthorizingUser

type AuthorizingUser struct {
	types.AuthorizingUser
	ID        int64     `igor:"primary_key"`
	CreatedAt time.Time `sql:"default:now()"`
}

AuthorizingUser wraps fitbit types.AuthorizingUser and adds: - The igor-required method TableName() - The primary key - The created at field

func (AuthorizingUser) TableName

func (AuthorizingUser) TableName() string

type PGDB

type PGDB struct {
	*igor.Database
}

PGDB implements the fitbit.Storage interface

func NewPGDB

func NewPGDB() *PGDB

NewPGDB creates a new connection to a PostgreSQL server using the following environment variables: - DB_USER - DB_PASS - DB_NAME Loaded from a `.env` file, if present.

It implements the `fitbit.Storage` interface.

func (*PGDB) AuthorizedUser

func (s *PGDB) AuthorizedUser(accessToken string) (*types.AuthorizedUser, error)

AuthorizedUser executes a SELECT for the types.AuthorizedUser using the `accessToken` as only query parameter. NOTE: the `accessToken` is unique on the underlying table.

func (*PGDB) AuthorizingUser

func (s *PGDB) AuthorizingUser(id string) (*types.AuthorizingUser, error)

AuthorizingUser executes a SELECT for the types.AuthorizingUser using the `id` provided as PRIMARY KEY for creating the query.

func (*PGDB) InsertAuhorizingUser

func (s *PGDB) InsertAuhorizingUser(authorizing *types.AuthorizingUser) error

InsertAuhorizingUser executes a CREATE query on the PostgreSQL database inserting the authorizing user in the associated table.

func (*PGDB) UpsertAuthorizedUser

func (s *PGDB) UpsertAuthorizedUser(authorized *types.AuthorizedUser) error

UpsertAuthorizedUser executes INSERT or UPDATE the user on the PostgreSQL database. It inserts the user if the SELECT by user UserID fields returns the empty set. If it finds the user insteads it updates all the other NON PRIMARY KEY (or equivalent like UserID) fields.

Jump to

Keyboard shortcuts

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