db

package
v0.0.0-...-335761d Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Map

func Map[T, U any](data []T, f func(T) U) []U

Types

type Conversation

type Conversation struct {
	ID        uint
	CreatedAt time.Time
	UpdatedAt time.Time
	Name      string
	UserID    uint
	User      User
}

func (*Conversation) ToCoreConversation

func (conversation *Conversation) ToCoreConversation() core.Conversation

ToCoreConversation mapper to convert db model conversation to core.Conversation

type DbAdapter

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

func GetDbAdapter

func GetDbAdapter(dbConnUrl string) (*DbAdapter, error)

func (*DbAdapter) CreateNewConversation

func (adapter *DbAdapter) CreateNewConversation(userId int, conversationName string) error

func (*DbAdapter) GetContextForQuery

func (adapter *DbAdapter) GetContextForQuery(conversationId int, context int) ([]core.Query, error)

func (*DbAdapter) GetConversationByUser

func (adapter *DbAdapter) GetConversationByUser(userId int) ([]core.Conversation, error)

GetConversationByUser function to get conversation based on user and return it after mapping it to core conversation using ToCoreConversation function and also fetch only last 20 conversations based on CreatedAt field

func (*DbAdapter) GetOrCreateUser

func (adapter *DbAdapter) GetOrCreateUser(email string, name string) (core.User, error)

func (*DbAdapter) GetQueriesByConversation

func (adapter *DbAdapter) GetQueriesByConversation(conversationId int) ([]core.Query, error)

GetQueriesByConversation function to get query based on ConversationID and return list after mapping it to core message model using ToCoreQuery function. Only fetch last 20 messages based on CreatedAt field

func (*DbAdapter) GetTemplatesByUserId

func (adapter *DbAdapter) GetTemplatesByUserId(userId int) ([]core.Template, error)

func (*DbAdapter) GetUserById

func (adapter *DbAdapter) GetUserById(userId int) (core.User, error)

func (*DbAdapter) RunMigrations

func (adapter *DbAdapter) RunMigrations()

func (*DbAdapter) StoreQueryForConversation

func (adapter *DbAdapter) StoreQueryForConversation(conversationId int, query string, response []byte, context int) error

func (*DbAdapter) StoreTemplate

func (adapter *DbAdapter) StoreTemplate(templateName string, userId int, parts []string, params []string) error

type InvalidData

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

func (InvalidData) Error

func (error InvalidData) Error() string

type JSON

type JSON json.RawMessage

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

Scan scan value into Jsonb, implements sql.Scanner interface

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value return json value, implement driver.Valuer interface

type Query

type Query struct {
	ID             uint
	CreatedAt      time.Time
	UpdatedAt      time.Time
	Query          string `gorm:"not null"`
	Context        int32  `gorm:"default:0"`
	ConversationID uint
	Response       JSON `gorm:"type:jsonb;default:'{}'"`
	Conversation   Conversation
}

func (*Query) ToCoreQuery

func (query *Query) ToCoreQuery() core.Query

ToCoreQuery mapper to convert db model conversation to core.Query

type Template

type Template struct {
	ID         uint
	CreatedAt  time.Time
	UpdatedAt  time.Time
	Name       string `gorm:"not null"`
	Properties JSON   `gorm:"type:jsonb;default:'{}'"`
	UserID     uint
	User       User
}

type TemplateProperties

type TemplateProperties struct {
	Parts  []string `json:"parts"`
	Params []string `json:"params"`
}

type User

type User struct {
	ID        uint
	CreatedAt time.Time
	UpdatedAt time.Time
	IsActive  bool   `gorm:"default:true"`
	Name      string `gorm:"not null"`
	Email     string `gorm:"not null;unique"`
}

func (*User) ToCoreUser

func (user *User) ToCoreUser() core.User

Jump to

Keyboard shortcuts

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