chatstore

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: AGPL-3.0 Imports: 17 Imported by: 0

README

ChatStore Open in Gitpod

Tests Status Go Report Card PkgGoDev

A Go library for storing and retrieving chat messages.

License

This project is dual-licensed under the following terms:

  • For non-commercial use, you may choose either the GNU Affero General Public License v3.0 (AGPLv3) or a separate commercial license (see below). You can find a copy of the AGPLv3 at: https://www.gnu.org/licenses/agpl-3.0.txt

  • For commercial use, a separate commercial license is required. Commercial licenses are available for various use cases. Please contact me via my contact page to obtain a commercial license.

Installation

go get github.com/dracory/chatstore

Usage Examples

Here are some examples demonstrating how to use the chatstore library.

Example 1: Creating a Chat Store

This example shows how to create a chat store.

// Initialize the database connection.
db, err := sql.Open("sqlite3", "./chatstore.db") // Replace with your database details
if err != nil {
    log.Fatalf("Failed to open database: %v", err)
}
defer db.Close()

// Create the store with database options.
store, err := chatstore.CreateStore(chatstore.NewStoreOptions{
    DB:                 db,
    TableChatName:      "chat_table",
    TableMessageName:   "message_table",
    AutomigrateEnabled: true,
})
if err != nil {
    log.Fatalf("Failed to create store: %v", err)
}
Example 2. Creating a Chat

This example shows how to create a chat.

chat := chatstore.NewChat().
		SetName("Test Chat").
		SetOwnerID(testUser_O1).
		SetStatus(CHAT_STATUS_ACTIVE)

err = store.ChatCreate(chat)
if err != nil {
    log.Fatalf("Failed to create chat: %v", err)
}

fmt.Println("Chat created successfully!")
Example 3: Creating a Chat Message

This example shows how to create and store a single chat message.

message := chatstore.NewMessage().
		SetChatID(chat.ID()).
		SetSenderID(user1.ID()).
		SetRecipientID(user2.ID()).
		SetText("Message 1")

err = store.MessageCreate(message)
if err != nil {
    log.Fatalf("Failed to create message: %v", err)
}

fmt.Println("Message stored successfully!")

Documentation

Index

Constants

View Source
const CHAT_MESSAGE_STATUS_ACTIVE = "active"
View Source
const CHAT_MESSAGE_STATUS_DELETED = "deleted"
View Source
const CHAT_MESSAGE_STATUS_INACTIVE = "inactive"
View Source
const CHAT_STATUS_ACTIVE = "active"
View Source
const CHAT_STATUS_DELETED = "deleted"
View Source
const CHAT_STATUS_INACTIVE = "inactive"
View Source
const CHAT_SYSTEM_ID = "00000000000000000000000000000001"
View Source
const COLUMN_CHAT_ID = "chat_id"
View Source
const COLUMN_CREATED_AT = "created_at"
View Source
const COLUMN_ID = "id"
View Source
const COLUMN_MEMO = "memo"
View Source
const COLUMN_METAS = "metas"
View Source
const COLUMN_OWNER_ID = "owner_id"
View Source
const COLUMN_RECIPIENT_ID = "recipient_id"
View Source
const COLUMN_SENDER_ID = "sender_id"
View Source
const COLUMN_SOFT_DELETED_AT = "soft_deleted_at"
View Source
const COLUMN_STATUS = "status"
View Source
const COLUMN_TEXT = "text"
View Source
const COLUMN_TITLE = "title"
View Source
const COLUMN_UPDATED_AT = "updated_at"
View Source
const MESSAGE_STATUS_ACTIVE = "active"
View Source
const MESSAGE_STATUS_DELETED = "deleted"
View Source
const MESSAGE_STATUS_INACTIVE = "inactive"

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatInterface

type ChatInterface interface {
	Data() map[string]string
	DataChanged() map[string]string
	MarkAsNotDirty()

	IsSoftDeleted() bool

	ID() string
	SetID(id string) ChatInterface

	OwnerID() string
	SetOwnerID(id string) ChatInterface

	Status() string
	SetStatus(status string) ChatInterface

	Title() string
	SetTitle(title string) ChatInterface

	Memo() string
	SetMemo(memo string) ChatInterface

	Meta(key string) (string, error)
	SetMeta(key string, value string) error

	Metas() (map[string]string, error)
	SetMetas(metas map[string]string) error

	UpsertMetas(metas map[string]string) error

	CreatedAt() string
	CreatedAtCarbon() *carbon.Carbon
	SetCreatedAt(createdAt string) ChatInterface

	SoftDeletedAt() string
	SoftDeletedAtCarbon() *carbon.Carbon
	SetSoftDeletedAt(softDeletedAt string) ChatInterface

	UpdatedAt() string
	UpdatedAtCarbon() *carbon.Carbon
	SetUpdatedAt(updatedAt string) ChatInterface
}

func NewChat

func NewChat() ChatInterface

func NewChatFromExistingData

func NewChatFromExistingData(data map[string]string) ChatInterface

type ChatQueryInterface

type ChatQueryInterface interface {
	// Validation method
	Validate() error

	// Count related methods
	IsCountOnlySet() bool
	GetCountOnly() bool
	SetCountOnly(countOnly bool) ChatQueryInterface

	// Soft delete related query methods
	IsWithSoftDeletedSet() bool
	GetWithSoftDeleted() bool
	SetWithSoftDeleted(withSoftDeleted bool) ChatQueryInterface

	IsOnlySoftDeletedSet() bool
	GetOnlySoftDeleted() bool
	SetOnlySoftDeleted(onlySoftDeleted bool) ChatQueryInterface

	// Dataset conversion methods
	ToSelectDataset(store *store) (selectDataset *goqu.SelectDataset, columns []any, err error)

	IsOwnerIDSet() bool
	GetOwnerID() string
	SetOwnerID(ownerID string) ChatQueryInterface

	IsCreatedAtGteSet() bool
	GetCreatedAtGte() string
	SetCreatedAtGte(createdAt string) ChatQueryInterface

	IsCreatedAtLteSet() bool
	GetCreatedAtLte() string
	SetCreatedAtLte(createdAt string) ChatQueryInterface

	IsIDSet() bool
	GetID() string
	SetID(id string) ChatQueryInterface

	IsIDInSet() bool
	GetIDIn() []string
	SetIDIn(ids []string) ChatQueryInterface

	IsLimitSet() bool
	GetLimit() int
	SetLimit(limit int) ChatQueryInterface

	IsOffsetSet() bool
	GetOffset() int
	SetOffset(offset int) ChatQueryInterface

	IsOrderBySet() bool
	GetOrderBy() string
	SetOrderBy(orderBy string) ChatQueryInterface

	IsOrderDirectionSet() bool
	GetOrderDirection() string
	SetOrderDirection(orderDirection string) ChatQueryInterface

	IsStatusSet() bool
	GetStatus() string
	SetStatus(status string) ChatQueryInterface
	SetStatusIn(statuses []string) ChatQueryInterface

	IsUpdatedAtGteSet() bool
	GetUpdatedAtGte() string
	SetUpdatedAtGte(updatedAt string) ChatQueryInterface

	IsUpdatedAtLteSet() bool
	GetUpdatedAtLte() string
	SetUpdatedAtLte(updatedAt string) ChatQueryInterface
}

ChatQueryInterface defines the interface for querying chats

func ChatQuery

func ChatQuery() ChatQueryInterface

ChatQuery creates a new chat query

type Message

type Message struct {
	dataobject.DataObject
}

func (*Message) ChatID

func (o *Message) ChatID() string

func (*Message) CreatedAt

func (o *Message) CreatedAt() string

func (*Message) CreatedAtCarbon

func (o *Message) CreatedAtCarbon() *carbon.Carbon

func (*Message) IsSoftDeleted

func (o *Message) IsSoftDeleted() bool

IsSoftDeleted checks if the message is soft deleted

func (*Message) Memo

func (o *Message) Memo() string

func (*Message) Meta

func (o *Message) Meta(key string) (string, error)

func (*Message) Metas

func (o *Message) Metas() (map[string]string, error)

func (*Message) RecipientID

func (o *Message) RecipientID() string

func (*Message) SenderID

func (o *Message) SenderID() string

func (*Message) SetChatID

func (o *Message) SetChatID(id string) MessageInterface

func (*Message) SetCreatedAt

func (o *Message) SetCreatedAt(createdAt string) MessageInterface

func (*Message) SetMemo

func (o *Message) SetMemo(memo string) MessageInterface

func (*Message) SetMeta

func (o *Message) SetMeta(key string, value string) error

func (*Message) SetMetas

func (o *Message) SetMetas(metas map[string]string) error

func (*Message) SetRecipientID

func (o *Message) SetRecipientID(id string) MessageInterface

func (*Message) SetSenderID

func (o *Message) SetSenderID(id string) MessageInterface

func (*Message) SetSoftDeletedAt

func (o *Message) SetSoftDeletedAt(softDeletedAt string) MessageInterface

func (*Message) SetStatus

func (o *Message) SetStatus(status string) MessageInterface

func (*Message) SetText

func (o *Message) SetText(text string) MessageInterface

func (*Message) SetUpdatedAt

func (o *Message) SetUpdatedAt(updatedAt string) MessageInterface

func (*Message) SoftDeletedAt

func (o *Message) SoftDeletedAt() string

func (*Message) SoftDeletedAtCarbon

func (o *Message) SoftDeletedAtCarbon() *carbon.Carbon

func (*Message) Status

func (o *Message) Status() string

func (*Message) Text

func (o *Message) Text() string

func (*Message) UpdatedAt

func (o *Message) UpdatedAt() string

func (*Message) UpdatedAtCarbon

func (o *Message) UpdatedAtCarbon() *carbon.Carbon

func (*Message) UpsertMetas

func (o *Message) UpsertMetas(metas map[string]string) error

type MessageInterface

type MessageInterface interface {
	dataobject.DataObjectInterface

	IsSoftDeleted() bool

	ChatID() string
	SetChatID(chatID string) MessageInterface

	SenderID() string
	SetSenderID(id string) MessageInterface

	RecipientID() string
	SetRecipientID(id string) MessageInterface

	Status() string
	SetStatus(status string) MessageInterface

	Memo() string
	SetMemo(memo string) MessageInterface

	Meta(key string) (string, error)
	SetMeta(key string, value string) error

	Metas() (map[string]string, error)
	SetMetas(metas map[string]string) error
	UpsertMetas(metas map[string]string) error

	Text() string
	SetText(text string) MessageInterface

	CreatedAt() string
	CreatedAtCarbon() *carbon.Carbon
	SetCreatedAt(createdAt string) MessageInterface

	SoftDeletedAt() string
	SoftDeletedAtCarbon() *carbon.Carbon
	SetSoftDeletedAt(softDeletedAt string) MessageInterface

	UpdatedAt() string
	UpdatedAtCarbon() *carbon.Carbon
	SetUpdatedAt(updatedAt string) MessageInterface
}

func NewMessage

func NewMessage() MessageInterface

func NewMessageFromExistingData

func NewMessageFromExistingData(data map[string]string) MessageInterface

type MessageQueryInterface

type MessageQueryInterface interface {
	// Validation method
	Validate() error

	// Basic query methods
	IsCreatedAtGteSet() bool
	GetCreatedAtGte() string
	SetCreatedAtGte(createdAt string) MessageQueryInterface

	IsCreatedAtLteSet() bool
	GetCreatedAtLte() string
	SetCreatedAtLte(createdAt string) MessageQueryInterface

	IsIDSet() bool
	GetID() string
	SetID(id string) MessageQueryInterface

	IsIDInSet() bool
	GetIDIn() []string
	SetIDIn(ids []string) MessageQueryInterface

	IsIDNotInSet() bool
	GetIDNotIn() []string
	SetIDNotIn(ids []string) MessageQueryInterface

	IsLimitSet() bool
	GetLimit() int
	SetLimit(limit int) MessageQueryInterface

	IsChatIDSet() bool
	GetChatID() string
	SetChatID(chatID string) MessageQueryInterface

	IsChatIDInSet() bool
	GetChatIDIn() []string
	SetChatIDIn(chatIDs []string) MessageQueryInterface

	IsOffsetSet() bool
	GetOffset() int
	SetOffset(offset int) MessageQueryInterface

	IsOrderBySet() bool
	GetOrderBy() string
	SetOrderBy(orderBy string) MessageQueryInterface

	IsOrderDirectionSet() bool
	GetOrderDirection() string
	SetOrderDirection(orderDirection string) MessageQueryInterface

	IsRecipientIDSet() bool
	GetRecipientID() string
	SetRecipientID(recipientID string) MessageQueryInterface

	IsSenderIDSet() bool
	GetSenderID() string
	SetSenderID(senderID string) MessageQueryInterface

	IsStatusSet() bool
	GetStatus() string
	SetStatus(status string) MessageQueryInterface
	SetStatusIn(statuses []string) MessageQueryInterface

	// Count related methods
	IsCountOnlySet() bool
	GetCountOnly() bool
	SetCountOnly(countOnly bool) MessageQueryInterface

	// Soft delete related query methods
	IsWithSoftDeletedSet() bool
	GetWithSoftDeleted() bool
	SetWithSoftDeleted(withSoftDeleted bool) MessageQueryInterface

	IsOnlySoftDeletedSet() bool
	GetOnlySoftDeleted() bool
	SetOnlySoftDeleted(onlySoftDeleted bool) MessageQueryInterface

	ToSelectDataset(store *store) (selectDataset *goqu.SelectDataset, columns []any, err error)
}

MessageQueryInterface defines the interface for querying messages

func MessageQuery

func MessageQuery() MessageQueryInterface

MessageQuery creates a new message query

type NewStoreOptions

type NewStoreOptions struct {
	TableChatName      string
	TableMessageName   string
	DB                 *sql.DB
	DbDriverName       string
	AutomigrateEnabled bool
	DebugEnabled       bool
	Logger             *slog.Logger
}

NewStoreOptions define the options for creating a new block store

type StoreInterface

type StoreInterface interface {
	AutoMigrate() error
	EnableDebug(enabled bool)

	ChatCount(options ChatQueryInterface) (int64, error)
	ChatCreate(chat ChatInterface) error
	ChatDelete(chat ChatInterface) error
	ChatDeleteByID(id string) error
	ChatFindByID(id string) (ChatInterface, error)
	ChatList(options ChatQueryInterface) ([]ChatInterface, error)
	ChatSoftDelete(chat ChatInterface) error
	ChatSoftDeleteByID(id string) error
	ChatUpdate(chat ChatInterface) error

	MessageCount(options MessageQueryInterface) (int64, error)
	MessageCreate(message MessageInterface) error
	MessageDelete(message MessageInterface) error
	MessageDeleteByID(id string) error
	MessageFindByID(id string) (MessageInterface, error)
	MessageList(options MessageQueryInterface) ([]MessageInterface, error)
	MessageSoftDelete(message MessageInterface) error
	MessageSoftDeleteByID(id string) error
	MessageUpdate(message MessageInterface) error
}

func NewStore

func NewStore(opts NewStoreOptions) (StoreInterface, error)

NewStore creates a new block store

Jump to

Keyboard shortcuts

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