persist

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

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

Go to latest
Published: Jul 2, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SqliteToMongoDB

func SqliteToMongoDB(sqliteDBFile string, mongoURI string, mongoDBName string, mongoCollectionName string, logger *zap.Logger) error

Disable this test for now, since it requires a MongoDB instance to be running.

Types

type Keywords

type Keywords []string

Keywords is a custom type that represents a slice of strings

func (*Keywords) Scan

func (k *Keywords) Scan(value interface{}) error

Scan implements the sql.Scanner interface

func (Keywords) Value

func (k Keywords) Value() (driver.Value, error)

Value implements the driver.Valuer interface

type MongoStoreDB

type MongoStoreDB struct {
	Coll     *mongo.Collection
	Name     string
	CollName string
	Logger   *zap.Logger
}

func New

func New(mongoUri string, dbName string, collName string, logger *zap.Logger) (*MongoStoreDB, error)

Connect to the mongo database

func (*MongoStoreDB) AddUser

func (mdb *MongoStoreDB) AddUser(user *models.UserData) error

Add user to the database

func (*MongoStoreDB) Close

func (mdb *MongoStoreDB) Close() error

Close the database

func (*MongoStoreDB) DeleteUser

func (mdb *MongoStoreDB) DeleteUser(user *models.UserData) error

Delete user from the database

func (*MongoStoreDB) GetUser

func (mdb *MongoStoreDB) GetUser(chatID int64) (*models.UserData, error)

Get user from the database by chat_id

func (*MongoStoreDB) ReadUserStore

func (mdb *MongoStoreDB) ReadUserStore() (*models.UserStore, error)

Read all users from the database

func (*MongoStoreDB) UpdateUser

func (mdb *MongoStoreDB) UpdateUser(user *models.UserData) error

Update user in the database

func (*MongoStoreDB) WriteUserStore

func (mdb *MongoStoreDB) WriteUserStore(userStore *models.UserStore) error

Write *models.UserStore to the database

type UserData

type UserData struct {
	ChatID         int64    `gorm:"column:chat_id"`         // Telegram chat ID
	Username       string   `gorm:"column:username"`        // Telegram username
	OzbGood        bool     `gorm:"column:ozb_good"`        // watch deals with 25+ upvotes in the last 24 hours
	OzbSuper       bool     `gorm:"column:ozb_super"`       // watch deals with 50+ upvotes in the last 24 hours
	Keywords       Keywords `gorm:"column:keywords"`        // list of keywords / deals to watch for
	OzbSent        Keywords `gorm:"column:ozb_sent"`        // comma separated list of ozb deals sent to user
	AmzDaily       bool     `gorm:"column:amz_daily"`       // watch top daily deals on amazon
	AmzWeekly      bool     `gorm:"column:amz_weekly"`      // watch top weekly deals on amazon
	AmzSent        Keywords `gorm:"column:amz_sent"`        // comma separated list of amz deals sent to user
	UsernameChosen string   `gorm:"column:username_chosen"` // username chosen by user
	Password       string   `gorm:"column:password"`        // password chosen by user
}

UserData represents the structure of the data in the SQLite database

func (UserData) TableName

func (UserData) TableName() string

TableName sets the table name for the UserData struct

Jump to

Keyboard shortcuts

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