store

package
v0.0.0-...-09e3a1a Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DB *sql.DB
)

Functions

func Close

func Close() error

Close closes the database connection

func CreateChat

func CreateChat(chat Chat) error

func CreateMessage

func CreateMessage(msg Message) error

func CreatePlatformError

func CreatePlatformError(error PlatformError) error

func CreateTransaction

func CreateTransaction(tx Transaction) error

func CreateUser

func CreateUser(user User) error

func DeleteAllChatsByUserID

func DeleteAllChatsByUserID(userID string) error

func DeleteAllMessageByChatID

func DeleteAllMessageByChatID(chatID string) error

func DeleteAllPlatformErrorByUserID

func DeleteAllPlatformErrorByUserID(userID string) error

func DeleteChatByID

func DeleteChatByID(ID string) error

func DeleteMessageByID

func DeleteMessageByID(ID string) error

func DeletePlatformErrorByID

func DeletePlatformErrorByID(errorID string) error

func DeleteUser

func DeleteUser(userID string) error

func ForceMigrationVersion

func ForceMigrationVersion(version int) error

ForceMigrationVersion forces the migration version (use when in dirty state)

func GetMigrationVersion

func GetMigrationVersion() (uint, bool, error)

GetMigrationVersion returns the current migration version and dirty state

func GetVersion

func GetVersion() string

func InitStorage

func InitStorage(connString string) error

InitStorage initializes the PostgreSQL database connection and runs migrations

func InitStorageWithoutMigration

func InitStorageWithoutMigration(connString string) error

InitStorageWithoutMigration initializes connection without running migrations

func MigrateDown

func MigrateDown() error

MigrateDown rolls back the last migration (use with caution)

func MigrateSteps

func MigrateSteps(steps int) error

MigrateSteps migrates up or down by the specified number of steps Positive number = migrate up, Negative number = migrate down

func MigrateTo

func MigrateTo(version uint) error

MigrateTo migrates to a specific version

func MigrateUp

func MigrateUp() error

MigrateUp runs all pending migrations

func RunMigrations

func RunMigrations() error

RunMigrations executes database migrations

func UpdateChat

func UpdateChat(chat Chat) error

func UpdateMessage

func UpdateMessage(msg Message) error

func UpdatePlatformError

func UpdatePlatformError(error PlatformError) error

func UpdateTransaction

func UpdateTransaction(tx Transaction) error

func UpdateUser

func UpdateUser(user User) error

Types

type Chat

type Chat struct {
	ID            string    `json:"id"`
	UserId        string    `json:"user_id"`
	Title         string    `json:"title"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
	IsArchived    bool      `json:"is_archived"`
	MessageCount  int       `json:"message_count"`
	LastMessageAt time.Time `json:"last_message_at"`
	IsPrivate     bool      `json:"is_private"`
	Messages      []Message `json:"messages"`
	IsReadOnly    bool      `json:"is_read_only"`
}

func GetChatById

func GetChatById(ID string) (*Chat, error)

func GetChatsByUserId

func GetChatsByUserId(userId string) ([]Chat, error)

type Message

type Message struct {
	ID         string    `json:"id"`
	ChatId     string    `json:"chat_id"`
	Prompt     string    `json:"prompt,omitempty"`
	Response   string    `json:"response"`
	CreatedAt  time.Time `json:"created_at"`
	Model      string    `json:"model,omitempty"`
	References []string  `json:"references,omitempty"`
}

func GetMessageById

func GetMessageById(ID string) (*Message, error)

func GetMessagesByChatId

func GetMessagesByChatId(chatId string) ([]Message, error)

type Modes

type Modes string
const (
	ModesLightResponse Modes = "light-response"
	ModesWebSearch     Modes = "web-search"
	ModesDeepSearch    Modes = "deep-search"
)

type PlatformError

type PlatformError struct {
	ID          string    `json:"id"`
	Message     string    `json:"message"`
	Description string    `json:"description,omitempty"`
	Action      string    `json:"action"`
	Status      string    `json:"status,omitempty"`
	UserId      string    `json:"user_id"`
	Context     string    `json:"context,omitempty"`
	Severity    string    `json:"severity"`
	CreatedAt   string    `json:"created_at"`
	UpdatedAt   time.Time `json:"UpdatedAt"`
}

func GetPlatformErrorByID

func GetPlatformErrorByID(errorID string) (*PlatformError, error)

func GetPlatformErrors

func GetPlatformErrors() ([]PlatformError, error)

type RequestCount

type RequestCount struct {
	Count     int   `json:"count"`
	Timestamp int64 `json:"timestamp"`
}

type Response

type Response struct {
	Success bool   `json:"success"`
	Status  int    `json:"status,omitempty"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

Response represents API response

type Transaction

type Transaction struct {
	ID                 string    `json:"id"`
	ExternalReference  string    `json:"ExternalReference"`
	MpesaReceiptNumber string    `json:"MpesaReceiptNumber"`
	CheckoutRequestID  string    `json:"CheckoutRequestID"`
	MerchantRequestID  string    `json:"MerchantRequestID"`
	Amount             int       `json:"Amount"`
	PhoneNumber        string    `json:"Phone"`
	ResultCode         int       `json:"ResultCode"`
	ResultDescription  string    `json:"ResultDesc"`
	Status             string    `json:"Status"`
	CreatedAt          time.Time `json:"CreatedAt"`
	UpdatedAt          time.Time `json:"UpdatedAt"`
}

func GetTransactionByExtRef

func GetTransactionByExtRef(ref string) (*Transaction, error)

func GetTransactionByID

func GetTransactionByID(txID string) (*Transaction, error)

func GetTransactions

func GetTransactions() ([]Transaction, error)

func GetUserTransactions

func GetUserTransactions(phoneNumber string) ([]Transaction, error)

GetUserTransactions retrieves all transactions for a user based on their phone number

type User

type User struct {
	ID                      string        `json:"id"`
	Username                string        `json:"username"`
	Email                   string        `json:"email"`
	PasswordHash            string        `json:"password_hash"`
	CreatedAt               time.Time     `json:"created_at"`
	UpdatedAt               time.Time     `json:"updated_at"`
	Preferences             string        `json:"preferences,omitempty"`
	WorkFunction            string        `json:"work_function,omitempty"`
	Theme                   string        `json:"theme,omitempty"`
	SyncEnabled             bool          `json:"sync_enabled"`
	Plan                    string        `json:"plan,omitempty"`
	PlanName                string        `json:"plan_name,omitempty"`
	Amount                  int           `json:"amount,omitempty"`
	Duration                string        `json:"duration,omitempty"`
	PhoneNumber             string        `json:"phone_number,omitempty"`
	ExpiryTimestamp         int64         `json:"expiry_timestamp,omitempty"`
	ExpireDuration          int64         `json:"expire_duration,omitempty"`
	Price                   string        `json:"price,omitempty"`
	ResponseMode            Modes         `json:"response_mode,omitempty"`
	AgreeToTerms            bool          `json:"agree_to_terms"`
	RequestCount            RequestCount  `json:"request_count"`
	EmailVerified           bool          `json:"email_verified"`
	EmailSubscribed         bool          `json:"email_subscribed"`
	VerificationToken       string        `json:"verification_token,omitempty"`
	VerificationTokenExpiry time.Time     `json:"verification_token_expiry"`
	UnsubscribeToken        string        `json:"unsubscribe_token,omitempty"`
	UserTransactions        []Transaction `json:"user_transactions,omitempty"`
	UserAgent               string        `json:"user_agent"`
}

func FindUserByEmailOrUsername

func FindUserByEmailOrUsername(identifier string) (*User, string, bool)

findUserByEmailOrUsername tries to find user by email or username in storage

func GetUserByEmail

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

func GetUserByID

func GetUserByID(userID string) (*User, error)

func GetUserByPhoneWithTransactions

func GetUserByPhoneWithTransactions(phoneNumber string) (*User, error)

GetUserByPhoneWithTransactions retrieves a user and their transactions

func GetUserByUsername

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

func GetUsers

func GetUsers() ([]User, error)

Jump to

Keyboard shortcuts

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