Documentation
¶
Index ¶
- func ContextWithTransaction(ctx context.Context, tx *gorm.DB) context.Context
- func InitDefaultTenant(db *gorm.DB) error
- func TransactionFromContext(ctx context.Context) *gorm.DB
- type Database
- type Message
- type MySQL
- func (db *MySQL) AddUserToTenant(ctx context.Context, userID, tenantID uint) error
- func (db *MySQL) Close() error
- func (db *MySQL) CreateSession(ctx context.Context, sessionId string) error
- func (db *MySQL) CreateTenant(ctx context.Context, tenant *Tenant) error
- func (db *MySQL) CreateUser(ctx context.Context, user *User) error
- func (db *MySQL) DeleteSession(ctx context.Context, sessionID string) error
- func (db *MySQL) DeleteTenant(ctx context.Context, id uint) error
- func (db *MySQL) DeleteUser(ctx context.Context, id uint) error
- func (db *MySQL) DeleteUserTenants(ctx context.Context, userID uint) error
- func (db *MySQL) GetMessages(ctx context.Context, sessionID string) ([]*Message, error)
- func (db *MySQL) GetMessagesWithPagination(ctx context.Context, sessionID string, page, pageSize int) ([]*Message, error)
- func (db *MySQL) GetSessions(ctx context.Context) ([]*Session, error)
- func (db *MySQL) GetTenantByID(ctx context.Context, id uint) (*Tenant, error)
- func (db *MySQL) GetTenantByName(ctx context.Context, name string) (*Tenant, error)
- func (db *MySQL) GetTenantUsers(ctx context.Context, tenantID uint) ([]*User, error)
- func (db *MySQL) GetUserByUsername(ctx context.Context, username string) (*User, error)
- func (db *MySQL) GetUserTenants(ctx context.Context, userID uint) ([]*Tenant, error)
- func (db *MySQL) ListTenants(ctx context.Context) ([]*Tenant, error)
- func (db *MySQL) ListUsers(ctx context.Context) ([]*User, error)
- func (db *MySQL) RemoveUserFromTenant(ctx context.Context, userID, tenantID uint) error
- func (db *MySQL) SaveMessage(ctx context.Context, message *Message) error
- func (db *MySQL) SessionExists(ctx context.Context, sessionID string) (bool, error)
- func (db *MySQL) Transaction(ctx context.Context, fn func(ctx context.Context) error) error
- func (db *MySQL) UpdateSessionTitle(ctx context.Context, sessionID string, title string) error
- func (db *MySQL) UpdateTenant(ctx context.Context, tenant *Tenant) error
- func (db *MySQL) UpdateUser(ctx context.Context, user *User) error
- type Postgres
- func (db *Postgres) AddUserToTenant(ctx context.Context, userID, tenantID uint) error
- func (db *Postgres) Close() error
- func (db *Postgres) CreateSession(ctx context.Context, sessionId string) error
- func (db *Postgres) CreateTenant(ctx context.Context, tenant *Tenant) error
- func (db *Postgres) CreateUser(ctx context.Context, user *User) error
- func (db *Postgres) DeleteSession(ctx context.Context, sessionID string) error
- func (db *Postgres) DeleteTenant(ctx context.Context, id uint) error
- func (db *Postgres) DeleteUser(ctx context.Context, id uint) error
- func (db *Postgres) DeleteUserTenants(ctx context.Context, userID uint) error
- func (db *Postgres) GetMessages(ctx context.Context, sessionID string) ([]*Message, error)
- func (db *Postgres) GetMessagesWithPagination(ctx context.Context, sessionID string, page, pageSize int) ([]*Message, error)
- func (db *Postgres) GetSessions(ctx context.Context) ([]*Session, error)
- func (db *Postgres) GetTenantByID(ctx context.Context, id uint) (*Tenant, error)
- func (db *Postgres) GetTenantByName(ctx context.Context, name string) (*Tenant, error)
- func (db *Postgres) GetTenantUsers(ctx context.Context, tenantID uint) ([]*User, error)
- func (db *Postgres) GetUserByUsername(ctx context.Context, username string) (*User, error)
- func (db *Postgres) GetUserTenants(ctx context.Context, userID uint) ([]*Tenant, error)
- func (db *Postgres) ListTenants(ctx context.Context) ([]*Tenant, error)
- func (db *Postgres) ListUsers(ctx context.Context) ([]*User, error)
- func (db *Postgres) RemoveUserFromTenant(ctx context.Context, userID, tenantID uint) error
- func (db *Postgres) SaveMessage(ctx context.Context, message *Message) error
- func (db *Postgres) SessionExists(ctx context.Context, sessionID string) (bool, error)
- func (db *Postgres) Transaction(ctx context.Context, fn func(ctx context.Context) error) error
- func (db *Postgres) UpdateSessionTitle(ctx context.Context, sessionID string, title string) error
- func (db *Postgres) UpdateTenant(ctx context.Context, tenant *Tenant) error
- func (db *Postgres) UpdateUser(ctx context.Context, user *User) error
- type SQLite
- func (db *SQLite) AddUserToTenant(ctx context.Context, userID, tenantID uint) error
- func (db *SQLite) Close() error
- func (db *SQLite) CreateSession(ctx context.Context, sessionId string) error
- func (db *SQLite) CreateTenant(ctx context.Context, tenant *Tenant) error
- func (db *SQLite) CreateUser(ctx context.Context, user *User) error
- func (db *SQLite) DeleteSession(ctx context.Context, sessionID string) error
- func (db *SQLite) DeleteTenant(ctx context.Context, id uint) error
- func (db *SQLite) DeleteUser(ctx context.Context, id uint) error
- func (db *SQLite) DeleteUserTenants(ctx context.Context, userID uint) error
- func (db *SQLite) GetMessages(ctx context.Context, sessionID string) ([]*Message, error)
- func (db *SQLite) GetMessagesWithPagination(ctx context.Context, sessionID string, page, pageSize int) ([]*Message, error)
- func (db *SQLite) GetSessions(ctx context.Context) ([]*Session, error)
- func (db *SQLite) GetTenantByID(ctx context.Context, id uint) (*Tenant, error)
- func (db *SQLite) GetTenantByName(ctx context.Context, name string) (*Tenant, error)
- func (db *SQLite) GetTenantUsers(ctx context.Context, tenantID uint) ([]*User, error)
- func (db *SQLite) GetUserByUsername(ctx context.Context, username string) (*User, error)
- func (db *SQLite) GetUserTenants(ctx context.Context, userID uint) ([]*Tenant, error)
- func (db *SQLite) ListTenants(ctx context.Context) ([]*Tenant, error)
- func (db *SQLite) ListUsers(ctx context.Context) ([]*User, error)
- func (db *SQLite) RemoveUserFromTenant(ctx context.Context, userID, tenantID uint) error
- func (db *SQLite) SaveMessage(ctx context.Context, message *Message) error
- func (db *SQLite) SessionExists(ctx context.Context, sessionID string) (bool, error)
- func (db *SQLite) Transaction(ctx context.Context, fn func(ctx context.Context) error) error
- func (db *SQLite) UpdateSessionTitle(ctx context.Context, sessionID string, title string) error
- func (db *SQLite) UpdateTenant(ctx context.Context, tenant *Tenant) error
- func (db *SQLite) UpdateUser(ctx context.Context, user *User) error
- type Session
- type Tenant
- type User
- type UserRole
- type UserTenant
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContextWithTransaction ¶ added in v0.4.0
ContextWithTransaction creates a context containing a transaction
func InitDefaultTenant ¶ added in v0.4.0
InitDefaultTenant initializes the default tenant if it doesn't exist
Types ¶
type Database ¶
type Database interface {
// Close closes the database connection.
Close() error
// SaveMessage saves a message to the database.
SaveMessage(ctx context.Context, message *Message) error
// GetMessages gets messages for a specific session.
GetMessages(ctx context.Context, sessionID string) ([]*Message, error)
// GetMessagesWithPagination gets messages for a specific session with pagination.
GetMessagesWithPagination(ctx context.Context, sessionID string, page, pageSize int) ([]*Message, error)
// CreateSession creates a new session with the given sessionId.
CreateSession(ctx context.Context, sessionId string) error
// SessionExists checks if a session exists.
SessionExists(ctx context.Context, sessionID string) (bool, error)
// GetSessions gets all chat sessions with their latest message.
GetSessions(ctx context.Context) ([]*Session, error)
// UpdateSessionTitle updates the title of a session.
UpdateSessionTitle(ctx context.Context, sessionID string, title string) error
// DeleteSession deletes a session by ID.
DeleteSession(ctx context.Context, sessionID string) error
CreateUser(ctx context.Context, user *User) error
GetUserByUsername(ctx context.Context, username string) (*User, error)
UpdateUser(ctx context.Context, user *User) error
DeleteUser(ctx context.Context, id uint) error
ListUsers(ctx context.Context) ([]*User, error)
CreateTenant(ctx context.Context, tenant *Tenant) error
GetTenantByName(ctx context.Context, name string) (*Tenant, error)
GetTenantByID(ctx context.Context, id uint) (*Tenant, error)
UpdateTenant(ctx context.Context, tenant *Tenant) error
DeleteTenant(ctx context.Context, id uint) error
ListTenants(ctx context.Context) ([]*Tenant, error)
AddUserToTenant(ctx context.Context, userID, tenantID uint) error
RemoveUserFromTenant(ctx context.Context, userID, tenantID uint) error
GetUserTenants(ctx context.Context, userID uint) ([]*Tenant, error)
GetTenantUsers(ctx context.Context, tenantID uint) ([]*User, error)
DeleteUserTenants(ctx context.Context, userID uint) error
Transaction(ctx context.Context, fn func(ctx context.Context) error) error
}
Database defines the methods for database operations.
func NewDatabase ¶ added in v0.2.6
func NewDatabase(cfg *config.DatabaseConfig) (Database, error)
NewDatabase creates a new database based on configuration
func NewMySQL ¶ added in v0.2.6
func NewMySQL(cfg *config.DatabaseConfig) (Database, error)
NewMySQL creates a new MySQL instance
func NewPostgres ¶ added in v0.2.6
func NewPostgres(cfg *config.DatabaseConfig) (Database, error)
NewPostgres creates a new Postgres instance
type Message ¶
type Message struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
Content string `json:"content"`
Sender string `json:"sender"`
Timestamp time.Time `json:"timestamp"`
ToolCalls string `json:"toolCalls,omitempty"`
ToolResult string `json:"toolResult,omitempty"`
}
Message represents a chat message
type MySQL ¶ added in v0.2.6
type MySQL struct {
// contains filtered or unexported fields
}
MySQL implements the Database interface using MySQL
func (*MySQL) AddUserToTenant ¶ added in v0.4.0
AddUserToTenant adds a user to a tenant
func (*MySQL) CreateSession ¶ added in v0.2.6
func (*MySQL) CreateTenant ¶ added in v0.4.0
CreateTenant creates a new tenant
func (*MySQL) CreateUser ¶ added in v0.3.1
CreateUser creates a new user
func (*MySQL) DeleteSession ¶ added in v0.5.1
DeleteSession deletes a session by ID
func (*MySQL) DeleteTenant ¶ added in v0.4.0
DeleteTenant deletes a tenant by ID
func (*MySQL) DeleteUser ¶ added in v0.3.1
DeleteUser deletes a user by ID
func (*MySQL) DeleteUserTenants ¶ added in v0.4.0
DeleteUserTenants deletes all tenant associations for a user
func (*MySQL) GetMessages ¶ added in v0.2.6
func (*MySQL) GetMessagesWithPagination ¶ added in v0.2.6
func (*MySQL) GetSessions ¶ added in v0.2.6
func (*MySQL) GetTenantByID ¶ added in v0.4.0
GetTenantByID retrieves a tenant by ID
func (*MySQL) GetTenantByName ¶ added in v0.4.0
GetTenantByName retrieves a tenant by name
func (*MySQL) GetTenantUsers ¶ added in v0.4.0
GetTenantUsers gets all users for a tenant
func (*MySQL) GetUserByUsername ¶ added in v0.3.1
GetUserByUsername retrieves a user by username
func (*MySQL) GetUserTenants ¶ added in v0.4.0
GetUserTenants gets all tenants for a user
func (*MySQL) ListTenants ¶ added in v0.4.0
ListTenants retrieves all tenants
func (*MySQL) RemoveUserFromTenant ¶ added in v0.4.0
RemoveUserFromTenant removes a user from a tenant
func (*MySQL) SaveMessage ¶ added in v0.2.6
func (*MySQL) SessionExists ¶ added in v0.2.6
func (*MySQL) Transaction ¶ added in v0.4.0
Transaction implements Database.Transaction
func (*MySQL) UpdateSessionTitle ¶ added in v0.2.6
func (*MySQL) UpdateTenant ¶ added in v0.4.0
UpdateTenant updates an existing tenant
type Postgres ¶ added in v0.2.6
type Postgres struct {
// contains filtered or unexported fields
}
Postgres implements the Database interface using PostgreSQL
func (*Postgres) AddUserToTenant ¶ added in v0.4.0
AddUserToTenant adds a user to a tenant
func (*Postgres) CreateSession ¶ added in v0.2.6
CreateSession creates a new session with the given sessionId
func (*Postgres) CreateTenant ¶ added in v0.4.0
CreateTenant creates a new tenant
func (*Postgres) CreateUser ¶ added in v0.3.1
CreateUser creates a new user
func (*Postgres) DeleteSession ¶ added in v0.5.1
DeleteSession deletes a session by ID
func (*Postgres) DeleteTenant ¶ added in v0.4.0
DeleteTenant deletes a tenant by ID
func (*Postgres) DeleteUser ¶ added in v0.3.1
DeleteUser deletes a user by ID
func (*Postgres) DeleteUserTenants ¶ added in v0.4.0
DeleteUserTenants deletes all tenant associations for a user
func (*Postgres) GetMessages ¶ added in v0.2.6
GetMessages retrieves all messages for a session
func (*Postgres) GetMessagesWithPagination ¶ added in v0.2.6
func (db *Postgres) GetMessagesWithPagination(ctx context.Context, sessionID string, page, pageSize int) ([]*Message, error)
GetMessagesWithPagination retrieves messages for a specific session with pagination
func (*Postgres) GetSessions ¶ added in v0.2.6
GetSessions retrieves all chat sessions with their latest message
func (*Postgres) GetTenantByID ¶ added in v0.4.0
GetTenantByID retrieves a tenant by ID
func (*Postgres) GetTenantByName ¶ added in v0.4.0
GetTenantByName retrieves a tenant by name
func (*Postgres) GetTenantUsers ¶ added in v0.4.0
GetTenantUsers gets all users for a tenant
func (*Postgres) GetUserByUsername ¶ added in v0.3.1
GetUserByUsername retrieves a user by username
func (*Postgres) GetUserTenants ¶ added in v0.4.0
GetUserTenants gets all tenants for a user
func (*Postgres) ListTenants ¶ added in v0.4.0
ListTenants retrieves all tenants
func (*Postgres) RemoveUserFromTenant ¶ added in v0.4.0
RemoveUserFromTenant removes a user from a tenant
func (*Postgres) SaveMessage ¶ added in v0.2.6
SaveMessage saves a message to the database
func (*Postgres) SessionExists ¶ added in v0.2.6
SessionExists checks if a session exists
func (*Postgres) Transaction ¶ added in v0.4.0
Transaction implements Database.Transaction
func (*Postgres) UpdateSessionTitle ¶ added in v0.2.6
UpdateSessionTitle updates the title of a session
func (*Postgres) UpdateTenant ¶ added in v0.4.0
UpdateTenant updates an existing tenant
type SQLite ¶ added in v0.2.6
type SQLite struct {
// contains filtered or unexported fields
}
SQLite implements the Database interface using SQLite
func (*SQLite) AddUserToTenant ¶ added in v0.4.0
AddUserToTenant adds a user to a tenant
func (*SQLite) CreateSession ¶ added in v0.2.6
func (*SQLite) CreateTenant ¶ added in v0.4.0
CreateTenant creates a new tenant
func (*SQLite) CreateUser ¶ added in v0.3.1
CreateUser creates a new user
func (*SQLite) DeleteSession ¶ added in v0.5.1
DeleteSession deletes a session by ID
func (*SQLite) DeleteTenant ¶ added in v0.4.0
DeleteTenant deletes a tenant by ID
func (*SQLite) DeleteUser ¶ added in v0.3.1
DeleteUser deletes a user by ID
func (*SQLite) DeleteUserTenants ¶ added in v0.4.0
DeleteUserTenants deletes all tenant associations for a user
func (*SQLite) GetMessages ¶ added in v0.2.6
func (*SQLite) GetMessagesWithPagination ¶ added in v0.2.6
func (*SQLite) GetSessions ¶ added in v0.2.6
func (*SQLite) GetTenantByID ¶ added in v0.4.0
GetTenantByID retrieves a tenant by ID
func (*SQLite) GetTenantByName ¶ added in v0.4.0
GetTenantByName retrieves a tenant by name
func (*SQLite) GetTenantUsers ¶ added in v0.4.0
GetTenantUsers gets all users for a tenant
func (*SQLite) GetUserByUsername ¶ added in v0.3.1
GetUserByUsername retrieves a user by username
func (*SQLite) GetUserTenants ¶ added in v0.4.0
GetUserTenants gets all tenants for a user
func (*SQLite) ListTenants ¶ added in v0.4.0
ListTenants retrieves all tenants
func (*SQLite) RemoveUserFromTenant ¶ added in v0.4.0
RemoveUserFromTenant removes a user from a tenant
func (*SQLite) SaveMessage ¶ added in v0.2.6
func (*SQLite) SessionExists ¶ added in v0.2.6
func (*SQLite) Transaction ¶ added in v0.4.0
Transaction implements Database.Transaction
func (*SQLite) UpdateSessionTitle ¶ added in v0.2.6
func (*SQLite) UpdateTenant ¶ added in v0.4.0
UpdateTenant updates an existing tenant
type Session ¶
type Session struct {
ID string `json:"id"`
CreatedAt time.Time `json:"createdAt"`
Title string `json:"title"`
}
Session represents a chat session
type Tenant ¶ added in v0.4.0
type Tenant struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
Name string `json:"name" gorm:"type:varchar(50);uniqueIndex"`
Prefix string `json:"prefix" gorm:"type:varchar(50);uniqueIndex"`
Description string `json:"description" gorm:"type:varchar(255)"`
IsActive bool `json:"isActive" gorm:"not null;default:true"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
Tenant represents a tenant in the system
type User ¶ added in v0.3.1
type User struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
Username string `json:"username" gorm:"type:varchar(50);uniqueIndex"`
Password string `json:"-" gorm:"not null"` // Password is not exposed in JSON
Role UserRole `json:"role" gorm:"not null;default:'normal'"`
IsActive bool `json:"isActive" gorm:"not null;default:true"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
User represents an admin user
type UserTenant ¶ added in v0.4.0
type UserTenant struct {
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
UserID uint `json:"userId" gorm:"index:idx_user_tenant,unique;not null"`
TenantID uint `json:"tenantId" gorm:"index:idx_user_tenant,unique;not null"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
UserTenant represents the relationship between a user and a tenant