store

package
v0.0.0-...-f0f2526 Latest Latest
Warning

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

Go to latest
Published: May 29, 2018 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const DB_SCHEMA string = `` /* 870-byte string literal not displayed */

Variables

View Source
var ErrFailedToConnect = errors.New("Could not connect to database")

ErrFailedToConnect produced when cannot connect

View Source
var ErrUserNotFound = errors.New("User not found")

ErrUserNotFound produced when a user cannot be found

Functions

func Register

func Register(name string, factory DataStoreFactory)

Register a data store factory

func Tomorrow

func Tomorrow(t time.Time) time.Time

func Ulogme7amTime

func Ulogme7amTime(t time.Time) int64

func Yesterday

func Yesterday(t time.Time) time.Time

Types

type DataStore

type DataStore interface {
	LogToDb(
		uid int,
		windowlogs []*gologme.WindowLogs,
		keylogs []*gologme.KeyLogs,
	)
	CreateNote(
		uid int,
		date time.Time,
		message string,
	)
	CreateBlog(
		uid int,
		date time.Time,
		message string,
	)
	CheckAuth(
		key string,
	) (int, error)
	Name() string
	FindUserNameByID(id int) (string, error)
	SetupDb()
	ExportWindowLogsByRange(t0, t1 int64) []*gologme.SEvent
	ExportEventsByDate(tm time.Time) *gologme.EventLog
	MinDate() int
	MaxDate() int
}

DataStore interface definition, all DBs must implement this

func CreateDataStore

func CreateDataStore(conf map[string]string) (DataStore, error)

CreateDataStore creates a new database connection

func NewFileDataStore

func NewFileDataStore(conf map[string]string) (DataStore, error)

NewFileDataStore builds a new sqlite3 DS

func NewPostgreSQLDataStore

func NewPostgreSQLDataStore(conf map[string]string) (DataStore, error)

NewPostgreSQLDataStore builds a new PG DS

func NewSqliteSQLDataStore

func NewSqliteSQLDataStore(conf map[string]string) (DataStore, error)

NewSqliteSQLDataStore builds a new sqlite3 DS

type DataStoreFactory

type DataStoreFactory func(conf map[string]string) (DataStore, error)

DataStoreFactory config

type FileDataStore

type FileDataStore struct {
	DSN      string
	KeyFreqs *os.File
	Windows  *os.File
	Blog     *os.File
	Notes    *os.File
}

FileDataStore struct

func (*FileDataStore) CheckAuth

func (ds *FileDataStore) CheckAuth(key string) (int, error)

CheckAuth of the key, returning -1 or the user's ID

func (*FileDataStore) CreateBlog

func (ds *FileDataStore) CreateBlog(uid int, date time.Time, message string)

func (*FileDataStore) CreateNote

func (ds *FileDataStore) CreateNote(uid int, date time.Time, message string)

func (*FileDataStore) ExportEventsByDate

func (ds *FileDataStore) ExportEventsByDate(tm time.Time) *gologme.EventLog

ExportEventsByDate extracts events for a given day

func (*FileDataStore) ExportWindowLogsByRange

func (ds *FileDataStore) ExportWindowLogsByRange(t0 int64, t1 int64) []*gologme.SEvent

func (*FileDataStore) FindUserNameByID

func (ds *FileDataStore) FindUserNameByID(id int) (string, error)

FindUserNameByID returns a username for a given ID

func (*FileDataStore) LogToDb

func (ds *FileDataStore) LogToDb(uid int, windowlogs []*gologme.WindowLogs, keylogs []*gologme.KeyLogs)

LogToDb logs a set of windowLogs and keyLogs to the DB

func (*FileDataStore) MaxDate

func (ds *FileDataStore) MaxDate() int

MaxDate returns latest log entry

func (*FileDataStore) MinDate

func (ds *FileDataStore) MinDate() int

MinDate returns first log entry

func (*FileDataStore) Name

func (ds *FileDataStore) Name() string

Name of the DS implementatino

func (*FileDataStore) SetupDb

func (ds *FileDataStore) SetupDb()

SetupDb runs any migrations needed

type PostgreSQLDataStore

type PostgreSQLDataStore struct {
	DSN string
	DB  *sql.DB
}

PostgreSQLDataStore struct

func (*PostgreSQLDataStore) CheckAuth

func (ds *PostgreSQLDataStore) CheckAuth(key string) (int, error)

CheckAuth of the key, returning -1 or the user's ID

func (*PostgreSQLDataStore) CreateBlog

func (ds *PostgreSQLDataStore) CreateBlog(uid int, date time.Time, message string)

func (*PostgreSQLDataStore) CreateBlogNote

func (ds *PostgreSQLDataStore) CreateBlogNote(uid int, date time.Time, message string, noteType int)

func (*PostgreSQLDataStore) CreateNote

func (ds *PostgreSQLDataStore) CreateNote(uid int, date time.Time, message string)

func (*PostgreSQLDataStore) ExportEventsByDate

func (ds *PostgreSQLDataStore) ExportEventsByDate(tm time.Time) *gologme.EventLog

ExportEventsByDate extracts events for a given day

func (*PostgreSQLDataStore) ExportWindowLogsByRange

func (ds *PostgreSQLDataStore) ExportWindowLogsByRange(t0 int64, t1 int64) []*gologme.SEvent

func (*PostgreSQLDataStore) FindUserNameByID

func (ds *PostgreSQLDataStore) FindUserNameByID(id int) (string, error)

FindUserNameByID returns a username for a given ID

func (*PostgreSQLDataStore) LogToDb

func (ds *PostgreSQLDataStore) LogToDb(uid int, windowlogs []*gologme.WindowLogs, keylogs []*gologme.KeyLogs)

LogToDb logs a set of windowLogs and keyLogs to the DB

func (*PostgreSQLDataStore) MaxDate

func (ds *PostgreSQLDataStore) MaxDate() int

MaxDate returns latest log entry

func (*PostgreSQLDataStore) MinDate

func (ds *PostgreSQLDataStore) MinDate() int

MinDate returns first log entry

func (*PostgreSQLDataStore) Name

func (ds *PostgreSQLDataStore) Name() string

Name of the DS implementatino

func (*PostgreSQLDataStore) SetupDb

func (ds *PostgreSQLDataStore) SetupDb()

SetupDb runs any migrations needed

type SqliteSQLDataStore

type SqliteSQLDataStore struct {
	DSN string
	DB  *sql.DB
}

SqliteSQLDataStore struct

func (*SqliteSQLDataStore) CheckAuth

func (ds *SqliteSQLDataStore) CheckAuth(key string) (int, error)

CheckAuth of the key, returning -1 or the user's ID

func (*SqliteSQLDataStore) CreateBlog

func (ds *SqliteSQLDataStore) CreateBlog(uid int, date time.Time, message string)

func (*SqliteSQLDataStore) CreateBlogNote

func (ds *SqliteSQLDataStore) CreateBlogNote(uid int, date time.Time, message string, noteType int)

func (*SqliteSQLDataStore) CreateNote

func (ds *SqliteSQLDataStore) CreateNote(uid int, date time.Time, message string)

func (*SqliteSQLDataStore) ExportEventsByDate

func (ds *SqliteSQLDataStore) ExportEventsByDate(tm time.Time) *gologme.EventLog

ExportEventsByDate extracts events for a given day

func (*SqliteSQLDataStore) ExportWindowLogsByRange

func (ds *SqliteSQLDataStore) ExportWindowLogsByRange(t0 int64, t1 int64) []*gologme.SEvent

func (*SqliteSQLDataStore) FindUserNameByID

func (ds *SqliteSQLDataStore) FindUserNameByID(id int) (string, error)

FindUserNameByID returns a username for a given ID

func (*SqliteSQLDataStore) LogToDb

func (ds *SqliteSQLDataStore) LogToDb(uid int, windowlogs []*gologme.WindowLogs, keylogs []*gologme.KeyLogs)

LogToDb logs a set of windowLogs and keyLogs to the DB

func (*SqliteSQLDataStore) MaxDate

func (ds *SqliteSQLDataStore) MaxDate() int

MaxDate returns latest log entry

func (*SqliteSQLDataStore) MinDate

func (ds *SqliteSQLDataStore) MinDate() int

MinDate returns first log entry

func (*SqliteSQLDataStore) Name

func (ds *SqliteSQLDataStore) Name() string

Name of the DS implementatino

func (*SqliteSQLDataStore) SetupDb

func (ds *SqliteSQLDataStore) SetupDb()

SetupDb runs any migrations needed

Jump to

Keyboard shortcuts

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